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 747E7C433F5 for ; Thu, 3 Feb 2022 21:20:37 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 77B2C83A3F; Thu, 3 Feb 2022 22:20:35 +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="dlMleZEp"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D297483A3A; Thu, 3 Feb 2022 22:20:33 +0100 (CET) Received: from mail-il1-x133.google.com (mail-il1-x133.google.com [IPv6:2607:f8b0:4864:20::133]) (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 E8A1B83A41 for ; Thu, 3 Feb 2022 22:20:30 +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-x133.google.com with SMTP id y17so3236510ilm.1 for ; Thu, 03 Feb 2022 13:20:30 -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=takMbaFpd+uqBYwR8J5uSW63JGjw1o8X/MZsaliFDp4=; b=dlMleZEp75g1Ji1fYfAw/GKmE9sZPIrH1wxeRHPhMjVkahsrdGnxzrQ6y+xa7Rf2v2 G136Uj1/ucTDB2TnTT7StVaVmCOVLiRwTOEMZeRZhC0C2A6jm8761Cs8APVntpxVoupd h/4K0ppThb+WQkt5eoop575queY+poLNXoOTQ6kttbTnfzN7keyzyZc+S7P9qIoo/3aj 3m9sELiyUwKcJkLdQKwNm20gfAnLEG6+RSJCaMEzi8rbWysRT6BlTbOIhrXURF7MZpFU R8DBl9g3XVAVbxk1g0jTsBVrvBF7ZlUPh2rlncW89x51ac21ZXn4doCrtjk2/ijrtX8Y 5Xvw== 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=takMbaFpd+uqBYwR8J5uSW63JGjw1o8X/MZsaliFDp4=; b=ijvemD9TW3VoOLQhnQG+OgvH6R+pUoHMAOxTP/j/O5FoT5mPiMSPDXyzMVvykPp8sn wUtfOm/Cw8FamSFa8jHAxU0L+6erex++7Vjlj6SDUfREgH/OpZAvKigyTVDNg7CI4OfA TFmr4PeNvaxnPsnczrGLQgxQNM2bxfb2M9PDEaAaSyEMX1l+5maNgVmmdXw7RLNLKgYY ILaQv2Nr85xfQsAcBLsv8//TWYYkBaN8wzAJaoRR89rK8q0hCOnJ3cLhLo5NlRfKycvA niicMY/oeA1vcgxHEAxGJl+acbwzt+nOwumh429XI3+XJ2llvxAGsszWtj8zrbCz0H+C hxdQ== X-Gm-Message-State: AOAM532YF9WevnM/f019DOI2G2lxOW1laLo4VH6cIQHBMjOlw/lHIS/L SgmX5OYXyyq1bt8mvflPDtG1+nCdFQM= X-Google-Smtp-Source: ABdhPJw5nJLrfNvnbQuBnGiqMqSGHa0N4waZyOLLI+Hg+UE1/+ngJ6uQCY6GvyqxuxquVXX9jqdvXg== X-Received: by 2002:a92:870b:: with SMTP id m11mr49ild.106.1643923229237; Thu, 03 Feb 2022 13:20:29 -0800 (PST) Received: from aford-IdeaCentre-A730.lan ([2601:448:8400:9e8:1b09:52f2:439d:6acc]) by smtp.gmail.com with ESMTPSA id ay35sm18488622iob.3.2022.02.03.13.20.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Feb 2022 13:20:28 -0800 (PST) From: Adam Ford To: u-boot@lists.denx.de Cc: marex@denx.de, marcel.ziswiler@toradex.com, festevam@gmail.com, tharvey@gateworks.com, aford@beaconembedded.com, Adam Ford Subject: [PATCH V4] usb: ehci-mx6: Enable OTG detection on imx8mm and imx8mn Date: Thu, 3 Feb 2022 15:20:11 -0600 Message-Id: <20220203212011.829122-1-aford173@gmail.com> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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.5 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 --- V4: Fix 'err_clk' reference, so it is not encapsulated in an ifdef making it available at all times. 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 t diff --git a/drivers/usb/host/ehci-mx6.c b/drivers/usb/host/ehci-mx6.c index 1bd6147c76..060b02accc 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); @@ -741,8 +754,8 @@ err_regulator: #if CONFIG_IS_ENABLED(DM_REGULATOR) if (priv->vbus_supply) regulator_set_enable(priv->vbus_supply, false); -err_clk: #endif +err_clk: #if CONFIG_IS_ENABLED(CLK) clk_disable(&priv->clk); #else diff --git a/include/usb.h b/include/usb.h index f032de8af9..7e3796bd5b 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, }; /********************************************************************** -- 2.32.0