Skip to contentSkip to conversation

usb: musb bugfixes

PATCH Superseded Markus Pargmann 3 participants 9 messages Oct 14, 2013 – Oct 15, 2013

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover usb: musb bugfixes

Hi,

the series contains two bugfixes and some debugfs file operations for dsps similar to the musb core regdump debugfs file.

v2 removes the dev_info() in patch 3 in dsps_musb_init.

Regards,

Markus Pargmann

Markus Pargmann (3):
usb: musb: Handle nullpointer
usb: musb: Bugfix of_node assignment
usb: musb: dsps, debugfs files

 drivers/usb/musb/musb_core.c | 15 +++++++-
 drivers/usb/musb/musb_dsps.c | 88 +++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 100 insertions(+), 3 deletions(-)
#1 lore raw

PATCH v2 1/3 usb: musb: Handle nullpointer

When the device is connected to a host without a gadget driver, otg->gadget is NULL.

---
 drivers/usb/musb/musb_core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/usb/musb/musb_core.c +2 -1
index 18e877f..baa4f6a 100644
@@ -654,7 +654,8 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb,
 				break;
 		case OTG_STATE_B_PERIPHERAL:
 			musb_g_suspend(musb);
-			musb->is_active = otg->gadget->b_hnp_enable;
+			musb->is_active = otg->gadget &&
+					otg->gadget->b_hnp_enable;
 			if (musb->is_active) {
 				musb->xceiv->state = OTG_STATE_B_WAIT_ACON;
 				dev_dbg(musb->controller, "HNP: Setting timer for b_ase0_brst\n");
Signature · 1 line
1.8.4.rc3
#2 lore raw

PATCH v2 1/3 usb: musb: Handle nullpointer

Quoted 13 lines · Markus Pargmann

When the device is connected to a host without a gadget driver, otg->gadget is NULL.

---
 drivers/usb/musb/musb_core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/usb/musb/musb_core.c +0 -0
index 18e877f..baa4f6a 100644

drivers/usb/musb/musb_core.c static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb, · line 655

Quoted 2 lines
drivers/usb/musb/musb_core.c +0 -0
@@ -654,7 +654,8 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb,
 				break;
 		case OTG_STATE_B_PERIPHERAL:

why would we be in B peripheral if we're host only ? Bug seems to be else where.

Signature · 8 lines
balbi
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20131014/09b8e5b9/attachment.sig>
#3 lore raw

PATCH v2 1/3 usb: musb: Handle nullpointer

Quoted 9 lines · Felipe Balbi
Quoted 8 lines · Markus Pargmann

When the device is connected to a host without a gadget driver, otg->gadget is NULL.

---
 drivers/usb/musb/musb_core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
Quoted 10 lines

drivers/usb/musb/musb_core.c static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb, · line 655

Quoted 7 lines
drivers/usb/musb/musb_core.c +0 -0
index 18e877f..baa4f6a 100644
@@ -654,7 +654,8 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb,
                              break;
              case OTG_STATE_B_PERIPHERAL:

why would we be in B peripheral if we're host only ? Bug seems to be else where.

We are not host, we are in device mode.

But I would think the proper fix should be not setting DEVCTL[SOFTCONN] until a gadget driver is loaded. Then the host will not see the device which does not have a gadget driver.

Regards,
-Bin.

Quoted 3 lines

--
balbi

#4 lore raw

PATCH v2 1/3 usb: musb: Handle nullpointer

Quoted 21 lines · Bin Liu
Quoted 9 lines · Felipe Balbi
Quoted 8 lines · Markus Pargmann

When the device is connected to a host without a gadget driver, otg->gadget is NULL.

---
 drivers/usb/musb/musb_core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
Quoted 10 lines

drivers/usb/musb/musb_core.c static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb, · line 655

Quoted 7 lines
drivers/usb/musb/musb_core.c +0 -0
index 18e877f..baa4f6a 100644
@@ -654,7 +654,8 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb,
                              break;
              case OTG_STATE_B_PERIPHERAL:

why would we be in B peripheral if we're host only ? Bug seems to be else where.

Quoted 5 lines

We are not host, we are in device mode.

But I would think the proper fix should be not setting DEVCTL[SOFTCONN] until a gadget driver is loaded. Then the host will not see the device which does not have a gadget driver.

Sorry, I meant POWER[SOFTCONN] bit.

Quoted 7 lines

Regards,
-Bin.

Quoted 3 lines

--
balbi

#5 lore raw

PATCH v2 1/3 usb: musb: Handle nullpointer

Quoted 22 lines · Bin Liu
Quoted 21 lines · Bin Liu
Quoted 19 lines · Felipe Balbi
Quoted 13 lines · Markus Pargmann

When the device is connected to a host without a gadget driver, otg->gadget is NULL.

---
 drivers/usb/musb/musb_core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/usb/musb/musb_core.c +0 -0
index 18e877f..baa4f6a 100644

drivers/usb/musb/musb_core.c static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb, · line 655

Quoted 2 lines
drivers/usb/musb/musb_core.c +0 -0
@@ -654,7 +654,8 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb,
                              break;
              case OTG_STATE_B_PERIPHERAL:

why would we be in B peripheral if we're host only ? Bug seems to be else where.

Quoted 7 lines
Quoted 5 lines

We are not host, we are in device mode.

But I would think the proper fix should be not setting DEVCTL[SOFTCONN] until a gadget driver is loaded. Then the host will not see the device which does not have a gadget driver.

Sorry, I meant POWER[SOFTCONN] bit.

I agree with you and my bad that I misread commit log.

Signature · 8 lines
balbi
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20131014/06cf6c3e/attachment.sig>
#6 lore raw

PATCH v2 2/3 usb: musb: Bugfix of_node assignment

In reply to Markus Pargmann

It is not safe to assign the of_node to a device without driver. The device is matched against a list of drivers and the of_node could lead to a DT match with the parent driver.

---
 drivers/usb/musb/musb_core.c | 12 +++++++++++-
 drivers/usb/musb/musb_dsps.c |  1 -
 2 files changed, 11 insertions(+), 2 deletions(-)
drivers/usb/musb/musb_core.c +11 -1
index baa4f6a..a26eccd 100644
@@ -1962,6 +1962,7 @@ static int musb_probe(struct platform_device *pdev)
 	int		irq = platform_get_irq_byname(pdev, "mc");
 	struct resource	*iomem;
 	void __iomem	*base;
+	int ret;
 
 	iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	if (!iomem || irq <= 0)
@@ -1971,7 +1972,16 @@ static int musb_probe(struct platform_device *pdev)
 	if (IS_ERR(base))
 		return PTR_ERR(base);
 
-	return musb_init_controller(dev, irq, base);
+	if (dev->parent)
+		dev->of_node = dev->parent->of_node;
+
+	ret = musb_init_controller(dev, irq, base);
+	if (ret) {
+		dev->of_node = NULL;
+		return ret;
+	}
+
+	return 0;
 }
 
 static int musb_remove(struct platform_device *pdev)
