2008-11-28 12:22:09 +00:00
|
|
|
/*
|
2011-03-23 09:50:43 +00:00
|
|
|
* (C) Copyright 2009, 2011 Freescale Semiconductor, Inc.
|
2009-05-25 11:53:16 +00:00
|
|
|
*
|
2008-11-28 12:22:09 +00:00
|
|
|
* (C) Copyright 2008, Excito Elektronik i Sk=E5ne AB
|
|
|
|
*
|
|
|
|
* Author: Tor Krill tor@excito.com
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of
|
|
|
|
* the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
|
|
|
* MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <pci.h>
|
|
|
|
#include <usb.h>
|
|
|
|
#include <asm/io.h>
|
2009-05-25 11:53:16 +00:00
|
|
|
#include <usb/ehci-fsl.h>
|
2011-03-23 09:50:43 +00:00
|
|
|
#include <hwconfig.h>
|
2008-11-28 12:22:09 +00:00
|
|
|
|
2009-04-03 10:46:58 +00:00
|
|
|
#include "ehci.h"
|
2008-11-28 12:22:09 +00:00
|
|
|
|
2012-10-22 05:18:24 +00:00
|
|
|
/* Check USB PHY clock valid */
|
|
|
|
static int usb_phy_clk_valid(struct usb_ehci *ehci)
|
|
|
|
{
|
|
|
|
if (!((in_be32(&ehci->control) & PHY_CLK_VALID) ||
|
|
|
|
in_be32(&ehci->prictrl))) {
|
|
|
|
printf("USB PHY clock invalid!\n");
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-28 12:22:09 +00:00
|
|
|
/*
|
|
|
|
* Create the appropriate control structures to manage
|
|
|
|
* a new EHCI host controller.
|
|
|
|
*
|
|
|
|
* Excerpts from linux ehci fsl driver.
|
|
|
|
*/
|
2012-09-25 22:14:35 +00:00
|
|
|
int ehci_hcd_init(int index, struct ehci_hccr **hccr, struct ehci_hcor **hcor)
|
2008-11-28 12:22:09 +00:00
|
|
|
{
|
2009-05-25 11:53:16 +00:00
|
|
|
struct usb_ehci *ehci;
|
2011-03-23 09:50:43 +00:00
|
|
|
const char *phy_type = NULL;
|
|
|
|
size_t len;
|
2011-11-09 16:04:15 +00:00
|
|
|
#ifdef CONFIG_SYS_FSL_USB_INTERNAL_UTMI_PHY
|
|
|
|
char usb_phy[5];
|
2011-03-23 09:50:43 +00:00
|
|
|
|
|
|
|
usb_phy[0] = '\0';
|
2011-11-09 16:04:15 +00:00
|
|
|
#endif
|
2008-11-28 12:22:09 +00:00
|
|
|
|
2010-10-14 13:27:06 +00:00
|
|
|
ehci = (struct usb_ehci *)CONFIG_SYS_FSL_USB_ADDR;
|
2012-09-25 22:14:35 +00:00
|
|
|
*hccr = (struct ehci_hccr *)((uint32_t)&ehci->caplength);
|
|
|
|
*hcor = (struct ehci_hcor *)((uint32_t) *hccr +
|
|
|
|
HC_LENGTH(ehci_readl(&(*hccr)->cr_capbase)));
|
2008-11-28 12:22:09 +00:00
|
|
|
|
|
|
|
/* Set to Host mode */
|
2009-06-19 12:26:00 +00:00
|
|
|
setbits_le32(&ehci->usbmode, CM_HOST);
|
2008-11-28 12:22:09 +00:00
|
|
|
|
2009-06-19 12:26:00 +00:00
|
|
|
out_be32(&ehci->snoop1, SNOOP_SIZE_2GB);
|
|
|
|
out_be32(&ehci->snoop2, 0x80000000 | SNOOP_SIZE_2GB);
|
2008-11-28 12:22:09 +00:00
|
|
|
|
|
|
|
/* Init phy */
|
2011-03-23 09:50:43 +00:00
|
|
|
if (hwconfig_sub("usb1", "phy_type"))
|
|
|
|
phy_type = hwconfig_subarg("usb1", "phy_type", &len);
|
2009-05-25 11:53:16 +00:00
|
|
|
else
|
2011-03-23 09:50:43 +00:00
|
|
|
phy_type = getenv("usb_phy_type");
|
|
|
|
|
|
|
|
if (!phy_type) {
|
|
|
|
#ifdef CONFIG_SYS_FSL_USB_INTERNAL_UTMI_PHY
|
|
|
|
/* if none specified assume internal UTMI */
|
|
|
|
strcpy(usb_phy, "utmi");
|
|
|
|
phy_type = usb_phy;
|
|
|
|
#else
|
|
|
|
printf("WARNING: USB phy type not defined !!\n");
|
|
|
|
return -1;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp(phy_type, "utmi")) {
|
|
|
|
#if defined(CONFIG_SYS_FSL_USB_INTERNAL_UTMI_PHY)
|
|
|
|
setbits_be32(&ehci->control, PHY_CLK_SEL_UTMI);
|
|
|
|
setbits_be32(&ehci->control, UTMI_PHY_EN);
|
|
|
|
udelay(1000); /* delay required for PHY Clk to appear */
|
|
|
|
#endif
|
2012-09-25 22:14:35 +00:00
|
|
|
out_le32(&(*hcor)->or_portsc[0], PORT_PTS_UTMI);
|
2012-10-22 05:18:24 +00:00
|
|
|
setbits_be32(&ehci->control, USB_EN);
|
2011-03-23 09:50:43 +00:00
|
|
|
} else {
|
|
|
|
setbits_be32(&ehci->control, PHY_CLK_SEL_ULPI);
|
2012-10-22 05:18:24 +00:00
|
|
|
clrsetbits_be32(&ehci->control, UTMI_PHY_EN, USB_EN);
|
2011-03-23 09:50:43 +00:00
|
|
|
udelay(1000); /* delay required for PHY Clk to appear */
|
2012-10-22 05:18:24 +00:00
|
|
|
if (!usb_phy_clk_valid(ehci))
|
|
|
|
return -EINVAL;
|
2012-09-25 22:14:35 +00:00
|
|
|
out_le32(&(*hcor)->or_portsc[0], PORT_PTS_ULPI);
|
2011-03-23 09:50:43 +00:00
|
|
|
}
|
2008-11-28 12:22:09 +00:00
|
|
|
|
2009-06-19 12:26:00 +00:00
|
|
|
out_be32(&ehci->prictrl, 0x0000000c);
|
|
|
|
out_be32(&ehci->age_cnt_limit, 0x00000040);
|
|
|
|
out_be32(&ehci->sictrl, 0x00000001);
|
2008-11-28 12:22:09 +00:00
|
|
|
|
2009-06-19 12:26:00 +00:00
|
|
|
in_le32(&ehci->usbmode);
|
2008-11-28 12:22:09 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Destroy the appropriate control structures corresponding
|
|
|
|
* the the EHCI host controller.
|
|
|
|
*/
|
2012-09-25 22:14:35 +00:00
|
|
|
int ehci_hcd_stop(int index)
|
2008-11-28 12:22:09 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|