All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tim Harvey <tharvey@gateworks.com>
To: Adam Ford <aford173@gmail.com>
Cc: u-boot <u-boot@lists.denx.de>, Marek Vasut <marex@denx.de>,
	Simon Glass <sjg@chromium.org>, Fabio Estevam <festevam@denx.de>
Subject: Re: [PATCH V2] usb: ehci-mx6: Enable OTG detection on imx8mm and imx8mn
Date: Mon, 3 Jan 2022 15:47:48 -0800	[thread overview]
Message-ID: <CAJ+vNU3emps8+VGOfzaPG723AJ+q0RKrYJYtcttx4vWMduHrJQ@mail.gmail.com> (raw)
In-Reply-To: <CAHCN7xKGptAi7-mrEoe=vOytavE4-StfPggj91+NZ6zs6gZZMQ@mail.gmail.com>

On Mon, Jan 3, 2022 at 2:32 PM Adam Ford <aford173@gmail.com> wrote:
>
>
>
> On Mon, Jan 3, 2022 at 10:20 PM Tim Harvey <tharvey@gateworks.com> wrote:
>>
>> On Thu, Dec 23, 2021 at 6:08 AM Adam Ford <aford173@gmail.com> 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.
>> >
>> > 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 <aford173@gmail.com>
>> > ---
>> > 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
>> >
>>
>> Adam,
>>
>> How are you testing this for IMX8MM or IMX8MN?
>
>
> I ran "ums 0 mmc 2" to  test peripheral mode and verified that I could see the corresponding MMC device appear on my host machine.  I actually burned an image to the eMMC and I was able to get Linux to run the eMMC I burned.
>
> I connected a USB host adapter that grounds the ID pin and ran "usb start" to test for mass storage devices, and did simple tests like "fatls usb 0" to verify I could read the thumb drive.
>
> I had to enable power-domain support, USB, mass storage, and a few other items in my config file to get it all to work.  I'm traveling, so I won't be able to give you my exact config options that I enabled.
>

Adam,

Thanks - It was the various configs that I was having trouble with...
there are a bunch of dependencies that are not obvious making me think
something else was still missing.

Tested-By: Tim Harvey <tharvey@gateworks.com> on imx8mm-venice-gw73xx-0x

I tested gadget mode via ums as well as host via asix_eth and this was
my defconfig diff for testing:
diff --git a/configs/imx8mm_venice_defconfig b/configs/imx8mm_venice_defconfig
index 822324766843..36a16866f1a0 100644
--- a/configs/imx8mm_venice_defconfig
+++ b/configs/imx8mm_venice_defconfig
@@ -48,6 +48,8 @@ CONFIG_CMD_FUSE=y
 CONFIG_CMD_GPIO=y
 CONFIG_CMD_I2C=y
 CONFIG_CMD_MMC=y
+CONFIG_CMD_USB=y
+CONFIG_CMD_USB_MASS_STORAGE=y
 CONFIG_CMD_CACHE=y
 CONFIG_CMD_TIME=y
 CONFIG_CMD_UUID=y
@@ -97,6 +99,8 @@ CONFIG_MII=y
 CONFIG_PINCTRL=y
 CONFIG_SPL_PINCTRL=y
 CONFIG_PINCTRL_IMX8M=y
+CONFIG_POWER_DOMAIN=y
+CONFIG_IMX8M_POWER_DOMAIN=y
 CONFIG_DM_PMIC=y
 CONFIG_DM_PMIC_BD71837=y
 CONFIG_SPL_DM_PMIC_BD71837=y
@@ -112,5 +116,21 @@ CONFIG_SYSRESET_PSCI=y
 CONFIG_SYSRESET_WATCHDOG=y
 CONFIG_DM_THERMAL=y
 CONFIG_IMX_TMU=y
+CONFIG_USB=y
+CONFIG_USB_EHCI_HCD=y
+CONFIG_USB_HOST_ETHER=y
+CONFIG_USB_ETHER_ASIX=y
+CONFIG_USB_ETHER_ASIX88179=y
+CONFIG_USB_ETHER_LAN75XX=y
+CONFIG_USB_ETHER_LAN78XX=y
+CONFIG_USB_ETHER_MCS7830=y
+CONFIG_USB_ETHER_RTL8152=y
+CONFIG_USB_ETHER_SMSC95XX=y
+CONFIG_USB_GADGET=y
+CONFIG_USB_GADGET_MANUFACTURER="Gateworks"
+CONFIG_USB_GADGET_VENDOR_NUM=0x0525
+CONFIG_USB_GADGET_PRODUCT_NUM=0xa4a5
+CONFIG_CI_UDC=y
+CONFIG_USB_GADGET_DOWNLOAD=y
 CONFIG_IMX_WATCHDOG=y
 CONFIG_HEXDUMP=y

Best Regards,

Tim

  reply	other threads:[~2022-01-03 23:48 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-23 14:07 [PATCH V2] usb: ehci-mx6: Enable OTG detection on imx8mm and imx8mn Adam Ford
2021-12-23 14:56 ` Fabio Estevam
2022-01-03 22:19 ` Tim Harvey
2022-01-03 22:32   ` Adam Ford
2022-01-03 23:47     ` Tim Harvey [this message]
2022-01-04  8:31 ` Michael Walle
2022-01-11 14:20   ` Adam Ford
2022-01-11 15:31     ` Michael Walle
2022-01-11 16:52       ` Adam Ford
2022-01-12  8:17         ` Michael Walle
2022-01-14  0:35           ` Adam Ford
2022-01-14  0:49             ` Adam Ford
2022-01-18  0:06               ` Adam Ford

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAJ+vNU3emps8+VGOfzaPG723AJ+q0RKrYJYtcttx4vWMduHrJQ@mail.gmail.com \
    --to=tharvey@gateworks.com \
    --cc=aford173@gmail.com \
    --cc=festevam@denx.de \
    --cc=marex@denx.de \
    --cc=sjg@chromium.org \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.