drivers/usb/musb/musb_dsps.c +0 -1
index bd4138d..189e52c 100644
@@ -483,7 +483,6 @@ static int dsps_create_musb_pdev(struct dsps_glue *glue,
 	musb->dev.parent		= dev;
 	musb->dev.dma_mask		= &musb_dmamask;
 	musb->dev.coherent_dma_mask	= musb_dmamask;
-	musb->dev.of_node		= of_node_get(dn);
 
 	glue->musb = musb;
 
Signature · 1 line
1.8.4.rc3
#7 lore raw

PATCH v2 3/3 usb: musb: dsps, debugfs files

In reply to Markus Pargmann

debugfs files to show the contents of important dsps registers.

---
 drivers/usb/musb/musb_dsps.c | 87 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 87 insertions(+)
drivers/usb/musb/musb_dsps.c +87 -0
index 189e52c..43b22ab 100644
@@ -46,6 +46,8 @@
 #include <linux/of_irq.h>
 #include <linux/usb/of.h>
 
+#include <linux/debugfs.h>
+
 #include "musb_core.h"
 
 static const struct of_device_id musb_dsps_of_match[];
@@ -121,6 +123,61 @@ struct dsps_glue {
 	unsigned long last_timer;    /* last timer data for each instance */
 };
 
+#if IS_ENABLED(CONFIG_DEBUG_FS)
+
+struct musb_register_map {
+	char			*name;
+	unsigned		offset;
+};
+
+static const struct musb_register_map musb_regmap[] = {
+	{ "revision",		0x00 },
+	{ "control",		0x14 },
+	{ "status",		0x18 },
+	{ "eoi",		0x24 },
+	{ "intr0_stat",		0x30 },
+	{ "intr1_stat",		0x34 },
+	{ "intr0_set",		0x38 },
+	{ "intr1_set",		0x3c },
+	{ "txmode",		0x70 },
+	{ "rxmode",		0x74 },
+	{ "autoreq",		0xd0 },
+	{ "srpfixtime",		0xd4 },
+	{ "tdown",		0xd8 },
+	{ "phy_utmi",		0xe0 },
+	{ "mode",		0xe8 },
+	{  }	/* Terminating Entry */
+};
+
+static int musb_regdump_show(struct seq_file *s, void *unused)
+{
+	struct musb		*musb = s->private;
+	unsigned		i;
+
+	seq_puts(s, "MUSB (M)HDRC dsps Register Dump\n");
+
+	for (i = 0; i < ARRAY_SIZE(musb_regmap); i++) {
+		u32 val = musb_readl(musb->ctrl_base, musb_regmap[i].offset);
+		seq_printf(s, "%-12s: %08x\n", musb_regmap[i].name, val);
+	}
+
+	return 0;
+}
+
+static int musb_regdump_open(struct inode *inode, struct file *file)
+{
+	return single_open(file, musb_regdump_show, inode->i_private);
+}
+
+static const struct file_operations musb_regdump_fops = {
+	.open			= musb_regdump_open,
+	.read			= seq_read,
+	.llseek			= seq_lseek,
+	.release		= single_release,
+};
+
+#endif /* IS_ENABLED(CONFIG_DEBUG_FS) */
+
 /**
  * dsps_musb_enable - enable interrupts
  */
@@ -348,6 +405,31 @@ out:
 	return ret;
 }
 
