Marek Vasut | f2ebfeb | 2011-06-24 21:46:07 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 Marek Vasut <marek.vasut@gmail.com> |
| 3 | * |
| 4 | * (C) Copyright 2009 Freescale Semiconductor, Inc. |
| 5 | * |
| 6 | * See file CREDITS for list of people who contributed to this |
| 7 | * project. |
| 8 | * |
| 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. |
| 13 | * |
| 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. |
| 18 | * |
| 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, |
| 22 | * MA 02111-1307 USA |
| 23 | */ |
| 24 | |
| 25 | #include <common.h> |
| 26 | #include <usb.h> |
| 27 | #include <asm/io.h> |
| 28 | #include <asm/arch/imx-regs.h> |
Benoît Thébaudeau | d484f20 | 2013-05-03 10:32:28 +0000 | [diff] [blame] | 29 | #include <asm/arch/iomux-mx51.h> |
Marek Vasut | f2ebfeb | 2011-06-24 21:46:07 +0200 | [diff] [blame] | 30 | #include <asm/gpio.h> |
| 31 | #include <usb/ehci-fsl.h> |
| 32 | #include <usb/ulpi.h> |
| 33 | #include <errno.h> |
| 34 | |
Matt Sealey | af8f53b | 2012-08-22 09:25:38 +0000 | [diff] [blame] | 35 | #include "../../../drivers/usb/host/ehci.h" |
Marek Vasut | f2ebfeb | 2011-06-24 21:46:07 +0200 | [diff] [blame] | 36 | |
Marek Vasut | f2ebfeb | 2011-06-24 21:46:07 +0200 | [diff] [blame] | 37 | /* |
| 38 | * Configure the USB H1 and USB H2 IOMUX |
| 39 | */ |
| 40 | void setup_iomux_usb(void) |
| 41 | { |
Benoît Thébaudeau | d484f20 | 2013-05-03 10:32:28 +0000 | [diff] [blame] | 42 | static const iomux_v3_cfg_t usb_h1_pads[] = { |
| 43 | MX51_PAD_USBH1_CLK__USBH1_CLK, |
| 44 | MX51_PAD_USBH1_DIR__USBH1_DIR, |
| 45 | MX51_PAD_USBH1_STP__USBH1_STP, |
| 46 | MX51_PAD_USBH1_NXT__USBH1_NXT, |
| 47 | MX51_PAD_USBH1_DATA0__USBH1_DATA0, |
| 48 | MX51_PAD_USBH1_DATA1__USBH1_DATA1, |
| 49 | MX51_PAD_USBH1_DATA2__USBH1_DATA2, |
| 50 | MX51_PAD_USBH1_DATA3__USBH1_DATA3, |
| 51 | MX51_PAD_USBH1_DATA4__USBH1_DATA4, |
| 52 | MX51_PAD_USBH1_DATA5__USBH1_DATA5, |
| 53 | MX51_PAD_USBH1_DATA6__USBH1_DATA6, |
| 54 | MX51_PAD_USBH1_DATA7__USBH1_DATA7, |
| 55 | }; |
Marek Vasut | f2ebfeb | 2011-06-24 21:46:07 +0200 | [diff] [blame] | 56 | |
Benoît Thébaudeau | d484f20 | 2013-05-03 10:32:28 +0000 | [diff] [blame] | 57 | static const iomux_v3_cfg_t usb_pads[] = { |
| 58 | MX51_PAD_EIM_D27__GPIO2_9, /* USB PHY reset */ |
| 59 | MX51_PAD_GPIO1_5__GPIO1_5, /* USB HUB reset */ |
| 60 | NEW_PAD_CTRL(MX51_PAD_EIM_A22__GPIO2_16, 0), /* WIFI /EN */ |
| 61 | NEW_PAD_CTRL(MX51_PAD_EIM_A16__GPIO2_10, 0), /* WIFI RESET */ |
| 62 | NEW_PAD_CTRL(MX51_PAD_EIM_A17__GPIO2_11, 0), /* BT /EN */ |
| 63 | }; |
Marek Vasut | f2ebfeb | 2011-06-24 21:46:07 +0200 | [diff] [blame] | 64 | |
Benoît Thébaudeau | d484f20 | 2013-05-03 10:32:28 +0000 | [diff] [blame] | 65 | imx_iomux_v3_setup_multiple_pads(usb_h1_pads, ARRAY_SIZE(usb_h1_pads)); |
Marek Vasut | f2ebfeb | 2011-06-24 21:46:07 +0200 | [diff] [blame] | 66 | |
Benoît Thébaudeau | d484f20 | 2013-05-03 10:32:28 +0000 | [diff] [blame] | 67 | if (machine_is_efikasb()) { |
| 68 | static const iomux_v3_cfg_t usb_h2_pads[] = { |
| 69 | MX51_PAD_EIM_A24__USBH2_CLK, |
| 70 | MX51_PAD_EIM_A25__USBH2_DIR, |
| 71 | MX51_PAD_EIM_A26__USBH2_STP, |
| 72 | MX51_PAD_EIM_A27__USBH2_NXT, |
| 73 | MX51_PAD_EIM_D16__USBH2_DATA0, |
| 74 | MX51_PAD_EIM_D17__USBH2_DATA1, |
| 75 | MX51_PAD_EIM_D18__USBH2_DATA2, |
| 76 | MX51_PAD_EIM_D19__USBH2_DATA3, |
| 77 | MX51_PAD_EIM_D20__USBH2_DATA4, |
| 78 | MX51_PAD_EIM_D21__USBH2_DATA5, |
| 79 | MX51_PAD_EIM_D22__USBH2_DATA6, |
| 80 | MX51_PAD_EIM_D23__USBH2_DATA7, |
| 81 | }; |
| 82 | |
| 83 | imx_iomux_v3_setup_multiple_pads(usb_h2_pads, |
| 84 | ARRAY_SIZE(usb_h2_pads)); |
| 85 | } |
Marek Vasut | f2ebfeb | 2011-06-24 21:46:07 +0200 | [diff] [blame] | 86 | |
Benoît Thébaudeau | d484f20 | 2013-05-03 10:32:28 +0000 | [diff] [blame] | 87 | imx_iomux_v3_setup_multiple_pads(usb_pads, ARRAY_SIZE(usb_pads)); |
Marek Vasut | f2ebfeb | 2011-06-24 21:46:07 +0200 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | /* |
| 91 | * Enable devices connected to USB BUSes |
| 92 | */ |
| 93 | static void efika_usb_enable_devices(void) |
| 94 | { |
| 95 | /* Enable Bluetooth */ |
Benoît Thébaudeau | d484f20 | 2013-05-03 10:32:28 +0000 | [diff] [blame] | 96 | gpio_direction_output(IMX_GPIO_NR(2, 11), 0); |
Marek Vasut | f2ebfeb | 2011-06-24 21:46:07 +0200 | [diff] [blame] | 97 | udelay(10000); |
Benoît Thébaudeau | d484f20 | 2013-05-03 10:32:28 +0000 | [diff] [blame] | 98 | gpio_set_value(IMX_GPIO_NR(2, 11), 1); |
Marek Vasut | f2ebfeb | 2011-06-24 21:46:07 +0200 | [diff] [blame] | 99 | |
| 100 | /* Enable WiFi */ |
Benoît Thébaudeau | d484f20 | 2013-05-03 10:32:28 +0000 | [diff] [blame] | 101 | gpio_direction_output(IMX_GPIO_NR(2, 16), 1); |
Marek Vasut | f2ebfeb | 2011-06-24 21:46:07 +0200 | [diff] [blame] | 102 | udelay(10000); |
| 103 | |
| 104 | /* Reset the WiFi chip */ |
Benoît Thébaudeau | d484f20 | 2013-05-03 10:32:28 +0000 | [diff] [blame] | 105 | gpio_direction_output(IMX_GPIO_NR(2, 10), 0); |
Marek Vasut | f2ebfeb | 2011-06-24 21:46:07 +0200 | [diff] [blame] | 106 | udelay(10000); |
Benoît Thébaudeau | d484f20 | 2013-05-03 10:32:28 +0000 | [diff] [blame] | 107 | gpio_set_value(IMX_GPIO_NR(2, 10), 1); |
Marek Vasut | f2ebfeb | 2011-06-24 21:46:07 +0200 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | /* |
| 111 | * Reset USB HUB (or HUBs on EfikaSB) |
| 112 | */ |
| 113 | static void efika_usb_hub_reset(void) |
| 114 | { |
| 115 | /* HUB reset */ |
Benoît Thébaudeau | d484f20 | 2013-05-03 10:32:28 +0000 | [diff] [blame] | 116 | gpio_direction_output(IMX_GPIO_NR(1, 5), 1); |
Marek Vasut | f2ebfeb | 2011-06-24 21:46:07 +0200 | [diff] [blame] | 117 | udelay(1000); |
Benoît Thébaudeau | d484f20 | 2013-05-03 10:32:28 +0000 | [diff] [blame] | 118 | gpio_set_value(IMX_GPIO_NR(1, 5), 0); |
Marek Vasut | f2ebfeb | 2011-06-24 21:46:07 +0200 | [diff] [blame] | 119 | udelay(1000); |
Benoît Thébaudeau | d484f20 | 2013-05-03 10:32:28 +0000 | [diff] [blame] | 120 | gpio_set_value(IMX_GPIO_NR(1, 5), 1); |
Marek Vasut | f2ebfeb | 2011-06-24 21:46:07 +0200 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | /* |
| 124 | * Reset USB PHY (or PHYs on EfikaSB) |
| 125 | */ |
| 126 | static void efika_usb_phy_reset(void) |
| 127 | { |
| 128 | /* SMSC 3317 PHY reset */ |
Benoît Thébaudeau | d484f20 | 2013-05-03 10:32:28 +0000 | [diff] [blame] | 129 | gpio_direction_output(IMX_GPIO_NR(2, 9), 0); |
Marek Vasut | f2ebfeb | 2011-06-24 21:46:07 +0200 | [diff] [blame] | 130 | udelay(1000); |
Benoît Thébaudeau | d484f20 | 2013-05-03 10:32:28 +0000 | [diff] [blame] | 131 | gpio_set_value(IMX_GPIO_NR(2, 9), 1); |
Marek Vasut | f2ebfeb | 2011-06-24 21:46:07 +0200 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | static void efika_ehci_init(struct usb_ehci *ehci, uint32_t stp_gpio, |
Benoît Thébaudeau | d484f20 | 2013-05-03 10:32:28 +0000 | [diff] [blame] | 135 | iomux_v3_cfg_t stp_pad_gpio, |
| 136 | iomux_v3_cfg_t stp_pad_usb) |
Marek Vasut | f2ebfeb | 2011-06-24 21:46:07 +0200 | [diff] [blame] | 137 | { |
| 138 | int ret; |
| 139 | struct ulpi_regs *ulpi = (struct ulpi_regs *)0; |
Govindraj.R | 6645d9e | 2012-02-06 03:55:31 +0000 | [diff] [blame] | 140 | struct ulpi_viewport ulpi_vp; |
Marek Vasut | f2ebfeb | 2011-06-24 21:46:07 +0200 | [diff] [blame] | 141 | |
Benoît Thébaudeau | d484f20 | 2013-05-03 10:32:28 +0000 | [diff] [blame] | 142 | imx_iomux_v3_setup_pad(stp_pad_gpio); |
| 143 | gpio_direction_output(stp_gpio, 0); |
Marek Vasut | f2ebfeb | 2011-06-24 21:46:07 +0200 | [diff] [blame] | 144 | udelay(1000); |
Benoît Thébaudeau | d484f20 | 2013-05-03 10:32:28 +0000 | [diff] [blame] | 145 | gpio_set_value(stp_gpio, 1); |
Marek Vasut | f2ebfeb | 2011-06-24 21:46:07 +0200 | [diff] [blame] | 146 | udelay(1000); |
| 147 | |
Benoît Thébaudeau | d484f20 | 2013-05-03 10:32:28 +0000 | [diff] [blame] | 148 | imx_iomux_v3_setup_pad(stp_pad_usb); |
Marek Vasut | f2ebfeb | 2011-06-24 21:46:07 +0200 | [diff] [blame] | 149 | udelay(10000); |
| 150 | |
Govindraj.R | 6645d9e | 2012-02-06 03:55:31 +0000 | [diff] [blame] | 151 | ulpi_vp.viewport_addr = (u32)&ehci->ulpi_viewpoint; |
| 152 | ulpi_vp.port_num = 0; |
| 153 | |
| 154 | ret = ulpi_init(&ulpi_vp); |
Marek Vasut | f2ebfeb | 2011-06-24 21:46:07 +0200 | [diff] [blame] | 155 | if (ret) { |
| 156 | printf("Efika USB ULPI initialization failed\n"); |
| 157 | return; |
| 158 | } |
| 159 | |
| 160 | /* ULPI set flags */ |
Govindraj.R | 6645d9e | 2012-02-06 03:55:31 +0000 | [diff] [blame] | 161 | ulpi_write(&ulpi_vp, &ulpi->otg_ctrl, |
Marek Vasut | f2ebfeb | 2011-06-24 21:46:07 +0200 | [diff] [blame] | 162 | ULPI_OTG_DP_PULLDOWN | ULPI_OTG_DM_PULLDOWN | |
| 163 | ULPI_OTG_EXTVBUSIND); |
Govindraj.R | 6645d9e | 2012-02-06 03:55:31 +0000 | [diff] [blame] | 164 | ulpi_write(&ulpi_vp, &ulpi->function_ctrl, |
Marek Vasut | f2ebfeb | 2011-06-24 21:46:07 +0200 | [diff] [blame] | 165 | ULPI_FC_FULL_SPEED | ULPI_FC_OPMODE_NORMAL | |
| 166 | ULPI_FC_SUSPENDM); |
Govindraj.R | 6645d9e | 2012-02-06 03:55:31 +0000 | [diff] [blame] | 167 | ulpi_write(&ulpi_vp, &ulpi->iface_ctrl, 0); |
Marek Vasut | f2ebfeb | 2011-06-24 21:46:07 +0200 | [diff] [blame] | 168 | |
| 169 | /* Set VBus */ |
Govindraj.R | 6645d9e | 2012-02-06 03:55:31 +0000 | [diff] [blame] | 170 | ulpi_write(&ulpi_vp, &ulpi->otg_ctrl_set, |
Marek Vasut | f2ebfeb | 2011-06-24 21:46:07 +0200 | [diff] [blame] | 171 | ULPI_OTG_DRVVBUS | ULPI_OTG_DRVVBUS_EXT); |
| 172 | |
| 173 | /* |
| 174 | * Set VBusChrg |
| 175 | * |
| 176 | * NOTE: This violates USB specification, but otherwise, USB on Efika |
| 177 | * doesn't work. |
| 178 | */ |
Govindraj.R | 6645d9e | 2012-02-06 03:55:31 +0000 | [diff] [blame] | 179 | ulpi_write(&ulpi_vp, &ulpi->otg_ctrl_set, ULPI_OTG_CHRGVBUS); |
Marek Vasut | f2ebfeb | 2011-06-24 21:46:07 +0200 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | int board_ehci_hcd_init(int port) |
| 183 | { |
| 184 | /* Init iMX51 EHCI */ |
| 185 | efika_usb_phy_reset(); |
| 186 | efika_usb_hub_reset(); |
| 187 | efika_usb_enable_devices(); |
| 188 | |
| 189 | return 0; |
| 190 | } |
| 191 | |
| 192 | void ehci_powerup_fixup(uint32_t *status_reg, uint32_t *reg) |
| 193 | { |
| 194 | uint32_t port = OTG_BASE_ADDR + (0x200 * CONFIG_MXC_USB_PORT); |
| 195 | struct usb_ehci *ehci = (struct usb_ehci *)port; |
| 196 | struct ulpi_regs *ulpi = (struct ulpi_regs *)0; |
Govindraj.R | 6645d9e | 2012-02-06 03:55:31 +0000 | [diff] [blame] | 197 | struct ulpi_viewport ulpi_vp; |
| 198 | |
| 199 | ulpi_vp.viewport_addr = (u32)&ehci->ulpi_viewpoint; |
| 200 | ulpi_vp.port_num = 0; |
Marek Vasut | f2ebfeb | 2011-06-24 21:46:07 +0200 | [diff] [blame] | 201 | |
Govindraj.R | 6645d9e | 2012-02-06 03:55:31 +0000 | [diff] [blame] | 202 | ulpi_write(&ulpi_vp, &ulpi->otg_ctrl_set, ULPI_OTG_CHRGVBUS); |
Marek Vasut | f2ebfeb | 2011-06-24 21:46:07 +0200 | [diff] [blame] | 203 | |
Mike Frysinger | 60ce19a | 2012-03-05 13:47:00 +0000 | [diff] [blame] | 204 | mdelay(50); |
Marek Vasut | f2ebfeb | 2011-06-24 21:46:07 +0200 | [diff] [blame] | 205 | |
| 206 | /* terminate the reset */ |
| 207 | *reg = ehci_readl(status_reg); |
| 208 | *reg |= EHCI_PS_PE; |
| 209 | } |
| 210 | |
| 211 | void board_ehci_hcd_postinit(struct usb_ehci *ehci, int port) |
| 212 | { |
| 213 | uint32_t tmp; |
| 214 | |
| 215 | if (port == 0) { |
| 216 | /* Adjust UTMI PHY frequency to 24MHz */ |
| 217 | tmp = readl(OTG_BASE_ADDR + 0x80c); |
| 218 | tmp = (tmp & ~0x3) | 0x01; |
| 219 | writel(tmp, OTG_BASE_ADDR + 0x80c); |
| 220 | } else if (port == 1) { |
Benoît Thébaudeau | d484f20 | 2013-05-03 10:32:28 +0000 | [diff] [blame] | 221 | efika_ehci_init(ehci, IMX_GPIO_NR(1, 27), |
| 222 | MX51_PAD_USBH1_STP__GPIO1_27, |
| 223 | MX51_PAD_USBH1_STP__USBH1_STP); |
Marek Vasut | f2ebfeb | 2011-06-24 21:46:07 +0200 | [diff] [blame] | 224 | } else if ((port == 2) && machine_is_efikasb()) { |
Benoît Thébaudeau | d484f20 | 2013-05-03 10:32:28 +0000 | [diff] [blame] | 225 | efika_ehci_init(ehci, IMX_GPIO_NR(2, 20), |
| 226 | MX51_PAD_EIM_A26__GPIO2_20, |
| 227 | MX51_PAD_EIM_A26__USBH2_STP); |
Marek Vasut | f2ebfeb | 2011-06-24 21:46:07 +0200 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | if (port) |
| 231 | mdelay(10); |
| 232 | } |
Matt Sealey | c4ad2cb | 2012-08-23 04:52:33 +0000 | [diff] [blame] | 233 | |
| 234 | /* |
| 235 | * Ethernet on the Smarttop is on the USB bus. Rather than give an error about |
| 236 | * "CPU Net Initialization Failed", just pass this test since no other settings |
| 237 | * are required. Smartbook doesn't have built-in Ethernet but we will let it |
| 238 | * pass anyway considering someone may have plugged in a USB stick and all |
| 239 | * they need to do is run "usb start". |
| 240 | */ |
| 241 | int board_eth_init(bd_t *bis) |
| 242 | { |
| 243 | return 0; |
| 244 | } |