diff mbox series

[RFC,v1,2/3] usb: chipidea: set mode for usb phy driver

Message ID 20191007124607.20618-2-igor.opaniuk@gmail.com (mailing list archive)
State Superseded
Headers show
Series [RFC,v1,1/3] usb: phy: add usb mode for usb_phy | expand

Commit Message

Igor Opaniuk Oct. 7, 2019, 12:46 p.m. UTC
From: Igor Opaniuk <igor.opaniuk@toradex.com>

After enters one specific role, notify usb phy driver.

Signed-off-by: Li Jun <jun.li@nxp.com>
Signed-off-by: Igor Opaniuk <igor.opaniuk@toradex.com>
---

 drivers/usb/chipidea/ci.h | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

Comments

Peter Chen Oct. 8, 2019, 3:23 a.m. UTC | #1
On 19-10-07 15:46:06, Igor Opaniuk wrote:
> From: Igor Opaniuk <igor.opaniuk@toradex.com>
> 
> After enters one specific role, notify usb phy driver.
> 
> Signed-off-by: Li Jun <jun.li@nxp.com>
> Signed-off-by: Igor Opaniuk <igor.opaniuk@toradex.com>
> ---
> 
>  drivers/usb/chipidea/ci.h | 21 ++++++++++++++++++---
>  1 file changed, 18 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/usb/chipidea/ci.h b/drivers/usb/chipidea/ci.h
> index 6911aef500e9..a11d23910b12 100644
> --- a/drivers/usb/chipidea/ci.h
> +++ b/drivers/usb/chipidea/ci.h
> @@ -275,9 +275,21 @@ static inline int ci_role_start(struct ci_hdrc *ci, enum ci_role role)
>  		return -ENXIO;
>  
>  	ret = ci->roles[role]->start(ci);
> -	if (!ret)
> -		ci->role = role;
> -	return ret;
> +	if (ret)
> +		return ret;
> +
> +	ci->role = role;
> +
> +	if (ci->usb_phy) {
> +		if (role == CI_ROLE_HOST)
> +			usb_phy_set_mode(ci->usb_phy,
> +					USB_MODE_HOST);
> +		else
> +			usb_phy_set_mode(ci->usb_phy,
> +					USB_MODE_DEVICE);
> +	}
> +
> +	return 0;
>  }
>  
>  static inline void ci_role_stop(struct ci_hdrc *ci)
> @@ -290,6 +302,9 @@ static inline void ci_role_stop(struct ci_hdrc *ci)
>  	ci->role = CI_ROLE_END;
>  
>  	ci->roles[role]->stop(ci);
> +
> +	if (ci->usb_phy)
> +		usb_phy_set_mode(ci->usb_phy, USB_MODE_NONE);
>  }
>  
>  static inline enum usb_role ci_role_to_usb_role(struct ci_hdrc *ci)
> -- 

Hi Igor,

Thanks for doing that.

We just find this series patch will break ARM32 multi_v7_defconfig
build. You may need to fix it at next revision, see below.

  CC [M]  drivers/gpu/drm/nouveau/nvkm/subdev/fb/gm200.o
In file included from /home/b29397/work/projects/usb/drivers/phy/ti/phy-omap-usb2.c:20:0:
/home/b29397/work/projects/usb/include/linux/phy/omap_control_phy.h:36:2: error: redeclaration of enumerator ‘USB_MODE_HOST’
  USB_MODE_HOST,
  ^~~~~~~~~~~~~
In file included from /home/b29397/work/projects/usb/include/linux/usb/otg.h:14:0,
                 from /home/b29397/work/projects/usb/include/linux/phy/omap_usb.h:13,
                 from /home/b29397/work/projects/usb/drivers/phy/ti/phy-omap-usb2.c:14:
/home/b29397/work/projects/usb/include/linux/usb/phy.h:69:2: note: previous definition of ‘USB_MODE_HOST’ was here
  USB_MODE_HOST,
  ^~~~~~~~~~~~~
In file included from /home/b29397/work/projects/usb/drivers/phy/ti/phy-omap-usb2.c:20:0:
/home/b29397/work/projects/usb/include/linux/phy/omap_control_phy.h:37:2: error: redeclaration of enumerator ‘USB_MODE_DEVICE’
  USB_MODE_DEVICE,
  ^~~~~~~~~~~~~~~
In file included from /home/b29397/work/projects/usb/include/linux/usb/otg.h:14:0,
                 from /home/b29397/work/projects/usb/include/linux/phy/omap_usb.h:13,
                 from /home/b29397/work/projects/usb/drivers/phy/ti/phy-omap-usb2.c:14:
