blob: 9872415562c26203d349f0ca63fa2a0cd9deda80 [file] [log] [blame]
Marek Vasutf7d7f942011-11-08 23:18:26 +00001/*
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 Denkd79de1d2013-07-08 09:37:19 +02007 * SPDX-License-Identifier: GPL-2.0+
Marek Vasutf7d7f942011-11-08 23:18:26 +00008 */
9
10#include <common.h>
11#include <asm/io.h>
Marek Vasut83e330c2013-02-23 02:43:01 +000012#include <asm/arch/imx-regs.h>
Marek Vasut191a2ce2013-02-23 02:43:02 +000013#include <errno.h>
Marek Vasutf7d7f942011-11-08 23:18:26 +000014
Marek Vasutf7d7f942011-11-08 23:18:26 +000015#include "ehci.h"
16
Marek Vasut191a2ce2013-02-23 02:43:02 +000017/* 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 Vasutf7d7f942011-11-08 23:18:26 +000021
Marek Vasut191a2ce2013-02-23 02:43:02 +000022struct ehci_mxs_port {
23 uint32_t usb_regs;
Otavio Salvador22f4ff92012-08-05 09:05:31 +000024 struct mxs_usbphy_regs *phy_regs;
Marek Vasut191a2ce2013-02-23 02:43:02 +000025
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
32static 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 Vasutf7d7f942011-11-08 23:18:26 +000058
Marek Vasut191a2ce2013-02-23 02:43:02 +000059static int ehci_mxs_toggle_clock(const struct ehci_mxs_port *port, int enable)
Marek Vasutf7d7f942011-11-08 23:18:26 +000060{
Marek Vasut191a2ce2013-02-23 02:43:02 +000061 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 Vasutf7d7f942011-11-08 23:18:26 +000075 }
76
Marek Vasutf7d7f942011-11-08 23:18:26 +000077 return 0;
78}
79
Marek Vasut809860b2014-04-28 03:38:39 +020080int __weak board_ehci_hcd_init(int port)
81{
82 return 0;
83}
84
85int __weak board_ehci_hcd_exit(int port)
86{
87 return 0;
88}
89
Troy Kisky7d6bbb92013-10-10 15:27:57 -070090int ehci_hcd_init(int index, enum usb_init_type init,
91 struct ehci_hccr **hccr, struct ehci_hcor **hcor)
Marek Vasutf7d7f942011-11-08 23:18:26 +000092{
93
94 int ret;
95 uint32_t usb_base, cap_base;
Marek Vasut191a2ce2013-02-23 02:43:02 +000096 const struct ehci_mxs_port *port;
Marek Vasutf7d7f942011-11-08 23:18:26 +000097
Marek Vasut191a2ce2013-02-23 02:43:02 +000098 if ((index < 0) || (index >= ARRAY_SIZE(mxs_port))) {
99 printf("Invalid port index (index = %d)!\n", index);
100 return -EINVAL;
101 }
102
Marek Vasut809860b2014-04-28 03:38:39 +0200103 ret = board_ehci_hcd_init(index);
104 if (ret)
105 return ret;
106
Marek Vasut191a2ce2013-02-23 02:43:02 +0000107 port = &mxs_port[index];
Marek Vasutf7d7f942011-11-08 23:18:26 +0000108
109 /* Reset the PHY block */
Marek Vasut191a2ce2013-02-23 02:43:02 +0000110 writel(USBPHY_CTRL_SFTRST, &port->phy_regs->hw_usbphy_ctrl_set);
Marek Vasutf7d7f942011-11-08 23:18:26 +0000111 udelay(10);
112 writel(USBPHY_CTRL_SFTRST | USBPHY_CTRL_CLKGATE,
Marek Vasut191a2ce2013-02-23 02:43:02 +0000113 &port->phy_regs->hw_usbphy_ctrl_clr);
Marek Vasutf7d7f942011-11-08 23:18:26 +0000114
115 /* Enable USB clock */
Marek Vasut191a2ce2013-02-23 02:43:02 +0000116 ret = ehci_mxs_toggle_clock(port, 1);
117 if (ret)
118 return ret;
Marek Vasutf7d7f942011-11-08 23:18:26 +0000119
120 /* Start USB PHY */
Marek Vasut191a2ce2013-02-23 02:43:02 +0000121 writel(0, &port->phy_regs->hw_usbphy_pwd);
Marek Vasutf7d7f942011-11-08 23:18:26 +0000122
123 /* Enable UTMI+ Level 2 and Level 3 compatibility */
124 writel(USBPHY_CTRL_ENUTMILEVEL3 | USBPHY_CTRL_ENUTMILEVEL2 | 1,
Marek Vasut191a2ce2013-02-23 02:43:02 +0000125 &port->phy_regs->hw_usbphy_ctrl_set);
Marek Vasutf7d7f942011-11-08 23:18:26 +0000126
Marek Vasut191a2ce2013-02-23 02:43:02 +0000127 usb_base = port->usb_regs + 0x100;
Lucas Stach3494a4c2012-09-26 00:14:35 +0200128 *hccr = (struct ehci_hccr *)usb_base;
Marek Vasutf7d7f942011-11-08 23:18:26 +0000129
Lucas Stach3494a4c2012-09-26 00:14:35 +0200130 cap_base = ehci_readl(&(*hccr)->cr_capbase);
131 *hcor = (struct ehci_hcor *)(usb_base + HC_LENGTH(cap_base));
Marek Vasutf7d7f942011-11-08 23:18:26 +0000132
133 return 0;
134}
135
Lucas Stach3494a4c2012-09-26 00:14:35 +0200136int ehci_hcd_stop(int index)
Marek Vasutf7d7f942011-11-08 23:18:26 +0000137{
138 int ret;
Lucas Stach3494a4c2012-09-26 00:14:35 +0200139 uint32_t usb_base, cap_base, tmp;
Lucas Stach3494a4c2012-09-26 00:14:35 +0200140 struct ehci_hccr *hccr;
141 struct ehci_hcor *hcor;
Marek Vasut191a2ce2013-02-23 02:43:02 +0000142 const struct ehci_mxs_port *port;
Marek Vasutf7d7f942011-11-08 23:18:26 +0000143
Marek Vasut191a2ce2013-02-23 02:43:02 +0000144 if ((index < 0) || (index >= ARRAY_SIZE(mxs_port))) {
145 printf("Invalid port index (index = %d)!\n", index);
146 return -EINVAL;
147 }
148
149 port = &mxs_port[index];
Marek Vasutf7d7f942011-11-08 23:18:26 +0000150
151 /* Stop the USB port */
Marek Vasut191a2ce2013-02-23 02:43:02 +0000152 usb_base = port->usb_regs + 0x100;
Lucas Stach3494a4c2012-09-26 00:14:35 +0200153 hccr = (struct ehci_hccr *)usb_base;
154 cap_base = ehci_readl(&hccr->cr_capbase);
155 hcor = (struct ehci_hcor *)(usb_base + HC_LENGTH(cap_base));
156
Marek Vasutf7d7f942011-11-08 23:18:26 +0000157 tmp = ehci_readl(&hcor->or_usbcmd);
158 tmp &= ~CMD_RUN;
Daniel Schwierzeck4e9b4c42018-01-25 20:43:58 +0100159 ehci_writel(&hcor->or_usbcmd, tmp);
Marek Vasutf7d7f942011-11-08 23:18:26 +0000160
161 /* Disable the PHY */
162 tmp = USBPHY_PWD_RXPWDRX | USBPHY_PWD_RXPWDDIFF |
163 USBPHY_PWD_RXPWD1PT1 | USBPHY_PWD_RXPWDENV |
164 USBPHY_PWD_TXPWDV2I | USBPHY_PWD_TXPWDIBIAS |
165 USBPHY_PWD_TXPWDFS;
Marek Vasut191a2ce2013-02-23 02:43:02 +0000166 writel(tmp, &port->phy_regs->hw_usbphy_pwd);
Marek Vasutf7d7f942011-11-08 23:18:26 +0000167
168 /* Disable USB clock */
Marek Vasut191a2ce2013-02-23 02:43:02 +0000169 ret = ehci_mxs_toggle_clock(port, 0);
Marek Vasutf7d7f942011-11-08 23:18:26 +0000170
Marek Vasut809860b2014-04-28 03:38:39 +0200171 board_ehci_hcd_exit(index);
172
Marek Vasut191a2ce2013-02-23 02:43:02 +0000173 return ret;
Marek Vasutf7d7f942011-11-08 23:18:26 +0000174}