xref: /OK3568_Linux_fs/u-boot/drivers/usb/host/xhci-omap.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * OMAP USB HOST xHCI Controller
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * (C) Copyright 2013
5*4882a593Smuzhiyun  * Texas Instruments, <www.ti.com>
6*4882a593Smuzhiyun  *
7*4882a593Smuzhiyun  * Author: Dan Murphy <dmurphy@ti.com>
8*4882a593Smuzhiyun  *
9*4882a593Smuzhiyun  * SPDX-License-Identifier:	GPL-2.0+
10*4882a593Smuzhiyun  */
11*4882a593Smuzhiyun 
12*4882a593Smuzhiyun #include <common.h>
13*4882a593Smuzhiyun #include <usb.h>
14*4882a593Smuzhiyun #include <linux/errno.h>
15*4882a593Smuzhiyun #include <asm/omap_common.h>
16*4882a593Smuzhiyun #include <asm/arch/cpu.h>
17*4882a593Smuzhiyun #include <asm/arch/sys_proto.h>
18*4882a593Smuzhiyun 
19*4882a593Smuzhiyun #include <linux/compat.h>
20*4882a593Smuzhiyun #include <linux/usb/dwc3.h>
21*4882a593Smuzhiyun #include <linux/usb/xhci-omap.h>
22*4882a593Smuzhiyun 
23*4882a593Smuzhiyun #include <usb/xhci.h>
24*4882a593Smuzhiyun 
25*4882a593Smuzhiyun /* Declare global data pointer */
26*4882a593Smuzhiyun DECLARE_GLOBAL_DATA_PTR;
27*4882a593Smuzhiyun 
28*4882a593Smuzhiyun static struct omap_xhci omap;
29*4882a593Smuzhiyun 
omap_xhci_core_init(struct omap_xhci * omap)30*4882a593Smuzhiyun static int omap_xhci_core_init(struct omap_xhci *omap)
31*4882a593Smuzhiyun {
32*4882a593Smuzhiyun 	int ret = 0;
33*4882a593Smuzhiyun 
34*4882a593Smuzhiyun 	usb_phy_power(1);
35*4882a593Smuzhiyun 	omap_enable_phy(omap);
36*4882a593Smuzhiyun 
37*4882a593Smuzhiyun 	ret = dwc3_core_init(omap->dwc3_reg);
38*4882a593Smuzhiyun 	if (ret) {
39*4882a593Smuzhiyun 		debug("%s:failed to initialize core\n", __func__);
40*4882a593Smuzhiyun 		return ret;
41*4882a593Smuzhiyun 	}
42*4882a593Smuzhiyun 
43*4882a593Smuzhiyun 	/* We are hard-coding DWC3 core to Host Mode */
44*4882a593Smuzhiyun 	dwc3_set_mode(omap->dwc3_reg, DWC3_GCTL_PRTCAP_HOST);
45*4882a593Smuzhiyun 
46*4882a593Smuzhiyun 	return ret;
47*4882a593Smuzhiyun }
48*4882a593Smuzhiyun 
omap_xhci_core_exit(struct omap_xhci * omap)49*4882a593Smuzhiyun static void omap_xhci_core_exit(struct omap_xhci *omap)
50*4882a593Smuzhiyun {
51*4882a593Smuzhiyun 	usb_phy_power(0);
52*4882a593Smuzhiyun }
53*4882a593Smuzhiyun 
xhci_hcd_init(int index,struct xhci_hccr ** hccr,struct xhci_hcor ** hcor)54*4882a593Smuzhiyun int xhci_hcd_init(int index, struct xhci_hccr **hccr, struct xhci_hcor **hcor)
55*4882a593Smuzhiyun {
56*4882a593Smuzhiyun 	struct omap_xhci *ctx = &omap;
57*4882a593Smuzhiyun 	int ret = 0;
58*4882a593Smuzhiyun 
59*4882a593Smuzhiyun 	ctx->hcd = (struct xhci_hccr *)OMAP_XHCI_BASE;
60*4882a593Smuzhiyun 	ctx->dwc3_reg = (struct dwc3 *)((char *)(ctx->hcd) + DWC3_REG_OFFSET);
61*4882a593Smuzhiyun 	ctx->usb3_phy = (struct omap_usb3_phy *)OMAP_OCP1_SCP_BASE;
62*4882a593Smuzhiyun 	ctx->otg_wrapper = (struct omap_dwc_wrapper *)OMAP_OTG_WRAPPER_BASE;
63*4882a593Smuzhiyun 
64*4882a593Smuzhiyun 	ret = board_usb_init(index, USB_INIT_HOST);
65*4882a593Smuzhiyun 	if (ret != 0) {
66*4882a593Smuzhiyun 		puts("Failed to initialize board for USB\n");
67*4882a593Smuzhiyun 		return ret;
68*4882a593Smuzhiyun 	}
69*4882a593Smuzhiyun 
70*4882a593Smuzhiyun 	ret = omap_xhci_core_init(ctx);
71*4882a593Smuzhiyun 	if (ret < 0) {
72*4882a593Smuzhiyun 		puts("Failed to initialize xhci\n");
73*4882a593Smuzhiyun 		return ret;
74*4882a593Smuzhiyun 	}
75*4882a593Smuzhiyun 
76*4882a593Smuzhiyun 	*hccr = (struct xhci_hccr *)(OMAP_XHCI_BASE);
77*4882a593Smuzhiyun 	*hcor = (struct xhci_hcor *)((uint32_t) *hccr
78*4882a593Smuzhiyun 				+ HC_LENGTH(xhci_readl(&(*hccr)->cr_capbase)));
79*4882a593Smuzhiyun 
80*4882a593Smuzhiyun 	debug("omap-xhci: init hccr %x and hcor %x hc_length %d\n",
81*4882a593Smuzhiyun 	      (uint32_t)*hccr, (uint32_t)*hcor,
82*4882a593Smuzhiyun 	      (uint32_t)HC_LENGTH(xhci_readl(&(*hccr)->cr_capbase)));
83*4882a593Smuzhiyun 
84*4882a593Smuzhiyun 	return ret;
85*4882a593Smuzhiyun }
86*4882a593Smuzhiyun 
xhci_hcd_stop(int index)87*4882a593Smuzhiyun void xhci_hcd_stop(int index)
88*4882a593Smuzhiyun {
89*4882a593Smuzhiyun 	struct omap_xhci *ctx = &omap;
90*4882a593Smuzhiyun 
91*4882a593Smuzhiyun 	omap_xhci_core_exit(ctx);
92*4882a593Smuzhiyun 	board_usb_cleanup(index, USB_INIT_HOST);
93*4882a593Smuzhiyun }
94