From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 22CDBCCF9E9 for ; Thu, 26 Sep 2024 08:06:49 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 08F7B88D7C; Thu, 26 Sep 2024 10:03:00 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=9elements.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; secure) header.d=9elements.com header.i=@9elements.com header.b="Oude+TTB"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A61FB88DB8; Thu, 26 Sep 2024 10:02:58 +0200 (CEST) Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [IPv6:2a00:1450:4864:20::52b]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id B8D2788D55 for ; Thu, 26 Sep 2024 10:02:49 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=9elements.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=patrick.rudolph@9elements.com Received: by mail-ed1-x52b.google.com with SMTP id 4fb4d7f45d1cf-5c46680a71bso728926a12.2 for ; Thu, 26 Sep 2024 01:02:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=9elements.com; s=google; t=1727337769; x=1727942569; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=t0TfdAnaRsRvzq36BQ8UIf5Ol+QdbW4GC/e/Uh2O1mo=; b=Oude+TTBu+VVsKKZ+YN4/Fh4/rlRbhuKDgP+gAMBbR/PclOqn4NuBHlOTryxN9IOry +KBoYDQLmtXIe3t8+7jsmqYkLt5bqkslCwNGOCJHyciS59ZPsV9siLq4yRmshIOSXI4N OJCrRwy6WDZcZfBRzBP2PNwXfwVdOp0fggaDjokNMpdOfCZTQKOu2esye7tQaXWrkKbU TA6sTVDEaDdViwMa9RS0kJGhbrUC7AZ1yDdNTlfaUK9dKR2t9XHpxSqhg9rL+C4XNu1F tvYms1qbrun049Jt1eUxdvVVyEtG4/4Xd6OD6Q2hDyKLnLGZHWv4UwlmFvV8rtnspMWw HTuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727337769; x=1727942569; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=t0TfdAnaRsRvzq36BQ8UIf5Ol+QdbW4GC/e/Uh2O1mo=; b=dccmngcyrhQBWoeRKtzmmi1rXXw4ugSDq637c88rG4LtUzY7cYHqV/As1JoFN1kBK+ +UE5dJjHAUdbN1WlkCPKkqgymqdIyeAedR5usHpvWkpY0FgwUnnDDVNj67CVZEi6ZaYt Vg0bYmQmZeFd8zH+8xq5l6IXkcX4CVnYxfCOVTyukIbCP75uec3QxDlWBY1FhdMt/xBr w3Wmu5MBBZAts8H5B6cY6FdXhf9A1A0ylk5WPU5clwBUfohQh9Y8ypDDxJS+M3E29dEU oJ/jxTbZVHAet4r8eGC2FIFdxJw2jEhs6sV59DXOv1n/fSwN2m4HthmRAKMcvQTGpfWj 42aw== X-Gm-Message-State: AOJu0YwuvSWDdWb9wWcsnbjsO4KmCMcU629IqyEWAzD2T+KElhd0aGhp MTQDps8HpOCU3k+R00ANaisCclYLkyEjBffdaE5fj2dMe4MbSN6dkWRorOhpKizKFdDtjDsdq2w D X-Google-Smtp-Source: AGHT+IHJcFYjCZZvblFKUzfEgtsEo/cRniiX83QRUZpqX3QtwFWyom4Qw3Tt00r2JoIBEMK+KdbIAg== X-Received: by 2002:a05:6402:3486:b0:5c4:ad0:c941 with SMTP id 4fb4d7f45d1cf-5c72060943emr4192238a12.7.1727337769121; Thu, 26 Sep 2024 01:02:49 -0700 (PDT) Received: from fedora.sec.9e.network (ip-037-049-067-221.um09.pools.vodafone-ip.de. [37.49.67.221]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c5cf4c4fe3sm2822449a12.68.2024.09.26.01.02.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Sep 2024 01:02:48 -0700 (PDT) From: Patrick Rudolph To: u-boot@lists.denx.de, Bin Meng Cc: Patrick Rudolph , Marek Vasut , Tom Rini Subject: [PATCH v5 16/36] drivers: usb: Add generic XHCI Date: Thu, 26 Sep 2024 09:59:04 +0200 Message-ID: <20240926080021.148031-17-patrick.rudolph@9elements.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240926080021.148031-1-patrick.rudolph@9elements.com> References: <20240926080021.148031-1-patrick.rudolph@9elements.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Add support for the generic XHCI driver that contains no SoC specific code. It can be used on platforms that simply work out of the box, like on emulated platforms. TEST: Booted on QEMU sbsa machine using the generic xhci driver. Signed-off-by: Patrick Rudolph Reviewed-by: Marek Vasut Cc: Tom Rini Cc: Marek Vasut --- Changelog v3: - Drop weak board_xhci_enable() Changelog v4: - Use dev_dbg() instead of debug() --- drivers/usb/host/Kconfig | 8 ++++ drivers/usb/host/Makefile | 1 + drivers/usb/host/xhci-generic.c | 77 +++++++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+) create mode 100644 drivers/usb/host/xhci-generic.c diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig index 6e10b629a3..bb5893d56d 100644 --- a/drivers/usb/host/Kconfig +++ b/drivers/usb/host/Kconfig @@ -68,6 +68,14 @@ config USB_XHCI_MVEBU SoCs, which includes Armada8K, Armada3700 and other Armada family SoCs. +config USB_XHCI_GENERIC + bool "Generic SoC USB 3.0 support" + depends on OF_CONTROL + default n + help + Choose this option to add support for USB 3.0 driver for SoCs + that do not need platform specific code, like on emulated targets. + config USB_XHCI_OCTEON bool "Support for Marvell Octeon family on-chip xHCI USB controller" depends on ARCH_OCTEON diff --git a/drivers/usb/host/Makefile b/drivers/usb/host/Makefile index 8dad36f936..9e880195ec 100644 --- a/drivers/usb/host/Makefile +++ b/drivers/usb/host/Makefile @@ -50,6 +50,7 @@ obj-$(CONFIG_USB_XHCI_EXYNOS) += xhci-exynos5.o obj-$(CONFIG_USB_XHCI_FSL) += xhci-fsl.o obj-$(CONFIG_USB_XHCI_MTK) += xhci-mtk.o obj-$(CONFIG_USB_XHCI_MVEBU) += xhci-mvebu.o +obj-$(CONFIG_USB_XHCI_GENERIC) += xhci-generic.o obj-$(CONFIG_USB_XHCI_OMAP) += xhci-omap.o obj-$(CONFIG_USB_XHCI_PCI) += xhci-pci.o obj-$(CONFIG_USB_XHCI_RCAR) += xhci-rcar.o diff --git a/drivers/usb/host/xhci-generic.c b/drivers/usb/host/xhci-generic.c new file mode 100644 index 0000000000..5131f37991 --- /dev/null +++ b/drivers/usb/host/xhci-generic.c @@ -0,0 +1,77 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2024 9elements GmbH + * + * GENERIC USB HOST xHCI Controller + */ + +#include +#include +#include +#include +#include +#include + +#include + +struct generic_xhci_plat { + fdt_addr_t hcd_base; +}; + +/** + * Contains pointers to register base addresses + * for the usb controller. + */ +struct generic_xhci { + struct xhci_ctrl ctrl; /* Needs to come first in this struct! */ + struct usb_plat usb_plat; + struct xhci_hccr *hcd; +}; + +static int xhci_usb_probe(struct udevice *dev) +{ + struct generic_xhci_plat *plat = dev_get_plat(dev); + struct generic_xhci *ctx = dev_get_priv(dev); + struct xhci_hcor *hcor; + int len; + + ctx->hcd = (struct xhci_hccr *)phys_to_virt(plat->hcd_base); + len = HC_LENGTH(xhci_readl(&ctx->hcd->cr_capbase)); + hcor = (struct xhci_hcor *)((uintptr_t)ctx->hcd + len); + + return xhci_register(dev, ctx->hcd, hcor); +} + +static int xhci_usb_of_to_plat(struct udevice *dev) +{ + struct generic_xhci_plat *plat = dev_get_plat(dev); + + /* + * Get the base address for XHCI controller from the device node + */ + plat->hcd_base = dev_read_addr(dev); + if (plat->hcd_base == FDT_ADDR_T_NONE) { + dev_dbg(dev, "Can't get the XHCI register base address\n"); + return -ENXIO; + } + + return 0; +} + +static const struct udevice_id xhci_usb_ids[] = { + { .compatible = "generic-xhci" }, + { } +}; + +U_BOOT_DRIVER(usb_xhci) = { + .name = "xhci_generic", + .id = UCLASS_USB, + .of_match = xhci_usb_ids, + .of_to_plat = xhci_usb_of_to_plat, + .probe = xhci_usb_probe, + .remove = xhci_deregister, + .ops = &xhci_usb_ops, + .plat_auto = sizeof(struct generic_xhci_plat), + .priv_auto = sizeof(struct generic_xhci), + .flags = DM_FLAG_ALLOC_PRIV_DMA, +}; -- 2.46.0