diff mbox

[v2,2/4] usb: renesas_usbhs: gadget: fix the behavior of pullup

Message ID 1414641767-5780-3-git-send-email-yoshihiro.shimoda.uh@renesas.com (mailing list archive)
State Superseded
Headers show

Commit Message

Yoshihiro Shimoda Oct. 30, 2014, 4:02 a.m. UTC
From: Takeshi Kihara <takeshi.kihara.df@renesas.com>

This patch fixes an issue that this driver always enable the D+ pullup
after it detected the VBUS connection even though this usb controller
can control the D+ pullup timing by software. So, this driver should
enable the D+ pullup after a gadget driver called usb_gadget_connect().

Signed-off-by: Takeshi Kihara <takeshi.kihara.df@renesas.com>
Signed-off-by: Kazuya Mizuguchi <kazuya.mizuguchi.ks@renesas.com>
Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
---
 drivers/usb/renesas_usbhs/common.c     |    6 ++++--
 drivers/usb/renesas_usbhs/mod_gadget.c |   27 ++++++++++++++++++++++++++-
 2 files changed, 30 insertions(+), 3 deletions(-)

Comments

Kuninori Morimoto Oct. 30, 2014, 6:40 a.m. UTC | #1
Hi shimoda-san

> From: Takeshi Kihara <takeshi.kihara.df@renesas.com>
> 
> This patch fixes an issue that this driver always enable the D+ pullup
> after it detected the VBUS connection even though this usb controller
> can control the D+ pullup timing by software. So, this driver should
> enable the D+ pullup after a gadget driver called usb_gadget_connect().
> 
> Signed-off-by: Takeshi Kihara <takeshi.kihara.df@renesas.com>
> Signed-off-by: Kazuya Mizuguchi <kazuya.mizuguchi.ks@renesas.com>
> Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
> ---
(snip)
> diff --git a/drivers/usb/renesas_usbhs/mod_gadget.c b/drivers/usb/renesas_usbhs/mod_gadget.c
> index 2d0903f..0d50be0 100644
> --- a/drivers/usb/renesas_usbhs/mod_gadget.c
> +++ b/drivers/usb/renesas_usbhs/mod_gadget.c
> @@ -56,6 +56,8 @@ struct usbhsg_gpriv {
>  #define USBHSG_STATUS_REGISTERD		(1 << 1)
>  #define USBHSG_STATUS_WEDGE		(1 << 2)
>  #define USBHSG_STATUS_SELF_POWERED	(1 << 3)
> +
> +	unsigned		softconnect:1;
>  };

We can re-use USBHSG_STATUS_xxx instead of new variable ?
renesas_usb driver has usbhsg_status_xxx() macro.

Best regards
---
Kuninori Morimoto
--
To unsubscribe from this list: send the line "unsubscribe linux-sh" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Yoshihiro Shimoda Oct. 30, 2014, 6:47 a.m. UTC | #2
Hi Morimoto-san,

> Hi shimoda-san
> 
> > From: Takeshi Kihara <takeshi.kihara.df@renesas.com>
> >
> > This patch fixes an issue that this driver always enable the D+ pullup
> > after it detected the VBUS connection even though this usb controller
> > can control the D+ pullup timing by software. So, this driver should
> > enable the D+ pullup after a gadget driver called usb_gadget_connect().
> >
> > Signed-off-by: Takeshi Kihara <takeshi.kihara.df@renesas.com>
> > Signed-off-by: Kazuya Mizuguchi <kazuya.mizuguchi.ks@renesas.com>
> > Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
> > ---
> (snip)
> > diff --git a/drivers/usb/renesas_usbhs/mod_gadget.c
> > b/drivers/usb/renesas_usbhs/mod_gadget.c
> > index 2d0903f..0d50be0 100644
> > --- a/drivers/usb/renesas_usbhs/mod_gadget.c
> > +++ b/drivers/usb/renesas_usbhs/mod_gadget.c
> > @@ -56,6 +56,8 @@ struct usbhsg_gpriv {
> >  #define USBHSG_STATUS_REGISTERD		(1 << 1)
> >  #define USBHSG_STATUS_WEDGE		(1 << 2)
> >  #define USBHSG_STATUS_SELF_POWERED	(1 << 3)
> > +
> > +	unsigned		softconnect:1;
> >  };
> 
> We can re-use USBHSG_STATUS_xxx instead of new variable ?
> renesas_usb driver has usbhsg_status_xxx() macro.

