blob: db007af37fee627cd2b8b56a98b39c00531628e4 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Dan Murphy677ff202013-08-26 08:54:52 -05002/*
3 * OMAP USB HOST xHCI Controller
4 *
5 * (C) Copyright 2013
6 * Texas Instruments, <www.ti.com>
7 *
8 * Author: Dan Murphy <dmurphy@ti.com>
Dan Murphy677ff202013-08-26 08:54:52 -05009 */
10
11#include <common.h>
12#include <usb.h>
Masahiro Yamada64e4f7f2016-09-21 11:28:57 +090013#include <linux/errno.h>
Dan Murphy677ff202013-08-26 08:54:52 -050014#include <asm/omap_common.h>
15#include <asm/arch/cpu.h>
16#include <asm/arch/sys_proto.h>
Dan Murphy677ff202013-08-26 08:54:52 -050017
18#include <linux/compat.h>
19#include <linux/usb/dwc3.h>
Dan Murphy1aca6192013-10-11 12:28:14 -050020#include <linux/usb/xhci-omap.h>
Dan Murphy677ff202013-08-26 08:54:52 -050021
22#include "xhci.h"
23
24/* Declare global data pointer */
Dan Murphy677ff202013-08-26 08:54:52 -050025static struct omap_xhci omap;
26
Dan Murphy677ff202013-08-26 08:54:52 -050027static int omap_xhci_core_init(struct omap_xhci *omap)
28{
29 int ret = 0;
30
Felipe Balbiae46a4c2014-06-23 16:25:38 -050031 usb_phy_power(1);
Dan Murphy69521c12013-10-11 12:28:17 -050032 omap_enable_phy(omap);
Dan Murphy677ff202013-08-26 08:54:52 -050033
34 ret = dwc3_core_init(omap->dwc3_reg);
35 if (ret) {
36 debug("%s:failed to initialize core\n", __func__);
37 return ret;
38 }
39
40 /* We are hard-coding DWC3 core to Host Mode */
41 dwc3_set_mode(omap->dwc3_reg, DWC3_GCTL_PRTCAP_HOST);
42
43 return ret;
44}
45
46static void omap_xhci_core_exit(struct omap_xhci *omap)
47{
Dan Murphy69521c12013-10-11 12:28:17 -050048 usb_phy_power(0);
Dan Murphy677ff202013-08-26 08:54:52 -050049}
50
51int xhci_hcd_init(int index, struct xhci_hccr **hccr, struct xhci_hcor **hcor)
52{
53 struct omap_xhci *ctx = &omap;
54 int ret = 0;
55
56 ctx->hcd = (struct xhci_hccr *)OMAP_XHCI_BASE;
57 ctx->dwc3_reg = (struct dwc3 *)((char *)(ctx->hcd) + DWC3_REG_OFFSET);
58 ctx->usb3_phy = (struct omap_usb3_phy *)OMAP_OCP1_SCP_BASE;
59 ctx->otg_wrapper = (struct omap_dwc_wrapper *)OMAP_OTG_WRAPPER_BASE;
60
Dan Murphy90690752013-10-11 12:28:15 -050061 ret = board_usb_init(index, USB_INIT_HOST);
Dan Murphy677ff202013-08-26 08:54:52 -050062 if (ret != 0) {
63 puts("Failed to initialize board for USB\n");
64 return ret;
65 }
66
67 ret = omap_xhci_core_init(ctx);
68 if (ret < 0) {
69 puts("Failed to initialize xhci\n");
70 return ret;
71 }
72
73 *hccr = (struct xhci_hccr *)(OMAP_XHCI_BASE);
74 *hcor = (struct xhci_hcor *)((uint32_t) *hccr
75 + HC_LENGTH(xhci_readl(&(*hccr)->cr_capbase)));
76
77 debug("omap-xhci: init hccr %x and hcor %x hc_length %d\n",
78 (uint32_t)*hccr, (uint32_t)*hcor,
79 (uint32_t)HC_LENGTH(xhci_readl(&(*hccr)->cr_capbase)));
80
81 return ret;
82}
83
84void xhci_hcd_stop(int index)
85{
86 struct omap_xhci *ctx = &omap;
87
88 omap_xhci_core_exit(ctx);
Kishon Vijay Abraham I9cceb952015-08-19 13:49:47 +053089 board_usb_cleanup(index, USB_INIT_HOST);
Dan Murphy677ff202013-08-26 08:54:52 -050090}