blob: 1d012db92e6ff2cb2618321c550e70f6aa9f7177 [file] [log] [blame]
Michael Trimarchie30a3362008-11-28 13:22:09 +01001/*
Ramneek Mehresh3fb68ee2011-03-23 15:20:43 +05302 * (C) Copyright 2009, 2011 Freescale Semiconductor, Inc.
Vivek Mahajan288f7fb2009-05-25 17:23:16 +05303 *
Michael Trimarchie30a3362008-11-28 13:22:09 +01004 * (C) Copyright 2008, Excito Elektronik i Sk=E5ne AB
5 *
6 * Author: Tor Krill tor@excito.com
7 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02008 * SPDX-License-Identifier: GPL-2.0+
Michael Trimarchie30a3362008-11-28 13:22:09 +01009 */
10
11#include <common.h>
12#include <pci.h>
13#include <usb.h>
Michael Trimarchie30a3362008-11-28 13:22:09 +010014#include <asm/io.h>
Vivek Mahajan288f7fb2009-05-25 17:23:16 +053015#include <usb/ehci-fsl.h>
Ramneek Mehresh3fb68ee2011-03-23 15:20:43 +053016#include <hwconfig.h>
Nikhil Badola2613cfc2014-02-26 17:43:15 +053017#include <asm/fsl_errata.h>
Michael Trimarchie30a3362008-11-28 13:22:09 +010018
Jean-Christophe PLAGNIOL-VILLARD8f6bcf42009-04-03 12:46:58 +020019#include "ehci.h"
Michael Trimarchie30a3362008-11-28 13:22:09 +010020
Shengzhou Liud407e1f2012-10-22 13:18:24 +080021/* Check USB PHY clock valid */
22static int usb_phy_clk_valid(struct usb_ehci *ehci)
23{
24 if (!((in_be32(&ehci->control) & PHY_CLK_VALID) ||
25 in_be32(&ehci->prictrl))) {
26 printf("USB PHY clock invalid!\n");
27 return 0;
28 } else {
29 return 1;
30 }
31}
32
Michael Trimarchie30a3362008-11-28 13:22:09 +010033/*
34 * Create the appropriate control structures to manage
35 * a new EHCI host controller.
36 *
37 * Excerpts from linux ehci fsl driver.
38 */
Troy Kisky7d6bbb92013-10-10 15:27:57 -070039int ehci_hcd_init(int index, enum usb_init_type init,
40 struct ehci_hccr **hccr, struct ehci_hcor **hcor)
Michael Trimarchie30a3362008-11-28 13:22:09 +010041{
ramneek mehresh16b08062013-09-12 16:35:49 +053042 struct usb_ehci *ehci = NULL;
Ramneek Mehresh3fb68ee2011-03-23 15:20:43 +053043 const char *phy_type = NULL;
44 size_t len;
Nikhil Badolaeb97e252013-12-19 11:08:46 +053045 char current_usb_controller[5];
Kumar Gala7b83c352011-11-09 10:04:15 -060046#ifdef CONFIG_SYS_FSL_USB_INTERNAL_UTMI_PHY
47 char usb_phy[5];
Ramneek Mehresh3fb68ee2011-03-23 15:20:43 +053048
49 usb_phy[0] = '\0';
Kumar Gala7b83c352011-11-09 10:04:15 -060050#endif
Nikhil Badola2613cfc2014-02-26 17:43:15 +053051 if (has_erratum_a007075()) {
52 /*
53 * A 5ms delay is needed after applying soft-reset to the
54 * controller to let external ULPI phy come out of reset.
55 * This delay needs to be added before re-initializing
56 * the controller after soft-resetting completes
57 */
58 mdelay(5);
59 }
Nikhil Badolaeb97e252013-12-19 11:08:46 +053060 memset(current_usb_controller, '\0', 5);
61 snprintf(current_usb_controller, 4, "usb%d", index+1);
Michael Trimarchie30a3362008-11-28 13:22:09 +010062
ramneek mehresh16b08062013-09-12 16:35:49 +053063 switch (index) {
64 case 0:
65 ehci = (struct usb_ehci *)CONFIG_SYS_FSL_USB1_ADDR;
66 break;
67 case 1:
68 ehci = (struct usb_ehci *)CONFIG_SYS_FSL_USB2_ADDR;
69 break;
70 default:
71 printf("ERROR: wrong controller index!!\n");
72 break;
73 };
74
Lucas Stach3494a4c2012-09-26 00:14:35 +020075 *hccr = (struct ehci_hccr *)((uint32_t)&ehci->caplength);
76 *hcor = (struct ehci_hcor *)((uint32_t) *hccr +
77 HC_LENGTH(ehci_readl(&(*hccr)->cr_capbase)));
Michael Trimarchie30a3362008-11-28 13:22:09 +010078
Michael Trimarchie30a3362008-11-28 13:22:09 +010079 /* Set to Host mode */
Vivek Mahajan32c52202009-06-19 17:56:00 +053080 setbits_le32(&ehci->usbmode, CM_HOST);
Michael Trimarchie30a3362008-11-28 13:22:09 +010081
Vivek Mahajan32c52202009-06-19 17:56:00 +053082 out_be32(&ehci->snoop1, SNOOP_SIZE_2GB);
83 out_be32(&ehci->snoop2, 0x80000000 | SNOOP_SIZE_2GB);
Michael Trimarchie30a3362008-11-28 13:22:09 +010084
85 /* Init phy */
Nikhil Badolaeb97e252013-12-19 11:08:46 +053086 if (hwconfig_sub(current_usb_controller, "phy_type"))
87 phy_type = hwconfig_subarg(current_usb_controller,
88 "phy_type", &len);
Vivek Mahajan288f7fb2009-05-25 17:23:16 +053089 else
Ramneek Mehresh3fb68ee2011-03-23 15:20:43 +053090 phy_type = getenv("usb_phy_type");
91
92 if (!phy_type) {
93#ifdef CONFIG_SYS_FSL_USB_INTERNAL_UTMI_PHY
94 /* if none specified assume internal UTMI */
95 strcpy(usb_phy, "utmi");
96 phy_type = usb_phy;
97#else
98 printf("WARNING: USB phy type not defined !!\n");
99 return -1;
100#endif
101 }
102
Nikhil Badola09a3b562014-02-17 16:58:36 +0530103 if (!strncmp(phy_type, "utmi", 4)) {
Ramneek Mehresh3fb68ee2011-03-23 15:20:43 +0530104#if defined(CONFIG_SYS_FSL_USB_INTERNAL_UTMI_PHY)
105 setbits_be32(&ehci->control, PHY_CLK_SEL_UTMI);
106 setbits_be32(&ehci->control, UTMI_PHY_EN);
107 udelay(1000); /* delay required for PHY Clk to appear */
108#endif
Lucas Stach3494a4c2012-09-26 00:14:35 +0200109 out_le32(&(*hcor)->or_portsc[0], PORT_PTS_UTMI);
Shengzhou Liud407e1f2012-10-22 13:18:24 +0800110 setbits_be32(&ehci->control, USB_EN);
Ramneek Mehresh3fb68ee2011-03-23 15:20:43 +0530111 } else {
Ramneek Mehresh3fb68ee2011-03-23 15:20:43 +0530112 setbits_be32(&ehci->control, PHY_CLK_SEL_ULPI);
Shengzhou Liud407e1f2012-10-22 13:18:24 +0800113 clrsetbits_be32(&ehci->control, UTMI_PHY_EN, USB_EN);
Ramneek Mehresh3fb68ee2011-03-23 15:20:43 +0530114 udelay(1000); /* delay required for PHY Clk to appear */
Shengzhou Liud407e1f2012-10-22 13:18:24 +0800115 if (!usb_phy_clk_valid(ehci))
116 return -EINVAL;
Lucas Stach3494a4c2012-09-26 00:14:35 +0200117 out_le32(&(*hcor)->or_portsc[0], PORT_PTS_ULPI);
Ramneek Mehresh3fb68ee2011-03-23 15:20:43 +0530118 }
Michael Trimarchie30a3362008-11-28 13:22:09 +0100119
Vivek Mahajan32c52202009-06-19 17:56:00 +0530120 out_be32(&ehci->prictrl, 0x0000000c);
121 out_be32(&ehci->age_cnt_limit, 0x00000040);
122 out_be32(&ehci->sictrl, 0x00000001);
Michael Trimarchie30a3362008-11-28 13:22:09 +0100123
Vivek Mahajan32c52202009-06-19 17:56:00 +0530124 in_le32(&ehci->usbmode);
Michael Trimarchie30a3362008-11-28 13:22:09 +0100125
126 return 0;
127}
128
129/*
130 * Destroy the appropriate control structures corresponding
131 * the the EHCI host controller.
132 */
Lucas Stach3494a4c2012-09-26 00:14:35 +0200133int ehci_hcd_stop(int index)
Michael Trimarchie30a3362008-11-28 13:22:09 +0100134{
135 return 0;
136}