Thank you for the review.
Yes, we can re-use that. So, I will fix this patch.

Best regards,
Yoshihiro Shimoda

> Best regards
> ---
> Kuninori Morimoto
--
To unsubscribe from this list: send the line "unsubscribe linux-sh" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/usb/renesas_usbhs/common.c b/drivers/usb/renesas_usbhs/common.c
index b3b6813..7099f17 100644
--- a/drivers/usb/renesas_usbhs/common.c
+++ b/drivers/usb/renesas_usbhs/common.c
@@ -126,13 +126,15 @@  void usbhs_sys_host_ctrl(struct usbhs_priv *priv, int enable)
 void usbhs_sys_function_ctrl(struct usbhs_priv *priv, int enable)
 {
 	u16 mask = DCFM | DRPD | DPRPU | HSE | USBE;
-	u16 val  = DPRPU | HSE | USBE;
+	u16 val  = HSE | USBE;
 
 	/*
 	 * if enable
 	 *
 	 * - select Function mode
-	 * - D+ Line Pull-up
+	 * - D+ Line Pull-up is disabled
+	 *      When D+ Line Pull-up is enabled,
+	 *      calling usbhs_sys_function_pullup(,1)
 	 */
 	usbhs_bset(priv, SYSCFG, mask, enable ? val : 0);
 }
diff --git a/drivers/usb/renesas_usbhs/mod_gadget.c b/drivers/usb/renesas_usbhs/mod_gadget.c
index 2d0903f..0d50be0 100644
--- a/drivers/usb/renesas_usbhs/mod_gadget.c
+++ b/drivers/usb/renesas_usbhs/mod_gadget.c
@@ -56,6 +56,8 @@  struct usbhsg_gpriv {
 #define USBHSG_STATUS_REGISTERD		(1 << 1)
 #define USBHSG_STATUS_WEDGE		(1 << 2)
 #define USBHSG_STATUS_SELF_POWERED	(1 << 3)
+
+	unsigned		softconnect:1;
 };
 
 struct usbhsg_recip_handle {
@@ -726,6 +728,24 @@  static struct usb_ep_ops usbhsg_ep_ops = {
 };
 
 /*
+ *		pullup control
+ */
+static int usbhsg_can_pullup(struct usbhs_priv *priv)
+{
+	struct usbhsg_gpriv *gpriv = usbhsg_priv_to_gpriv(priv);
+
+	return gpriv->driver && gpriv->softconnect;
+}
+
+static void usbhsg_update_pullup(struct usbhs_priv *priv)
+{
+	if (usbhsg_can_pullup(priv))
+		usbhs_sys_function_pullup(priv, 1);
+	else
+		usbhs_sys_function_pullup(priv, 0);
+}
+
+/*
  *		usb module start/end
  */
 static int usbhsg_try_start(struct usbhs_priv *priv, u32 status)
@@ -775,6 +795,7 @@  static int usbhsg_try_start(struct usbhs_priv *priv, u32 status)
 	 * - usb module
 	 */
 	usbhs_sys_function_ctrl(priv, 1);
+	usbhsg_update_pullup(priv);
 
 	/*
 	 * enable irq callback
@@ -881,8 +902,12 @@  static int usbhsg_pullup(struct usb_gadget *gadget, int is_on)
 {
 	struct usbhsg_gpriv *gpriv = usbhsg_gadget_to_gpriv(gadget);
 	struct usbhs_priv *priv = usbhsg_gpriv_to_priv(gpriv);
+	unsigned long flags;
 
-	usbhs_sys_function_pullup(priv, is_on);
+	usbhs_lock(priv, flags);
+	gpriv->softconnect = (is_on != 0);
+	usbhsg_update_pullup(priv);
+	usbhs_unlock(priv, flags);
 
 	return 0;
 }