From: Peter Chen <peter.chen@nxp.com>
To: Roger Quadros <rogerq@ti.com>
Cc: "heikki.krogerus@linux.intel.com"
<heikki.krogerus@linux.intel.com>,
"pawell@cadence.com" <pawell@cadence.com>,
"gregkh@linuxfoundation.org" <gregkh@linuxfoundation.org>,
"balbi@kernel.org" <balbi@kernel.org>,
"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] Revert "usb: cdns3: core: quit if it uses role switch class"
Date: Wed, 25 Nov 2020 00:36:19 +0000 [thread overview]
Message-ID: <20201125003550.GB9929@b29397-desktop> (raw)
In-Reply-To: <1c4fb95a-97b7-9022-7062-8fafcfe42c3d@ti.com>
On 20-11-24 14:22:25, Roger Quadros wrote:
> Peter,
>
> On 24/11/2020 13:47, Peter Chen wrote:
> > On 20-11-24 12:33:34, Roger Quadros wrote:
> > > > > >
> > > > > > I am sorry about that. Do you use role switch /sys entry, if you have
> > > > > > used, I prefer using "usb-role-switch" property at dts to judge if SoC
> > > > > > OTG signals or external signals for role switch. If you have not used
> > > > > > it, I prefer only setting cdns->role_sw for role switch use cases.
> > > > > >
> > > > >
> > > > > We use both hardware role switch and /sys entries for manually forcing a
> > > > > certain role.
> > > > >
> > > > > We do not set any "usb-role-switch" property at DTS.
> > > > >
> > > > > Currently cdns->role_sw is being always set by driver irrespective of any DT
> > > > > property, so this patch is clearly wrong and needs to be reverted.
> > > > >
> > > > > What do you think?
> > > > >
> > > >
> > > > Could you accept below fix?
> > > >
> > > > diff --git a/drivers/usb/cdns3/core.c b/drivers/usb/cdns3/core.c
> > > > index 2e469139769f..fdd52e87a7b2 100644
> > > > --- a/drivers/usb/cdns3/core.c
> > > > +++ b/drivers/usb/cdns3/core.c
> > > > @@ -280,8 +280,8 @@ int cdns3_hw_role_switch(struct cdns3 *cdns)
> > > > enum usb_role real_role, current_role;
> > > > int ret = 0;
> > > >
> > > > - /* Depends on role switch class */
> > > > - if (cdns->role_sw)
> > > > + /* quit if switch role through external signals */
> > > > + if (device_property_read_bool(cdns->dev, "usb-role-switch"))
> > > > return 0;
> > > >
> > > > pm_runtime_get_sync(cdns->dev);
> > >
> > > Although this will fix the issue I don't think this is making the driver to behave
> > > as expected with usb-role-switch property.
> > >
> > > Now, even if usb-role-switch property is not present the driver will still register
> > > the role switch driver.
> > >
> > > I think we need to register the role switch driver only if usb-role-switch property
> > > is present. We would also need to set the default role if role-switch-default-mode is present.
> > >
> > > How about the following? It still doesn't handle role-switch-default-mode property though.
> > >
> >
> > Roger, you said you also use /sys entries (I suppose it means through role
> > switch class) to do role switch, with your change, there will be no /sys
> > entry for role switch.
>
> Sorry for the confusion. Although we do need both features (SW role switch + HW role switch)
> I don't think it is required to operate simultaneously. If users need SW control they can set the DT flag.
>
I see. I prefer embracing all things related to role switch under the
firmware entry condition. Besides, I find another issue that devm_request_irq
for wakeup_irq does not call usb_role_switch_unregister if it has
failed. So, probably, two patches are needed. I am OK you send the
patches to fix both.
diff --git a/drivers/usb/cdns3/core.c b/drivers/usb/cdns3/core.c
index 2e469139769f..fc6a8152406c 100644
--- a/drivers/usb/cdns3/core.c
+++ b/drivers/usb/cdns3/core.c
@@ -427,7 +427,6 @@ static irqreturn_t cdns3_wakeup_irq(int irq, void *data)
*/
static int cdns3_probe(struct platform_device *pdev)
{
- struct usb_role_switch_desc sw_desc = { };
struct device *dev = &pdev->dev;
struct resource *res;
struct cdns3 *cdns;
@@ -529,18 +528,21 @@ static int cdns3_probe(struct platform_device *pdev)
if (ret)
goto err2;
- sw_desc.set = cdns3_role_set;
- sw_desc.get = cdns3_role_get;
- sw_desc.allow_userspace_control = true;
- sw_desc.driver_data = cdns;
- if (device_property_read_bool(dev, "usb-role-switch"))
+ if (device_property_read_bool(dev, "usb-role-switch")) {
+ struct usb_role_switch_desc sw_desc = { };
+
+ sw_desc.set = cdns3_role_set;
+ sw_desc.get = cdns3_role_get;
+ sw_desc.allow_userspace_control = true;
+ sw_desc.driver_data = cdns;
sw_desc.fwnode = dev->fwnode;
- cdns->role_sw = usb_role_switch_register(dev, &sw_desc);
- if (IS_ERR(cdns->role_sw)) {
- ret = PTR_ERR(cdns->role_sw);
- dev_warn(dev, "Unable to register Role Switch\n");
- goto err3;
+ cdns->role_sw = usb_role_switch_register(dev, &sw_desc);
+ if (IS_ERR(cdns->role_sw)) {
+ ret = PTR_ERR(cdns->role_sw);
+ dev_warn(dev, "Unable to register Role Switch\n");
+ goto err3;
+ }
}
if (cdns->wakeup_irq) {
@@ -583,7 +585,8 @@ static int cdns3_probe(struct platform_device *pdev)
return 0;
err4:
cdns3_drd_exit(cdns);
- usb_role_switch_unregister(cdns->role_sw);
+ if (cdns->role_sw)
+ usb_role_switch_unregister(cdns->role_sw);
err3:
set_phy_power_off(cdns);
err2:
--
Thanks,
Peter Chen
next prev parent reply other threads:[~2020-11-25 0:36 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-23 11:50 [PATCH] Revert "usb: cdns3: core: quit if it uses role switch class" Roger Quadros
2020-11-24 6:43 ` Peter Chen
2020-11-24 9:39 ` Roger Quadros
2020-11-24 9:57 ` Peter Chen
2020-11-24 10:33 ` Roger Quadros
2020-11-24 11:00 ` Heikki Krogerus
2020-11-24 11:47 ` Peter Chen
2020-11-24 12:22 ` Roger Quadros
2020-11-25 0:36 ` Peter Chen [this message]
2020-11-25 9:52 ` Roger Quadros
2020-11-25 10:14 ` Pawel Laszczak
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=20201125003550.GB9929@b29397-desktop \
--to=peter.chen@nxp.com \
--cc=balbi@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=heikki.krogerus@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=pawell@cadence.com \
--cc=rogerq@ti.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).