From patchwork Tue Jan 18 00:21:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adam Ford X-Patchwork-Id: 1581008 X-Patchwork-Delegate: sbabic@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=ebXHPhKQ; dkim-atps=neutral Authentication-Results: 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=) 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 RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Jd8Zz202gz9sXM for ; Tue, 18 Jan 2022 11:21:29 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 76F6B834A0; Tue, 18 Jan 2022 01:21:21 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.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=gmail.com header.i=@gmail.com header.b="ebXHPhKQ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C0164803CF; Tue, 18 Jan 2022 01:21:19 +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=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.2 Received: from mail-il1-x12d.google.com (mail-il1-x12d.google.com [IPv6:2607:f8b0:4864:20::12d]) (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 AE193834B1 for ; Tue, 18 Jan 2022 01:21:16 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=aford173@gmail.com Received: by mail-il1-x12d.google.com with SMTP id e8so16142005ilm.13 for ; Mon, 17 Jan 2022 16:21:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=q2JfOAsgPp5R1v2kCNs/IunAjcO60kXdiRO44OZc8+k=; b=ebXHPhKQL4cHcRyCFTXgbABSL/bTTZozLqZZLuyVcdl3pRCra9WkwwGeJylnNoTBwV bdIGWRorY0+f9XXjLCEvwZPLmTRQNeMS98mR411Mz3veFMjE+kMr/iFbyZ8+FqJroLX0 C+zC7SOWUnohyLjSYombx5D1Zwc/yiNz6ZbaVaj5cDzQHkf6ubniTnaE3wwdjnNAObP9 5YBtaxSqsCgfaj+mtbqKMIbIbS0siliNbXfeRMYnsQrTkt/mu/DL6TK4nvlflSVZU4Wj mnJuOYnR9jBAwWVEdBAfcC4x4xHzz02l/UEuytdK5BFhtG6/1TqPThBGKLkbrxjeamvz bIjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=q2JfOAsgPp5R1v2kCNs/IunAjcO60kXdiRO44OZc8+k=; b=bMeDeOnGRIgggmQ0xRHbFkPaWSxiQBb5zFuqNnRcNNrtnMcrawfICORzC9IhGmlH3M is5S7lCzM87+FobpOXrs/V95om9GQQVeW1/Kt2fiOf1xUYfaVy6yXumCHEeHtnBs+efn LMl6eo13BveJWBD7BogTHNFEiOKlYdbhGVlq+/isaQCMEBshrJPGWwfBImwiykLnsUCP I+dGWiGkESMKCZoD2FKKfO/ZEbEoCN7iM4yQ10xuVz+2rMIr/4r3FMzBjGGmSuAgRTua G99VtiBtg/p+i69JZjbjej2IU0eKz7jn5JTfFEF4hmxM71FjKpcx5nglujlGgUj4QJzr oNXA== X-Gm-Message-State: AOAM531rxA8DjT3W2rK4lZdKy4SmE8lS96iLR7uz+MORUFT5GQBjz5Tb dMPr/QPuvLyjhNcz7xCay44HGVl/jOo= X-Google-Smtp-Source: ABdhPJz0HoC7p3yivAdUm6GnUS8apxS5Y6HukybSw1hOGv13BFO4khUxzOl9aN9Ps5HL57hj1PDfVQ== X-Received: by 2002:a05:6e02:1bc7:: with SMTP id x7mr10911796ilv.255.1642465274696; Mon, 17 Jan 2022 16:21:14 -0800 (PST) Received: from aford-IdeaCentre-A730.lan ([2601:448:8400:9e8:a8b:557:cea0:b490]) by smtp.gmail.com with ESMTPSA id f20sm5223126ile.14.2022.01.17.16.21.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Jan 2022 16:21:14 -0800 (PST) From: Adam Ford To: u-boot@lists.denx.de Cc: marex@denx.de, tharvey@gateworks.com, festevam@denx.de, aford@beaconembedded.com, Adam Ford Subject: [PATCH V3] usb: ehci-mx6: Enable OTG detection on imx8mm and imx8mn Date: Mon, 17 Jan 2022 18:21:03 -0600 Message-Id: <20220118002103.112748-1-aford173@gmail.com> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 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.2 at phobos.denx.de X-Virus-Status: Clean The imx8mm and imx8mn appear compatible with imx7d-usb flags in the OTG driver. If the dr_mode is defined as host or peripheral, the device appears to operate correctly, however the auto host/peripheral detection results in an error. The solution isn't just adding checks for imx8mm and imx8mn to the check for imx7, because the USB clock needs to be running to read from the USBNC_PHY_STATUS_OFFSET register or it will hang. Marek requested that I not enable the clocks in ehci_usb_of_to_plat, so I modified that function to return an unknown state if the device tree does not explicitly state whether it is a host or a peripheral. When the driver probes, it looks to see if it's in the unknown state, and only then will it read the register to auto-detect. Signed-off-by: Adam Ford Tested-By: Tim Harvey --- V3: Keep ehci_usb_of_to_plat but add the ability to return and unknown state instead of reading the register. If the probe determines the states is unknown, it will query the register after the clocks have been enabled. Because of the slight behavior change, I removed any review or tested tags. V2: Rename ehci_usb_of_to_plat to ehci_usb_dr_mode and call it from the probe after the clocks are enabled, but before the data is needed. diff --git a/drivers/usb/host/ehci-mx6.c b/drivers/usb/host/ehci-mx6.c index 1bd6147c76..cf44e53ff7 100644 --- a/drivers/usb/host/ehci-mx6.c +++ b/drivers/usb/host/ehci-mx6.c @@ -543,7 +543,7 @@ static int ehci_usb_phy_mode(struct udevice *dev) plat->init_type = USB_INIT_DEVICE; else plat->init_type = USB_INIT_HOST; - } else if (is_mx7()) { + } else if (is_mx7() || is_imx8mm() || is_imx8mn()) { phy_status = (void __iomem *)(addr + USBNC_PHY_STATUS_OFFSET); val = readl(phy_status); @@ -573,9 +573,8 @@ static int ehci_usb_of_to_plat(struct udevice *dev) case USB_DR_MODE_PERIPHERAL: plat->init_type = USB_INIT_DEVICE; break; - case USB_DR_MODE_OTG: - case USB_DR_MODE_UNKNOWN: - return ehci_usb_phy_mode(dev); + default: + plat->init_type = USB_INIT_UNKNOWN; }; return 0; @@ -677,6 +676,20 @@ static int ehci_usb_probe(struct udevice *dev) mdelay(1); #endif + /* + * If the device tree didn't specify host or device, + * the default is USB_INIT_UNKNOWN, so we need to check + * the register. For imx8mm and imx8mn, the clocks need to be + * running first, so we defer the check until they are. + */ + if (priv->init_type == USB_INIT_UNKNOWN) { + ret = ehci_usb_phy_mode(dev); + if (ret) + goto err_clk; + else + priv->init_type = plat->init_type; + } + #if CONFIG_IS_ENABLED(DM_REGULATOR) ret = device_get_supply_regulator(dev, "vbus-supply", &priv->vbus_supply); diff --git a/include/usb.h b/include/usb.h index b3851fdb4f..47d738a786 100644 --- a/include/usb.h +++ b/include/usb.h @@ -163,7 +163,8 @@ struct int_queue; */ enum usb_init_type { USB_INIT_HOST, - USB_INIT_DEVICE + USB_INIT_DEVICE, + USB_INIT_UNKNOWN, }; /**********************************************************************