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 32E64C433EF for ; Thu, 23 Dec 2021 14:08:25 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 5EB6383003; Thu, 23 Dec 2021 15:08:22 +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="PLbG/7if"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id EDE008142D; Thu, 23 Dec 2021 15:08:19 +0100 (CET) Received: from mail-il1-x132.google.com (mail-il1-x132.google.com [IPv6:2607:f8b0:4864:20::132]) (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 6EA6983003 for ; Thu, 23 Dec 2021 15:08:10 +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-x132.google.com with SMTP id e8so4301800ilm.13 for ; Thu, 23 Dec 2021 06:08:10 -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=lHR59KNQq9k5vwYrQJYmn+/aNLsCyqdfYnJbnY5O1sM=; b=PLbG/7iflcH83ML15XqOkIVqJxsvt4C9wR4Yy1XojMJhv9sbO7nrKTeeovDPDMpBJQ Ed7I1iwWCrD3erWs9Bz16wjlHtzGltAA7AbaPiVkDhBk7EgWZ8LH4nY1plIV75tU8Qvq Q/Z03c/gruGLttwolXwKwZgE8k9UXN7de3AZWZ6YgOL+a1q3yAI1nGa8nHNDa2iEMu1s 9DfB7Vk0BNjRne+/DNpHg1IIjoaiIRFtIin8AiBiyr4B28jul/9a0TZkGg2N+H+wxrwQ Owx+UXv+VHV2gMzMSxUP/RQMgMARmetjgiv3HcpaIruNSFR1LiVPH84D7AsypuAGv422 zwpA== 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=lHR59KNQq9k5vwYrQJYmn+/aNLsCyqdfYnJbnY5O1sM=; b=NCacr0QDCNYwixoy5OFAbokbnwG1XdbzqGEiuD8fXT9N1R3cEjm7UGeSHTz3hw/FPD cbekVbNwxHDbrdeTktUjE5y14zFfrODSs2o4n40U7t0gq9ePtaEZabqQUG3oT59mc+W/ v96HOEdCc9yPuBw75ezaPDj1B09kfz0YF3nCXtCymm63Kib4n2xh1ZGG2AeVII/cg+SB XoXzuGKruRbdodIWXi80m4dOJIotcmP4HBuHgZO0ojqvsncWpa6IOa6RzLpx7o5WjBEp Kh4kDEGUavCqKOBleCxYcS1ml0+Wvp7fzsOBEDpIrSXsAQokBfQVQeZk57o2wngYEK1L 81lQ== X-Gm-Message-State: AOAM531illFKagVhHmbBwcKBlUB+nFiQ0zSRQE5/Wd8J+bWNu2YJcqXd xNIud+SPjJcEBNyD+l3UYK3o5fvcpIzisw== X-Google-Smtp-Source: ABdhPJw6KgPj0yn6S6w0ZzEyijNIHIUBT9C/FNT8j4kIz2sJHCskFNRYqRisblSjQpkr+wocEBrkyA== X-Received: by 2002:a92:da42:: with SMTP id p2mr383150ilq.80.1640268488582; Thu, 23 Dec 2021 06:08:08 -0800 (PST) Received: from aford-IdeaCentre-A730.lan ([2601:448:8400:9e8:f7b6:6820:eda0:e208]) by smtp.gmail.com with ESMTPSA id m2sm3158459iob.21.2021.12.23.06.08.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Dec 2021 06:08:07 -0800 (PST) From: Adam Ford To: u-boot@lists.denx.de Cc: marex@denx.de, sjg@chromium.org, festevam@denx.de, Adam Ford Subject: [PATCH V2] usb: ehci-mx6: Enable OTG detection on imx8mm and imx8mn Date: Thu, 23 Dec 2021 08:07:56 -0600 Message-Id: <20211223140756.304527-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.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 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. The init_type in both priv and plat data are the same, so it doesn't make sense to configure the data in the plat data and copy the data to priv when priv can be configured directly. Instead, rename ehci_usb_of_to_plat to ehci_usb_dr_mode and call it from the probe functions after the clocks are enabled, but before the data is required. With that added, the additional checks for imx8mm and imx8mn will allow reading the register to automatically determine the state (host or device) of the OTG controller. Signed-off-by: Adam Ford --- 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..f2a34b7f06 100644 --- a/drivers/usb/host/ehci-mx6.c +++ b/drivers/usb/host/ehci-mx6.c @@ -513,7 +513,7 @@ static const struct ehci_ops mx6_ehci_ops = { static int ehci_usb_phy_mode(struct udevice *dev) { - struct usb_plat *plat = dev_get_plat(dev); + struct ehci_mx6_priv_data *priv = dev_get_priv(dev); void *__iomem addr = dev_read_addr_ptr(dev); void *__iomem phy_ctrl, *__iomem phy_status; const void *blob = gd->fdt_blob; @@ -540,18 +540,18 @@ static int ehci_usb_phy_mode(struct udevice *dev) val = readl(phy_ctrl); if (val & USBPHY_CTRL_OTG_ID) - plat->init_type = USB_INIT_DEVICE; + priv->init_type = USB_INIT_DEVICE; else - plat->init_type = USB_INIT_HOST; - } else if (is_mx7()) { + priv->init_type = USB_INIT_HOST; + } else if (is_mx7() || is_imx8mm() || is_imx8mn()) { phy_status = (void __iomem *)(addr + USBNC_PHY_STATUS_OFFSET); val = readl(phy_status); if (val & USBNC_PHYSTATUS_ID_DIG) - plat->init_type = USB_INIT_DEVICE; + priv->init_type = USB_INIT_DEVICE; else - plat->init_type = USB_INIT_HOST; + priv->init_type = USB_INIT_HOST; } else { return -EINVAL; } @@ -559,19 +559,19 @@ static int ehci_usb_phy_mode(struct udevice *dev) return 0; } -static int ehci_usb_of_to_plat(struct udevice *dev) +static int ehci_usb_dr_mode(struct udevice *dev) { - struct usb_plat *plat = dev_get_plat(dev); + struct ehci_mx6_priv_data *priv = dev_get_priv(dev); enum usb_dr_mode dr_mode; dr_mode = usb_get_dr_mode(dev_ofnode(dev)); switch (dr_mode) { case USB_DR_MODE_HOST: - plat->init_type = USB_INIT_HOST; + priv->init_type = USB_INIT_HOST; break; case USB_DR_MODE_PERIPHERAL: - plat->init_type = USB_INIT_DEVICE; + priv->init_type = USB_INIT_DEVICE; break; case USB_DR_MODE_OTG: case USB_DR_MODE_UNKNOWN: @@ -639,10 +639,8 @@ static int mx6_parse_dt_addrs(struct udevice *dev) static int ehci_usb_probe(struct udevice *dev) { - struct usb_plat *plat = dev_get_plat(dev); struct usb_ehci *ehci = dev_read_addr_ptr(dev); struct ehci_mx6_priv_data *priv = dev_get_priv(dev); - enum usb_init_type type = plat->init_type; struct ehci_hccr *hccr; struct ehci_hcor *hcor; int ret; @@ -660,8 +658,6 @@ static int ehci_usb_probe(struct udevice *dev) return ret; priv->ehci = ehci; - priv->init_type = type; - priv->phy_type = usb_get_phy_mode(dev_ofnode(dev)); #if CONFIG_IS_ENABLED(CLK) ret = clk_get_by_index(dev, 0, &priv->clk); @@ -677,6 +673,11 @@ static int ehci_usb_probe(struct udevice *dev) mdelay(1); #endif + ret = ehci_usb_dr_mode(dev); + if (ret) + goto err_clk; + priv->phy_type = usb_get_phy_mode(dev_ofnode(dev)); + #if CONFIG_IS_ENABLED(DM_REGULATOR) ret = device_get_supply_regulator(dev, "vbus-supply", &priv->vbus_supply); @@ -700,7 +701,7 @@ static int ehci_usb_probe(struct udevice *dev) #if CONFIG_IS_ENABLED(DM_REGULATOR) if (priv->vbus_supply) { ret = regulator_set_enable(priv->vbus_supply, - (type == USB_INIT_DEVICE) ? + (priv->init_type == USB_INIT_DEVICE) ? false : true); if (ret && ret != -ENOSYS) { printf("Error enabling VBUS supply (ret=%i)\n", ret); @@ -785,11 +786,9 @@ U_BOOT_DRIVER(usb_mx6) = { .name = "ehci_mx6", .id = UCLASS_USB, .of_match = mx6_usb_ids, - .of_to_plat = ehci_usb_of_to_plat, .probe = ehci_usb_probe, .remove = ehci_usb_remove, .ops = &ehci_usb_ops, - .plat_auto = sizeof(struct usb_plat), .priv_auto = sizeof(struct ehci_mx6_priv_data), .flags = DM_FLAG_ALLOC_PRIV_DMA, }; -- 2.32.0