blob: 0ca7545a349dc50bb1bcf9cc29f4af9cd680e8ae [file] [log] [blame]
Marek Vasutdbb8f272011-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 *
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 Vasut47f13312013-02-23 02:43:01 +000024#include <asm/arch/imx-regs.h>
Marek Vasutdbb8f272011-11-08 23:18:26 +000025
Marek Vasutdbb8f272011-11-08 23:18:26 +000026#include "ehci.h"
27
28#if (CONFIG_EHCI_MXS_PORT != 0) && (CONFIG_EHCI_MXS_PORT != 1)
29#error "MXS EHCI: Invalid port selected!"
30#endif
31
32#ifndef CONFIG_EHCI_MXS_PORT
33#error "MXS EHCI: Please define correct port using CONFIG_EHCI_MXS_PORT!"
34#endif
35
36static struct ehci_mxs {
Otavio Salvador9c471142012-08-05 09:05:31 +000037 struct mxs_usb_regs *usb_regs;
38 struct mxs_usbphy_regs *phy_regs;
Marek Vasutdbb8f272011-11-08 23:18:26 +000039} ehci_mxs;
40
41int mxs_ehci_get_port(struct ehci_mxs *mxs_usb, int port)
42{
43 uint32_t usb_base, phy_base;
44 switch (port) {
45 case 0:
46 usb_base = MXS_USBCTRL0_BASE;
47 phy_base = MXS_USBPHY0_BASE;
48 break;
49 case 1:
50 usb_base = MXS_USBCTRL1_BASE;
51 phy_base = MXS_USBPHY1_BASE;
52 break;
53 default:
54 printf("CONFIG_EHCI_MXS_PORT (port = %d)\n", port);
55 return -1;
56 }
57
Otavio Salvador9c471142012-08-05 09:05:31 +000058 mxs_usb->usb_regs = (struct mxs_usb_regs *)usb_base;
59 mxs_usb->phy_regs = (struct mxs_usbphy_regs *)phy_base;
Marek Vasutdbb8f272011-11-08 23:18:26 +000060 return 0;
61}
62
63/* This DIGCTL register ungates clock to USB */
64#define HW_DIGCTL_CTRL 0x8001c000
65#define HW_DIGCTL_CTRL_USB0_CLKGATE (1 << 2)
66#define HW_DIGCTL_CTRL_USB1_CLKGATE (1 << 16)
67
Lucas Stach676ae062012-09-26 00:14:35 +020068int ehci_hcd_init(int index, struct ehci_hccr **hccr, struct ehci_hcor **hcor)
Marek Vasutdbb8f272011-11-08 23:18:26 +000069{
70
71 int ret;
72 uint32_t usb_base, cap_base;
Otavio Salvadorddcf13b2012-08-05 09:05:30 +000073 struct mxs_register_32 *digctl_ctrl =
74 (struct mxs_register_32 *)HW_DIGCTL_CTRL;
Otavio Salvador9c471142012-08-05 09:05:31 +000075 struct mxs_clkctrl_regs *clkctrl_regs =
76 (struct mxs_clkctrl_regs *)MXS_CLKCTRL_BASE;
Marek Vasutdbb8f272011-11-08 23:18:26 +000077
78 ret = mxs_ehci_get_port(&ehci_mxs, CONFIG_EHCI_MXS_PORT);
79 if (ret)
80 return ret;
81
82 /* Reset the PHY block */
83 writel(USBPHY_CTRL_SFTRST, &ehci_mxs.phy_regs->hw_usbphy_ctrl_set);
84 udelay(10);
85 writel(USBPHY_CTRL_SFTRST | USBPHY_CTRL_CLKGATE,
86 &ehci_mxs.phy_regs->hw_usbphy_ctrl_clr);
87
88 /* Enable USB clock */
89 writel(CLKCTRL_PLL0CTRL0_EN_USB_CLKS | CLKCTRL_PLL0CTRL0_POWER,
90 &clkctrl_regs->hw_clkctrl_pll0ctrl0_set);
91 writel(CLKCTRL_PLL1CTRL0_EN_USB_CLKS | CLKCTRL_PLL1CTRL0_POWER,
92 &clkctrl_regs->hw_clkctrl_pll1ctrl0_set);
93
94 writel(HW_DIGCTL_CTRL_USB0_CLKGATE | HW_DIGCTL_CTRL_USB1_CLKGATE,
95 &digctl_ctrl->reg_clr);
96
97 /* Start USB PHY */
98 writel(0, &ehci_mxs.phy_regs->hw_usbphy_pwd);
99
100 /* Enable UTMI+ Level 2 and Level 3 compatibility */
101 writel(USBPHY_CTRL_ENUTMILEVEL3 | USBPHY_CTRL_ENUTMILEVEL2 | 1,
102 &ehci_mxs.phy_regs->hw_usbphy_ctrl_set);
103
104 usb_base = ((uint32_t)ehci_mxs.usb_regs) + 0x100;
Lucas Stach676ae062012-09-26 00:14:35 +0200105 *hccr = (struct ehci_hccr *)usb_base;
Marek Vasutdbb8f272011-11-08 23:18:26 +0000106
Lucas Stach676ae062012-09-26 00:14:35 +0200107 cap_base = ehci_readl(&(*hccr)->cr_capbase);
108 *hcor = (struct ehci_hcor *)(usb_base + HC_LENGTH(cap_base));
Marek Vasutdbb8f272011-11-08 23:18:26 +0000109
110 return 0;
111}
112
Lucas Stach676ae062012-09-26 00:14:35 +0200113int ehci_hcd_stop(int index)
Marek Vasutdbb8f272011-11-08 23:18:26 +0000114{
115 int ret;
Lucas Stach676ae062012-09-26 00:14:35 +0200116 uint32_t usb_base, cap_base, tmp;
Otavio Salvadorddcf13b2012-08-05 09:05:30 +0000117 struct mxs_register_32 *digctl_ctrl =
118 (struct mxs_register_32 *)HW_DIGCTL_CTRL;
Otavio Salvador9c471142012-08-05 09:05:31 +0000119 struct mxs_clkctrl_regs *clkctrl_regs =
120 (struct mxs_clkctrl_regs *)MXS_CLKCTRL_BASE;
Lucas Stach676ae062012-09-26 00:14:35 +0200121 struct ehci_hccr *hccr;
122 struct ehci_hcor *hcor;
Marek Vasutdbb8f272011-11-08 23:18:26 +0000123
124 ret = mxs_ehci_get_port(&ehci_mxs, CONFIG_EHCI_MXS_PORT);
125 if (ret)
126 return ret;
127
128 /* Stop the USB port */
Lucas Stach676ae062012-09-26 00:14:35 +0200129 usb_base = ((uint32_t)ehci_mxs.usb_regs) + 0x100;
130 hccr = (struct ehci_hccr *)usb_base;
131 cap_base = ehci_readl(&hccr->cr_capbase);
132 hcor = (struct ehci_hcor *)(usb_base + HC_LENGTH(cap_base));
133
Marek Vasutdbb8f272011-11-08 23:18:26 +0000134 tmp = ehci_readl(&hcor->or_usbcmd);
135 tmp &= ~CMD_RUN;
136 ehci_writel(tmp, &hcor->or_usbcmd);
137
138 /* Disable the PHY */
139 tmp = USBPHY_PWD_RXPWDRX | USBPHY_PWD_RXPWDDIFF |
140 USBPHY_PWD_RXPWD1PT1 | USBPHY_PWD_RXPWDENV |
141 USBPHY_PWD_TXPWDV2I | USBPHY_PWD_TXPWDIBIAS |
142 USBPHY_PWD_TXPWDFS;
143 writel(tmp, &ehci_mxs.phy_regs->hw_usbphy_pwd);
144
145 /* Disable USB clock */
146 writel(CLKCTRL_PLL0CTRL0_EN_USB_CLKS,
147 &clkctrl_regs->hw_clkctrl_pll0ctrl0_clr);
148 writel(CLKCTRL_PLL1CTRL0_EN_USB_CLKS,
149 &clkctrl_regs->hw_clkctrl_pll1ctrl0_clr);
150
151 /* Gate off the USB clock */
152 writel(HW_DIGCTL_CTRL_USB0_CLKGATE | HW_DIGCTL_CTRL_USB1_CLKGATE,
153 &digctl_ctrl->reg_set);
154
155 return 0;
156}