]> git.ipfire.org Git - thirdparty/u-boot.git/blame - drivers/usb/host/xhci-mvebu.c
Revert "Merge patch series "arm: dts: am62-beagleplay: Fix Beagleplay Ethernet""
[thirdparty/u-boot.git] / drivers / usb / host / xhci-mvebu.c
CommitLineData
83d290c5 1// SPDX-License-Identifier: GPL-2.0+
81c1f6f0
SR
2/*
3 * Copyright (C) 2015 Marvell International Ltd.
4 *
5 * MVEBU USB HOST xHCI Controller
81c1f6f0
SR
6 */
7
d678a59d 8#include <common.h>
81c1f6f0
SR
9#include <dm.h>
10#include <fdtdec.h>
f7ae49fc 11#include <log.h>
81c1f6f0 12#include <usb.h>
81192b79 13#include <power/regulator.h>
81c1f6f0
SR
14#include <asm/gpio.h>
15
1708a123 16#include <usb/xhci.h>
81c1f6f0 17
8a8d24bd 18struct mvebu_xhci_plat {
81c1f6f0
SR
19 fdt_addr_t hcd_base;
20};
21
22/**
23 * Contains pointers to register base addresses
24 * for the usb controller.
25 */
26struct mvebu_xhci {
27 struct xhci_ctrl ctrl; /* Needs to come first in this struct! */
8a8d24bd 28 struct usb_plat usb_plat;
81c1f6f0
SR
29 struct xhci_hccr *hcd;
30};
31
32/*
33 * Dummy implementation that can be overwritten by a board
34 * specific function
35 */
d3d036af 36__weak int board_xhci_enable(fdt_addr_t base)
81c1f6f0
SR
37{
38 return 0;
39}
40
41static int xhci_usb_probe(struct udevice *dev)
42{
8a8d24bd 43 struct mvebu_xhci_plat *plat = dev_get_plat(dev);
81c1f6f0
SR
44 struct mvebu_xhci *ctx = dev_get_priv(dev);
45 struct xhci_hcor *hcor;
81192b79
KP
46 int len, ret;
47 struct udevice *regulator;
81c1f6f0
SR
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
81192b79
KP
53 ret = device_get_supply_regulator(dev, "vbus-supply", &regulator);
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
81c1f6f0 62 /* Enable USB xHCI (VBUS, reset etc) in board specific code */
d3d036af 63 board_xhci_enable(devfdt_get_addr_index(dev, 1));
81c1f6f0
SR
64
65 return xhci_register(dev, ctx->hcd, hcor);
66}
67
d1998a9f 68static int xhci_usb_of_to_plat(struct udevice *dev)
81c1f6f0 69{
8a8d24bd 70 struct mvebu_xhci_plat *plat = dev_get_plat(dev);
81c1f6f0
SR
71
72 /*
73 * Get the base address for XHCI controller from the device node
74 */
2548493a 75 plat->hcd_base = dev_read_addr(dev);
81c1f6f0
SR
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
84static const struct udevice_id xhci_usb_ids[] = {
85 { .compatible = "marvell,armada3700-xhci" },
d3d036af 86 { .compatible = "marvell,armada-380-xhci" },
d36277ef 87 { .compatible = "marvell,armada-8k-xhci" },
81c1f6f0
SR
88 { }
89};
90
91U_BOOT_DRIVER(usb_xhci) = {
92 .name = "xhci_mvebu",
93 .id = UCLASS_USB,
94 .of_match = xhci_usb_ids,
d1998a9f 95 .of_to_plat = xhci_usb_of_to_plat,
81c1f6f0 96 .probe = xhci_usb_probe,
9eea45f5 97 .remove = xhci_deregister,
81c1f6f0 98 .ops = &xhci_usb_ops,
8a8d24bd 99 .plat_auto = sizeof(struct mvebu_xhci_plat),
41575d8e 100 .priv_auto = sizeof(struct mvebu_xhci),
81c1f6f0
SR
101 .flags = DM_FLAG_ALLOC_PRIV_DMA,
102};