+#if IS_ENABLED(CONFIG_DEBUG_FS)
+static int dsps_musb_dbg_init(struct musb *musb)
+{
+	struct dentry *root;
+	struct dentry *file;
+	char buf[128];
+
+	sprintf(buf, "%s.dsps", dev_name(musb->controller));
+	root = debugfs_create_dir(buf, NULL);
+	if (!root)
+		return -ENOMEM;
+
+	file = debugfs_create_file("regdump", S_IRUGO, root, musb,
+			&musb_regdump_fops);
+	if (!file)
+		return -ENOMEM;
+	return 0;
+}
+#else
+static int dsps_musb_dbg_init(struct musb *musb)
+{
+	return 0;
+}
+#endif
+
 static int dsps_musb_init(struct musb *musb)
 {
 	struct device *dev = musb->controller;
@@ -357,6 +439,7 @@ static int dsps_musb_init(struct musb *musb)
 	void __iomem *reg_base;
 	struct resource *r;
 	u32 rev, val;
+	int ret;
 
 	r = platform_get_resource_byname(parent, IORESOURCE_MEM, "control");
 	if (!r)
@@ -390,6 +473,10 @@ static int dsps_musb_init(struct musb *musb)
 	val &= ~(1 << wrp->otg_disable);
 	dsps_writel(musb->ctrl_base, wrp->phy_utmi, val);
 
+	ret = dsps_musb_dbg_init(musb);
+	if (ret)
+		return ret;
+
 	return 0;
 }
 
