Marek Vasut | f7d7f94 | 2011-11-08 23:18:26 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Freescale i.MX28 USB Host driver |
| 3 | * |
| 4 | * Copyright (C) 2011 Marek Vasut <marek.vasut@gmail.com> |
| 5 | * on behalf of DENX Software Engineering GmbH |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 20 | */ |
| 21 | |
| 22 | #include <common.h> |
| 23 | #include <asm/io.h> |
Marek Vasut | 83e330c | 2013-02-23 02:43:01 +0000 | [diff] [blame] | 24 | #include <asm/arch/imx-regs.h> |
Marek Vasut | 191a2ce | 2013-02-23 02:43:02 +0000 | [diff] [blame] | 25 | #include <errno.h> |
Marek Vasut | f7d7f94 | 2011-11-08 23:18:26 +0000 | [diff] [blame] | 26 | |
Marek Vasut | f7d7f94 | 2011-11-08 23:18:26 +0000 | [diff] [blame] | 27 | #include "ehci.h" |
| 28 | |
Marek Vasut | 191a2ce | 2013-02-23 02:43:02 +0000 | [diff] [blame] | 29 | /* This DIGCTL register ungates clock to USB */ |
| 30 | #define HW_DIGCTL_CTRL 0x8001c000 |
| 31 | #define HW_DIGCTL_CTRL_USB0_CLKGATE (1 << 2) |
| 32 | #define HW_DIGCTL_CTRL_USB1_CLKGATE (1 << 16) |
Marek Vasut | f7d7f94 | 2011-11-08 23:18:26 +0000 | [diff] [blame] | 33 | |
Marek Vasut | 191a2ce | 2013-02-23 02:43:02 +0000 | [diff] [blame] | 34 | struct ehci_mxs_port { |
| 35 | uint32_t usb_regs; |
Otavio Salvador | 22f4ff9 | 2012-08-05 09:05:31 +0000 | [diff] [blame] | 36 | struct mxs_usbphy_regs *phy_regs; |
Marek Vasut | 191a2ce | 2013-02-23 02:43:02 +0000 | [diff] [blame] | 37 | |
| 38 | struct mxs_register_32 *pll; |
| 39 | uint32_t pll_en_bits; |
| 40 | uint32_t pll_dis_bits; |
| 41 | uint32_t gate_bits; |
| 42 | }; |
| 43 | |
| 44 | static const struct ehci_mxs_port mxs_port[] = { |
| 45 | #ifdef CONFIG_EHCI_MXS_PORT0 |
| 46 | { |
| 47 | MXS_USBCTRL0_BASE, |
| 48 | (struct mxs_usbphy_regs *)MXS_USBPHY0_BASE, |
| 49 | (struct mxs_register_32 *)(MXS_CLKCTRL_BASE + |
| 50 | offsetof(struct mxs_clkctrl_regs, |
| 51 | hw_clkctrl_pll0ctrl0_reg)), |
| 52 | CLKCTRL_PLL0CTRL0_EN_USB_CLKS | CLKCTRL_PLL0CTRL0_POWER, |
| 53 | CLKCTRL_PLL0CTRL0_EN_USB_CLKS, |
| 54 | HW_DIGCTL_CTRL_USB0_CLKGATE, |
| 55 | }, |
| 56 | #endif |
| 57 | #ifdef CONFIG_EHCI_MXS_PORT1 |
| 58 | { |
| 59 | MXS_USBCTRL1_BASE, |
| 60 | (struct mxs_usbphy_regs *)MXS_USBPHY1_BASE, |
| 61 | (struct mxs_register_32 *)(MXS_CLKCTRL_BASE + |
| 62 | offsetof(struct mxs_clkctrl_regs, |
| 63 | hw_clkctrl_pll1ctrl0_reg)), |
| 64 | CLKCTRL_PLL1CTRL0_EN_USB_CLKS | CLKCTRL_PLL1CTRL0_POWER, |
| 65 | CLKCTRL_PLL1CTRL0_EN_USB_CLKS, |
| 66 | HW_DIGCTL_CTRL_USB1_CLKGATE, |
| 67 | }, |
| 68 | #endif |
| 69 | }; |
Marek Vasut | f7d7f94 | 2011-11-08 23:18:26 +0000 | [diff] [blame] | 70 | |
Marek Vasut | 191a2ce | 2013-02-23 02:43:02 +0000 | [diff] [blame] | 71 | static int ehci_mxs_toggle_clock(const struct ehci_mxs_port *port, int enable) |
Marek Vasut | f7d7f94 | 2011-11-08 23:18:26 +0000 | [diff] [blame] | 72 | { |
Marek Vasut | 191a2ce | 2013-02-23 02:43:02 +0000 | [diff] [blame] | 73 | struct mxs_register_32 *digctl_ctrl = |
| 74 | (struct mxs_register_32 *)HW_DIGCTL_CTRL; |
| 75 | int pll_offset, dig_offset; |
| 76 | |
| 77 | if (enable) { |
| 78 | pll_offset = offsetof(struct mxs_register_32, reg_set); |
| 79 | dig_offset = offsetof(struct mxs_register_32, reg_clr); |
| 80 | writel(port->gate_bits, (u32)&digctl_ctrl->reg + dig_offset); |
| 81 | writel(port->pll_en_bits, (u32)port->pll + pll_offset); |
| 82 | } else { |
| 83 | pll_offset = offsetof(struct mxs_register_32, reg_clr); |
| 84 | dig_offset = offsetof(struct mxs_register_32, reg_set); |
| 85 | writel(port->pll_dis_bits, (u32)port->pll + pll_offset); |
| 86 | writel(port->gate_bits, (u32)&digctl_ctrl->reg + dig_offset); |
Marek Vasut | f7d7f94 | 2011-11-08 23:18:26 +0000 | [diff] [blame] | 87 | } |
| 88 | |
Marek Vasut | f7d7f94 | 2011-11-08 23:18:26 +0000 | [diff] [blame] | 89 | return 0; |
| 90 | } |
| 91 | |
Lucas Stach | 3494a4c | 2012-09-26 00:14:35 +0200 | [diff] [blame] | 92 | int ehci_hcd_init(int index, struct ehci_hccr **hccr, struct ehci_hcor **hcor) |
Marek Vasut | f7d7f94 | 2011-11-08 23:18:26 +0000 | [diff] [blame] | 93 | { |
| 94 | |
| 95 | int ret; |
| 96 | uint32_t usb_base, cap_base; |
Marek Vasut | 191a2ce | 2013-02-23 02:43:02 +0000 | [diff] [blame] | 97 | const struct ehci_mxs_port *port; |
Marek Vasut | f7d7f94 | 2011-11-08 23:18:26 +0000 | [diff] [blame] | 98 | |
Marek Vasut | 191a2ce | 2013-02-23 02:43:02 +0000 | [diff] [blame] | 99 | if ((index < 0) || (index >= ARRAY_SIZE(mxs_port))) { |
| 100 | printf("Invalid port index (index = %d)!\n", index); |
| 101 | return -EINVAL; |
| 102 | } |
| 103 | |
| 104 | port = &mxs_port[index]; |
Marek Vasut | f7d7f94 | 2011-11-08 23:18:26 +0000 | [diff] [blame] | 105 | |
| 106 | /* Reset the PHY block */ |
Marek Vasut | 191a2ce | 2013-02-23 02:43:02 +0000 | [diff] [blame] | 107 | writel(USBPHY_CTRL_SFTRST, &port->phy_regs->hw_usbphy_ctrl_set); |
Marek Vasut | f7d7f94 | 2011-11-08 23:18:26 +0000 | [diff] [blame] | 108 | udelay(10); |
| 109 | writel(USBPHY_CTRL_SFTRST | USBPHY_CTRL_CLKGATE, |
Marek Vasut | 191a2ce | 2013-02-23 02:43:02 +0000 | [diff] [blame] | 110 | &port->phy_regs->hw_usbphy_ctrl_clr); |
Marek Vasut | f7d7f94 | 2011-11-08 23:18:26 +0000 | [diff] [blame] | 111 | |
| 112 | /* Enable USB clock */ |
Marek Vasut | 191a2ce | 2013-02-23 02:43:02 +0000 | [diff] [blame] | 113 | ret = ehci_mxs_toggle_clock(port, 1); |
| 114 | if (ret) |
| 115 | return ret; |
Marek Vasut | f7d7f94 | 2011-11-08 23:18:26 +0000 | [diff] [blame] | 116 | |
| 117 | /* Start USB PHY */ |
Marek Vasut | 191a2ce | 2013-02-23 02:43:02 +0000 | [diff] [blame] | 118 | writel(0, &port->phy_regs->hw_usbphy_pwd); |
Marek Vasut | f7d7f94 | 2011-11-08 23:18:26 +0000 | [diff] [blame] | 119 | |
| 120 | /* Enable UTMI+ Level 2 and Level 3 compatibility */ |
| 121 | writel(USBPHY_CTRL_ENUTMILEVEL3 | USBPHY_CTRL_ENUTMILEVEL2 | 1, |
Marek Vasut | 191a2ce | 2013-02-23 02:43:02 +0000 | [diff] [blame] | 122 | &port->phy_regs->hw_usbphy_ctrl_set); |
Marek Vasut | f7d7f94 | 2011-11-08 23:18:26 +0000 | [diff] [blame] | 123 | |
Marek Vasut | 191a2ce | 2013-02-23 02:43:02 +0000 | [diff] [blame] | 124 | usb_base = port->usb_regs + 0x100; |
Lucas Stach | 3494a4c | 2012-09-26 00:14:35 +0200 | [diff] [blame] | 125 | *hccr = (struct ehci_hccr *)usb_base; |
Marek Vasut | f7d7f94 | 2011-11-08 23:18:26 +0000 | [diff] [blame] | 126 | |
Lucas Stach | 3494a4c | 2012-09-26 00:14:35 +0200 | [diff] [blame] | 127 | cap_base = ehci_readl(&(*hccr)->cr_capbase); |
| 128 | *hcor = (struct ehci_hcor *)(usb_base + HC_LENGTH(cap_base)); |
Marek Vasut | f7d7f94 | 2011-11-08 23:18:26 +0000 | [diff] [blame] | 129 | |
| 130 | return 0; |
| 131 | } |
| 132 | |
Lucas Stach | 3494a4c | 2012-09-26 00:14:35 +0200 | [diff] [blame] | 133 | int ehci_hcd_stop(int index) |
Marek Vasut | f7d7f94 | 2011-11-08 23:18:26 +0000 | [diff] [blame] | 134 | { |
| 135 | int ret; |
Lucas Stach | 3494a4c | 2012-09-26 00:14:35 +0200 | [diff] [blame] | 136 | uint32_t usb_base, cap_base, tmp; |
Lucas Stach | 3494a4c | 2012-09-26 00:14:35 +0200 | [diff] [blame] | 137 | struct ehci_hccr *hccr; |
| 138 | struct ehci_hcor *hcor; |
Marek Vasut | 191a2ce | 2013-02-23 02:43:02 +0000 | [diff] [blame] | 139 | const struct ehci_mxs_port *port; |
Marek Vasut | f7d7f94 | 2011-11-08 23:18:26 +0000 | [diff] [blame] | 140 | |
Marek Vasut | 191a2ce | 2013-02-23 02:43:02 +0000 | [diff] [blame] | 141 | if ((index < 0) || (index >= ARRAY_SIZE(mxs_port))) { |
| 142 | printf("Invalid port index (index = %d)!\n", index); |
| 143 | return -EINVAL; |
| 144 | } |
| 145 | |
| 146 | port = &mxs_port[index]; |
Marek Vasut | f7d7f94 | 2011-11-08 23:18:26 +0000 | [diff] [blame] | 147 | |
| 148 | /* Stop the USB port */ |
Marek Vasut | 191a2ce | 2013-02-23 02:43:02 +0000 | [diff] [blame] | 149 | usb_base = port->usb_regs + 0x100; |
Lucas Stach | 3494a4c | 2012-09-26 00:14:35 +0200 | [diff] [blame] | 150 | hccr = (struct ehci_hccr *)usb_base; |
| 151 | cap_base = ehci_readl(&hccr->cr_capbase); |
| 152 | hcor = (struct ehci_hcor *)(usb_base + HC_LENGTH(cap_base)); |
| 153 | |
Marek Vasut | f7d7f94 | 2011-11-08 23:18:26 +0000 | [diff] [blame] | 154 | tmp = ehci_readl(&hcor->or_usbcmd); |
| 155 | tmp &= ~CMD_RUN; |
| 156 | ehci_writel(tmp, &hcor->or_usbcmd); |
| 157 | |
| 158 | /* Disable the PHY */ |
| 159 | tmp = USBPHY_PWD_RXPWDRX | USBPHY_PWD_RXPWDDIFF | |
| 160 | USBPHY_PWD_RXPWD1PT1 | USBPHY_PWD_RXPWDENV | |
| 161 | USBPHY_PWD_TXPWDV2I | USBPHY_PWD_TXPWDIBIAS | |
| 162 | USBPHY_PWD_TXPWDFS; |
Marek Vasut | 191a2ce | 2013-02-23 02:43:02 +0000 | [diff] [blame] | 163 | writel(tmp, &port->phy_regs->hw_usbphy_pwd); |
Marek Vasut | f7d7f94 | 2011-11-08 23:18:26 +0000 | [diff] [blame] | 164 | |
| 165 | /* Disable USB clock */ |
Marek Vasut | 191a2ce | 2013-02-23 02:43:02 +0000 | [diff] [blame] | 166 | ret = ehci_mxs_toggle_clock(port, 0); |
Marek Vasut | f7d7f94 | 2011-11-08 23:18:26 +0000 | [diff] [blame] | 167 | |
Marek Vasut | 191a2ce | 2013-02-23 02:43:02 +0000 | [diff] [blame] | 168 | return ret; |
Marek Vasut | f7d7f94 | 2011-11-08 23:18:26 +0000 | [diff] [blame] | 169 | } |