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 BE6CDC46467 for ; Wed, 11 Jan 2023 08:19:48 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id A3934856E1; Wed, 11 Jan 2023 09:19:46 +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.20210112.gappssmtp.com header.i=@baylibre-com.20210112.gappssmtp.com header.b="yV4IF45F"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 96AAB856DD; Wed, 11 Jan 2023 09:19:44 +0100 (CET) Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) (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 820CB856E1 for ; Wed, 11 Jan 2023 09:19:40 +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-wm1-x32f.google.com with SMTP id p1-20020a05600c1d8100b003d8c9b191e0so11983734wms.4 for ; Wed, 11 Jan 2023 00:19:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:from:to:cc:subject:date:message-id:reply-to; bh=p9PEd1SEYJBx30fLQTOP+FzZGAApQCt3/tVASEWJUFs=; b=yV4IF45F5r4Z2EqYFkJi0yIngckskM1/NpSFBuVz61pMKm1wbReTdaLp4gS5IO6Jfh T91K4SQkzNqBkB1FfsvimfHnPwftkWCZbkY6zVnOZfCn1/Vj73Uxgvh25SR2n6S05PVU ENRZkrwUHIykbrsV5GSuUyzk30zFQAPMMqWs2ZeP+PmgKe4QlSIB9WVlwIlhuBt1fJ+x Mm7695ODktmk05SXAJsdJgb770A9pwmGfqUnldFZVwj2gQbtEBdtMAMSnu3NJnop+HB5 DjugCmR3aAIF9+MbNyNbvllv4nS8z19lmNnGqSK5hAjsAQd8PyEz+vZ+YBsvgawnj9ws o/Og== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=p9PEd1SEYJBx30fLQTOP+FzZGAApQCt3/tVASEWJUFs=; b=oGFSIHcg0IZarMUe+okAj7yuThJJoeGOnmKKnFXWQ1U4m7w1Fywokci29vUe0lv6LE BsgJk8ts7DhiNjY/WhL7GGyuZxe1BQNODS7Q/LKnr4Md0WNfqRgyyO+xGP9taYNdd38k ZeC1S++GvkmD1lrgXI+d/s4+30n8b9Fd/EFlQH4rUTNmVNzL63pX/DXWl3yuP1XejUYI eWNkZ1nqf4/shJE6ZzhpQNacmCNH8tOrrUsyrJoBYFJtk0XChE0fLJ0ZL1cFf4YMWH/3 oufl9vsZwl12NId2Gz8OGSGHYDp88LrYYa6+Ro2V/WWqkW4Om+arakIutR9hJyIGBmJq E0pQ== X-Gm-Message-State: AFqh2kqLh7P+ijQ0NBYbnWD0Nq4fBPdXXvEVHEM0wAFIfSYZMk+qKDQA cqB+8nem6M7hYR1IYAW+Qo8OQelgE1UuNqc5 X-Google-Smtp-Source: AMrXdXuRaJBAmfSBTwyojkw9JRy0bRUZnUPVWJgvgDuEhNnSCYWUGemMaWGphxgOJ0Ip9zBiXA0OoQ== X-Received: by 2002:a1c:7216:0:b0:3d3:49db:9b25 with SMTP id n22-20020a1c7216000000b003d349db9b25mr53489852wmc.26.1673425179984; Wed, 11 Jan 2023 00:19:39 -0800 (PST) Received: from groot.local ([2a01:cb19:85e6:1900:2bf7:7388:731d:c4e1]) by smtp.gmail.com with ESMTPSA id u8-20020a05600c19c800b003d9780466b0sm19388814wmq.31.2023.01.11.00.19.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Jan 2023 00:19:39 -0800 (PST) From: Mattijs Korpershoek Date: Wed, 11 Jan 2023 09:19:27 +0100 Subject: [PATCH v3] usb: gadget: dwc2_udc_otg: implement pullup() MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20230110-dwc2-pullup-v3-1-72d8027a97c2@baylibre.com> X-B4-Tracking: v=1; b=H4sIAA9xvmMC/32OSw7CMAxEr4KyxpAPoSor7oFY5OPSiNJUThtAq HcnZYkQy2fN88yLJaSAiR1WL0aYQwqxL6DWK+Za018Qgi/MJJeKC8HB352EYeq6aQBteaMNr5Tf W1YMaxKCJdO7dnFu10gDUmojXrcjphG8oRAhqyU8EDbh8ak+nQu3IY2Rnp8lWSzX36VZgABpm7r aKdQ16qM1zy5Ywo2LN7a8yvKPLovud45jpU2tav+lz/P8BrAwgqMVAQAA To: Lukasz Majewski , Marek Vasut Cc: Harald Seiler , Dario Binacchi , Michael Trimarchi , u-boot@lists.denx.de, Mattijs Korpershoek X-Mailer: b4 0.11.1 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.6 at phobos.denx.de X-Virus-Status: Clean Pullup is used by the usb framework in order to do software-controlled usb_gadget_connect() and usb_gadget_disconnect(). Implement pullup() for dwc2 using the SOFT_DISCONNECT bit in the dctl register: * when pullup is on, clear SOFT_DISCONNECT * when pullup is off, set SOFT_DISCONNECT This is especially useful when a gadget disconnection is initiated but no board_usb_cleanup() is called. Signed-off-by: Mattijs Korpershoek --- On some boards using the dwc2 controller, like the Khadas VIM3L, whenever usb_gadget_release() is called, the D+ and D- lines are in an unknown state. Because of that, the host can't detect usb disconnection. It was attempted to be be fixed with [1] but ended up doing the gadget disconnection too early, creating issues on NXP-based boards which use uuu [2]. By implementing pullup() in the controller driver, we ensure that the disconnection will only be done when the framework calls usb_gadget_disconnect(). [1] https://lore.kernel.org/all/20220728-reset-usb-controller-v2-1-ef7657ce78b1@baylibre.com/ [2] https://lore.kernel.org/all/20230107164807.3597020-1-dario.binacchi@amarulasolutions.com/ --- Changes in v3: - Simplified even further usage of clrsetbits_le32 (Marek) - Link to v2: https://lore.kernel.org/r/20230110-dwc2-pullup-v2-1-d4c0e75a939d@baylibre.com Changes in v2: - Simplified code to fix hungarian notation, appropriate type (u32) for register (Harald) - Use clrsetbits_le32() for register write (Marek) - Link to v1: https://lore.kernel.org/r/20230110-dwc2-pullup-v1-1-2bf9743e59e5@baylibre.com --- drivers/usb/gadget/dwc2_udc_otg.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/usb/gadget/dwc2_udc_otg.c b/drivers/usb/gadget/dwc2_udc_otg.c index 77988f78ab30..2bf7ed8d6046 100644 --- a/drivers/usb/gadget/dwc2_udc_otg.c +++ b/drivers/usb/gadget/dwc2_udc_otg.c @@ -236,6 +236,14 @@ static int udc_enable(struct dwc2_udc *dev) return 0; } +static int dwc2_gadget_pullup(struct usb_gadget *g, int is_on) +{ + clrsetbits_le32(®->dctl, SOFT_DISCONNECT, + is_on ? 0 : SOFT_DISCONNECT); + + return 0; +} + #if !CONFIG_IS_ENABLED(DM_USB_GADGET) /* Register entry point for the peripheral controller driver. @@ -805,6 +813,7 @@ static void dwc2_fifo_flush(struct usb_ep *_ep) } static const struct usb_gadget_ops dwc2_udc_ops = { + .pullup = dwc2_gadget_pullup, /* current versions must always be self-powered */ #if CONFIG_IS_ENABLED(DM_USB_GADGET) .udc_start = dwc2_gadget_start, --- base-commit: 81996adedf42e89de97c2ed5dcde62be4bb4e4e0 change-id: 20230110-dwc2-pullup-5b0f5a073d6b Best regards, -- Mattijs Korpershoek