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 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 7 | * SPDX-License-Identifier: GPL-2.0+ |
Marek Vasut | f7d7f94 | 2011-11-08 23:18:26 +0000 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <common.h> |
| 11 | #include <asm/io.h> |
Marek Vasut | 83e330c | 2013-02-23 02:43:01 +0000 | [diff] [blame] | 12 | #include <asm/arch/imx-regs.h> |
Marek Vasut | 191a2ce | 2013-02-23 02:43:02 +0000 | [diff] [blame] | 13 | #include <errno.h> |
Marek Vasut | f7d7f94 | 2011-11-08 23:18:26 +0000 | [diff] [blame] | 14 | |
Marek Vasut | f7d7f94 | 2011-11-08 23:18:26 +0000 | [diff] [blame] | 15 | #include "ehci.h" |
| 16 | |
Marek Vasut | 191a2ce | 2013-02-23 02:43:02 +0000 | [diff] [blame] | 17 | /* This DIGCTL register ungates clock to USB */ |
| 18 | #define HW_DIGCTL_CTRL 0x8001c000 |
| 19 | #define HW_DIGCTL_CTRL_USB0_CLKGATE (1 << 2) |
| 20 | #define HW_DIGCTL_CTRL_USB1_CLKGATE (1 << 16) |
Marek Vasut | f7d7f94 | 2011-11-08 23:18:26 +0000 | [diff] [blame] | 21 | |
Marek Vasut | 191a2ce | 2013-02-23 02:43:02 +0000 | [diff] [blame] | 22 | struct ehci_mxs_port { |
| 23 | uint32_t usb_regs; |
Otavio Salvador | 22f4ff9 | 2012-08-05 09:05:31 +0000 | [diff] [blame] | 24 | struct mxs_usbphy_regs *phy_regs; |
Marek Vasut | 191a2ce | 2013-02-23 02:43:02 +0000 | [diff] [blame] | 25 | |
| 26 | struct mxs_register_32 *pll; |
| 27 | uint32_t pll_en_bits; |
| 28 | uint32_t pll_dis_bits; |
| 29 | uint32_t gate_bits; |
| 30 | }; |
| 31 | |
| 32 | static const struct ehci_mxs_port mxs_port[] = { |
| 33 | #ifdef CONFIG_EHCI_MXS_PORT0 |
| 34 | { |
| 35 | MXS_USBCTRL0_BASE, |
| 36 | (struct mxs_usbphy_regs *)MXS_USBPHY0_BASE, |
| 37 | (struct mxs_register_32 *)(MXS_CLKCTRL_BASE + |
| 38 | offsetof(struct mxs_clkctrl_regs, |
| 39 | hw_clkctrl_pll0ctrl0_reg)), |
| 40 | CLKCTRL_PLL0CTRL0_EN_USB_CLKS | CLKCTRL_PLL0CTRL0_POWER, |
| 41 | CLKCTRL_PLL0CTRL0_EN_USB_CLKS, |
| 42 | HW_DIGCTL_CTRL_USB0_CLKGATE, |
| 43 | }, |
| 44 | #endif |
| 45 | #ifdef CONFIG_EHCI_MXS_PORT1 |
| 46 | { |
| 47 | MXS_USBCTRL1_BASE, |
| 48 | (struct mxs_usbphy_regs *)MXS_USBPHY1_BASE, |
| 49 | (struct mxs_register_32 *)(MXS_CLKCTRL_BASE + |
| 50 | offsetof(struct mxs_clkctrl_regs, |
| 51 | hw_clkctrl_pll1ctrl0_reg)), |
| 52 | CLKCTRL_PLL1CTRL0_EN_USB_CLKS | CLKCTRL_PLL1CTRL0_POWER, |
| 53 | CLKCTRL_PLL1CTRL0_EN_USB_CLKS, |
| 54 | HW_DIGCTL_CTRL_USB1_CLKGATE, |
| 55 | }, |
| 56 | #endif |
| 57 | }; |
Marek Vasut | f7d7f94 | 2011-11-08 23:18:26 +0000 | [diff] [blame] | 58 | |
Marek Vasut | 191a2ce | 2013-02-23 02:43:02 +0000 | [diff] [blame] | 59 | 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] | 60 | { |
Marek Vasut | 191a2ce | 2013-02-23 02:43:02 +0000 | [diff] [blame] | 61 | struct mxs_register_32 *digctl_ctrl = |
| 62 | (struct mxs_register_32 *)HW_DIGCTL_CTRL; |
| 63 | int pll_offset, dig_offset; |
| 64 | |
| 65 | if (enable) { |
| 66 | pll_offset = offsetof(struct mxs_register_32, reg_set); |
| 67 | dig_offset = offsetof(struct mxs_register_32, reg_clr); |
| 68 | writel(port->gate_bits, (u32)&digctl_ctrl->reg + dig_offset); |
| 69 | writel(port->pll_en_bits, (u32)port->pll + pll_offset); |
| 70 | } else { |
| 71 | pll_offset = offsetof(struct mxs_register_32, reg_clr); |
| 72 | dig_offset = offsetof(struct mxs_register_32, reg_set); |
| 73 | writel(port->pll_dis_bits, (u32)port->pll + pll_offset); |
| 74 | writel(port->gate_bits, (u32)&digctl_ctrl->reg + dig_offset); |
Marek Vasut | f7d7f94 | 2011-11-08 23:18:26 +0000 | [diff] [blame] | 75 | } |
| 76 | |
Marek Vasut | f7d7f94 | 2011-11-08 23:18:26 +0000 | [diff] [blame] | 77 | return 0; |
| 78 | } |
| 79 | |
Troy Kisky | 7d6bbb9 | 2013-10-10 15:27:57 -0700 | [diff] [blame^] | 80 | int ehci_hcd_init(int index, enum usb_init_type init, |
| 81 | struct ehci_hccr **hccr, struct ehci_hcor **hcor) |
Marek Vasut | f7d7f94 | 2011-11-08 23:18:26 +0000 | [diff] [blame] | 82 | { |
| 83 | |
| 84 | int ret; |
| 85 | uint32_t usb_base, cap_base; |
Marek Vasut | 191a2ce | 2013-02-23 02:43:02 +0000 | [diff] [blame] | 86 | const struct ehci_mxs_port *port; |
Marek Vasut | f7d7f94 | 2011-11-08 23:18:26 +0000 | [diff] [blame] | 87 | |
Marek Vasut | 191a2ce | 2013-02-23 02:43:02 +0000 | [diff] [blame] | 88 | if ((index < 0) || (index >= ARRAY_SIZE(mxs_port))) { |
| 89 | printf("Invalid port index (index = %d)!\n", index); |
| 90 | return -EINVAL; |
| 91 | } |
| 92 | |
| 93 | port = &mxs_port[index]; |
Marek Vasut | f7d7f94 | 2011-11-08 23:18:26 +0000 | [diff] [blame] | 94 | |
| 95 | /* Reset the PHY block */ |
Marek Vasut | 191a2ce | 2013-02-23 02:43:02 +0000 | [diff] [blame] | 96 | writel(USBPHY_CTRL_SFTRST, &port->phy_regs->hw_usbphy_ctrl_set); |
Marek Vasut | f7d7f94 | 2011-11-08 23:18:26 +0000 | [diff] [blame] | 97 | udelay(10); |
| 98 | writel(USBPHY_CTRL_SFTRST | USBPHY_CTRL_CLKGATE, |
Marek Vasut | 191a2ce | 2013-02-23 02:43:02 +0000 | [diff] [blame] | 99 | &port->phy_regs->hw_usbphy_ctrl_clr); |
Marek Vasut | f7d7f94 | 2011-11-08 23:18:26 +0000 | [diff] [blame] | 100 | |
| 101 | /* Enable USB clock */ |
Marek Vasut | 191a2ce | 2013-02-23 02:43:02 +0000 | [diff] [blame] | 102 | ret = ehci_mxs_toggle_clock(port, 1); |
| 103 | if (ret) |
| 104 | return ret; |
Marek Vasut | f7d7f94 | 2011-11-08 23:18:26 +0000 | [diff] [blame] | 105 | |
| 106 | /* Start USB PHY */ |
Marek Vasut | 191a2ce | 2013-02-23 02:43:02 +0000 | [diff] [blame] | 107 | writel(0, &port->phy_regs->hw_usbphy_pwd); |
Marek Vasut | f7d7f94 | 2011-11-08 23:18:26 +0000 | [diff] [blame] | 108 | |
| 109 | /* Enable UTMI+ Level 2 and Level 3 compatibility */ |
| 110 | writel(USBPHY_CTRL_ENUTMILEVEL3 | USBPHY_CTRL_ENUTMILEVEL2 | 1, |
Marek Vasut | 191a2ce | 2013-02-23 02:43:02 +0000 | [diff] [blame] | 111 | &port->phy_regs->hw_usbphy_ctrl_set); |
Marek Vasut | f7d7f94 | 2011-11-08 23:18:26 +0000 | [diff] [blame] | 112 | |
Marek Vasut | 191a2ce | 2013-02-23 02:43:02 +0000 | [diff] [blame] | 113 | usb_base = port->usb_regs + 0x100; |
Lucas Stach | 3494a4c | 2012-09-26 00:14:35 +0200 | [diff] [blame] | 114 | *hccr = (struct ehci_hccr *)usb_base; |
Marek Vasut | f7d7f94 | 2011-11-08 23:18:26 +0000 | [diff] [blame] | 115 | |
Lucas Stach | 3494a4c | 2012-09-26 00:14:35 +0200 | [diff] [blame] | 116 | cap_base = ehci_readl(&(*hccr)->cr_capbase); |
| 117 | *hcor = (struct ehci_hcor *)(usb_base + HC_LENGTH(cap_base)); |
Marek Vasut | f7d7f94 | 2011-11-08 23:18:26 +0000 | [diff] [blame] | 118 | |
| 119 | return 0; |
| 120 | } |
| 121 | |
Lucas Stach | 3494a4c | 2012-09-26 00:14:35 +0200 | [diff] [blame] | 122 | int ehci_hcd_stop(int index) |
Marek Vasut | f7d7f94 | 2011-11-08 23:18:26 +0000 | [diff] [blame] | 123 | { |
| 124 | int ret; |
Lucas Stach | 3494a4c | 2012-09-26 00:14:35 +0200 | [diff] [blame] | 125 | uint32_t usb_base, cap_base, tmp; |
Lucas Stach | 3494a4c | 2012-09-26 00:14:35 +0200 | [diff] [blame] | 126 | struct ehci_hccr *hccr; |
| 127 | struct ehci_hcor *hcor; |
Marek Vasut | 191a2ce | 2013-02-23 02:43:02 +0000 | [diff] [blame] | 128 | const struct ehci_mxs_port *port; |
Marek Vasut | f7d7f94 | 2011-11-08 23:18:26 +0000 | [diff] [blame] | 129 | |
Marek Vasut | 191a2ce | 2013-02-23 02:43:02 +0000 | [diff] [blame] | 130 | if ((index < 0) || (index >= ARRAY_SIZE(mxs_port))) { |
| 131 | printf("Invalid port index (index = %d)!\n", index); |
| 132 | return -EINVAL; |
| 133 | } |
| 134 | |
| 135 | port = &mxs_port[index]; |
Marek Vasut | f7d7f94 | 2011-11-08 23:18:26 +0000 | [diff] [blame] | 136 | |
| 137 | /* Stop the USB port */ |
Marek Vasut | 191a2ce | 2013-02-23 02:43:02 +0000 | [diff] [blame] | 138 | usb_base = port->usb_regs + 0x100; |
Lucas Stach | 3494a4c | 2012-09-26 00:14:35 +0200 | [diff] [blame] | 139 | hccr = (struct ehci_hccr *)usb_base; |
| 140 | cap_base = ehci_readl(&hccr->cr_capbase); |
| 141 | hcor = (struct ehci_hcor *)(usb_base + HC_LENGTH(cap_base)); |
| 142 | |
Marek Vasut | f7d7f94 | 2011-11-08 23:18:26 +0000 | [diff] [blame] | 143 | tmp = ehci_readl(&hcor->or_usbcmd); |
| 144 | tmp &= ~CMD_RUN; |
| 145 | ehci_writel(tmp, &hcor->or_usbcmd); |
| 146 | |
| 147 | /* Disable the PHY */ |
| 148 | tmp = USBPHY_PWD_RXPWDRX | USBPHY_PWD_RXPWDDIFF | |
| 149 | USBPHY_PWD_RXPWD1PT1 | USBPHY_PWD_RXPWDENV | |
| 150 | USBPHY_PWD_TXPWDV2I | USBPHY_PWD_TXPWDIBIAS | |
| 151 | USBPHY_PWD_TXPWDFS; |
Marek Vasut | 191a2ce | 2013-02-23 02:43:02 +0000 | [diff] [blame] | 152 | writel(tmp, &port->phy_regs->hw_usbphy_pwd); |
Marek Vasut | f7d7f94 | 2011-11-08 23:18:26 +0000 | [diff] [blame] | 153 | |
| 154 | /* Disable USB clock */ |
Marek Vasut | 191a2ce | 2013-02-23 02:43:02 +0000 | [diff] [blame] | 155 | ret = ehci_mxs_toggle_clock(port, 0); |
Marek Vasut | f7d7f94 | 2011-11-08 23:18:26 +0000 | [diff] [blame] | 156 | |
Marek Vasut | 191a2ce | 2013-02-23 02:43:02 +0000 | [diff] [blame] | 157 | return ret; |
Marek Vasut | f7d7f94 | 2011-11-08 23:18:26 +0000 | [diff] [blame] | 158 | } |