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