From: Tony Lindgren <tony@atomide.com>
To: min.guo@mediatek.com
Cc: Mark Rutland <mark.rutland@arm.com>,
devicetree@vger.kernel.org,
Yonglong Wu <yonglong.wu@mediatek.com>,
hdegoede@redhat.com,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
chunfeng.yun@mediatek.com, Rob Herring <robh+dt@kernel.org>,
Alan Stern <stern@rowland.harvard.edu>,
Matthias Brugger <matthias.bgg@gmail.com>,
linux-mediatek@lists.infradead.org, Bin Liu <b-liu@ti.com>,
linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH v8 6/6] usb: musb: Add support for MediaTek musb controller
Date: Thu, 17 Oct 2019 09:34:33 -0700 [thread overview]
Message-ID: <20191017163433.GN5610@atomide.com> (raw)
In-Reply-To: <20191017094126.29045-7-min.guo@mediatek.com>
Hi,
Just few comments for future changes that might help below.
* min.guo@mediatek.com <min.guo@mediatek.com> [191017 09:42]:
> --- /dev/null
> +++ b/drivers/usb/musb/mediatek.c
> +static int musb_usb_role_sx_set(struct device *dev, enum usb_role role)
> +{
> + struct mtk_glue *glue = dev_get_drvdata(dev);
> + struct musb *musb = glue->musb;
> + u8 devctl = readb(musb->mregs + MUSB_DEVCTL);
> + enum usb_role new_role;
> +
> + if (role == glue->role)
> + return 0;
> +
> + switch (role) {
> + case USB_ROLE_HOST:
> + musb->xceiv->otg->state = OTG_STATE_A_WAIT_VRISE;
> + glue->phy_mode = PHY_MODE_USB_HOST;
> + new_role = USB_ROLE_HOST;
> + if (glue->role == USB_ROLE_NONE)
> + phy_power_on(glue->phy);
> +
> + devctl |= MUSB_DEVCTL_SESSION;
> + musb_writeb(musb->mregs, MUSB_DEVCTL, devctl);
> + MUSB_HST_MODE(musb);
> + break;
> + case USB_ROLE_DEVICE:
> + musb->xceiv->otg->state = OTG_STATE_B_IDLE;
> + glue->phy_mode = PHY_MODE_USB_DEVICE;
> + new_role = USB_ROLE_DEVICE;
> + devctl &= ~MUSB_DEVCTL_SESSION;
> + musb_writeb(musb->mregs, MUSB_DEVCTL, devctl);
> + if (glue->role == USB_ROLE_NONE)
> + phy_power_on(glue->phy);
> +
> + MUSB_DEV_MODE(musb);
> + break;
> + case USB_ROLE_NONE:
> + glue->phy_mode = PHY_MODE_USB_OTG;
> + new_role = USB_ROLE_NONE;
> + devctl &= ~MUSB_DEVCTL_SESSION;
> + musb_writeb(musb->mregs, MUSB_DEVCTL, devctl);
> + if (glue->role != USB_ROLE_NONE)
> + phy_power_off(glue->phy);
> +
> + break;
> + default:
> + dev_err(glue->dev, "Invalid State\n");
> + return -EINVAL;
> + }
> +
> + glue->role = new_role;
> + phy_set_mode(glue->phy, glue->phy_mode);
> +
> + return 0;
> +}
For the role change, I recently posted a patch "[PATCH 4/7] usb: musb:
Add musb_set_host and peripheral and use them for omap2430". That
should work for you looking at the code above, so later on you might
want to change to use that. Probably best done as a follow-up patch
to avoid adding extra dependencies to your series.
Please also note that musb core attempts to do things automagically
on it's own. So trying to force mode in general does not work reliably.
This is because VBUS may not yet have risen for example.
The role change is best done based on the USB PHY as then usually
musb has already switched to the right mode automatically :)
> +static const struct musb_platform_ops mtk_musb_ops = {
> + .quirks = MUSB_DMA_INVENTRA,
> + .init = mtk_musb_init,
> + .get_toggle = mtk_musb_get_toggle,
> + .set_toggle = mtk_musb_set_toggle,
> + .exit = mtk_musb_exit,
> +#ifdef CONFIG_USB_INVENTRA_DMA
> + .dma_init = musbhs_dma_controller_create_noirq,
> + .dma_exit = musbhs_dma_controller_destroy,
> +#endif
> + .clearb = mtk_musb_clearb,
> + .clearw = mtk_musb_clearw,
> + .busctl_offset = mtk_musb_busctl_offset,
> + .set_mode = mtk_musb_set_mode,
> +};
So you may want to consider getting rid of .set_mode completely
and rely on USB PHY calls instead.
In some cases you need to use struct phy_companion for set_vbus
depending how things are wired.
Regards,
Tony
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2019-10-17 16:34 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-17 9:41 [PATCH v8 0/6] Add MediaTek MUSB Controller Driver min.guo
2019-10-17 9:41 ` [PATCH v8 1/6] dt-bindings: usb: musb: Add support for MediaTek musb controller min.guo
2019-10-17 9:41 ` [PATCH v8 2/6] arm: dts: mt2701: Add usb2 device nodes min.guo
2019-10-17 9:41 ` [PATCH v8 3/6] usb: musb: Add get/set toggle hooks min.guo
2019-10-17 9:41 ` [PATCH v8 4/6] usb: musb: Add noirq type of dma create interface min.guo
2019-10-17 9:41 ` [PATCH v8 5/6] usb: musb: Add musb_clearb/w() interface min.guo
2019-10-17 9:41 ` [PATCH v8 6/6] usb: musb: Add support for MediaTek musb controller min.guo
2019-10-17 16:34 ` Tony Lindgren [this message]
2019-10-18 9:10 ` Min Guo
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=20191017163433.GN5610@atomide.com \
--to=tony@atomide.com \
--cc=b-liu@ti.com \
--cc=chunfeng.yun@mediatek.com \
--cc=devicetree@vger.kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=hdegoede@redhat.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=linux-usb@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=matthias.bgg@gmail.com \
--cc=min.guo@mediatek.com \
--cc=robh+dt@kernel.org \
--cc=stern@rowland.harvard.edu \
--cc=yonglong.wu@mediatek.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).