From patchwork Fri Mar 15 15:06:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Caleb Connolly X-Patchwork-Id: 780505 Delivered-To: patch@linaro.org Received: by 2002:a5d:46c1:0:b0:33e:7753:30bd with SMTP id g1csp250077wrs; Fri, 15 Mar 2024 08:06:27 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUIzTpGT2tM00z96LJ38ragr53z61XArndZQCWgB2wmQsJt6fX6zPiUx9P3FttMRnqnOB5D/Lmpo2oiJrjl8mpI X-Google-Smtp-Source: AGHT+IFVcCTlAlRPKTgWJbO6DkhhxrpI1h8EWDvohlelYpoN+hLzJcCqI71lkQOSKe3dXRCv3cHQ X-Received: by 2002:a5d:674e:0:b0:33e:cbec:e98 with SMTP id l14-20020a5d674e000000b0033ecbec0e98mr3533438wrw.13.1710515187738; Fri, 15 Mar 2024 08:06:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1710515187; cv=none; d=google.com; s=arc-20160816; b=o+1MK+n+d661MAsia53MSwBIWMbIOjPCJ5J3Q3cybffcZhXKehrVfiVnUMLNu4dFhX DRW+QD5YUvH/uQ9f6oPW/+rV7ehVgnnL2zlqhUEfbkuecTNOjXTJOeqggRya+sFZEby6 GA+yAH85dSLkAzIIsLf5+iimZ1YVYuc7bhgRu8g/nCIaesYGzAAIq+TjkUY0O87WUMhk sJvTAiTdTcLRjGqGlJFVAwLxCa78F3EIxrHUGIvvzyDjpdqIuqRqpyvc5obXU3slc9V9 twwVBHkSvyBLewGJ0QT57TZwal3CG6dlzCPzUKA9dYncA6Tv1p1+aH4vliJ2fz9OGkFu Y6vQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:cc:to:in-reply-to:references :message-id:content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=PL6Z/zkvsAR1KzxwMv1rJzM4fB2Czula3XSPqEJDCS8=; fh=UJLfQHigVNNxRTyupVH3iuVYJLWMjRXGBkTXuIfaL+0=; b=cV/SgI9hGZxvMVc1W/TEafdNqTjYjJgiKSqJuMHdtjuJLmol3zHW0+YCqUnWavLYrS ZhYDZ2PwIQ3AVyI+acCTiYolvKUy1E8inaJ48tHXWbLe6W4VfouIaDDGu9kPWDIp/m7L O/ciJSeyO9aCXGjKuRmuM08Oy5jkskEv6mUr7qBEf/w94RWbGVqWPn62sdMiL0ni55cz crAdpdv5xf+6RdA9RZPjLUJAvO32jNMtTXYlpn9T+GfnO6xLXs4185bU3pTBBU7reYQY DZRTlrxdMxwZOhzrN58RAHKQ0iWkzYl5sNdzzmM/XeDff1CDEN9lcG/8o8dqs64UsyaX Kz6w==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=N14MTh64; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id f17-20020adfe911000000b0033e777c7cd3si1716120wrm.532.2024.03.15.08.06.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Mar 2024 08:06:27 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=N14MTh64; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 9914688004; Fri, 15 Mar 2024 16:06:16 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org 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=linaro.org header.i=@linaro.org header.b="N14MTh64"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 7C21688011; Fri, 15 Mar 2024 16:06:13 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.2 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) (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 0329A87FF2 for ; Fri, 15 Mar 2024 16:06:08 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=caleb.connolly@linaro.org Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-33ddd1624beso1410453f8f.1 for ; Fri, 15 Mar 2024 08:06:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1710515167; x=1711119967; darn=lists.denx.de; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=PL6Z/zkvsAR1KzxwMv1rJzM4fB2Czula3XSPqEJDCS8=; b=N14MTh642jeNU8WAEsvNxSgpwwpgXp3/X4zLt9QGP+Kfr2nYga+ckSlNhLQgjnoCgb 65UzaxKioVzUdTK6CygeIBQBwL1E25ZHJyIOj/+e2hMH1RWgStJgA618QhKLCo06lTRi v/Byg/kOya8AERp0zInkJ3E79ATwGqsZ55rBmVOvz9g5Qg4cu3xmoc3zbeFhmAYOgJkd iS4E6UFKlb7f6PTtlfW4oErPiG1r0/js6fLnrpFa3CIpNqy3whwPf+5lDNOemBBWIvhV Rf8ezo7cx3Ds/3CZQw6xqTRgi2aYDdBRyBU5xiyJgAqwG7fasE++9FX83fLU+QzPPOCE 2G7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710515167; x=1711119967; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PL6Z/zkvsAR1KzxwMv1rJzM4fB2Czula3XSPqEJDCS8=; b=KUoocNg8VLOayXg4QmZPidIcpMlZbeqPg9VOyfhTvAq2ANjo2EgBI2Bjsmvi9mY4Zt /U79fnJJylPWG+rB4kjHrG44aEURtoj4XhAYbhKttVFVLOlFNWXeZyP6tsyvDGkKM3RV MJLuL6BbDJZvrYjCDeUL90Xm7Q1F3xT8FQvk50ik4Ju2+OmecFJOA+x7e3Q/zxboQcXO WastsQTksUEDaPPLgUUOZ0LprqLcNlidqW4Xj4HCWl31lZF4bnXyyKEnLC85XUUuEGbp wu6sb2QsXUPbqmB8Z2h9H0jaAi9NgsC5B7KGCyPrh/j4WZEES0BRgamJbnMEyEqTPLv4 nOwQ== X-Gm-Message-State: AOJu0YwuXWxE831pWq0H6c0KiO4eOu8HCibU1oIvYjk13bePLeb15p7O cxbGw2vLP2uD5eckdwEESUEMCglK5OatONEGQPvYgNyn63JDpWgn/8uuItnksjI= X-Received: by 2002:adf:cb92:0:b0:33d:61c7:9b2c with SMTP id q18-20020adfcb92000000b0033d61c79b2cmr7745786wrh.34.1710515167313; Fri, 15 Mar 2024 08:06:07 -0700 (PDT) Received: from lion.localdomain (host-92-17-96-232.as13285.net. [92.17.96.232]) by smtp.gmail.com with ESMTPSA id jg28-20020a05600ca01c00b0041401fbe446sm1939502wmb.11.2024.03.15.08.06.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Mar 2024 08:06:06 -0700 (PDT) From: Caleb Connolly Date: Fri, 15 Mar 2024 15:06:00 +0000 Subject: [PATCH v2 1/5] usb: dwc3-generic: implement Qualcomm wrapper MIME-Version: 1.0 Message-Id: <20240315-b4-qcom-usb-v2-1-5467ec27cb26@linaro.org> References: <20240315-b4-qcom-usb-v2-0-5467ec27cb26@linaro.org> In-Reply-To: <20240315-b4-qcom-usb-v2-0-5467ec27cb26@linaro.org> To: Marek Vasut , Tom Rini , Lukasz Majewski , Mattijs Korpershoek , Caleb Connolly , Neil Armstrong , Sumit Garg Cc: u-boot@lists.denx.de X-Mailer: b4 0.14-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=4214; i=caleb.connolly@linaro.org; h=from:subject:message-id; bh=wyOgocaLbH2BVsPAtMVCO6/ZFsvVRUnte7CZsWHnPsE=; b=owGbwMvMwCFYaeA6f6eBkTjjabUkhtQvyXca71mev/ZyQc7791Kz32q/XuIvynlM3MFxwQXWc 2pHi8yrO0pZGAQ5GGTFFFnETyyzbFp72V5j+4ILMHNYmUCGMHBxCsBEPtgy/C9rM3mzUn2+0oqH tRm3VSa+E+AKO3OGZZfpRIFvjOxm3yMYGTYqe2iH6DU/iDvmWbKj997ynYuXJm7dZ3zVRZhf8Om vv9wA X-Developer-Key: i=caleb.connolly@linaro.org; a=openpgp; fpr=83B24DA7FE145076BC38BB250CD904EB673A7C47 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 The Qualcomm specific dwc3 wrapper isn't hugely complicated, implemented the missing initialisation for host and gadget mode. Reviewed-by: Mattijs Korpershoek Signed-off-by: Caleb Connolly Reviewed-by: Marek Vasut --- drivers/usb/dwc3/dwc3-generic.c | 81 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 80 insertions(+), 1 deletion(-) diff --git a/drivers/usb/dwc3/dwc3-generic.c b/drivers/usb/dwc3/dwc3-generic.c index a379a0002e77..5a355dd86c60 100644 --- a/drivers/usb/dwc3/dwc3-generic.c +++ b/drivers/usb/dwc3/dwc3-generic.c @@ -424,8 +424,79 @@ enum dwc3_omap_utmi_mode { struct dwc3_glue_ops ti_ops = { .glue_configure = dwc3_ti_glue_configure, }; +/* USB QSCRATCH Hardware registers */ +#define QSCRATCH_HS_PHY_CTRL 0x10 +#define UTMI_OTG_VBUS_VALID BIT(20) +#define SW_SESSVLD_SEL BIT(28) + +#define QSCRATCH_SS_PHY_CTRL 0x30 +#define LANE0_PWR_PRESENT BIT(24) + +#define QSCRATCH_GENERAL_CFG 0x08 +#define PIPE_UTMI_CLK_SEL BIT(0) +#define PIPE3_PHYSTATUS_SW BIT(3) +#define PIPE_UTMI_CLK_DIS BIT(8) + +#define PWR_EVNT_IRQ_STAT_REG 0x58 +#define PWR_EVNT_LPM_IN_L2_MASK BIT(4) +#define PWR_EVNT_LPM_OUT_L2_MASK BIT(5) + +#define SDM845_QSCRATCH_BASE_OFFSET 0xf8800 +#define SDM845_QSCRATCH_SIZE 0x400 +#define SDM845_DWC3_CORE_SIZE 0xcd00 + +static void dwc3_qcom_vbus_override_enable(void __iomem *qscratch_base, bool enable) +{ + if (enable) { + setbits_le32(qscratch_base + QSCRATCH_SS_PHY_CTRL, + LANE0_PWR_PRESENT); + setbits_le32(qscratch_base + QSCRATCH_HS_PHY_CTRL, + UTMI_OTG_VBUS_VALID | SW_SESSVLD_SEL); + } else { + clrbits_le32(qscratch_base + QSCRATCH_SS_PHY_CTRL, + LANE0_PWR_PRESENT); + clrbits_le32(qscratch_base + QSCRATCH_HS_PHY_CTRL, + UTMI_OTG_VBUS_VALID | SW_SESSVLD_SEL); + } +} + +/* For controllers running without superspeed PHYs */ +static void dwc3_qcom_select_utmi_clk(void __iomem *qscratch_base) +{ + /* Configure dwc3 to use UTMI clock as PIPE clock not present */ + setbits_le32(qscratch_base + QSCRATCH_GENERAL_CFG, + PIPE_UTMI_CLK_DIS); + + setbits_le32(qscratch_base + QSCRATCH_GENERAL_CFG, + PIPE_UTMI_CLK_SEL | PIPE3_PHYSTATUS_SW); + + clrbits_le32(qscratch_base + QSCRATCH_GENERAL_CFG, + PIPE_UTMI_CLK_DIS); +} + +static void dwc3_qcom_glue_configure(struct udevice *dev, int index, + enum usb_dr_mode mode) +{ + struct dwc3_glue_data *glue = dev_get_plat(dev); + void __iomem *qscratch_base = (void __iomem *)glue->regs; + if (IS_ERR_OR_NULL(qscratch_base)) { + log_err("%s: Invalid qscratch base address\n", dev->name); + return; + } + + if (dev_read_bool(dev, "qcom,select-utmi-as-pipe-clk")) + dwc3_qcom_select_utmi_clk(qscratch_base); + + if (mode != USB_DR_MODE_HOST) + dwc3_qcom_vbus_override_enable(qscratch_base, true); +} + +struct dwc3_glue_ops qcom_ops = { + .glue_configure = dwc3_qcom_glue_configure, +}; + static int dwc3_rk_glue_get_ctrl_dev(struct udevice *dev, ofnode *node) { *node = dev_ofnode(dev); if (!ofnode_valid(*node)) @@ -511,8 +582,16 @@ static int dwc3_glue_reset_init(struct udevice *dev, return 0; else if (ret) return ret; + if (device_is_compatible(dev, "qcom,dwc3")) { + reset_assert_bulk(&glue->resets); + /* We should wait at least 6 sleep clock cycles, that's + * (6 / 32764) * 1000000 ~= 200us. But some platforms + * have slower sleep clocks so we'll play it safe. + */ + udelay(500); + } ret = reset_deassert_bulk(&glue->resets); if (ret) { reset_release_bulk(&glue->resets); return ret; @@ -628,9 +707,9 @@ static const struct udevice_id dwc3_glue_ids[] = { { .compatible = "rockchip,rk3328-dwc3", .data = (ulong)&rk_ops }, { .compatible = "rockchip,rk3399-dwc3" }, { .compatible = "rockchip,rk3568-dwc3", .data = (ulong)&rk_ops }, { .compatible = "rockchip,rk3588-dwc3", .data = (ulong)&rk_ops }, - { .compatible = "qcom,dwc3" }, + { .compatible = "qcom,dwc3", .data = (ulong)&qcom_ops }, { .compatible = "fsl,imx8mp-dwc3", .data = (ulong)&imx8mp_ops }, { .compatible = "fsl,imx8mq-dwc3" }, { .compatible = "intel,tangier-dwc3" }, { }