blob: b814500bdbb7642941c192cef87e1dd97f92b17d [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>
Masahiro Yamada64e4f7f2016-09-21 11:28:57 +090014#include <linux/errno.h>
Dan Murphy677ff202013-08-26 08:54:52 -050015#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
Dan Murphy677ff202013-08-26 08:54:52 -050030static int omap_xhci_core_init(struct omap_xhci *omap)
31{
32 int ret = 0;
33
Felipe Balbiae46a4c2014-06-23 16:25:38 -050034 usb_phy_power(1);
Dan Murphy69521c12013-10-11 12:28:17 -050035 omap_enable_phy(omap);
Dan Murphy677ff202013-08-26 08:54:52 -050036
37 ret = dwc3_core_init(omap->dwc3_reg);
38 if (ret) {
39 debug("%s:failed to initialize core\n", __func__);
40 return ret;
41 }
42
43 /* We are hard-coding DWC3 core to Host Mode */
44 dwc3_set_mode(omap->dwc3_reg, DWC3_GCTL_PRTCAP_HOST);
45
46 return ret;
47}
48
49static void omap_xhci_core_exit(struct omap_xhci *omap)
50{
Dan Murphy69521c12013-10-11 12:28:17 -050051 usb_phy_power(0);
Dan Murphy677ff202013-08-26 08:54:52 -050052}
53
54int xhci_hcd_init(int index, struct xhci_hccr **hccr, struct xhci_hcor **hcor)
55{
56 struct omap_xhci *ctx = &omap;
57 int ret = 0;
58
59 ctx->hcd = (struct xhci_hccr *)OMAP_XHCI_BASE;
60 ctx->dwc3_reg = (struct dwc3 *)((char *)(ctx->hcd) + DWC3_REG_OFFSET);
61 ctx->usb3_phy = (struct omap_usb3_phy *)OMAP_OCP1_SCP_BASE;
62 ctx->otg_wrapper = (struct omap_dwc_wrapper *)OMAP_OTG_WRAPPER_BASE;
63
Dan Murphy90690752013-10-11 12:28:15 -050064 ret = board_usb_init(index, USB_INIT_HOST);
Dan Murphy677ff202013-08-26 08:54:52 -050065 if (ret != 0) {
66 puts("Failed to initialize board for USB\n");
67 return ret;
68 }
69
70 ret = omap_xhci_core_init(ctx);
71 if (ret < 0) {
72 puts("Failed to initialize xhci\n");
73 return ret;
74 }
75
76 *hccr = (struct xhci_hccr *)(OMAP_XHCI_BASE);
77 *hcor = (struct xhci_hcor *)((uint32_t) *hccr
78 + HC_LENGTH(xhci_readl(&(*hccr)->cr_capbase)));
79
80 debug("omap-xhci: init hccr %x and hcor %x hc_length %d\n",
81 (uint32_t)*hccr, (uint32_t)*hcor,
82 (uint32_t)HC_LENGTH(xhci_readl(&(*hccr)->cr_capbase)));
83
84 return ret;
85}
86
87void xhci_hcd_stop(int index)
88{
89 struct omap_xhci *ctx = &omap;
90
91 omap_xhci_core_exit(ctx);
Kishon Vijay Abraham I9cceb952015-08-19 13:49:47 +053092 board_usb_cleanup(index, USB_INIT_HOST);
Dan Murphy677ff202013-08-26 08:54:52 -050093}