Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Dan Murphy | 2d2358a | 2013-08-26 08:54:52 -0500 | [diff] [blame] | 2 | /* |
| 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 Murphy | 2d2358a | 2013-08-26 08:54:52 -0500 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #include <common.h> |
Simon Glass | f7ae49f | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 12 | #include <log.h> |
Dan Murphy | 2d2358a | 2013-08-26 08:54:52 -0500 | [diff] [blame] | 13 | #include <usb.h> |
Masahiro Yamada | 5d97dff | 2016-09-21 11:28:57 +0900 | [diff] [blame] | 14 | #include <linux/errno.h> |
Dan Murphy | 2d2358a | 2013-08-26 08:54:52 -0500 | [diff] [blame] | 15 | #include <asm/omap_common.h> |
| 16 | #include <asm/arch/cpu.h> |
| 17 | #include <asm/arch/sys_proto.h> |
Dan Murphy | 2d2358a | 2013-08-26 08:54:52 -0500 | [diff] [blame] | 18 | |
| 19 | #include <linux/compat.h> |
| 20 | #include <linux/usb/dwc3.h> |
Dan Murphy | 41b667b | 2013-10-11 12:28:14 -0500 | [diff] [blame] | 21 | #include <linux/usb/xhci-omap.h> |
Dan Murphy | 2d2358a | 2013-08-26 08:54:52 -0500 | [diff] [blame] | 22 | |
Jean-Jacques Hiblot | 1708a12 | 2019-09-11 11:33:46 +0200 | [diff] [blame] | 23 | #include <usb/xhci.h> |
Dan Murphy | 2d2358a | 2013-08-26 08:54:52 -0500 | [diff] [blame] | 24 | |
| 25 | /* Declare global data pointer */ |
Dan Murphy | 2d2358a | 2013-08-26 08:54:52 -0500 | [diff] [blame] | 26 | static struct omap_xhci omap; |
| 27 | |
Dan Murphy | 2d2358a | 2013-08-26 08:54:52 -0500 | [diff] [blame] | 28 | static int omap_xhci_core_init(struct omap_xhci *omap) |
| 29 | { |
| 30 | int ret = 0; |
| 31 | |
Felipe Balbi | 26707d9 | 2014-06-23 16:25:38 -0500 | [diff] [blame] | 32 | usb_phy_power(1); |
Dan Murphy | 834e91a | 2013-10-11 12:28:17 -0500 | [diff] [blame] | 33 | omap_enable_phy(omap); |
Dan Murphy | 2d2358a | 2013-08-26 08:54:52 -0500 | [diff] [blame] | 34 | |
| 35 | ret = dwc3_core_init(omap->dwc3_reg); |
| 36 | if (ret) { |
| 37 | debug("%s:failed to initialize core\n", __func__); |
| 38 | return ret; |
| 39 | } |
| 40 | |
| 41 | /* We are hard-coding DWC3 core to Host Mode */ |
| 42 | dwc3_set_mode(omap->dwc3_reg, DWC3_GCTL_PRTCAP_HOST); |
| 43 | |
| 44 | return ret; |
| 45 | } |
| 46 | |
| 47 | static void omap_xhci_core_exit(struct omap_xhci *omap) |
| 48 | { |
Dan Murphy | 834e91a | 2013-10-11 12:28:17 -0500 | [diff] [blame] | 49 | usb_phy_power(0); |
Dan Murphy | 2d2358a | 2013-08-26 08:54:52 -0500 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | int xhci_hcd_init(int index, struct xhci_hccr **hccr, struct xhci_hcor **hcor) |
| 53 | { |
| 54 | struct omap_xhci *ctx = &omap; |
| 55 | int ret = 0; |
| 56 | |
| 57 | ctx->hcd = (struct xhci_hccr *)OMAP_XHCI_BASE; |
| 58 | ctx->dwc3_reg = (struct dwc3 *)((char *)(ctx->hcd) + DWC3_REG_OFFSET); |
| 59 | ctx->usb3_phy = (struct omap_usb3_phy *)OMAP_OCP1_SCP_BASE; |
| 60 | ctx->otg_wrapper = (struct omap_dwc_wrapper *)OMAP_OTG_WRAPPER_BASE; |
| 61 | |
Dan Murphy | b216821 | 2013-10-11 12:28:15 -0500 | [diff] [blame] | 62 | ret = board_usb_init(index, USB_INIT_HOST); |
Dan Murphy | 2d2358a | 2013-08-26 08:54:52 -0500 | [diff] [blame] | 63 | if (ret != 0) { |
| 64 | puts("Failed to initialize board for USB\n"); |
| 65 | return ret; |
| 66 | } |
| 67 | |
| 68 | ret = omap_xhci_core_init(ctx); |
| 69 | if (ret < 0) { |
| 70 | puts("Failed to initialize xhci\n"); |
| 71 | return ret; |
| 72 | } |
| 73 | |
| 74 | *hccr = (struct xhci_hccr *)(OMAP_XHCI_BASE); |
| 75 | *hcor = (struct xhci_hcor *)((uint32_t) *hccr |
| 76 | + HC_LENGTH(xhci_readl(&(*hccr)->cr_capbase))); |
| 77 | |
| 78 | debug("omap-xhci: init hccr %x and hcor %x hc_length %d\n", |
| 79 | (uint32_t)*hccr, (uint32_t)*hcor, |
| 80 | (uint32_t)HC_LENGTH(xhci_readl(&(*hccr)->cr_capbase))); |
| 81 | |
| 82 | return ret; |
| 83 | } |
| 84 | |
| 85 | void xhci_hcd_stop(int index) |
| 86 | { |
| 87 | struct omap_xhci *ctx = &omap; |
| 88 | |
| 89 | omap_xhci_core_exit(ctx); |
Kishon Vijay Abraham I | f181144 | 2015-08-19 13:49:47 +0530 | [diff] [blame] | 90 | board_usb_cleanup(index, USB_INIT_HOST); |
Dan Murphy | 2d2358a | 2013-08-26 08:54:52 -0500 | [diff] [blame] | 91 | } |