2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2016-07-14 09:39:20 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2015 Marvell International Ltd.
|
|
|
|
*
|
|
|
|
* MVEBU USB HOST xHCI Controller
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <dm.h>
|
|
|
|
#include <fdtdec.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2016-07-14 09:39:20 +00:00
|
|
|
#include <usb.h>
|
2017-02-12 09:10:30 +00:00
|
|
|
#include <power/regulator.h>
|
2016-07-14 09:39:20 +00:00
|
|
|
#include <asm/gpio.h>
|
|
|
|
|
2019-09-11 09:33:46 +00:00
|
|
|
#include <usb/xhci.h>
|
2016-07-14 09:39:20 +00:00
|
|
|
|
|
|
|
struct mvebu_xhci_platdata {
|
|
|
|
fdt_addr_t hcd_base;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Contains pointers to register base addresses
|
|
|
|
* for the usb controller.
|
|
|
|
*/
|
|
|
|
struct mvebu_xhci {
|
|
|
|
struct xhci_ctrl ctrl; /* Needs to come first in this struct! */
|
|
|
|
struct usb_platdata usb_plat;
|
|
|
|
struct xhci_hccr *hcd;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Dummy implementation that can be overwritten by a board
|
|
|
|
* specific function
|
|
|
|
*/
|
2017-11-06 08:33:19 +00:00
|
|
|
__weak int board_xhci_enable(fdt_addr_t base)
|
2016-07-14 09:39:20 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int xhci_usb_probe(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct mvebu_xhci_platdata *plat = dev_get_platdata(dev);
|
|
|
|
struct mvebu_xhci *ctx = dev_get_priv(dev);
|
|
|
|
struct xhci_hcor *hcor;
|
2017-02-12 09:10:30 +00:00
|
|
|
int len, ret;
|
|
|
|
struct udevice *regulator;
|
2016-07-14 09:39:20 +00:00
|
|
|
|
|
|
|
ctx->hcd = (struct xhci_hccr *)plat->hcd_base;
|
|
|
|
len = HC_LENGTH(xhci_readl(&ctx->hcd->cr_capbase));
|
|
|
|
hcor = (struct xhci_hcor *)((uintptr_t)ctx->hcd + len);
|
|
|
|
|
2017-02-12 09:10:30 +00:00
|
|
|
ret = device_get_supply_regulator(dev, "vbus-supply", ®ulator);
|
|
|
|
if (!ret) {
|
|
|
|
ret = regulator_set_enable(regulator, true);
|
|
|
|
if (ret) {
|
|
|
|
printf("Failed to turn ON the VBUS regulator\n");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-14 09:39:20 +00:00
|
|
|
/* Enable USB xHCI (VBUS, reset etc) in board specific code */
|
2017-11-06 08:33:19 +00:00
|
|
|
board_xhci_enable(devfdt_get_addr_index(dev, 1));
|
2016-07-14 09:39:20 +00:00
|
|
|
|
|
|
|
return xhci_register(dev, ctx->hcd, hcor);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int xhci_usb_ofdata_to_platdata(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct mvebu_xhci_platdata *plat = dev_get_platdata(dev);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the base address for XHCI controller from the device node
|
|
|
|
*/
|
2020-07-17 05:36:48 +00:00
|
|
|
plat->hcd_base = dev_read_addr(dev);
|
2016-07-14 09:39:20 +00:00
|
|
|
if (plat->hcd_base == FDT_ADDR_T_NONE) {
|
|
|
|
debug("Can't get the XHCI register base address\n");
|
|
|
|
return -ENXIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct udevice_id xhci_usb_ids[] = {
|
|
|
|
{ .compatible = "marvell,armada3700-xhci" },
|
2017-11-06 08:33:19 +00:00
|
|
|
{ .compatible = "marvell,armada-380-xhci" },
|
2016-08-31 04:48:56 +00:00
|
|
|
{ .compatible = "marvell,armada-8k-xhci" },
|
2016-07-14 09:39:20 +00:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(usb_xhci) = {
|
|
|
|
.name = "xhci_mvebu",
|
|
|
|
.id = UCLASS_USB,
|
|
|
|
.of_match = xhci_usb_ids,
|
|
|
|
.ofdata_to_platdata = xhci_usb_ofdata_to_platdata,
|
|
|
|
.probe = xhci_usb_probe,
|
2016-10-14 01:30:01 +00:00
|
|
|
.remove = xhci_deregister,
|
2016-07-14 09:39:20 +00:00
|
|
|
.ops = &xhci_usb_ops,
|
2020-12-03 23:55:18 +00:00
|
|
|
.plat_auto = sizeof(struct mvebu_xhci_platdata),
|
2020-12-03 23:55:17 +00:00
|
|
|
.priv_auto = sizeof(struct mvebu_xhci),
|
2016-07-14 09:39:20 +00:00
|
|
|
.flags = DM_FLAG_ALLOC_PRIV_DMA,
|
|
|
|
};
|