Dan Murphy | 2d2358a | 2013-08-26 08:54:52 -0500 | [diff] [blame] | 1 | /* |
| 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 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 | |
| 23 | #include "xhci.h" |
| 24 | |
| 25 | /* Declare global data pointer */ |
| 26 | DECLARE_GLOBAL_DATA_PTR; |
| 27 | |
| 28 | static struct omap_xhci omap; |
| 29 | |
Uri Mashiach | 1a9a5f7 | 2017-02-23 15:39:37 +0200 | [diff] [blame^] | 30 | __weak int omap_xhci_board_usb_init(int index, enum usb_init_type init) |
Dan Murphy | 2d2358a | 2013-08-26 08:54:52 -0500 | [diff] [blame] | 31 | { |
| 32 | return 0; |
| 33 | } |
Uri Mashiach | 1a9a5f7 | 2017-02-23 15:39:37 +0200 | [diff] [blame^] | 34 | |
Troy Kisky | 7e575c4 | 2013-10-22 14:27:17 -0700 | [diff] [blame] | 35 | int board_usb_init(int index, enum usb_init_type init) |
Uri Mashiach | 1a9a5f7 | 2017-02-23 15:39:37 +0200 | [diff] [blame^] | 36 | { |
| 37 | return omap_xhci_board_usb_init(index, init); |
| 38 | } |
| 39 | |
| 40 | __weak int omap_xhci_board_usb_cleanup(int index, enum usb_init_type init) |
| 41 | { |
| 42 | return 0; |
| 43 | } |
| 44 | |
| 45 | int board_usb_cleanup(int index, enum usb_init_type init) |
| 46 | { |
| 47 | return omap_xhci_board_usb_cleanup(index, init); |
| 48 | } |
Dan Murphy | 2d2358a | 2013-08-26 08:54:52 -0500 | [diff] [blame] | 49 | |
Dan Murphy | 2d2358a | 2013-08-26 08:54:52 -0500 | [diff] [blame] | 50 | static int omap_xhci_core_init(struct omap_xhci *omap) |
| 51 | { |
| 52 | int ret = 0; |
| 53 | |
Felipe Balbi | 26707d9 | 2014-06-23 16:25:38 -0500 | [diff] [blame] | 54 | usb_phy_power(1); |
Dan Murphy | 834e91a | 2013-10-11 12:28:17 -0500 | [diff] [blame] | 55 | omap_enable_phy(omap); |
Dan Murphy | 2d2358a | 2013-08-26 08:54:52 -0500 | [diff] [blame] | 56 | |
| 57 | ret = dwc3_core_init(omap->dwc3_reg); |
| 58 | if (ret) { |
| 59 | debug("%s:failed to initialize core\n", __func__); |
| 60 | return ret; |
| 61 | } |
| 62 | |
| 63 | /* We are hard-coding DWC3 core to Host Mode */ |
| 64 | dwc3_set_mode(omap->dwc3_reg, DWC3_GCTL_PRTCAP_HOST); |
| 65 | |
| 66 | return ret; |
| 67 | } |
| 68 | |
| 69 | static void omap_xhci_core_exit(struct omap_xhci *omap) |
| 70 | { |
Dan Murphy | 834e91a | 2013-10-11 12:28:17 -0500 | [diff] [blame] | 71 | usb_phy_power(0); |
Dan Murphy | 2d2358a | 2013-08-26 08:54:52 -0500 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | int xhci_hcd_init(int index, struct xhci_hccr **hccr, struct xhci_hcor **hcor) |
| 75 | { |
| 76 | struct omap_xhci *ctx = &omap; |
| 77 | int ret = 0; |
| 78 | |
| 79 | ctx->hcd = (struct xhci_hccr *)OMAP_XHCI_BASE; |
| 80 | ctx->dwc3_reg = (struct dwc3 *)((char *)(ctx->hcd) + DWC3_REG_OFFSET); |
| 81 | ctx->usb3_phy = (struct omap_usb3_phy *)OMAP_OCP1_SCP_BASE; |
| 82 | ctx->otg_wrapper = (struct omap_dwc_wrapper *)OMAP_OTG_WRAPPER_BASE; |
| 83 | |
Dan Murphy | b216821 | 2013-10-11 12:28:15 -0500 | [diff] [blame] | 84 | ret = board_usb_init(index, USB_INIT_HOST); |
Dan Murphy | 2d2358a | 2013-08-26 08:54:52 -0500 | [diff] [blame] | 85 | if (ret != 0) { |
| 86 | puts("Failed to initialize board for USB\n"); |
| 87 | return ret; |
| 88 | } |
| 89 | |
| 90 | ret = omap_xhci_core_init(ctx); |
| 91 | if (ret < 0) { |
| 92 | puts("Failed to initialize xhci\n"); |
| 93 | return ret; |
| 94 | } |
| 95 | |
| 96 | *hccr = (struct xhci_hccr *)(OMAP_XHCI_BASE); |
| 97 | *hcor = (struct xhci_hcor *)((uint32_t) *hccr |
| 98 | + HC_LENGTH(xhci_readl(&(*hccr)->cr_capbase))); |
| 99 | |
| 100 | debug("omap-xhci: init hccr %x and hcor %x hc_length %d\n", |
| 101 | (uint32_t)*hccr, (uint32_t)*hcor, |
| 102 | (uint32_t)HC_LENGTH(xhci_readl(&(*hccr)->cr_capbase))); |
| 103 | |
| 104 | return ret; |
| 105 | } |
| 106 | |
| 107 | void xhci_hcd_stop(int index) |
| 108 | { |
| 109 | struct omap_xhci *ctx = &omap; |
| 110 | |
| 111 | omap_xhci_core_exit(ctx); |
Kishon Vijay Abraham I | f181144 | 2015-08-19 13:49:47 +0530 | [diff] [blame] | 112 | board_usb_cleanup(index, USB_INIT_HOST); |
Dan Murphy | 2d2358a | 2013-08-26 08:54:52 -0500 | [diff] [blame] | 113 | } |