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 1CCCAC46467 for ; Tue, 10 Jan 2023 09:12:05 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 609E0850DB; Tue, 10 Jan 2023 10:12:03 +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="u1hlo4rI"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9461285038; Tue, 10 Jan 2023 10:12:01 +0100 (CET) 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 31480851E0 for ; Tue, 10 Jan 2023 10:11:58 +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-x32d.google.com with SMTP id z8-20020a05600c220800b003d33b0bda11so645295wml.0 for ; Tue, 10 Jan 2023 01:11:58 -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=63iLDkccspBlxYBc00+HNyjHI/ObcW6scRK0APCsU4U=; b=u1hlo4rICngP98O7rLy0NMV0s/dFP9hiPFjexCBCBMCJ/YL2ypNgxPT1VDwXYXgwcI IFC940yVYFhBxFSBi5h2pdDe1C6XBaiXfMNXxa9dNGPN9+aoz8wkd4MmweNhkUmmpQWL ja58iaW6shffilc6LOcqH0YudKn1jkZxWbZzDrfjHhjFXH3cnoXMLjtlVmBVt+shc8pj BkaKeJkYuaSce8O6JXq1wcAQ3rnaJllAe0VyOnCchEvAz/66/J/lIWfVN84mfKDaCmCn rZgA/g5QJWQrQg+LHduJ7AYA+RVqlOhgV7OPhR9wWn8y0pyiytw1VjnBBcU1KTm6TG4x 4nMw== 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=63iLDkccspBlxYBc00+HNyjHI/ObcW6scRK0APCsU4U=; b=WNE7yPmf4MU0UQY6ntjIBpkvsUtzbP1w9GfuS13I4VUUET2CV7565hTorNsJhX4Min J/SgUNmV+IsDEsD24G2kWcymhU6R8s/WQ4oMTUjDZHJ3qU75Mlx0oVbqfsVrgMryaDH/ s2sW7nsJnOfN9VDyMiq2k6aLzw7QIVEGNRSpalLkBWa+EwD+temmtY1Yrj9WkFwlV8mO ygaCCNMDPxsdGpeRI1I+KvYlEiZ8ur6kkxRtQynXkT8H+tGhzm3CHIvIaFSY0DT/8OFZ y3peaZx2hC5925dlJikEVv9Xx26FDuZL18aXOAwRJsCbHnYBIxoe9EMterkOfkBK0Ks8 YxIQ== X-Gm-Message-State: AFqh2kq9DF+in/bWC+Xf/OYa63X7vB06jbHaTt3jaiJPw+mw4tqpHI7+ Os6x5SJ51cRjiGxGEkt1woBGng== X-Google-Smtp-Source: AMrXdXujrZLuUaa3Pp1RVsvkV0u4kfyyqEkpSMuJASMHZ7hTkroLN+giJkh9I1absuND9q9AHPw32g== X-Received: by 2002:a05:600c:1604:b0:3d5:b222:20a with SMTP id m4-20020a05600c160400b003d5b222020amr49181620wmn.32.1673341917546; Tue, 10 Jan 2023 01:11:57 -0800 (PST) Received: from mkorpershoek-xps-13-9370.home ([2a01:cb19:85e6:1900:5f1e:d910:dd1e:5b09]) by smtp.gmail.com with ESMTPSA id p11-20020a05600c358b00b003cfa3a12660sm1392185wmq.1.2023.01.10.01.11.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jan 2023 01:11:57 -0800 (PST) From: Mattijs Korpershoek Date: Tue, 10 Jan 2023 10:11:44 +0100 Subject: [PATCH] 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-v1-1-2bf9743e59e5@baylibre.com> X-B4-Tracking: v=1; b=H4sIANArvWMC/x2NywrCMBAAf6Xk7GIeVMFfEQ95bE1oTcJuH0Lpv 5t6HJhhdsFICVk8ul0QrolTyQ3UpRM+2vxGSKGx0FIbqZSEsHkNdZmmpULv5NBbeTfh5kQrnGUE Rzb7eDafsVBF4lhwvM7IMwRLqcBqTrkSDun7Xz9fx/EDNiSBbIoAAAA= To: Lukasz Majewski , Marek Vasut Cc: Dario Binacchi , Michael Trimarchi , u-boot@lists.denx.de, Mattijs Korpershoek X-Mailer: b4 0.12-dev-12cbf 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. 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/ --- drivers/usb/gadget/dwc2_udc_otg.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/drivers/usb/gadget/dwc2_udc_otg.c b/drivers/usb/gadget/dwc2_udc_otg.c index 77988f78ab30..93ed9712d18a 100644 --- a/drivers/usb/gadget/dwc2_udc_otg.c +++ b/drivers/usb/gadget/dwc2_udc_otg.c @@ -236,6 +236,21 @@ static int udc_enable(struct dwc2_udc *dev) return 0; } +static int dwc2_gadget_pullup(struct usb_gadget *g, int is_on) +{ + unsigned int uTemp; + + is_on = !!is_on; + uTemp = readl(®->dctl); + if (is_on) + uTemp = uTemp & ~SOFT_DISCONNECT; + else + uTemp |= SOFT_DISCONNECT; + writel(uTemp, ®->dctl); + + return 0; +} + #if !CONFIG_IS_ENABLED(DM_USB_GADGET) /* Register entry point for the peripheral controller driver. @@ -805,6 +820,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: 7b84c973b96775576dcff228d865e8570be26c82 change-id: 20230110-dwc2-pullup-5b0f5a073d6b Best regards, -- Mattijs Korpershoek