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 | |
Stefan Roese | 07faf11 | 2016-07-14 11:39:20 +0200 | [diff] [blame] | 8 | #include <dm.h> |
| 9 | #include <fdtdec.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 10 | #include <log.h> |
Stefan Roese | 07faf11 | 2016-07-14 11:39:20 +0200 | [diff] [blame] | 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 | |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 17 | struct mvebu_xhci_plat { |
Stefan Roese | 07faf11 | 2016-07-14 11:39:20 +0200 | [diff] [blame] | 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! */ |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 27 | struct usb_plat usb_plat; |
Stefan Roese | 07faf11 | 2016-07-14 11:39:20 +0200 | [diff] [blame] | 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 | { |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 42 | struct mvebu_xhci_plat *plat = dev_get_plat(dev); |
Stefan Roese | 07faf11 | 2016-07-14 11:39:20 +0200 | [diff] [blame] | 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 | |
Simon Glass | aad29ae | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 67 | static int xhci_usb_of_to_plat(struct udevice *dev) |
Stefan Roese | 07faf11 | 2016-07-14 11:39:20 +0200 | [diff] [blame] | 68 | { |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 69 | struct mvebu_xhci_plat *plat = dev_get_plat(dev); |
Stefan Roese | 07faf11 | 2016-07-14 11:39:20 +0200 | [diff] [blame] | 70 | |
| 71 | /* |
| 72 | * Get the base address for XHCI controller from the device node |
| 73 | */ |
Masahiro Yamada | a89b4de | 2020-07-17 14:36:48 +0900 | [diff] [blame] | 74 | plat->hcd_base = dev_read_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, |
Simon Glass | aad29ae | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 94 | .of_to_plat = xhci_usb_of_to_plat, |
Stefan Roese | 07faf11 | 2016-07-14 11:39:20 +0200 | [diff] [blame] | 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, |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 98 | .plat_auto = sizeof(struct mvebu_xhci_plat), |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 99 | .priv_auto = sizeof(struct mvebu_xhci), |
Stefan Roese | 07faf11 | 2016-07-14 11:39:20 +0200 | [diff] [blame] | 100 | .flags = DM_FLAG_ALLOC_PRIV_DMA, |
| 101 | }; |