Skip to contentSkip to conversation

usb: musb: core: add common method of getting vbus status

PATCH In review Roman Alyautdin 2 participants 4 messages Oct 12, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usb: musb: core: add common method of getting vbus status

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.

---
 drivers/usb/musb/musb_core.c |   13 ++++++++++---
 drivers/usb/musb/musb_core.h |    2 +-
 2 files changed, 11 insertions(+), 4 deletions(-)
drivers/usb/musb/musb_core.c +10 -3
index 4a518ff..3551540 100644
@@ -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",
drivers/usb/musb/musb_core.h +1 -1
index 4b886d0..2337d7a 100644
@@ -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);
 }
Signature · 1 line
1.7.9.5
#1 lore raw
Quoted 44 lines · 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.

---
  drivers/usb/musb/musb_core.c |   13 ++++++++++---
  drivers/usb/musb/musb_core.h |    2 +-
  2 files changed, 11 insertions(+), 4 deletions(-)
drivers/usb/musb/musb_core.c +10 -3
index 4a518ff..3551540 100644
@@ -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",
drivers/usb/musb/musb_core.h +0 -0
index 4b886d0..2337d7a 100644

drivers/usb/musb/musb_core.h static inline int musb_platform_recover(struct musb *musb) · line 585

Quoted 8 lines
drivers/usb/musb/musb_core.h +1 -1
@@ -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

#2 lore raw

PATCH 1/1 usb: musb: core: add common method of getting vbus status

In reply to 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.

---
 drivers/usb/musb/musb_core.c |   13 ++++++++++---
 drivers/usb/musb/musb_core.h |    2 +-
 2 files changed, 11 insertions(+), 4 deletions(-)
drivers/usb/musb/musb_core.c +10 -3
index 4a518ff..3551540 100644
@@ -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",
drivers/usb/musb/musb_core.h +1 -1
index 4b886d0..2337d7a 100644
@@ -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);
 }
Signature · 1 line
1.7.9.5
#3 lore raw

Hello.

Quoted 16 lines · 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.

---
  drivers/usb/musb/musb_core.c |   13 ++++++++++---
  drivers/usb/musb/musb_core.h |    2 +-
  2 files changed, 11 insertions(+), 4 deletions(-)
drivers/usb/musb/musb_core.c +0 -0
index 4a518ff..3551540 100644

drivers/usb/musb/musb_core.c musb_vbus_show(struct device *dev, struct device_attribute *attr, char *buf) · line 1774

Quoted 4 lines
drivers/usb/musb/musb_core.c +1 -0
@@ -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