All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] usb: musb: core: add common method of getting vbus status
@ 2015-10-12 13:59 Roman Alyautdin
  2015-10-12 14:13 ` Roman Alyautdin
  2015-10-12 14:14 ` Roman Alyautdin
  0 siblings, 2 replies; 4+ messages in thread
From: Roman Alyautdin @ 2015-10-12 13:59 UTC (permalink / raw)
  To: balbi; +Cc: linux-usb, linux-kernel, sergei.shtylyov, Roman Alyautdin

Fix musb_platform_get_vbus_status return value in case of platform
implementation is not defined, bringing expected behaviour of
musb_platform_get wrapper. Add musb_vbus_show default method to determine
VBUS status in case platform method is not defined.

Signed-off-by: Roman Alyautdin <ralyautdin@dev.rtsoft.ru>
---
 drivers/usb/musb/musb_core.c |   13 ++++++++++---
 drivers/usb/musb/musb_core.h |    2 +-
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
index 4a518ff..3551540 100644
--- a/drivers/usb/musb/musb_core.c
+++ b/drivers/usb/musb/musb_core.c
@@ -1771,13 +1771,20 @@ musb_vbus_show(struct device *dev, struct device_attribute *attr, char *buf)
 	unsigned long	flags;
 	unsigned long	val;
 	int		vbus;
+	u8		devctl;
 
 	spin_lock_irqsave(&musb->lock, flags);
 	val = musb->a_wait_bcon;
-	/* FIXME get_vbus_status() is normally #defined as false...
-	 * and is effectively TUSB-specific.
-	 */
 	vbus = musb_platform_get_vbus_status(musb);
+	if (vbus < 0) {
+		/* Use default MUSB method by means of DEVCTL register */
+		devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
+		if ((devctl & MUSB_DEVCTL_VBUS)
+				!= (3 << MUSB_DEVCTL_VBUS_SHIFT))
+			vbus = 1;
+		else
+			vbus = 0;
+	}
 	spin_unlock_irqrestore(&musb->lock, flags);
 
 	return sprintf(buf, "Vbus %s, timeout %lu msec\n",
diff --git a/drivers/usb/musb/musb_core.h b/drivers/usb/musb/musb_core.h
index 4b886d0..2337d7a 100644
--- a/drivers/usb/musb/musb_core.h
+++ b/drivers/usb/musb/musb_core.h
@@ -579,7 +579,7 @@ static inline int  musb_platform_recover(struct musb *musb)
 static inline int musb_platform_get_vbus_status(struct musb *musb)
 {
 	if (!musb->ops->vbus_status)
-		return 0;
+		return -EINVAL;
 
 	return musb->ops->vbus_status(musb);
 }
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] usb: musb: core: add common method of getting vbus status
  2015-10-12 13:59 [PATCH] usb: musb: core: add common method of getting vbus status Roman Alyautdin
@ 2015-10-12 14:13 ` Roman Alyautdin
  2015-10-12 14:14 ` Roman Alyautdin
  1 sibling, 0 replies; 4+ messages in thread
From: Roman Alyautdin @ 2015-10-12 14:13 UTC (permalink / raw)
  To: Roman Alyautdin; +Cc: balbi, linux-usb, linux-kernel, sergei.shtylyov

