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