Signature · 1 line
1.8.4.rc3
#8 lore raw

PATCH v2 3/3 usb: musb: dsps, debugfs files

Hi,

Quoted 90 lines · Markus Pargmann

debugfs files to show the contents of important dsps registers.

---
 drivers/usb/musb/musb_dsps.c | 87 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 87 insertions(+)
drivers/usb/musb/musb_dsps.c +61 -0
index 189e52c..43b22ab 100644
@@ -46,6 +46,8 @@
 #include <linux/of_irq.h>
 #include <linux/usb/of.h>
 
+#include <linux/debugfs.h>
+
 #include "musb_core.h"
 
 static const struct of_device_id musb_dsps_of_match[];
@@ -121,6 +123,61 @@ struct dsps_glue {
 	unsigned long last_timer;    /* last timer data for each instance */
 };
 
+#if IS_ENABLED(CONFIG_DEBUG_FS)
+
+struct musb_register_map {
+	char			*name;
+	unsigned		offset;
+};
+
+static const struct musb_register_map musb_regmap[] = {
+	{ "revision",		0x00 },
+	{ "control",		0x14 },
+	{ "status",		0x18 },
+	{ "eoi",		0x24 },
+	{ "intr0_stat",		0x30 },
+	{ "intr1_stat",		0x34 },
+	{ "intr0_set",		0x38 },
+	{ "intr1_set",		0x3c },
+	{ "txmode",		0x70 },
+	{ "rxmode",		0x74 },
+	{ "autoreq",		0xd0 },
+	{ "srpfixtime",		0xd4 },
+	{ "tdown",		0xd8 },
+	{ "phy_utmi",		0xe0 },
+	{ "mode",		0xe8 },
+	{  }	/* Terminating Entry */
+};
+
+static int musb_regdump_show(struct seq_file *s, void *unused)
+{
+	struct musb		*musb = s->private;
+	unsigned		i;
+
+	seq_puts(s, "MUSB (M)HDRC dsps Register Dump\n");
+
+	for (i = 0; i < ARRAY_SIZE(musb_regmap); i++) {
+		u32 val = musb_readl(musb->ctrl_base, musb_regmap[i].offset);
+		seq_printf(s, "%-12s: %08x\n", musb_regmap[i].name, val);
+	}
+
+	return 0;
+}
+
+static int musb_regdump_open(struct inode *inode, struct file *file)
+{
+	return single_open(file, musb_regdump_show, inode->i_private);
+}
+
+static const struct file_operations musb_regdump_fops = {
+	.open			= musb_regdump_open,
+	.read			= seq_read,
+	.llseek			= seq_lseek,
+	.release		= single_release,
+};
+
+#endif /* IS_ENABLED(CONFIG_DEBUG_FS) */
+
 /**
  * dsps_musb_enable - enable interrupts
  */
@@ -348,6 +405,31 @@ out:
 	return ret;
 }
 
+#if IS_ENABLED(CONFIG_DEBUG_FS)
+static int dsps_musb_dbg_init(struct musb *musb)
+{
+	struct dentry *root;

drivers/usb/musb/musb_dsps.c out: · line 421

Quoted 10 lines
drivers/usb/musb/musb_dsps.c +10 -0
+	struct dentry *file;
+	char buf[128];
+
+	sprintf(buf, "%s.dsps", dev_name(musb->controller));
+	root = debugfs_create_dir(buf, NULL);
+	if (!root)
+		return -ENOMEM;
+
+	file = debugfs_create_file("regdump", S_IRUGO, root, musb,
+			&musb_regdump_fops);

there is a generic regdump utility for debugfs, please use that instead. At least drivers/usb/dwc3/debugfs is using it.

Signature · 8 lines
balbi
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20131014/2004655a/attachment-0001.sig>