Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Stefan Roese | 07faf11 | 2016-07-14 11:39:20 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2015 Marvell International Ltd. |
| 4 | * |
| 5 | * MVEBU USB HOST xHCI Controller |
Stefan Roese | 07faf11 | 2016-07-14 11:39:20 +0200 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
| 9 | #include <dm.h> |
| 10 | #include <fdtdec.h> |
| 11 | #include <usb.h> |
Konstantin Porotchkin | 1b5ed4d | 2017-02-12 11:10:30 +0200 | [diff] [blame] | 12 | #include <power/regulator.h> |
Stefan Roese | 07faf11 | 2016-07-14 11:39:20 +0200 | [diff] [blame] | 13 | #include <asm/gpio.h> |
| 14 | |
Jean-Jacques Hiblot | ad4142b | 2019-09-11 11:33:46 +0200 | [diff] [blame] | 15 | #include <usb/xhci.h> |
Stefan Roese | 07faf11 | 2016-07-14 11:39:20 +0200 | [diff] [blame] | 16 | |
Stefan Roese | 07faf11 | 2016-07-14 11:39:20 +0200 | [diff] [blame] | 17 | struct mvebu_xhci_platdata { |
| 18 | fdt_addr_t hcd_base; |
| 19 | }; |
| 20 | |
| 21 | /** |
| 22 | * Contains pointers to register base addresses |
| 23 | * for the usb controller. |
| 24 | */ |
| 25 | struct mvebu_xhci { |
| 26 | struct xhci_ctrl ctrl; /* Needs to come first in this struct! */ |
| 27 | struct usb_platdata usb_plat; |
| 28 | struct xhci_hccr *hcd; |
| 29 | }; |
| 30 | |
| 31 | /* |
| 32 | * Dummy implementation that can be overwritten by a board |
| 33 | * specific function |
| 34 | */ |
Jon Nettleton | a81f47c | 2017-11-06 10:33:19 +0200 | [diff] [blame] | 35 | __weak int board_xhci_enable(fdt_addr_t base) |
Stefan Roese | 07faf11 | 2016-07-14 11:39:20 +0200 | [diff] [blame] | 36 | { |
| 37 | return 0; |
| 38 | } |
| 39 | |
| 40 | static int xhci_usb_probe(struct udevice *dev) |
| 41 | { |
| 42 | struct mvebu_xhci_platdata *plat = dev_get_platdata(dev); |
| 43 | struct mvebu_xhci *ctx = dev_get_priv(dev); |
| 44 | struct xhci_hcor *hcor; |
Konstantin Porotchkin | 1b5ed4d | 2017-02-12 11:10:30 +0200 | [diff] [blame] | 45 | int len, ret; |
| 46 | struct udevice *regulator; |
Stefan Roese | 07faf11 | 2016-07-14 11:39:20 +0200 | [diff] [blame] | 47 | |
| 48 | ctx->hcd = (struct xhci_hccr *)plat->hcd_base; |
| 49 | len = HC_LENGTH(xhci_readl(&ctx->hcd->cr_capbase)); |
| 50 | hcor = (struct xhci_hcor *)((uintptr_t)ctx->hcd + len); |
| 51 | |
Konstantin Porotchkin | 1b5ed4d | 2017-02-12 11:10:30 +0200 | [diff] [blame] | 52 | ret = device_get_supply_regulator(dev, "vbus-supply", ®ulator); |
| 53 | if (!ret) { |
| 54 | ret = regulator_set_enable(regulator, true); |
| 55 | if (ret) { |
| 56 | printf("Failed to turn ON the VBUS regulator\n"); |
| 57 | return ret; |
| 58 | } |
| 59 | } |
| 60 | |
Stefan Roese | 07faf11 | 2016-07-14 11:39:20 +0200 | [diff] [blame] | 61 | /* Enable USB xHCI (VBUS, reset etc) in board specific code */ |
Jon Nettleton | a81f47c | 2017-11-06 10:33:19 +0200 | [diff] [blame] | 62 | board_xhci_enable(devfdt_get_addr_index(dev, 1)); |
Stefan Roese | 07faf11 | 2016-07-14 11:39:20 +0200 | [diff] [blame] | 63 | |
| 64 | return xhci_register(dev, ctx->hcd, hcor); |
| 65 | } |
| 66 | |
Stefan Roese | 07faf11 | 2016-07-14 11:39:20 +0200 | [diff] [blame] | 67 | static int xhci_usb_ofdata_to_platdata(struct udevice *dev) |
| 68 | { |
| 69 | struct mvebu_xhci_platdata *plat = dev_get_platdata(dev); |
| 70 | |
| 71 | /* |
| 72 | * Get the base address for XHCI controller from the device node |
| 73 | */ |
Simon Glass | ba1dea4 | 2017-05-17 17:18:05 -0600 | [diff] [blame] | 74 | plat->hcd_base = devfdt_get_addr(dev); |
Stefan Roese | 07faf11 | 2016-07-14 11:39:20 +0200 | [diff] [blame] | 75 | if (plat->hcd_base == FDT_ADDR_T_NONE) { |
| 76 | debug("Can't get the XHCI register base address\n"); |
| 77 | return -ENXIO; |
| 78 | } |
| 79 | |
| 80 | return 0; |
| 81 | } |
| 82 | |
| 83 | static const struct udevice_id xhci_usb_ids[] = { |
| 84 | { .compatible = "marvell,armada3700-xhci" }, |
Jon Nettleton | a81f47c | 2017-11-06 10:33:19 +0200 | [diff] [blame] | 85 | { .compatible = "marvell,armada-380-xhci" }, |
Stefan Roese | 755e3f5 | 2016-08-31 06:48:56 +0200 | [diff] [blame] | 86 | { .compatible = "marvell,armada-8k-xhci" }, |
Stefan Roese | 07faf11 | 2016-07-14 11:39:20 +0200 | [diff] [blame] | 87 | { } |
| 88 | }; |
| 89 | |
| 90 | U_BOOT_DRIVER(usb_xhci) = { |
| 91 | .name = "xhci_mvebu", |
| 92 | .id = UCLASS_USB, |
| 93 | .of_match = xhci_usb_ids, |
| 94 | .ofdata_to_platdata = xhci_usb_ofdata_to_platdata, |
| 95 | .probe = xhci_usb_probe, |
Masahiro Yamada | 91b09aa | 2016-10-14 10:30:01 +0900 | [diff] [blame] | 96 | .remove = xhci_deregister, |
Stefan Roese | 07faf11 | 2016-07-14 11:39:20 +0200 | [diff] [blame] | 97 | .ops = &xhci_usb_ops, |
| 98 | .platdata_auto_alloc_size = sizeof(struct mvebu_xhci_platdata), |
| 99 | .priv_auto_alloc_size = sizeof(struct mvebu_xhci), |
| 100 | .flags = DM_FLAG_ALLOC_PRIV_DMA, |
| 101 | }; |