On 12/10/15 16:59, Roman Alyautdin wrote:
> Fix musb_platform_get_vbus_status return value in case of platform
> implementation is not defined, bringing expected behaviour of
> musb_platform_get wrapper. Add musb_vbus_show default method to determine
> VBUS status in case platform method is not defined.
>
> Signed-off-by: Roman Alyautdin <ralyautdin@dev.rtsoft.ru>
> ---
>   drivers/usb/musb/musb_core.c |   13 ++++++++++---
>   drivers/usb/musb/musb_core.h |    2 +-
>   2 files changed, 11 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
> index 4a518ff..3551540 100644
> --- a/drivers/usb/musb/musb_core.c
> +++ b/drivers/usb/musb/musb_core.c
> @@ -1771,13 +1771,20 @@ musb_vbus_show(struct device *dev, struct device_attribute *attr, char *buf)
>   	unsigned long	flags;
>   	unsigned long	val;
>   	int		vbus;
> +	u8		devctl;
>   
>   	spin_lock_irqsave(&musb->lock, flags);
>   	val = musb->a_wait_bcon;
> -	/* FIXME get_vbus_status() is normally #defined as false...
> -	 * and is effectively TUSB-specific.
> -	 */
>   	vbus = musb_platform_get_vbus_status(musb);
> +	if (vbus < 0) {
> +		/* Use default MUSB method by means of DEVCTL register */
> +		devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
> +		if ((devctl & MUSB_DEVCTL_VBUS)
> +				!= (3 << MUSB_DEVCTL_VBUS_SHIFT))
> +			vbus = 1;
> +		else
> +			vbus = 0;
> +	}
>   	spin_unlock_irqrestore(&musb->lock, flags);
>   
>   	return sprintf(buf, "Vbus %s, timeout %lu msec\n",
> diff --git a/drivers/usb/musb/musb_core.h b/drivers/usb/musb/musb_core.h
> index 4b886d0..2337d7a 100644
> --- a/drivers/usb/musb/musb_core.h
> +++ b/drivers/usb/musb/musb_core.h
> @@ -579,7 +579,7 @@ static inline int  musb_platform_recover(struct musb *musb)
>   static inline int musb_platform_get_vbus_status(struct musb *musb)
>   {
>   	if (!musb->ops->vbus_status)
> -		return 0;
> +		return -EINVAL;
>   
>   	return musb->ops->vbus_status(musb);
>   }
Sorry, looks like logic inversion, will update soon

Regards,
Roman

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH] usb: musb: core: add common method of getting vbus status
  2015-10-12 13:59 [PATCH] usb: musb: core: add common method of getting vbus status Roman Alyautdin
  2015-10-12 14:13 ` Roman Alyautdin
@ 2015-10-12 14:14 ` Roman Alyautdin
  2015-10-12 16:44   ` Sergei Shtylyov
  1 sibling, 1 reply; 4+ messages in thread
From: Roman Alyautdin @ 2015-10-12 14:14 UTC (permalink / raw)
  To: balbi; +Cc: linux-usb, linux-kernel, sergei.shtylyov, Roman Alyautdin

Fix musb_platform_get_vbus_status return value in case of platform
implementation is not defined, bringing expected behaviour of
musb_platform_get wrapper. Add musb_vbus_show default method to determine
VBUS status in case platform method is not defined.

Signed-off-by: Roman Alyautdin <ralyautdin@dev.rtsoft.ru>
---
 drivers/usb/musb/musb_core.c |   13 ++++++++++---
 drivers/usb/musb/musb_core.h |    2 +-
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
index 4a518ff..3551540 100644
--- a/drivers/usb/musb/musb_core.c
+++ b/drivers/usb/musb/musb_core.c
@@ -1771,13 +1771,20 @@ musb_vbus_show(struct device *dev, struct device_attribute *attr, char *buf)
 	unsigned long	flags;
 	unsigned long	val;
 	int		vbus;
+	u8		devctl;
 
 	spin_lock_irqsave(&musb->lock, flags);
 	val = musb->a_wait_bcon;
-	/* FIXME get_vbus_status() is normally #defined as false...
-	 * and is effectively TUSB-specific.
-	 */
 	vbus = musb_platform_get_vbus_status(musb);
+	if (vbus < 0) {
+		/* Use default MUSB method by means of DEVCTL register */
+		devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
+		if ((devctl & MUSB_DEVCTL_VBUS)
+				== (3 << MUSB_DEVCTL_VBUS_SHIFT))
+			vbus = 1;
+		else
+			vbus = 0;
+	}
 	spin_unlock_irqrestore(&musb->lock, flags);
 
 	return sprintf(buf, "Vbus %s, timeout %lu msec\n",
diff --git a/drivers/usb/musb/musb_core.h b/drivers/usb/musb/musb_core.h
index 4b886d0..2337d7a 100644
--- a/drivers/usb/musb/musb_core.h
+++ b/drivers/usb/musb/musb_core.h
@@ -579,7 +579,7 @@ static inline int  musb_platform_recover(struct musb *musb)
 static inline int musb_platform_get_vbus_status(struct musb *musb)
 {
 	if (!musb->ops->vbus_status)
-		return 0;
+		return -EINVAL;
 
 	return musb->ops->vbus_status(musb);
 }
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] usb: musb: core: add common method of getting vbus status
  2015-10-12 14:14 ` Roman Alyautdin
@ 2015-10-12 16:44   ` Sergei Shtylyov
  0 siblings, 0 replies; 4+ messages in thread
From: Sergei Shtylyov @ 2015-10-12 16:44 UTC (permalink / raw)
  To: Roman Alyautdin, balbi; +Cc: linux-usb, linux-kernel

Hello.

On 10/12/2015 05:14 PM, Roman Alyautdin wrote:

> Fix musb_platform_get_vbus_status return value in case of platform
> implementation is not defined, bringing expected behaviour of
> musb_platform_get wrapper. Add musb_vbus_show default method to determine
> VBUS status in case platform method is not defined.
>
> Signed-off-by: Roman Alyautdin <ralyautdin@dev.rtsoft.ru>
> ---
>   drivers/usb/musb/musb_core.c |   13 ++++++++++---
>   drivers/usb/musb/musb_core.h |    2 +-
>   2 files changed, 11 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
> index 4a518ff..3551540 100644
> --- a/drivers/usb/musb/musb_core.c
> +++ b/drivers/usb/musb/musb_core.c
> @@ -1771,13 +1771,20 @@ musb_vbus_show(struct device *dev, struct device_attribute *attr, char *buf)
>   	unsigned long	flags;
>   	unsigned long	val;
>   	int		vbus;
> +	u8		devctl;

    I'd add the variable to the block it's used in but this way is OK too.

[...]

MBR, Sergei


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-10-12 16:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-12 13:59 [PATCH] usb: musb: core: add common method of getting vbus status Roman Alyautdin
2015-10-12 14:13 ` Roman Alyautdin
2015-10-12 14:14 ` Roman Alyautdin
2015-10-12 16:44   ` Sergei Shtylyov

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.