From mboxrd@z Thu Jan 1 00:00:00 1970 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 687EAC433F5 for ; Wed, 22 Dec 2021 20:09:14 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 4E43983059; Wed, 22 Dec 2021 21:09:11 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (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=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Amvf0bFX"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id F2B6A82EBB; Wed, 22 Dec 2021 21:09:09 +0100 (CET) Received: from mail-ed1-x52e.google.com (mail-ed1-x52e.google.com [IPv6:2a00:1450:4864:20::52e]) (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 8078882EBB for ; Wed, 22 Dec 2021 21:09:04 +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-ed1-x52e.google.com with SMTP id f5so12927582edq.6 for ; Wed, 22 Dec 2021 12:09:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=5Q5f8c9+i2/Hy7mIl+taAKNafoyPvR/JEKn0tLDUW4c=; b=Amvf0bFX6PdbjPABGQeTRA1AvjCsigJZsZ/ZhgOu1zyKyBcfEU9/kXgZh0hyBGirBP 2Sx93nqUC/h5THZTxGCbLGvsDFXf2UeKdPD7KXZkB/yrL2uITiI/dKt8whlMMj3EvqNZ wQrzGeXml0CugGMPmZUz+SOrBVoHT7/s2EhgImzYoxLNDcgm9rzj2VUjW7oQlrNw0LNy qa6unPfaHl2oivF6qanlzIBzS+n+hEsjhZ8uNXUUW2ff6vnk14i52fzYQ+PqSggkR22/ Q6Duu5TaAUo/j/pIzJ02HN9/VzhwvSVP7mYWe4WyZjf30G1+MTGUU2It3Mbd9yTOIEN6 QetQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=5Q5f8c9+i2/Hy7mIl+taAKNafoyPvR/JEKn0tLDUW4c=; b=jAM2ISvQtQeIFh+gUC0xJ4mxHgtn3hbGbBIvvtPlvp+eT4R2jXakd0ukRJPKlROUtN 5bqFehjt118iGaBJyBui3glT4p+PqAO5O9SZpvJJGjjSkktMncylRxeOZgZvmzsVSqby d4O+IBHqAPiTxGqljky0sSwo4skL7cCRyDFrVPzmyRwArQYXDlhLh15sAvDdBa+oFNMp sV7g9UwfFTb6RTsZcS/A+MxvtjALFZ/JCg9zF7mI+1u9hmUK+S1rbsSaLL3KVThsuWd+ ZZBu2pLfpetOlyn6154wpHLv/wGJy3hyRotVE4AqkrzoUIz+Q0OODnWZdZfF6RU5uNFl GLBg== X-Gm-Message-State: AOAM530DQVKWzmNcCUL5sdLkjnBQedzWF3r5b6VfABDXqNKJH3QSMBmF M0HI4CAs//XdF0G7ssK4tqCUdNXE/7ICdI9olSM= X-Google-Smtp-Source: ABdhPJxJM7wcJsgiC0igHejOUIgRqNDgyzx0vjhcBjBOOWFThwLQlFIhFwKmyfgbzau/YrOtehHtS6C1OrYLxQiVvo0= X-Received: by 2002:a17:906:6dce:: with SMTP id j14mr3590014ejt.305.1640203743522; Wed, 22 Dec 2021 12:09:03 -0800 (PST) MIME-Version: 1.0 References: <20211222125213.124677-1-aford173@gmail.com> <5f1065a7-4b91-961f-4baf-78b784ff24bc@denx.de> In-Reply-To: <5f1065a7-4b91-961f-4baf-78b784ff24bc@denx.de> From: Adam Ford Date: Wed, 22 Dec 2021 14:08:52 -0600 Message-ID: Subject: Re: [PATCH] usb: ehci-mx6: Enable OTG detection on imx8mm and imx8mn To: Marek Vasut Cc: U-Boot Mailing List , festevam@denx.de, Simon Glass Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.38 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.38 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 On Wed, Dec 22, 2021 at 1:31 PM Marek Vasut wrote: > On 12/22/21 13:52, Adam Ford wrote: > > 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. > > > > Simply adding checks in ehci_usb_phy_mode for 8mm and > > 8mn in ehci_usb_phy_mode is not enough, because ehci_usb_of_to_plat > > is run before the clock is enabled which results in a hang. > > > > Enable the USB clock in ehci_usb_of_to_plat and add checks in > > ehci_usb_phy_mode for 8mm and 8mn to enable auto detection of > > the OTG mode on i.MX8M Mini and Nano. > > I was under the impression that of_to_plat() was meant to parse DT into > driver local data, so frobbing with clock there could be a problem, > right ? +CC Simon. > If that's true, we'll likely need to move the functions from ehci_usb_of_to_plat to the probe function to run after the clocks are enabled, because the call to usb_get_dr_mode hangs without the clocks running. usb_get_dr_mode tells the driver if it's a host or device mode. We could make a temporary clock instead of passing the clock to the priv structure. I intentionally shut the clock off as soon as we're finished reading the register so it didn't collide with the existing functions. adam > > > diff --git a/drivers/usb/host/ehci-mx6.c b/drivers/usb/host/ehci-mx6.c > > index 1bd6147c76..fa0798171b 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); > > @@ -561,11 +561,30 @@ static int ehci_usb_phy_mode(struct udevice *dev) > > > > static int ehci_usb_of_to_plat(struct udevice *dev) > > { > > +#if CONFIG_IS_ENABLED(CLK) > > + int ret = 0; > > + struct ehci_mx6_priv_data *priv = dev_get_priv(dev); > > + > > + ret = clk_get_by_index(dev, 0, &priv->clk); > > + if (ret < 0) > > + return ret; > > + > > + ret = clk_enable(&priv->clk); > > + if (ret) > > + return ret; > > +#endif > > + > > struct usb_plat *plat = dev_get_plat(dev); > > enum usb_dr_mode dr_mode; > > > > dr_mode = usb_get_dr_mode(dev_ofnode(dev)); > > > > +#if CONFIG_IS_ENABLED(CLK) > > + ret = clk_disable(&priv->clk); > > + if (ret) > > + return ret; > > +#endif > > + > > switch (dr_mode) { > > case USB_DR_MODE_HOST: > > plat->init_type = USB_INIT_HOST; >