1 /* 2 * Copyright (C) 2015 Marvell International Ltd. 3 * 4 * MVEBU USB HOST xHCI Controller 5 * 6 * SPDX-License-Identifier: GPL-2.0+ 7 */ 8 9 #include <common.h> 10 #include <dm.h> 11 #include <fdtdec.h> 12 #include <usb.h> 13 #include <asm/gpio.h> 14 15 #include "xhci.h" 16 17 DECLARE_GLOBAL_DATA_PTR; 18 19 struct mvebu_xhci_platdata { 20 fdt_addr_t hcd_base; 21 }; 22 23 /** 24 * Contains pointers to register base addresses 25 * for the usb controller. 26 */ 27 struct mvebu_xhci { 28 struct xhci_ctrl ctrl; /* Needs to come first in this struct! */ 29 struct usb_platdata usb_plat; 30 struct xhci_hccr *hcd; 31 }; 32 33 /* 34 * Dummy implementation that can be overwritten by a board 35 * specific function 36 */ 37 __weak int board_xhci_enable(void) 38 { 39 return 0; 40 } 41 42 static int xhci_usb_probe(struct udevice *dev) 43 { 44 struct mvebu_xhci_platdata *plat = dev_get_platdata(dev); 45 struct mvebu_xhci *ctx = dev_get_priv(dev); 46 struct xhci_hcor *hcor; 47 int len; 48 49 ctx->hcd = (struct xhci_hccr *)plat->hcd_base; 50 len = HC_LENGTH(xhci_readl(&ctx->hcd->cr_capbase)); 51 hcor = (struct xhci_hcor *)((uintptr_t)ctx->hcd + len); 52 53 /* Enable USB xHCI (VBUS, reset etc) in board specific code */ 54 board_xhci_enable(); 55 56 return xhci_register(dev, ctx->hcd, hcor); 57 } 58 59 static int xhci_usb_ofdata_to_platdata(struct udevice *dev) 60 { 61 struct mvebu_xhci_platdata *plat = dev_get_platdata(dev); 62 63 /* 64 * Get the base address for XHCI controller from the device node 65 */ 66 plat->hcd_base = dev_get_addr(dev); 67 if (plat->hcd_base == FDT_ADDR_T_NONE) { 68 debug("Can't get the XHCI register base address\n"); 69 return -ENXIO; 70 } 71 72 return 0; 73 } 74 75 static const struct udevice_id xhci_usb_ids[] = { 76 { .compatible = "marvell,armada3700-xhci" }, 77 { .compatible = "marvell,armada-8k-xhci" }, 78 { } 79 }; 80 81 U_BOOT_DRIVER(usb_xhci) = { 82 .name = "xhci_mvebu", 83 .id = UCLASS_USB, 84 .of_match = xhci_usb_ids, 85 .ofdata_to_platdata = xhci_usb_ofdata_to_platdata, 86 .probe = xhci_usb_probe, 87 .remove = xhci_deregister, 88 .ops = &xhci_usb_ops, 89 .platdata_auto_alloc_size = sizeof(struct mvebu_xhci_platdata), 90 .priv_auto_alloc_size = sizeof(struct mvebu_xhci), 91 .flags = DM_FLAG_ALLOC_PRIV_DMA, 92 }; 93