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 A02C0C02180 for ; Thu, 16 Jan 2025 10:24:39 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 28957801B0; Thu, 16 Jan 2025 11:24:38 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=baylibre.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; unprotected) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="NSUCm3t9"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3F4C38033D; Thu, 16 Jan 2025 11:24:37 +0100 (CET) Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) (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 0A6EE80040 for ; Thu, 16 Jan 2025 11:24:35 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=mkorpershoek@baylibre.com Received: by mail-wr1-x433.google.com with SMTP id ffacd0b85a97d-386329da1d9so395095f8f.1 for ; Thu, 16 Jan 2025 02:24:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1737023074; x=1737627874; darn=lists.denx.de; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:from:to:cc:subject:date:message-id:reply-to; bh=jrbh09noBsgvE3SaF+kxL2mY6exU1v6bOBGXytwzGv4=; b=NSUCm3t9267PA93wtzGqFcIysHqgK5n0QMSXTPIwRE4CO7uWARax/badzfsoehCd26 d+4O9EnLI3B3yg0QjojlWL/j9Rg9bNZLK2HiPPOAgvtsczgUxIV2ON6gLH7vzq1fjYAC xAq485cFiaqcZyIEWeerMaTDPMKhpGGHDxFUWZeKq05WYw0PK5KEsCqI/1eYz5zd+tvj X4k5SDVR9r/BhHBHKxAk27vwsM+/Ei+MTlDLiAlEY8cJkK8k1ZVfXx9loEmCR0mE6Y7A tlrqiieweA6E0Au/DKlmOWcykGOtuHMQFNX66YkuLRUlJtO9lEb/oD5VBCGl2eaRYvnt Zr1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737023074; x=1737627874; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=jrbh09noBsgvE3SaF+kxL2mY6exU1v6bOBGXytwzGv4=; b=LxLYoq9IqwH5CQvSjvrkEhb42PkKym0zjm9mVPgIg8xhQWcKC2PMXz3ZykBMmd2QgF SmWTqYJ1pu0YOnC6kFN6BVJIC2UJEx4CbEeWQbpO/GZzhRdcx55Xc425EqgOx3o5nHGI bbYstVGGkSCJRnTNHVRAD6aveXZqmY3vuJs/DA5Kve48Otc/SEzNODsJZzDqudg54EPJ QbZTSDg2/Nk8ZH9ikjoQpwsun75tJvh4Qgz3qv7ShWGV3w+5CIeCXLOaQm6Daj3fxDXt 68I4NScTicSCkpDlhzeibSTT5ORvog8VXmc07yI1LDfAFgmmvK4sp7zdWdD7NzCY2EQe V05g== X-Forwarded-Encrypted: i=1; AJvYcCW27z8ehGY36DK72kLfSQC0GWiyypn4GUlfCPYyPr3Ko4hWgUCYBphsU0hIFrtcFNNZZ8fVWg8=@lists.denx.de X-Gm-Message-State: AOJu0YzZtO8AQn2+jE0m5tEz1J/gvvcJbrBif7fwwf/174mx14vADzji Yn4jRv9/I5kBsAMJy75Hi+aJ57Wfv8KC194hcvIp1adyk1Z8Gt/89ARPrUrdlkw= X-Gm-Gg: ASbGncsKNkNdyTakXP4i9cK1ugW0mZMxRaN4ddFv8pS3vohi9VtvHHVyRPQHsoakJH7 koisOQVbkIfWInnqPqgl7LG/CRzdJ8ayfDoVPD+eEm/mCJITGVexiz6Y3LdoT7yYsGabtNGXRwU Z/mzalFz7c0KELd1tHf/qjOwdctL9M1uwZz0Z6ZEyCiRkYpZl9Gaz3YJnSVx6r37NhHE4gwxSAM wVMyfMUYMEzhXPucwnKMrh1iAxOBiSJajV2k78UcXSrBFY6qNoKHrn5jUH0dFcZlw== X-Google-Smtp-Source: AGHT+IFeMNLlTb85xnreknwKXTjqxkQ8KbqzzdjdBqzGesx90z2i/FXLfXqG1Yi2Pky+znippJjQew== X-Received: by 2002:a05:6000:710:b0:385:e0d6:fb73 with SMTP id ffacd0b85a97d-38a872da4ccmr27402272f8f.15.1737023074403; Thu, 16 Jan 2025 02:24:34 -0800 (PST) Received: from localhost ([2a01:cb19:95ba:5000:d6dd:417f:52ac:335b]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-437c74f9ccasm53618035e9.39.2025.01.16.02.24.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jan 2025 02:24:34 -0800 (PST) From: Mattijs Korpershoek To: Patrice Chotard , u-boot@lists.denx.de Cc: Patrice CHOTARD , Patrick DELAUNAY , U-Boot STM32 , Marek Vasut , Caleb Connolly , Nathan Barrett-Morrison , Oliver Gaskell , Robert Marko , Sam Protsenko , Simon Glass , Sjoerd Simons , Sumit Garg , Tom Rini Subject: Re: [PATCH v2 4/9] usb: dwc3-generic: Add STih407 support In-Reply-To: <20250116081738.2511223-5-patrice.chotard@foss.st.com> References: <20250116081738.2511223-1-patrice.chotard@foss.st.com> <20250116081738.2511223-5-patrice.chotard@foss.st.com> Date: Thu, 16 Jan 2025 11:24:33 +0100 Message-ID: <871px383a6.fsf@baylibre.com> MIME-Version: 1.0 Content-Type: text/plain 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 Hi Patrice, Thank you for the patch. On jeu., janv. 16, 2025 at 09:17, Patrice Chotard wrote: > Add STi glue logic to manage the DWC3 HC on STiH407 > SoC family. It configures the internal glue logic and > syscfg registers. > > Signed-off-by: Patrice Chotard > Cc: Marek Vasut > > --- > > Changes in v2: > - add dwc3-sti.c DWC3 wrapper as done for dwc3-am62.c > > MAINTAINERS | 1 + > drivers/usb/dwc3/Kconfig | 6 ++ > drivers/usb/dwc3/Makefile | 1 + > drivers/usb/dwc3/dwc3-generic-sti.c | 127 ++++++++++++++++++++++++++++ > 4 files changed, 135 insertions(+) > create mode 100644 drivers/usb/dwc3/dwc3-generic-sti.c > > diff --git a/MAINTAINERS b/MAINTAINERS > index 8c6c0c2a4bc..5d7e251e601 100644 > --- a/MAINTAINERS > +++ b/MAINTAINERS > @@ -656,6 +656,7 @@ F: drivers/mmc/sti_sdhci.c > F: drivers/reset/sti-reset.c > F: drivers/serial/serial_sti_asc.c > F: drivers/sysreset/sysreset_sti.c > +F: drivers/usb/host/dwc3-sti.c > F: drivers/timer/arm_global_timer.c > F: drivers/usb/host/dwc3-sti-glue.c > F: include/dwc3-sti-glue.h > diff --git a/drivers/usb/dwc3/Kconfig b/drivers/usb/dwc3/Kconfig > index 0100723a68b..7d58ae65fb6 100644 > --- a/drivers/usb/dwc3/Kconfig > +++ b/drivers/usb/dwc3/Kconfig > @@ -87,6 +87,12 @@ config USB_DWC3_LAYERSCAPE > Host and Peripheral operation modes are supported. OTG is not > supported. > > +config USB_DWC3_STI > + bool "STi USB wrapper" > + depends on DM_USB && USB_DWC3_GENERIC && SYSCON > + help > + Select this for STi Platforms. > + > menu "PHY Subsystem" > > config USB_DWC3_PHY_OMAP > diff --git a/drivers/usb/dwc3/Makefile b/drivers/usb/dwc3/Makefile > index a085c9d4628..985206eafe4 100644 > --- a/drivers/usb/dwc3/Makefile > +++ b/drivers/usb/dwc3/Makefile > @@ -15,3 +15,4 @@ obj-$(CONFIG_USB_DWC3_UNIPHIER) += dwc3-uniphier.o > obj-$(CONFIG_USB_DWC3_LAYERSCAPE) += dwc3-layerscape.o > obj-$(CONFIG_USB_DWC3_PHY_OMAP) += ti_usb_phy.o > obj-$(CONFIG_USB_DWC3_PHY_SAMSUNG) += samsung_usb_phy.o > +obj-$(CONFIG_USB_DWC3_STI) += dwc3-generic-sti.o > diff --git a/drivers/usb/dwc3/dwc3-generic-sti.c b/drivers/usb/dwc3/dwc3-generic-sti.c > new file mode 100644 > index 00000000000..e316e88d2f8 > --- /dev/null > +++ b/drivers/usb/dwc3/dwc3-generic-sti.c > @@ -0,0 +1,127 @@ > +// SPDX-License-Identifier: GPL-2.0-or-later OR BSD-3-Clause > +/* > + * STi specific glue layer for DWC3 > + * > + * Copyright (C) 2025, STMicroelectronics - All Rights Reserved > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include "dwc3-generic.h" > + > +/* glue registers */ > +#define CLKRST_CTRL 0x00 > +#define AUX_CLK_EN BIT(0) > +#define SW_PIPEW_RESET_N BIT(4) > +#define EXT_CFG_RESET_N BIT(8) > + > +#define XHCI_REVISION BIT(12) > + > +#define USB2_VBUS_MNGMNT_SEL1 0x2C > +#define USB2_VBUS_UTMIOTG 0x1 > + > +#define SEL_OVERRIDE_VBUSVALID(n) ((n) << 0) > +#define SEL_OVERRIDE_POWERPRESENT(n) ((n) << 4) > +#define SEL_OVERRIDE_BVALID(n) ((n) << 8) > + > +/* Static DRD configuration */ > +#define USB3_CONTROL_MASK 0xf77 > + > +#define USB3_DEVICE_NOT_HOST BIT(0) > +#define USB3_FORCE_VBUSVALID BIT(1) > +#define USB3_DELAY_VBUSVALID BIT(2) > +#define USB3_SEL_FORCE_OPMODE BIT(4) > +#define USB3_FORCE_OPMODE(n) ((n) << 5) > +#define USB3_SEL_FORCE_DPPULLDOWN2 BIT(8) > +#define USB3_FORCE_DPPULLDOWN2 BIT(9) > +#define USB3_SEL_FORCE_DMPULLDOWN2 BIT(10) > +#define USB3_FORCE_DMPULLDOWN2 BIT(11) > + > +static void dwc3_stih407_glue_configure(struct udevice *dev, int index, > + enum usb_dr_mode mode) > +{ > + struct dwc3_glue_data *glue = dev_get_plat(dev); > + struct regmap *regmap; > + ulong syscfg_base; > + ulong syscfg_offset; > + ulong glue_base; > + int ret; > + > + /* deassert both powerdown and softreset */ > + ret = reset_deassert_bulk(&glue->resets); > + if (ret) { > + debug("reset_deassert_bulk error: %d\n", ret); Maybe promote this to a warning message? debug() seems a little too low priority for an error like this. > + return; > + } > + > + regmap = syscon_regmap_lookup_by_phandle(dev, "st,syscfg"); syscon_regmap_lookup_by_phandle() can fail, in that case, error handling should be done with IS_ERR(regmap). Can we add that, please? Otherwise we might do PTR_ERR->ranges[0].start the line below. > + > + syscfg_base = regmap->ranges[0].start; > + glue_base = dev_read_addr_index(dev, 0); > + syscfg_offset = dev_read_addr_index(dev, 1); > + > + clrbits_le32(syscfg_base + syscfg_offset, USB3_CONTROL_MASK); > + > + /* glue drd init */ > + switch (mode) { > + case USB_DR_MODE_PERIPHERAL: > + clrbits_le32(syscfg_base + syscfg_offset, > + USB3_DELAY_VBUSVALID | USB3_SEL_FORCE_OPMODE | > + USB3_FORCE_OPMODE(0x3) | USB3_SEL_FORCE_DPPULLDOWN2 | > + USB3_FORCE_DPPULLDOWN2 | USB3_SEL_FORCE_DMPULLDOWN2 | > + USB3_FORCE_DMPULLDOWN2); > + > + setbits_le32(syscfg_base + syscfg_offset, > + USB3_DEVICE_NOT_HOST | USB3_FORCE_VBUSVALID); > + break; > + > + case USB_DR_MODE_HOST: > + clrbits_le32(syscfg_base + syscfg_offset, > + USB3_DEVICE_NOT_HOST | USB3_FORCE_VBUSVALID | > + USB3_SEL_FORCE_OPMODE | USB3_FORCE_OPMODE(0x3) | > + USB3_SEL_FORCE_DPPULLDOWN2 | USB3_FORCE_DPPULLDOWN2 | > + USB3_SEL_FORCE_DMPULLDOWN2 | USB3_FORCE_DMPULLDOWN2); > + > + setbits_le32(syscfg_base + syscfg_offset, USB3_DELAY_VBUSVALID); > + break; > + > + default: > + debug("Unsupported mode of operation %d\n", mode); > + return; Nitpick, I think that mode being an enum (with a finite number of values possibles), we not necessarily have to check if the value is invalid. But it's okay for me if this stays the same. > + } > + > + /* glue init */ > + setbits_le32(glue_base + CLKRST_CTRL, AUX_CLK_EN | EXT_CFG_RESET_N | XHCI_REVISION); > + clrbits_le32(glue_base + CLKRST_CTRL, SW_PIPEW_RESET_N); > + > + /* configure mux for vbus, powerpresent and bvalid signals */ > + setbits_le32(glue_base + USB2_VBUS_MNGMNT_SEL1, > + SEL_OVERRIDE_VBUSVALID(USB2_VBUS_UTMIOTG) | > + SEL_OVERRIDE_POWERPRESENT(USB2_VBUS_UTMIOTG) | > + SEL_OVERRIDE_BVALID(USB2_VBUS_UTMIOTG)); > + setbits_le32(glue_base + CLKRST_CTRL, SW_PIPEW_RESET_N); > +}; > + > +struct dwc3_glue_ops stih407_ops = { > + .glue_configure = dwc3_stih407_glue_configure, > +}; > + > +static const struct udevice_id dwc3_sti_match[] = { > + { .compatible = "st,stih407-dwc3", .data = (ulong)&stih407_ops}, > + { /* sentinel */ } > +}; > + > +U_BOOT_DRIVER(dwc3_sti_wrapper) = { > + .name = "dwc3-sti", > + .id = UCLASS_SIMPLE_BUS, > + .of_match = dwc3_sti_match, > + .bind = dwc3_glue_bind, > + .probe = dwc3_glue_probe, > + .remove = dwc3_glue_remove, > + .plat_auto = sizeof(struct dwc3_glue_data), > +}; > -- > 2.25.1