blob: 3a5520838447d75102e383ffb771e5ab0cab6213 [file] [log] [blame]
Dan Murphy677ff202013-08-26 08:54:52 -05001/*
2 * OMAP USB HOST xHCI Controller
3 *
4 * (C) Copyright 2013
5 * Texas Instruments, <www.ti.com>
6 *
7 * Author: Dan Murphy <dmurphy@ti.com>
8 *
9 * SPDX-License-Identifier: GPL-2.0+
10 */
11
12#include <common.h>
13#include <usb.h>
14#include <asm-generic/errno.h>
15#include <asm/omap_common.h>
16#include <asm/arch/cpu.h>
17#include <asm/arch/sys_proto.h>
Dan Murphy677ff202013-08-26 08:54:52 -050018
19#include <linux/compat.h>
20#include <linux/usb/dwc3.h>
Dan Murphy1aca6192013-10-11 12:28:14 -050021#include <linux/usb/xhci-omap.h>
Dan Murphy677ff202013-08-26 08:54:52 -050022
23#include "xhci.h"
24
25/* Declare global data pointer */
26DECLARE_GLOBAL_DATA_PTR;
27
28static struct omap_xhci omap;
29
Troy Kisky3135dba2013-10-22 14:27:17 -070030inline int __board_usb_init(int index, enum usb_init_type init)
Dan Murphy677ff202013-08-26 08:54:52 -050031{
32 return 0;
33}
Troy Kisky3135dba2013-10-22 14:27:17 -070034int board_usb_init(int index, enum usb_init_type init)
Dan Murphy90690752013-10-11 12:28:15 -050035 __attribute__((weak, alias("__board_usb_init")));
Dan Murphy677ff202013-08-26 08:54:52 -050036
Dan Murphy677ff202013-08-26 08:54:52 -050037static int omap_xhci_core_init(struct omap_xhci *omap)
38{
39 int ret = 0;
40
Felipe Balbiae46a4c2014-06-23 16:25:38 -050041 usb_phy_power(1);
Dan Murphy69521c12013-10-11 12:28:17 -050042 omap_enable_phy(omap);
Dan Murphy677ff202013-08-26 08:54:52 -050043
44 ret = dwc3_core_init(omap->dwc3_reg);
45 if (ret) {
46 debug("%s:failed to initialize core\n", __func__);
47 return ret;
48 }
49
50 /* We are hard-coding DWC3 core to Host Mode */
51 dwc3_set_mode(omap->dwc3_reg, DWC3_GCTL_PRTCAP_HOST);
52
53 return ret;
54}
55
56static void omap_xhci_core_exit(struct omap_xhci *omap)
57{
Dan Murphy69521c12013-10-11 12:28:17 -050058 usb_phy_power(0);
Dan Murphy677ff202013-08-26 08:54:52 -050059}
60
61int xhci_hcd_init(int index, struct xhci_hccr **hccr, struct xhci_hcor **hcor)
62{
63 struct omap_xhci *ctx = &omap;
64 int ret = 0;
65
66 ctx->hcd = (struct xhci_hccr *)OMAP_XHCI_BASE;
67 ctx->dwc3_reg = (struct dwc3 *)((char *)(ctx->hcd) + DWC3_REG_OFFSET);
68 ctx->usb3_phy = (struct omap_usb3_phy *)OMAP_OCP1_SCP_BASE;
69 ctx->otg_wrapper = (struct omap_dwc_wrapper *)OMAP_OTG_WRAPPER_BASE;
70
Dan Murphy90690752013-10-11 12:28:15 -050071 ret = board_usb_init(index, USB_INIT_HOST);
Dan Murphy677ff202013-08-26 08:54:52 -050072 if (ret != 0) {
73 puts("Failed to initialize board for USB\n");
74 return ret;
75 }
76
77 ret = omap_xhci_core_init(ctx);
78 if (ret < 0) {
79 puts("Failed to initialize xhci\n");
80 return ret;
81 }
82
83 *hccr = (struct xhci_hccr *)(OMAP_XHCI_BASE);
84 *hcor = (struct xhci_hcor *)((uint32_t) *hccr
85 + HC_LENGTH(xhci_readl(&(*hccr)->cr_capbase)));
86
87 debug("omap-xhci: init hccr %x and hcor %x hc_length %d\n",
88 (uint32_t)*hccr, (uint32_t)*hcor,
89 (uint32_t)HC_LENGTH(xhci_readl(&(*hccr)->cr_capbase)));
90
91 return ret;
92}
93
94void xhci_hcd_stop(int index)
95{
96 struct omap_xhci *ctx = &omap;
97
98 omap_xhci_core_exit(ctx);
99}