/home/b29397/work/projects/usb/include/linux/usb/phy.h:70:2: note: previous definition of ‘USB_MODE_DEVICE’ was here
  USB_MODE_DEVICE,
  ^~~~~~~~~~~~~~~
/home/b29397/work/projects/usb/scripts/Makefile.build:280: recipe for target 'drivers/phy/ti/phy-omap-usb2.o' failed
make[4]: *** [drivers/phy/ti/phy-omap-usb2.o] Error 1
make[4]: *** Waiting for unfinished jobs....
  CC      drivers/pinctrl/qcom/pinctrl-ssbi-gpio.o
  CC      drivers/regulator/bcm590xx-regulator.o
  CC      drivers/pinctrl/qcom/pinctrl-spmi-mpp.o
  CC      drivers/pinctrl/qcom/pinctrl-ssbi-mpp.o
  CC      drivers/rpmsg/imx_rpmsg.o
  CC [M]  drivers/rpmsg/rpmsg_core.o
  CC      drivers/regulator/da9210-regulator.o
  CC      drivers/gpu/drm/drm_crtc_helper.o
  CC      drivers/pinctrl/samsung/pinctrl-exynos.o
  CC      drivers/gpu/drm/drm_dp_helper.o
/home/b29397/work/projects/usb/scripts/Makefile.build:497: recipe for target 'drivers/phy/ti' failed
make[3]: *** [drivers/phy/ti] Error 2
Igor Opaniuk Oct. 8, 2019, 9:40 a.m. UTC | #2
Hi Peter,

On Tue, Oct 8, 2019 at 6:23 AM Peter Chen <peter.chen@nxp.com> wrote:
>
> On 19-10-07 15:46:06, Igor Opaniuk wrote:
> > From: Igor Opaniuk <igor.opaniuk@toradex.com>
> >
> > After enters one specific role, notify usb phy driver.
> >
> > Signed-off-by: Li Jun <jun.li@nxp.com>
> > Signed-off-by: Igor Opaniuk <igor.opaniuk@toradex.com>
> > ---
> >
> >  drivers/usb/chipidea/ci.h | 21 ++++++++++++++++++---
> >  1 file changed, 18 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/usb/chipidea/ci.h b/drivers/usb/chipidea/ci.h
> > index 6911aef500e9..a11d23910b12 100644
> > --- a/drivers/usb/chipidea/ci.h
> > +++ b/drivers/usb/chipidea/ci.h
> > @@ -275,9 +275,21 @@ static inline int ci_role_start(struct ci_hdrc *ci, enum ci_role role)
> >               return -ENXIO;
> >
> >       ret = ci->roles[role]->start(ci);
> > -     if (!ret)
> > -             ci->role = role;
> > -     return ret;
> > +     if (ret)
> > +             return ret;
> > +
> > +     ci->role = role;
> > +
> > +     if (ci->usb_phy) {
> > +             if (role == CI_ROLE_HOST)
> > +                     usb_phy_set_mode(ci->usb_phy,
> > +                                     USB_MODE_HOST);
> > +             else
> > +                     usb_phy_set_mode(ci->usb_phy,
> > +                                     USB_MODE_DEVICE);
> > +     }
> > +
> > +     return 0;
> >  }
> >
> >  static inline void ci_role_stop(struct ci_hdrc *ci)
> > @@ -290,6 +302,9 @@ static inline void ci_role_stop(struct ci_hdrc *ci)
> >       ci->role = CI_ROLE_END;
> >
> >       ci->roles[role]->stop(ci);
> > +
> > +     if (ci->usb_phy)
> > +             usb_phy_set_mode(ci->usb_phy, USB_MODE_NONE);
> >  }
> >
> >  static inline enum usb_role ci_role_to_usb_role(struct ci_hdrc *ci)
> > --
>
> Hi Igor,
>
> Thanks for doing that.
>
> We just find this series patch will break ARM32 multi_v7_defconfig
> build. You may need to fix it at next revision, see below.
>
>   CC [M]  drivers/gpu/drm/nouveau/nvkm/subdev/fb/gm200.o
> In file included from /home/b29397/work/projects/usb/drivers/phy/ti/phy-omap-usb2.c:20:0:
> /home/b29397/work/projects/usb/include/linux/phy/omap_control_phy.h:36:2: error: redeclaration of enumerator ‘USB_MODE_HOST’
>   USB_MODE_HOST,
>   ^~~~~~~~~~~~~
> In file included from /home/b29397/work/projects/usb/include/linux/usb/otg.h:14:0,
>                  from /home/b29397/work/projects/usb/include/linux/phy/omap_usb.h:13,
>                  from /home/b29397/work/projects/usb/drivers/phy/ti/phy-omap-usb2.c:14:
> /home/b29397/work/projects/usb/include/linux/usb/phy.h:69:2: note: previous definition of ‘USB_MODE_HOST’ was here
>   USB_MODE_HOST,
>   ^~~~~~~~~~~~~
> In file included from /home/b29397/work/projects/usb/drivers/phy/ti/phy-omap-usb2.c:20:0:
> /home/b29397/work/projects/usb/include/linux/phy/omap_control_phy.h:37:2: error: redeclaration of enumerator ‘USB_MODE_DEVICE’
>   USB_MODE_DEVICE,
>   ^~~~~~~~~~~~~~~
> In file included from /home/b29397/work/projects/usb/include/linux/usb/otg.h:14:0,
>                  from /home/b29397/work/projects/usb/include/linux/phy/omap_usb.h:13,
>                  from /home/b29397/work/projects/usb/drivers/phy/ti/phy-omap-usb2.c:14:
> /home/b29397/work/projects/usb/include/linux/usb/phy.h:70:2: note: previous definition of ‘USB_MODE_DEVICE’ was here
>   USB_MODE_DEVICE,
>   ^~~~~~~~~~~~~~~
> /home/b29397/work/projects/usb/scripts/Makefile.build:280: recipe for target 'drivers/phy/ti/phy-omap-usb2.o' failed
> make[4]: *** [drivers/phy/ti/phy-omap-usb2.o] Error 1
> make[4]: *** Waiting for unfinished jobs....
>   CC      drivers/pinctrl/qcom/pinctrl-ssbi-gpio.o
>   CC      drivers/regulator/bcm590xx-regulator.o
>   CC      drivers/pinctrl/qcom/pinctrl-spmi-mpp.o
>   CC      drivers/pinctrl/qcom/pinctrl-ssbi-mpp.o
>   CC      drivers/rpmsg/imx_rpmsg.o
>   CC [M]  drivers/rpmsg/rpmsg_core.o
>   CC      drivers/regulator/da9210-regulator.o
>   CC      drivers/gpu/drm/drm_crtc_helper.o
>   CC      drivers/pinctrl/samsung/pinctrl-exynos.o
>   CC      drivers/gpu/drm/drm_dp_helper.o
> /home/b29397/work/projects/usb/scripts/Makefile.build:497: recipe for target 'drivers/phy/ti' failed
> make[3]: *** [drivers/phy/ti] Error 2
>
> --
>
> Thanks,
> Peter Chen

