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: 1912568 X-Patchwork-Delegate: marek.vasut@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=N14MTh64; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=patchwork.ozlabs.org) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Tx6yt1h7qz1yWn for ; Sat, 16 Mar 2024 02:06:30 +1100 (AEDT) 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-Google-Smtp-Source: AGHT+IGT05Tp2EhhWUbnk4GZjf6nlKrP1X/1PS7qxTcZDhi6pf/XmTWkqxeun5PcA222iZ5+ciCfZQ== 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" }, { } From patchwork Fri Mar 15 15:06:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Caleb Connolly X-Patchwork-Id: 1912569 X-Patchwork-Delegate: marek.vasut@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=we+cU4Lh; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=patchwork.ozlabs.org) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Tx6z524bfz1yWn for ; Sat, 16 Mar 2024 02:06:41 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 45F0087FF1; Fri, 15 Mar 2024 16:06:17 +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="we+cU4Lh"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 559FF88003; Fri, 15 Mar 2024 16:06:14 +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=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) (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 D164888004 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-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-414008713beso4908955e9.1 for ; Fri, 15 Mar 2024 08:06:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1710515168; x=1711119968; 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=cnrSRMGhccGbRZbFvxipCAyufaiPSD/lfhCstPEB5Ls=; b=we+cU4LhTuFGEClJ75KlzxgsRFDA0RzEzjQQysSWu1hCijBEKaJcVRVgr38MvjoHZC 9L/tDoNXeO2jr5EL6/cK2KqJDYtuiduHcmFeTzg8NweEF+n3p2sgDzvoQoNL7IZAjyuc zBmpgqaFRItbfc8hA+0L8YFwCxvAtvQ4virnTYPD+JlATd+wwtB+XvctU9fROgzPx3Kt kzP3zfi16+Jn6cOSE6bDd9hGj/SO5zof08O4yy26otiozl3F3kouAOCnV6R32Cokxtzh iSJt69fW2KPT/7BorG8TFNd0Ens4HVUKIAaSzO98QtujX3avrcVX47ljRGMQtqTEWmN9 50cQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710515168; x=1711119968; 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=cnrSRMGhccGbRZbFvxipCAyufaiPSD/lfhCstPEB5Ls=; b=UjQdLM9CeCuyJCfblQl0AVROCZ4TRprF1/PwdMkX/UX45LPV0KBZNdCczYCxR6hNzb 1vQ6bLZiBBB80fE4bWtoWlK6003RKgD5GwupF+HbQKrclRQP1HQc3mSBcgX6+3qRhmb+ 0K28DvytY12/jJCwf3oCDRtKzQstRsB5rbGH5Um/Bymb1t6kvAe2FEhgRjWbmEEuagHw Ep1MCSeKKUJcVilxjPsAmLw2h0K+Gk1DzqA+aBp1xbiJAweIfCrN0WRkHrRDMeLUKpx7 eiV4pkhfPdaOsey4SEixR5z+6AW0f4+DcbIlRbuHGFXVTJR4fr8bd8Zusg1oZQp1IJTj FUKg== X-Gm-Message-State: AOJu0Yx7Bl2djTbudsPSn1HZ7O7xH0EKYRXv3WtYjp2nfidBf0/ZSVGc 4qWNIAGDVoOcFGkWePBlukyJMxaBy1KNruV2LfEuYRyhvsu2N9t1fzuR3ZB1Snc= X-Google-Smtp-Source: AGHT+IEriPhAebo5bWmX0BLke29eA38Izu8SWbylPuxNVBhdyQQVufwQ3NJHbstIwCB9yNbj2h8ZPw== X-Received: by 2002:a05:600c:444b:b0:413:f276:1123 with SMTP id v11-20020a05600c444b00b00413f2761123mr3523966wmn.35.1710515168357; Fri, 15 Mar 2024 08:06:08 -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.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Mar 2024 08:06:07 -0700 (PDT) From: Caleb Connolly Date: Fri, 15 Mar 2024 15:06:01 +0000 Subject: [PATCH v2 2/5] usb: dwc3: select DM_USB_GADGET MIME-Version: 1.0 Message-Id: <20240315-b4-qcom-usb-v2-2-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=777; i=caleb.connolly@linaro.org; h=from:subject:message-id; bh=FFtOCdyc7kFWeNXYCi6LiWr/yQ+G2PLU3dzzfBLIqOM=; b=owGbwMvMwCFYaeA6f6eBkTjjabUkhtQvyXd9p0ka/L+UoDzvwtnwB28ihE9lFZ0pTM68/FBp1 uMvB3MWd5SyMAhyMMiKKbKIn1hm2bT2sr3G9gUXYOawMoEMYeDiFICJHD3J8IcnsmlBYdh6lV9C yVXcD6Y/ffLmRG75FZPfFx7LNnpWs3ky/BX/skymuYTzw/EXP8yYjjRs7NVedsjtxqXC21cS7mb 88xMHAA== 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 DWC3 platforms depend on DM_USB_GADGET for gadget drivers to work, otherwise compilation fails due to no implementation of dm_usb_gadget_handle_interrupts(). Reviewed-by: Mattijs Korpershoek Signed-off-by: Caleb Connolly --- drivers/usb/dwc3/Kconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/usb/dwc3/Kconfig b/drivers/usb/dwc3/Kconfig index c0c8c16fd9c2..8a70bc682322 100644 --- a/drivers/usb/dwc3/Kconfig +++ b/drivers/usb/dwc3/Kconfig @@ -10,8 +10,9 @@ if USB_DWC3 config USB_DWC3_GADGET bool "USB Gadget support for DWC3" default y depends on USB_GADGET + select DM_USB_GADGET select USB_GADGET_DUALSPEED comment "Platform Glue Driver Support" From patchwork Fri Mar 15 15:06:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Caleb Connolly X-Patchwork-Id: 1912570 X-Patchwork-Delegate: marek.vasut@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=XHHQ8Y2X; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=patchwork.ozlabs.org) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Tx6zJ31J7z1yWn for ; Sat, 16 Mar 2024 02:06:52 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id B025E87FFF; Fri, 15 Mar 2024 16:06:17 +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="XHHQ8Y2X"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8FCE887FDD; Fri, 15 Mar 2024 16:06:15 +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=ham autolearn_force=no version=3.4.2 Received: from mail-lf1-x136.google.com (mail-lf1-x136.google.com [IPv6:2a00:1450:4864:20::136]) (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 069508800B for ; Fri, 15 Mar 2024 16:06:10 +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-lf1-x136.google.com with SMTP id 2adb3069b0e04-5131a9b3d5bso2634441e87.0 for ; Fri, 15 Mar 2024 08:06:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1710515169; x=1711119969; 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=e9PNn3A0M8j5XRDzvbl1vLHxbY2HeF4JRZJRcDlmjgE=; b=XHHQ8Y2XpHeG7uMhfEfLxw1mq4xoKJIFydTi0oYZ2Lk6ENr8DD1WwDVjOFoNrnQibd B7fdWzOZz7Pnop6BhawGz/+xKxEoT6+gRi60oiOihMjUucodbDzzjiNRgvesp8WtvRVw o7h19FhYrKyen1w3hoOTafV2yZagWzPm8SXh1Cp1eAInQAsFqSzPHiDMZcS5dKgO5aq0 d1XsGOC1vHi4cSweSLGgn8X3aF46rvsPDY/IAIYmhW6KAPICmm+AYn9NT1X/g4op94g7 Sm9Akj3buiRSvlQ7ESiY4cidEM0C1+DIQ/qjHloA/FtR7OuLCq0w9Wo6iFbqxcu2WUvz UIKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710515169; x=1711119969; 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=e9PNn3A0M8j5XRDzvbl1vLHxbY2HeF4JRZJRcDlmjgE=; b=jnIPbV3tlQvZi/bvb2d2M5lK7alKLvSX/8nuXODkLDb1aMC1RICKleQjoYf+l/ofwG wHS2NpcrBq0LpnLjxEjaXXzC9V5cuA8/cuYOY3SSmU3rbJibwilF0wIirMQ3vZLrKc62 RLCRXc8Wf1E6Z7whWu7fzKruhf2iNLY7L0EO22Mj+QkECYDmwsnQB1UOK1fG0x5QJJj5 /MUuHDueVopFsfPErY13Nf8e5zo1yJRZR0Iw+PzrFvehI4eqaw8Vr9ifjvcsHfW2ixPR g4wIYrPEfy5jKRzc5pNtKwKBh/b91ICk6FXsav6jANhAdiNsy7/v1muW0+CvPmdNsSzO Zu8g== X-Gm-Message-State: AOJu0YxADFl17vwm79kX6Hjw+5egAmVMmsHTEf6lx1MGdYf7et8kgksI lxxN5QStNjhWy7WYjR7K22ZqcNs6g9vZTdY68dW0S60pf0TbcyG39USnVynRHIw= X-Google-Smtp-Source: AGHT+IGbJmQGgDwFXBg0ghjxNiXHSqmcc2f4MO7f+iugGXweGVwmFnPfF+2Av5FEVUzSxtSkLHdqJA== X-Received: by 2002:a19:5f04:0:b0:513:cd2e:ceae with SMTP id t4-20020a195f04000000b00513cd2eceaemr3541890lfb.20.1710515169373; Fri, 15 Mar 2024 08:06:09 -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.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Mar 2024 08:06:08 -0700 (PDT) From: Caleb Connolly Date: Fri, 15 Mar 2024 15:06:02 +0000 Subject: [PATCH v2 3/5] usb: gadget: CDC ACM: call usb_gadget_initialize MIME-Version: 1.0 Message-Id: <20240315-b4-qcom-usb-v2-3-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=1071; i=caleb.connolly@linaro.org; h=from:subject:message-id; bh=iF44ey0WhRVVVgOg2Xo34JBjuNlV4OImTlpeBMxGr20=; b=owGbwMvMwCFYaeA6f6eBkTjjabUkhtQvyXc1Fuc4y10SOP4idWL8zd8PuFdWNW8OF1S8GFk74 51mpgxjRykLgyAHg6yYIov4iWWWTWsv22tsX3ABZg4rE8gQBi5OAZhI+29GhtbSpud+Jpc/58RK fK28s+3ZA8cQtffP/livL7nU2eccupqRYUptx/nwmxJ/Z3sxyPgwNTu4Wt24PdV59u2+lyH1NjF nLwIA 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 To actually use the gadget the peripheral driver must be probed and we must call g_dnl_clear_detach(). Otherwise acm_stdio_start() will always fail to find a UDC on DT platforms. Reviewed-by: Mattijs Korpershoek Signed-off-by: Caleb Connolly --- drivers/usb/gadget/f_acm.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/usb/gadget/f_acm.c b/drivers/usb/gadget/f_acm.c index de42e0189e8d..ba216128ab27 100644 --- a/drivers/usb/gadget/f_acm.c +++ b/drivers/usb/gadget/f_acm.c @@ -622,14 +622,23 @@ static void acm_stdio_puts(struct stdio_dev *dev, const char *str) } static int acm_stdio_start(struct stdio_dev *dev) { + struct udevice *udc; int ret; if (dev->priv) { /* function already exist */ return 0; } + ret = udc_device_get_by_index(0, &udc); + if (ret) { + pr_err("USB init failed: %d\n", ret); + return ret; + } + + g_dnl_clear_detach(); + ret = g_dnl_register("usb_serial_acm"); if (ret) return ret; From patchwork Fri Mar 15 15:06:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Caleb Connolly X-Patchwork-Id: 1912571 X-Patchwork-Delegate: marek.vasut@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=ICYuDSkS; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=patchwork.ozlabs.org) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Tx6zX2sqmz1yWn for ; Sat, 16 Mar 2024 02:07:04 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 2E5A987FF2; Fri, 15 Mar 2024 16:06:19 +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="ICYuDSkS"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9FD7A87FD2; Fri, 15 Mar 2024 16:06:16 +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=ham autolearn_force=no version=3.4.2 Received: from mail-lf1-x12a.google.com (mail-lf1-x12a.google.com [IPv6:2a00:1450:4864:20::12a]) (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 3125B88010 for ; Fri, 15 Mar 2024 16:06:11 +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-lf1-x12a.google.com with SMTP id 2adb3069b0e04-512f892500cso2565377e87.3 for ; Fri, 15 Mar 2024 08:06:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1710515170; x=1711119970; 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=A3DkjF1TR/8nRXVHAMS8QpF7WwBh/qeL566sftZQEnw=; b=ICYuDSkStrdZGt4IrZFkHUkIPw708A41QNNAZqEdZPkNhLdMP/mxjLqFQoBkmrrIW1 YK4of5VwyZkXYNatoLATTd2zMf12vZ6bPZcaXwO41ot1K7HQVPrPZXtQ26X4e9CaVKyi D9bVfP25Vh0FLf7bAb1U6QIxXYxptz6NLbvPgWxFCAnVNWriHa5/8Hq9l/xrzlwvjAp2 QLoWaXEH6lvSmmoYXVCE6SIOViuHVSksf6vbWqXfD4+zpBshSEwGdIOJcft2a7DzH/B9 GW1M7RVpNWQ3xul9ufkkP+FNE1O0rCdAewGMzHY/6pq9kVXftSZsNMRScyJhWLb6kVCL +V5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710515170; x=1711119970; 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=A3DkjF1TR/8nRXVHAMS8QpF7WwBh/qeL566sftZQEnw=; b=uWJKRjfMFBEMBjer13R/S6xBIPjZ9ORlKXVHH4Oixjfje9/sddgRM0wcHYw2amwrms Kc5645cmq/RWTD8eIVipf4pK/Qs4Cuh0X5AsRqHiNPOVj8bcnlSY5GOjSi5ubgLLUB7s a/Aa6MlquRu6YC7o2Q1iLY7oq50FAs2cfdJP2SwVZzUYtQBWnD/BbpS37svOoxXi81ZN 6gRvd3d5dd2SO2KF/GG2jzzEQUHn1I1d8DXjtPu9Rifn0sYpKfosDD3zw1SIRauva7zH kG64l8XP2lRhorHJgbR5+Mq9K/S26N0v8TwuWzKN4ZasyyKtlfFQ6uk/Yy0rHdFuHzvq iyPg== X-Gm-Message-State: AOJu0Yy27lDenARG0ZJm087w75s2SPMJ90QIZft2t/VsrE2McWwldjN3 ykLJ5xCLZEueocj+vD+UyTzlpZZ0g2WFAB7dBWooHzZjQOK4s2dqRuMo05o/hhs= X-Google-Smtp-Source: AGHT+IGxt/IN/95JGHwF68Q9BuFlhRj9vQPcBrLcVx5CU+QzaZH3kvPBkHkPC+V5YWt1LWDBnlkaHA== X-Received: by 2002:ac2:5185:0:b0:513:cf77:48c5 with SMTP id u5-20020ac25185000000b00513cf7748c5mr2939106lfi.38.1710515170248; Fri, 15 Mar 2024 08:06:10 -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.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Mar 2024 08:06:09 -0700 (PDT) From: Caleb Connolly Date: Fri, 15 Mar 2024 15:06:03 +0000 Subject: [PATCH v2 4/5] usb: gadget: UMS: support multiple sector sizes MIME-Version: 1.0 Message-Id: <20240315-b4-qcom-usb-v2-4-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=12955; i=caleb.connolly@linaro.org; h=from:subject:message-id; bh=pZeFdHwOydCXfHRFprpcAo1xgzNFwT7FwdbRs3US3LE=; b=owGbwMvMwCFYaeA6f6eBkTjjabUkhtQvyXdLetOa/h9cv/Pep/SJh33UJnzeUq3r9OBAu8nZO 8rt2114OkpZGAQ5GGTFFFnETyyzbFp72V5j+4ILMHNYmUCGMHBxCsBE1LgZ/lnX/ymsfPrm3n9n jv0WGx5VfnZ837fz1bdfh97XGNeZuHxl+F8gefeolthbmQWJr7MyuF6cq5FbX/d5d7mLaC/HYbb GXXcB 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 UFS storage often uses a 4096-byte sector size, add support for dynamic sector sizes based loosely on the Linux implementation. Reviewed-by: Mattijs Korpershoek Signed-off-by: Caleb Connolly --- cmd/usb_mass_storage.c | 4 -- drivers/usb/gadget/f_mass_storage.c | 101 ++++++++++++++++++++---------------- drivers/usb/gadget/storage_common.c | 12 +++-- include/usb_mass_storage.h | 1 - 4 files changed, 65 insertions(+), 53 deletions(-) diff --git a/cmd/usb_mass_storage.c b/cmd/usb_mass_storage.c index a8ddeb494628..751701fe73af 100644 --- a/cmd/usb_mass_storage.c +++ b/cmd/usb_mass_storage.c @@ -87,12 +87,8 @@ static int ums_init(const char *devtype, const char *devnums_part_str) */ if (!strchr(devnum_part_str, ':')) partnum = 0; - /* f_mass_storage.c assumes SECTOR_SIZE sectors */ - if (block_dev->blksz != SECTOR_SIZE) - goto cleanup; - ums_new = realloc(ums, (ums_count + 1) * sizeof(*ums)); if (!ums_new) goto cleanup; ums = ums_new; diff --git a/drivers/usb/gadget/f_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c index c725aed3f626..d880928044f4 100644 --- a/drivers/usb/gadget/f_mass_storage.c +++ b/drivers/usb/gadget/f_mass_storage.c @@ -723,14 +723,15 @@ static int do_read(struct fsg_common *common) if (lba >= curlun->num_sectors) { curlun->sense_data = SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE; return -EINVAL; } - file_offset = ((loff_t) lba) << 9; + file_offset = ((loff_t)lba) << curlun->blkbits; /* Carry out the file reads */ amount_left = common->data_size_from_cmnd; - if (unlikely(amount_left == 0)) + if (unlikely(amount_left == 0)) { return -EIO; /* No default reply */ + } for (;;) { /* Figure out how much we need to read: @@ -767,15 +768,15 @@ static int do_read(struct fsg_common *common) } /* Perform the read */ rc = ums[common->lun].read_sector(&ums[common->lun], - file_offset / SECTOR_SIZE, - amount / SECTOR_SIZE, + file_offset / curlun->blksize, + amount / curlun->blksize, (char __user *)bh->buf); if (!rc) return -EIO; - nread = rc * SECTOR_SIZE; + nread = rc * curlun->blksize; VLDBG(curlun, "file read %u @ %llu -> %d\n", amount, (unsigned long long) file_offset, (int) nread); @@ -786,9 +787,9 @@ static int do_read(struct fsg_common *common) nread = 0; } else if (nread < amount) { LDBG(curlun, "partial file read: %d/%u\n", (int) nread, amount); - nread -= (nread & 511); /* Round down to a block */ + nread -= (nread & (curlun->blksize - 1)); /* Round down to a block */ } file_offset += nread; amount_left -= nread; common->residue -= nread; @@ -860,9 +861,9 @@ static int do_write(struct fsg_common *common) } /* Carry out the file writes */ get_some_more = 1; - file_offset = usb_offset = ((loff_t) lba) << 9; + file_offset = usb_offset = ((loff_t)lba) << curlun->blkbits; amount_left_to_req = common->data_size_from_cmnd; amount_left_to_write = common->data_size_from_cmnd; while (amount_left_to_write > 0) { @@ -892,9 +893,9 @@ static int do_write(struct fsg_common *common) SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE; curlun->info_valid = 1; continue; } - amount -= (amount & 511); + amount -= (amount & (curlun->blksize - 1)); if (amount == 0) { /* Why were we were asked to transfer a * partial block? */ @@ -941,14 +942,14 @@ static int do_write(struct fsg_common *common) amount = bh->outreq->actual; /* Perform the write */ rc = ums[common->lun].write_sector(&ums[common->lun], - file_offset / SECTOR_SIZE, - amount / SECTOR_SIZE, + file_offset / curlun->blksize, + amount / curlun->blksize, (char __user *)bh->buf); if (!rc) return -EIO; - nwritten = rc * SECTOR_SIZE; + nwritten = rc * curlun->blksize; VLDBG(curlun, "file write %u @ %llu -> %d\n", amount, (unsigned long long) file_offset, (int) nwritten); @@ -959,9 +960,9 @@ static int do_write(struct fsg_common *common) nwritten = 0; } else if (nwritten < amount) { LDBG(curlun, "partial file write: %d/%u\n", (int) nwritten, amount); - nwritten -= (nwritten & 511); + nwritten -= (nwritten & (curlun->blksize - 1)); /* Round down to a block */ } file_offset += nwritten; amount_left_to_write -= nwritten; @@ -1033,10 +1034,10 @@ static int do_verify(struct fsg_common *common) if (unlikely(verification_length == 0)) return -EIO; /* No default reply */ /* Prepare to carry out the file verify */ - amount_left = verification_length << 9; - file_offset = ((loff_t) lba) << 9; + amount_left = verification_length << curlun->blkbits; + file_offset = ((loff_t) lba) << curlun->blkbits; /* Write out all the dirty buffers before invalidating them */ /* Just try to read the requested blocks */ @@ -1057,14 +1058,14 @@ static int do_verify(struct fsg_common *common) } /* Perform the read */ rc = ums[common->lun].read_sector(&ums[common->lun], - file_offset / SECTOR_SIZE, - amount / SECTOR_SIZE, + file_offset / curlun->blksize, + amount / curlun->blksize, (char __user *)bh->buf); if (!rc) return -EIO; - nread = rc * SECTOR_SIZE; + nread = rc * curlun->blksize; VLDBG(curlun, "file read %u @ %llu -> %d\n", amount, (unsigned long long) file_offset, (int) nread); @@ -1074,9 +1075,9 @@ static int do_verify(struct fsg_common *common) nread = 0; } else if (nread < amount) { LDBG(curlun, "partial file verify: %d/%u\n", (int) nread, amount); - nread -= (nread & 511); /* Round down to a sector */ + nread -= (nread & (curlun->blksize - 1)); /* Round down to a sector */ } if (nread == 0) { curlun->sense_data = SS_UNRECOVERED_READ_ERROR; curlun->info_valid = 1; @@ -1182,9 +1183,9 @@ static int do_read_capacity(struct fsg_common *common, struct fsg_buffhd *bh) } put_unaligned_be32(curlun->num_sectors - 1, &buf[0]); /* Max logical block */ - put_unaligned_be32(512, &buf[4]); /* Block length */ + put_unaligned_be32(curlun->blksize, &buf[4]); /* Block length */ return 8; } static int do_read_header(struct fsg_common *common, struct fsg_buffhd *bh) @@ -1369,9 +1370,9 @@ static int do_read_format_capacities(struct fsg_common *common, buf += 4; put_unaligned_be32(curlun->num_sectors, &buf[0]); /* Number of blocks */ - put_unaligned_be32(512, &buf[4]); /* Block length */ + put_unaligned_be32(curlun->blksize, &buf[4]); /* Block length */ buf[4] = 0x02; /* Current capacity */ return 12; } @@ -1780,8 +1781,18 @@ static int check_command(struct fsg_common *common, int cmnd_size, return 0; } +/* wrapper of check_command for data size in blocks handling */ +static int check_command_size_in_blocks(struct fsg_common *common, + int cmnd_size, enum data_direction data_dir, + unsigned int mask, int needs_medium, const char *name) +{ + common->data_size_from_cmnd <<= common->luns[common->lun].blkbits; + return check_command(common, cmnd_size, data_dir, + mask, needs_medium, name); +} + static int do_scsi_command(struct fsg_common *common) { struct fsg_buffhd *bh; @@ -1864,32 +1875,32 @@ static int do_scsi_command(struct fsg_common *common) break; case SC_READ_6: i = common->cmnd[4]; - common->data_size_from_cmnd = (i == 0 ? 256 : i) << 9; - reply = check_command(common, 6, DATA_DIR_TO_HOST, - (7<<1) | (1<<4), 1, - "READ(6)"); + common->data_size_from_cmnd = (i == 0 ? 256 : i); + reply = check_command_size_in_blocks(common, 6, DATA_DIR_TO_HOST, + (7<<1) | (1<<4), 1, + "READ(6)"); if (reply == 0) reply = do_read(common); break; case SC_READ_10: common->data_size_from_cmnd = - get_unaligned_be16(&common->cmnd[7]) << 9; - reply = check_command(common, 10, DATA_DIR_TO_HOST, - (1<<1) | (0xf<<2) | (3<<7), 1, - "READ(10)"); + get_unaligned_be16(&common->cmnd[7]); + reply = check_command_size_in_blocks(common, 10, DATA_DIR_TO_HOST, + (1<<1) | (0xf<<2) | (3<<7), 1, + "READ(10)"); if (reply == 0) reply = do_read(common); break; case SC_READ_12: common->data_size_from_cmnd = - get_unaligned_be32(&common->cmnd[6]) << 9; - reply = check_command(common, 12, DATA_DIR_TO_HOST, - (1<<1) | (0xf<<2) | (0xf<<6), 1, - "READ(12)"); + get_unaligned_be32(&common->cmnd[6]); + reply = check_command_size_in_blocks(common, 12, DATA_DIR_TO_HOST, + (1<<1) | (0xf<<2) | (0xf<<6), 1, + "READ(12)"); if (reply == 0) reply = do_read(common); break; @@ -1982,32 +1993,32 @@ static int do_scsi_command(struct fsg_common *common) break; case SC_WRITE_6: i = common->cmnd[4]; - common->data_size_from_cmnd = (i == 0 ? 256 : i) << 9; - reply = check_command(common, 6, DATA_DIR_FROM_HOST, - (7<<1) | (1<<4), 1, - "WRITE(6)"); + common->data_size_from_cmnd = (i == 0 ? 256 : i); + reply = check_command_size_in_blocks(common, 6, DATA_DIR_FROM_HOST, + (7<<1) | (1<<4), 1, + "WRITE(6)"); if (reply == 0) reply = do_write(common); break; case SC_WRITE_10: common->data_size_from_cmnd = - get_unaligned_be16(&common->cmnd[7]) << 9; - reply = check_command(common, 10, DATA_DIR_FROM_HOST, - (1<<1) | (0xf<<2) | (3<<7), 1, - "WRITE(10)"); + get_unaligned_be16(&common->cmnd[7]); + reply = check_command_size_in_blocks(common, 10, DATA_DIR_FROM_HOST, + (1<<1) | (0xf<<2) | (3<<7), 1, + "WRITE(10)"); if (reply == 0) reply = do_write(common); break; case SC_WRITE_12: common->data_size_from_cmnd = - get_unaligned_be32(&common->cmnd[6]) << 9; - reply = check_command(common, 12, DATA_DIR_FROM_HOST, - (1<<1) | (0xf<<2) | (0xf<<6), 1, - "WRITE(12)"); + get_unaligned_be32(&common->cmnd[6]); + reply = check_command_size_in_blocks(common, 12, DATA_DIR_FROM_HOST, + (1<<1) | (0xf<<2) | (0xf<<6), 1, + "WRITE(12)"); if (reply == 0) reply = do_write(common); break; @@ -2496,9 +2507,9 @@ static struct fsg_common *fsg_common_init(struct fsg_common *common, for (i = 0; i < nluns; i++) { common->luns[i].removable = 1; - rc = fsg_lun_open(&common->luns[i], ums[i].num_sectors, ""); + rc = fsg_lun_open(&common->luns[i], ums[i].num_sectors, ums->block_dev.blksz, ""); if (rc) goto error_luns; } common->lun = 0; diff --git a/drivers/usb/gadget/storage_common.c b/drivers/usb/gadget/storage_common.c index 5674e8fe4940..97dc6b6f729c 100644 --- a/drivers/usb/gadget/storage_common.c +++ b/drivers/usb/gadget/storage_common.c @@ -268,8 +268,9 @@ struct interrupt_data { struct device_attribute { int i; }; #define ETOOSMALL 525 #include +#include #include #include /*-------------------------------------------------------------------------*/ @@ -289,8 +290,10 @@ struct fsg_lun { u32 sense_data; u32 sense_data_info; u32 unit_attention_data; + unsigned int blkbits; + unsigned int blksize; /* logical block size of bound block device */ struct device dev; }; @@ -565,19 +568,22 @@ static struct usb_gadget_strings fsg_stringtab = { * the caller must own fsg->filesem for writing. */ static int fsg_lun_open(struct fsg_lun *curlun, unsigned int num_sectors, - const char *filename) + unsigned int sector_size, const char *filename) { int ro; /* R/W if we can, R/O if we must */ ro = curlun->initially_ro; curlun->ro = ro; - curlun->file_length = num_sectors << 9; + curlun->file_length = num_sectors * sector_size; curlun->num_sectors = num_sectors; - debug("open backing file: %s\n", filename); + curlun->blksize = sector_size; + curlun->blkbits = order_base_2(sector_size >> 9) + 9; + debug("blksize: %u\n", sector_size); + debug("open backing file: '%s'\n", filename); return 0; } diff --git a/include/usb_mass_storage.h b/include/usb_mass_storage.h index 83ab93b530d7..6d83d93cad7f 100644 --- a/include/usb_mass_storage.h +++ b/include/usb_mass_storage.h @@ -6,9 +6,8 @@ #ifndef __USB_MASS_STORAGE_H__ #define __USB_MASS_STORAGE_H__ -#define SECTOR_SIZE 0x200 #include #include /* Wait at maximum 60 seconds for cable connection */ From patchwork Fri Mar 15 15:06:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Caleb Connolly X-Patchwork-Id: 1912572 X-Patchwork-Delegate: marek.vasut@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=yY5MAZau; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=patchwork.ozlabs.org) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Tx6zk6XKhz1yWn for ; Sat, 16 Mar 2024 02:07:14 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id A7B4188023; Fri, 15 Mar 2024 16:06:19 +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="yY5MAZau"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 42DD288008; Fri, 15 Mar 2024 16:06:17 +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=ham autolearn_force=no version=3.4.2 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) (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 70EFA88019 for ; Fri, 15 Mar 2024 16:06:12 +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-x431.google.com with SMTP id ffacd0b85a97d-33ed6078884so255589f8f.1 for ; Fri, 15 Mar 2024 08:06:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1710515172; x=1711119972; 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=Zbk4r4UyBzKuozH08fyGqwtHnRd654EBpMK0f9wmWRc=; b=yY5MAZauBCgd5QwuzTK3jztJryPWMGC74BpCQDaXg/dNJGq44KzjS4WIpeJAEVZqD5 fNdxUhIvEt+DlAyDcsorH+tvcg9eE04LM8miTWMJraK66rQCnX5FDCbeoX2AzpHVi1O4 aVNBeH2wmdzq5P+S0Un4plOox40OWChTxXGYGTvBzSb0CGKgEgWxpBPgxJSTlTo20OkY Yo4g8HcCqGt/wM8hkHYTzzzHv2R0H/08L62a4oy4CFLgGFxUyz47UnM6OA5Hu4FT3SAK DPLgWggJaE5efSj+7P9AHXnO7sPSlJHZDsnJ2/YY+vLjZwM4bqaWmqV/G/QDeueoRcMP WnIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710515172; x=1711119972; 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=Zbk4r4UyBzKuozH08fyGqwtHnRd654EBpMK0f9wmWRc=; b=HiNNvnN+k4htyF9fTTxvh+u25ab6uQ54rLtslnZT1gDHkOtC0bO3wBSqMoDSF1bAfw g2WwDL4bPTeJP+5d9BnoxAio8Uy5qhkkvZ8Usu2cn4axu0ZNr8Uk9HjleIR4wr4K3Aye bFN6eY0RCJYdK4IpA/s0Celgxvh8Zn7P0ujBPhVf8NdgnRmIX1xmDGo76JGAAHAqvoi+ WD2sNgL/nm7rAAzV3+c0y08B8f+lQ3BTntBjDyk+zSKRX9FukdV/XXr4I02xU7LKqOcV ld/cCOp7uMSqFnfzuotAn7mjzKyroBhN3+dwD7ABfpOIjiSUe0RuimlKhF/RutlypqvX Yr7w== X-Gm-Message-State: AOJu0Yx5/y+u7cVI2VK8eztBISXBovtW8b/KvqdmrRUmp3o4kcN1NJLn YBT1L9ym0XelkkDa6mrpWBsEbqmAjwICa0nXtUYvSk1hVt+Wwtd2yRBrwntTHW/vPbz5hHw5PBd K X-Google-Smtp-Source: AGHT+IENJ/9sQd/0FPlqvidJ7nJjIqTeGucjcRO/C2MdO8C9cqzba6lwgMA62WubYJqm4w1laMI4Og== X-Received: by 2002:adf:f5c6:0:b0:33e:2d7b:c5a8 with SMTP id k6-20020adff5c6000000b0033e2d7bc5a8mr6838335wrp.17.1710515171690; Fri, 15 Mar 2024 08:06:11 -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.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Mar 2024 08:06:10 -0700 (PDT) From: Caleb Connolly Date: Fri, 15 Mar 2024 15:06:04 +0000 Subject: [PATCH v2 5/5] iommu: qcom-smmu: fix debugging MIME-Version: 1.0 Message-Id: <20240315-b4-qcom-usb-v2-5-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=802; i=caleb.connolly@linaro.org; h=from:subject:message-id; bh=Vh7wChQ7oSn3qK3m6JbZXYrVDFhwkmOI9fGRczQh+FQ=; b=owGbwMvMwCFYaeA6f6eBkTjjabUkhtQvyXfvKa6T8VW6sWjfifvbtQLWtc2UPs3w8P/mr3zNR q+urSlx7yhlYRDkYJAVU2QRP7HMsmntZXuN7QsuwMxhZQIZwsDFKQAT6V/O8L9ye/cD7colsS+N 5kxKPJnIccd+iinXo3d24feD83+fV5rB8Ff4D4tpWETV/pOlMSEFd14Lxnx+c2nd8TnzTgf+WJx y2zUAAA== 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 priv struct was wrong in dump_boot_mappings(). Causing errors when compiling with -DDEBUG. Fix this. Reviewed-by: Mattijs Korpershoek Signed-off-by: Caleb Connolly --- drivers/iommu/qcom-hyp-smmu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/iommu/qcom-hyp-smmu.c b/drivers/iommu/qcom-hyp-smmu.c index 8e5cdb581550..f2b39de56f4a 100644 --- a/drivers/iommu/qcom-hyp-smmu.c +++ b/drivers/iommu/qcom-hyp-smmu.c @@ -318,9 +318,9 @@ static int qcom_smmu_connect(struct udevice *dev) return 0; } #ifdef DEBUG -static inline void dump_boot_mappings(struct arm_smmu_priv *priv) +static inline void dump_boot_mappings(struct qcom_smmu_priv *priv) { u32 val; int i;