blob: 46b89de85d1edf84a1c1270226c8890a71728936 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Stefan Roese07faf112016-07-14 11:39:20 +02002/*
3 * Copyright (C) 2015 Marvell International Ltd.
4 *
5 * MVEBU USB HOST xHCI Controller
Stefan Roese07faf112016-07-14 11:39:20 +02006 */
7
Tom Riniabb9a042024-05-18 20:20:43 -06008#include <common.h>
Stefan Roese07faf112016-07-14 11:39:20 +02009#include <dm.h>
10#include <fdtdec.h>
Simon Glass0f2af882020-05-10 11:40:05 -060011#include <log.h>
Stefan Roese07faf112016-07-14 11:39:20 +020012#include <usb.h>
Konstantin Porotchkin1b5ed4d2017-02-12 11:10:30 +020013#include <power/regulator.h>
Stefan Roese07faf112016-07-14 11:39:20 +020014#include <asm/gpio.h>
15
Jean-Jacques Hiblotad4142b2019-09-11 11:33:46 +020016#include <usb/xhci.h>
Stefan Roese07faf112016-07-14 11:39:20 +020017
Simon Glassb75b15b2020-12-03 16:55:23 -070018struct mvebu_xhci_plat {
Stefan Roese07faf112016-07-14 11:39:20 +020019 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! */
Simon Glassb75b15b2020-12-03 16:55:23 -070028 struct usb_plat usb_plat;
Stefan Roese07faf112016-07-14 11:39:20 +020029 struct xhci_hccr *hcd;
30};
31
32/*
33 * Dummy implementation that can be overwritten by a board
34 * specific function
35 */
Jon Nettletona81f47c2017-11-06 10:33:19 +020036__weak int board_xhci_enable(fdt_addr_t base)
Stefan Roese07faf112016-07-14 11:39:20 +020037{
38 return 0;
39}
40
41static int xhci_usb_probe(struct udevice *dev)
42{
Simon Glassb75b15b2020-12-03 16:55:23 -070043 struct mvebu_xhci_plat *plat = dev_get_plat(dev);
Stefan Roese07faf112016-07-14 11:39:20 +020044 struct mvebu_xhci *ctx = dev_get_priv(dev);
45 struct xhci_hcor *hcor;
Konstantin Porotchkin1b5ed4d2017-02-12 11:10:30 +020046 int len, ret;
47 struct udevice *regulator;
Stefan Roese07faf112016-07-14 11:39:20 +020048
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 Porotchkin1b5ed4d2017-02-12 11:10:30 +020053 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
Stefan Roese07faf112016-07-14 11:39:20 +020062 /* Enable USB xHCI (VBUS, reset etc) in board specific code */
Jon Nettletona81f47c2017-11-06 10:33:19 +020063 board_xhci_enable(devfdt_get_addr_index(dev, 1));
Stefan Roese07faf112016-07-14 11:39:20 +020064
65 return xhci_register(dev, ctx->hcd, hcor);
66}
67
Simon Glassaad29ae2020-12-03 16:55:21 -070068static int xhci_usb_of_to_plat(struct udevice *dev)
Stefan Roese07faf112016-07-14 11:39:20 +020069{
Simon Glassb75b15b2020-12-03 16:55:23 -070070 struct mvebu_xhci_plat *plat = dev_get_plat(dev);
Stefan Roese07faf112016-07-14 11:39:20 +020071
72 /*
73 * Get the base address for XHCI controller from the device node
74 */
Masahiro Yamadaa89b4de2020-07-17 14:36:48 +090075 plat->hcd_base = dev_read_addr(dev);
Stefan Roese07faf112016-07-14 11:39:20 +020076 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" },
Jon Nettletona81f47c2017-11-06 10:33:19 +020086 { .compatible = "marvell,armada-380-xhci" },
Stefan Roese755e3f52016-08-31 06:48:56 +020087 { .compatible = "marvell,armada-8k-xhci" },
Stefan Roese07faf112016-07-14 11:39:20 +020088 { }
89};
90
91U_BOOT_DRIVER(usb_xhci) = {
92 .name = "xhci_mvebu",
93 .id = UCLASS_USB,
94 .of_match = xhci_usb_ids,
Simon Glassaad29ae2020-12-03 16:55:21 -070095 .of_to_plat = xhci_usb_of_to_plat,
Stefan Roese07faf112016-07-14 11:39:20 +020096 .probe = xhci_usb_probe,
Masahiro Yamada91b09aa2016-10-14 10:30:01 +090097 .remove = xhci_deregister,
Stefan Roese07faf112016-07-14 11:39:20 +020098 .ops = &xhci_usb_ops,
Simon Glassb75b15b2020-12-03 16:55:23 -070099 .plat_auto = sizeof(struct mvebu_xhci_plat),
Simon Glass8a2b47f2020-12-03 16:55:17 -0700100 .priv_auto = sizeof(struct mvebu_xhci),
Stefan Roese07faf112016-07-14 11:39:20 +0200101 .flags = DM_FLAG_ALLOC_PRIV_DMA,
102};