Seems familiar to me, AFAIK we already fixed that in
our downstream kernel, will add the fix for v1.

Thanks!

--
Best regards - Freundliche Grüsse - Meilleures salutations

Igor Opaniuk

mailto: igor.opaniuk@gmail.com
skype: igor.opanyuk
+380 (93) 836 40 67
http://ua.linkedin.com/in/iopaniuk
diff mbox series

Patch

diff --git a/drivers/usb/chipidea/ci.h b/drivers/usb/chipidea/ci.h
index 6911aef500e9..a11d23910b12 100644
--- a/drivers/usb/chipidea/ci.h
+++ b/drivers/usb/chipidea/ci.h
@@ -275,9 +275,21 @@  static inline int ci_role_start(struct ci_hdrc *ci, enum ci_role role)
 		return -ENXIO;
 
 	ret = ci->roles[role]->start(ci);
-	if (!ret)
-		ci->role = role;
-	return ret;
+	if (ret)
+		return ret;
+
+	ci->role = role;
+
+	if (ci->usb_phy) {
+		if (role == CI_ROLE_HOST)
+			usb_phy_set_mode(ci->usb_phy,
+					USB_MODE_HOST);
+		else
+			usb_phy_set_mode(ci->usb_phy,
+					USB_MODE_DEVICE);
+	}
+
+	return 0;
 }
 
 static inline void ci_role_stop(struct ci_hdrc *ci)
@@ -290,6 +302,9 @@  static inline void ci_role_stop(struct ci_hdrc *ci)
 	ci->role = CI_ROLE_END;
 
 	ci->roles[role]->stop(ci);
+
+	if (ci->usb_phy)
+		usb_phy_set_mode(ci->usb_phy, USB_MODE_NONE);
 }
 
 static inline enum usb_role ci_role_to_usb_role(struct ci_hdrc *ci)