xref: /rk3399_rockchip-uboot/drivers/usb/host/xhci-omap.c (revision 1a4f6af8bfd44c8ae6e87a81ff125eed47042cc5)
12d2358acSDan Murphy /*
22d2358acSDan Murphy  * OMAP USB HOST xHCI Controller
32d2358acSDan Murphy  *
42d2358acSDan Murphy  * (C) Copyright 2013
52d2358acSDan Murphy  * Texas Instruments, <www.ti.com>
62d2358acSDan Murphy  *
72d2358acSDan Murphy  * Author: Dan Murphy <dmurphy@ti.com>
82d2358acSDan Murphy  *
92d2358acSDan Murphy  * SPDX-License-Identifier:	GPL-2.0+
102d2358acSDan Murphy  */
112d2358acSDan Murphy 
122d2358acSDan Murphy #include <common.h>
132d2358acSDan Murphy #include <usb.h>
145d97dff0SMasahiro Yamada #include <linux/errno.h>
152d2358acSDan Murphy #include <asm/omap_common.h>
162d2358acSDan Murphy #include <asm/arch/cpu.h>
172d2358acSDan Murphy #include <asm/arch/sys_proto.h>
182d2358acSDan Murphy 
192d2358acSDan Murphy #include <linux/compat.h>
202d2358acSDan Murphy #include <linux/usb/dwc3.h>
2141b667b8SDan Murphy #include <linux/usb/xhci-omap.h>
222d2358acSDan Murphy 
23*143fc13bSJean-Jacques Hiblot #include <usb/xhci.h>
242d2358acSDan Murphy 
252d2358acSDan Murphy /* Declare global data pointer */
262d2358acSDan Murphy DECLARE_GLOBAL_DATA_PTR;
272d2358acSDan Murphy 
282d2358acSDan Murphy static struct omap_xhci omap;
292d2358acSDan Murphy 
omap_xhci_core_init(struct omap_xhci * omap)302d2358acSDan Murphy static int omap_xhci_core_init(struct omap_xhci *omap)
312d2358acSDan Murphy {
322d2358acSDan Murphy 	int ret = 0;
332d2358acSDan Murphy 
3426707d9eSFelipe Balbi 	usb_phy_power(1);
35834e91afSDan Murphy 	omap_enable_phy(omap);
362d2358acSDan Murphy 
372d2358acSDan Murphy 	ret = dwc3_core_init(omap->dwc3_reg);
382d2358acSDan Murphy 	if (ret) {
392d2358acSDan Murphy 		debug("%s:failed to initialize core\n", __func__);
402d2358acSDan Murphy 		return ret;
412d2358acSDan Murphy 	}
422d2358acSDan Murphy 
432d2358acSDan Murphy 	/* We are hard-coding DWC3 core to Host Mode */
442d2358acSDan Murphy 	dwc3_set_mode(omap->dwc3_reg, DWC3_GCTL_PRTCAP_HOST);
452d2358acSDan Murphy 
462d2358acSDan Murphy 	return ret;
472d2358acSDan Murphy }
482d2358acSDan Murphy 
omap_xhci_core_exit(struct omap_xhci * omap)492d2358acSDan Murphy static void omap_xhci_core_exit(struct omap_xhci *omap)
502d2358acSDan Murphy {
51834e91afSDan Murphy 	usb_phy_power(0);
522d2358acSDan Murphy }
532d2358acSDan Murphy 
xhci_hcd_init(int index,struct xhci_hccr ** hccr,struct xhci_hcor ** hcor)542d2358acSDan Murphy int xhci_hcd_init(int index, struct xhci_hccr **hccr, struct xhci_hcor **hcor)
552d2358acSDan Murphy {
562d2358acSDan Murphy 	struct omap_xhci *ctx = &omap;
572d2358acSDan Murphy 	int ret = 0;
582d2358acSDan Murphy 
592d2358acSDan Murphy 	ctx->hcd = (struct xhci_hccr *)OMAP_XHCI_BASE;
602d2358acSDan Murphy 	ctx->dwc3_reg = (struct dwc3 *)((char *)(ctx->hcd) + DWC3_REG_OFFSET);
612d2358acSDan Murphy 	ctx->usb3_phy = (struct omap_usb3_phy *)OMAP_OCP1_SCP_BASE;
622d2358acSDan Murphy 	ctx->otg_wrapper = (struct omap_dwc_wrapper *)OMAP_OTG_WRAPPER_BASE;
632d2358acSDan Murphy 
64b2168211SDan Murphy 	ret = board_usb_init(index, USB_INIT_HOST);
652d2358acSDan Murphy 	if (ret != 0) {
662d2358acSDan Murphy 		puts("Failed to initialize board for USB\n");
672d2358acSDan Murphy 		return ret;
682d2358acSDan Murphy 	}
692d2358acSDan Murphy 
702d2358acSDan Murphy 	ret = omap_xhci_core_init(ctx);
712d2358acSDan Murphy 	if (ret < 0) {
722d2358acSDan Murphy 		puts("Failed to initialize xhci\n");
732d2358acSDan Murphy 		return ret;
742d2358acSDan Murphy 	}
752d2358acSDan Murphy 
762d2358acSDan Murphy 	*hccr = (struct xhci_hccr *)(OMAP_XHCI_BASE);
772d2358acSDan Murphy 	*hcor = (struct xhci_hcor *)((uint32_t) *hccr
782d2358acSDan Murphy 				+ HC_LENGTH(xhci_readl(&(*hccr)->cr_capbase)));
792d2358acSDan Murphy 
802d2358acSDan Murphy 	debug("omap-xhci: init hccr %x and hcor %x hc_length %d\n",
812d2358acSDan Murphy 	      (uint32_t)*hccr, (uint32_t)*hcor,
822d2358acSDan Murphy 	      (uint32_t)HC_LENGTH(xhci_readl(&(*hccr)->cr_capbase)));
832d2358acSDan Murphy 
842d2358acSDan Murphy 	return ret;
852d2358acSDan Murphy }
862d2358acSDan Murphy 
xhci_hcd_stop(int index)872d2358acSDan Murphy void xhci_hcd_stop(int index)
882d2358acSDan Murphy {
892d2358acSDan Murphy 	struct omap_xhci *ctx = &omap;
902d2358acSDan Murphy 
912d2358acSDan Murphy 	omap_xhci_core_exit(ctx);
92f1811443SKishon Vijay Abraham I 	board_usb_cleanup(index, USB_INIT_HOST);
932d2358acSDan Murphy }
94