Skip to contentSkip to conversation

Bug fixes and improvements to Broadcom BDC driver

PATCH In review Al Cooper 2 participants 11 messages Jul 19, 2017 – Jul 24, 2017

Subsystems (3)
lore
Share & tools
lore

Al Cooper

author maintainer
#0 lore raw

v2 cover Bug fixes and improvements to Broadcom BDC driver

V2 Changes:
- Add support for USB phys. We need to handle systems with either a single phy or systems with both a USB2.0 and USB3.0 phy
- Fixes to the dt-bindings document based on feedback from Rob Herring. Changes include changing the compatible base name to "brcm,bdc" because "brcm,bdc-udc" seemed redundant
- Add proper suspend/resume support with clock control
- Split out code cleanup into separate patch

Bug fixes and improvements to the Broadcom USB STB BDC driver.

Al Cooper (8):
usb: bdc: Fix misleading register names
dt-bindings: usb: bdc: Add Device Tree binding for Broadcom UDC driver
usb: bdc: Add clock enable for new chips with a separate BDC clock
usb: bdc: Small code cleanup
usb: bdc: Add support for suspend/resume
usb: bdc: fix "xsf for ep not enabled" errror
usb: bdc: Enable in Kconfig for ARCH_BRCMSTB systems
usb: bdc: Add support for USB phy

Florian Fainelli (1):
usb: bdc: hook a quick Device Tree compatible string

 Documentation/devicetree/bindings/usb/brcm,bdc.txt |  29 ++++
 drivers/usb/gadget/udc/bdc/Kconfig                 |   1 +
 drivers/usb/gadget/udc/bdc/bdc.h                   |  24 ++--
 drivers/usb/gadget/udc/bdc/bdc_core.c              | 148 +++++++++++++++++++--
 drivers/usb/gadget/udc/bdc/bdc_dbg.c               |  16 +--
 drivers/usb/gadget/udc/bdc/bdc_ep.c                |   4 +-
 drivers/usb/gadget/udc/bdc/bdc_udc.c               |   7 +-
 7 files changed, 197 insertions(+), 32 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/usb/brcm,bdc.txt
Signature · 1 line
1.9.0.138.g2de3478
author maintainer
#1 lore raw

PATCH v2 1/9 usb: bdc: Fix misleading register names

The BDC endpoint status registers 0-7 were originally each going to be an array of regsiters. This was later changed to being a single register. The register definitions are being changed from:
"#define BDC_EPSTS0(n) (0x60 + (n * 0x10))"
to
"#define BDC_EPSTS0 0x60"
to reflect this change and to avoid future coding mistakes.

---
 drivers/usb/gadget/udc/bdc/bdc.h     | 16 ++++++++--------
 drivers/usb/gadget/udc/bdc/bdc_dbg.c | 16 ++++++++--------
 drivers/usb/gadget/udc/bdc/bdc_ep.c  |  4 ++--
 3 files changed, 18 insertions(+), 18 deletions(-)
drivers/usb/gadget/udc/bdc/bdc.h +8 -8
index 916d471..3664808 100644
@@ -83,14 +83,14 @@
 
 #define BDC_DVCSA	0x50
 #define BDC_DVCSB	0x54
-#define BDC_EPSTS0(n)	(0x60 + (n * 0x10))
-#define BDC_EPSTS1(n)	(0x64 + (n * 0x10))
-#define BDC_EPSTS2(n)	(0x68 + (n * 0x10))
-#define BDC_EPSTS3(n)	(0x6c + (n * 0x10))
-#define BDC_EPSTS4(n)	(0x70 + (n * 0x10))
-#define BDC_EPSTS5(n)	(0x74 + (n * 0x10))
-#define BDC_EPSTS6(n)	(0x78 + (n * 0x10))
-#define BDC_EPSTS7(n)	(0x7c + (n * 0x10))
+#define BDC_EPSTS0	0x60
+#define BDC_EPSTS1	0x64
+#define BDC_EPSTS2	0x68
+#define BDC_EPSTS3	0x6c
+#define BDC_EPSTS4	0x70
+#define BDC_EPSTS5	0x74
+#define BDC_EPSTS6	0x78
+#define BDC_EPSTS7	0x7c
 #define BDC_SRRBAL(n)	(0x200 + (n * 0x10))
 #define BDC_SRRBAH(n)	(0x204 + (n * 0x10))
 #define BDC_SRRINT(n)	(0x208 + (n * 0x10))
drivers/usb/gadget/udc/bdc/bdc_dbg.c +8 -8
index 5945dbc..ac98f6f 100644
@@ -40,28 +40,28 @@ void bdc_dump_epsts(struct bdc *bdc)
 {
 	u32 temp;
 
-	temp = bdc_readl(bdc->regs, BDC_EPSTS0(0));
+	temp = bdc_readl(bdc->regs, BDC_EPSTS0);
 	dev_vdbg(bdc->dev, "BDC_EPSTS0:0x%08x\n", temp);
 
-	temp = bdc_readl(bdc->regs, BDC_EPSTS1(0));
+	temp = bdc_readl(bdc->regs, BDC_EPSTS1);
 	dev_vdbg(bdc->dev, "BDC_EPSTS1:0x%x\n", temp);
 
-	temp = bdc_readl(bdc->regs, BDC_EPSTS2(0));
+	temp = bdc_readl(bdc->regs, BDC_EPSTS2);
 	dev_vdbg(bdc->dev, "BDC_EPSTS2:0x%08x\n", temp);
 
-	temp = bdc_readl(bdc->regs, BDC_EPSTS3(0));
+	temp = bdc_readl(bdc->regs, BDC_EPSTS3);
 	dev_vdbg(bdc->dev, "BDC_EPSTS3:0x%08x\n", temp);
 
-	temp = bdc_readl(bdc->regs, BDC_EPSTS4(0));
+	temp = bdc_readl(bdc->regs, BDC_EPSTS4);
 	dev_vdbg(bdc->dev, "BDC_EPSTS4:0x%08x\n", temp);
 
-	temp = bdc_readl(bdc->regs, BDC_EPSTS5(0));
+	temp = bdc_readl(bdc->regs, BDC_EPSTS5);
 	dev_vdbg(bdc->dev, "BDC_EPSTS5:0x%08x\n", temp);
 
-	temp = bdc_readl(bdc->regs, BDC_EPSTS6(0));
+	temp = bdc_readl(bdc->regs, BDC_EPSTS6);
 	dev_vdbg(bdc->dev, "BDC_EPSTS6:0x%08x\n", temp);
 
-	temp = bdc_readl(bdc->regs, BDC_EPSTS7(0));
+	temp = bdc_readl(bdc->regs, BDC_EPSTS7);
 	dev_vdbg(bdc->dev, "BDC_EPSTS7:0x%08x\n", temp);
 }
 
drivers/usb/gadget/udc/bdc/bdc_ep.c +2 -2
index ff1ef24..bfd8f7a 100644
@@ -777,9 +777,9 @@ static int ep_dequeue(struct bdc_ep *ep, struct bdc_req *req)
 	 */
 
 	/* The current hw dequeue pointer */
-	tmp_32 = bdc_readl(bdc->regs, BDC_EPSTS0(0));
+	tmp_32 = bdc_readl(bdc->regs, BDC_EPSTS0);
 	deq_ptr_64 = tmp_32;
-	tmp_32 = bdc_readl(bdc->regs, BDC_EPSTS1(0));
+	tmp_32 = bdc_readl(bdc->regs, BDC_EPSTS1);
 	deq_ptr_64 |= ((u64)tmp_32 << 32);
 
 	/* we have the dma addr of next bd that will be fetched by hardware */
Signature · 1 line
1.9.0.138.g2de3478
author maintainer
#2 lore raw

PATCH v2 2/9 dt-bindings: usb: bdc: Add Device Tree binding for Broadcom UDC driver

In reply to Al Cooper

Add Device Tree binding document for Broadcom USB Device Controller (BDC).

---
 Documentation/devicetree/bindings/usb/brcm,bdc.txt | 29 ++++++++++++++++++++++
 1 file changed, 29 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/usb/brcm,bdc.txt
Documentation/devicetree/bindings/usb/brcm,bdc.txt new file +29 -0
new file mode 100644
index 0000000..63e63af
@@ -0,0 +1,29 @@
+Broadcom USB Device Controller (BDC)
+====================================
+
+Required properties:
+
+- compatible: must be one of:
+                "brcm,bdc-v0.16"
+                "brcm,bdc"
+- reg: the base register address and length
+- interrupts: the interrupt line for this controller
+
+Optional properties:
+
+On Broadcom STB platforms, these properties are required:
+
+- phys: phandle to one or two USB PHY blocks
+        NOTE: Some SoC's have a single phy and some have
+        USB 2.0 and USB 3.0 phys
+- clocks: phandle to the functional clock of this block
+
+Example:
+
+        bdc@f0b02000 {
+                compatible = "brcm,bdc-v0.16";
+                reg = <0xf0b02000 0xfc4>;
+                interrupts = <0x0 0x60 0x0>;
+                phys = <&usbphy_0 0x0>;
+                clocks = <&sw_usbd>;
+        };
Signature · 1 line
1.9.0.138.g2de3478
author maintainer
#4 lore raw

PATCH v2 3/9 usb: bdc: Add clock enable for new chips with a separate BDC clock

In reply to Al Cooper

Newer SoC's have added a BDC clock to the Device Tree, so get and enable it.

---
 drivers/usb/gadget/udc/bdc/bdc_core.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
drivers/usb/gadget/udc/bdc/bdc_core.c +15 -0
index e9bd8d4..dda7b43 100644
@@ -27,6 +27,7 @@
 #include <linux/moduleparam.h>
 #include <linux/usb/ch9.h>
 #include <linux/usb/gadget.h>
+#include <linux/clk.h>
 
 #include "bdc.h"
 #include "bdc_dbg.h"
@@ -452,8 +453,22 @@ static int bdc_probe(struct platform_device *pdev)
 	int irq;
 	u32 temp;
 	struct device *dev = &pdev->dev;
+	struct clk *clk;
 
 	dev_dbg(dev, "%s()\n", __func__);
+
+	clk = devm_clk_get(dev, "sw_usbd");
+	if (IS_ERR(clk)) {
+		dev_info(dev, "Clock not found in Device Tree\n");
+		clk = NULL;
+	}
+
+	ret = clk_prepare_enable(clk);
+	if (ret) {
+		dev_err(dev, "could not enable clock\n");
+		return ret;
+	}
+
 	bdc = devm_kzalloc(dev, sizeof(*bdc), GFP_KERNEL);
 	if (!bdc)
 		return -ENOMEM;
Signature · 1 line
1.9.0.138.g2de3478
author maintainer
#5 lore raw

PATCH v2 4/9 usb: bdc: Small code cleanup

In reply to Al Cooper
---
 drivers/usb/gadget/udc/bdc/bdc_core.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
drivers/usb/gadget/udc/bdc/bdc_core.c +8 -7
index dda7b43..c2bfae2 100644
@@ -488,28 +488,29 @@ static int bdc_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, bdc);
 	bdc->irq = irq;
 	bdc->dev = dev;
-	dev_dbg(bdc->dev, "bdc->regs: %p irq=%d\n", bdc->regs, bdc->irq);
+	dev_dbg(dev, "bdc->regs: %p irq=%d\n", bdc->regs, bdc->irq);
 
 	temp = bdc_readl(bdc->regs, BDC_BDCCAP1);
 	if ((temp & BDC_P64) &&
 			!dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64))) {
-		dev_dbg(bdc->dev, "Using 64-bit address\n");
+		dev_dbg(dev, "Using 64-bit address\n");
 	} else {
-		ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
+		ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32));
 		if (ret) {
-			dev_err(bdc->dev, "No suitable DMA config available, abort\n");
+			dev_err(dev,
+				"No suitable DMA config available, abort\n");
 			return -ENOTSUPP;
 		}
-		dev_dbg(bdc->dev, "Using 32-bit address\n");
+		dev_dbg(dev, "Using 32-bit address\n");
 	}
 	ret = bdc_hw_init(bdc);
 	if (ret) {
-		dev_err(bdc->dev, "BDC init failure:%d\n", ret);
+		dev_err(dev, "BDC init failure:%d\n", ret);
 		return ret;
 	}
 	ret = bdc_udc_init(bdc);
 	if (ret) {
-		dev_err(bdc->dev, "BDC Gadget init failure:%d\n", ret);
+		dev_err(dev, "BDC Gadget init failure:%d\n", ret);
 		goto cleanup;
 	}
 	return 0;
Signature · 1 line
1.9.0.138.g2de3478
author maintainer
#6 lore raw

PATCH v2 5/9 usb: bdc: hook a quick Device Tree compatible string

In reply to Al Cooper

From: Florian Fainelli <[email protected]>

Allows Device Tree probing

---
 drivers/usb/gadget/udc/bdc/bdc.h      | 4 ++--
 drivers/usb/gadget/udc/bdc/bdc_core.c | 8 ++++++++
 2 files changed, 10 insertions(+), 2 deletions(-)
drivers/usb/gadget/udc/bdc/bdc.h +2 -2
index 3664808..f657a4e 100644
@@ -27,8 +27,8 @@
 #include <linux/usb/gadget.h>
 #include <asm/unaligned.h>
 
-#define BRCM_BDC_NAME "bdc_usb3"
-#define BRCM_BDC_DESC "BDC device controller driver"
+#define BRCM_BDC_NAME "bdc"
+#define BRCM_BDC_DESC "Broadcom USB Device Controller driver"
 
 #define DMA_ADDR_INVALID        (~(dma_addr_t)0)
 
drivers/usb/gadget/udc/bdc/bdc_core.c +8 -0
index c2bfae2..bc0729b 100644
@@ -533,9 +533,17 @@ static int bdc_remove(struct platform_device *pdev)
 	return 0;
 }
 
+static const struct of_device_id bdc_of_match[] = {
+	{ .compatible = "brcm,bdc-v0.16" },
+	{ .compatible = "brcm,bdc" },
+	{ /* sentinel */ }
+};
+
 static struct platform_driver bdc_driver = {
 	.driver		= {
 		.name	= BRCM_BDC_NAME,
+		.owner	= THIS_MODULE,
+		.of_match_table	= bdc_of_match,
 	},
 	.probe		= bdc_probe,
 	.remove		= bdc_remove,
Signature · 1 line
1.9.0.138.g2de3478
author maintainer
#7 lore raw

PATCH v2 6/9 usb: bdc: Add support for suspend/resume

In reply to Al Cooper

Based on a previous commit by Danesh Petigara <dpetigara-dY08KVG/lbpWk0Htik3J/[email protected]> that added resume to solve the following problem:
"The BDC driver will fail after resuming from S3 suspend and this
will cause any upper layer gadget driver to fail."
This commit also adds support for suspend and manages the clock during suspend/resume.

---
 drivers/usb/gadget/udc/bdc/bdc.h      |  1 +
 drivers/usb/gadget/udc/bdc/bdc_core.c | 36 +++++++++++++++++++++++++++++++++++
 2 files changed, 37 insertions(+)
drivers/usb/gadget/udc/bdc/bdc.h +1 -0
index f657a4e..67c5f23 100644
@@ -454,6 +454,7 @@ struct bdc {
 	 * Func Wake packet every 2.5 secs. Refer to USB3 spec section 8.5.6.4
 	 */
 	struct delayed_work	func_wake_notify;
+	struct clk		*clk;
 };
 
 static inline u32 bdc_readl(void __iomem *base, u32 offset)
drivers/usb/gadget/udc/bdc/bdc_core.c +36 -0
index bc0729b..2690b6f 100644
@@ -473,6 +473,8 @@ static int bdc_probe(struct platform_device *pdev)
 	if (!bdc)
 		return -ENOMEM;
 
+	bdc->clk = clk;
+
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	bdc->regs = devm_ioremap_resource(dev, res);
 	if (IS_ERR(bdc->regs)) {
@@ -529,10 +531,43 @@ static int bdc_remove(struct platform_device *pdev)
 	dev_dbg(bdc->dev, "%s ()\n", __func__);
 	bdc_udc_exit(bdc);
 	bdc_hw_exit(bdc);
+	clk_disable_unprepare(bdc->clk);
+	return 0;
+}
+
+#ifdef CONFIG_PM_SLEEP
+static int bdc_suspend(struct device *dev)
+{
+	struct bdc *bdc = dev_get_drvdata(dev);
+
+	clk_disable_unprepare(bdc->clk);
+	return 0;
+}
+
+static int bdc_resume(struct device *dev)
+{
+	struct bdc *bdc = dev_get_drvdata(dev);
+	int ret;
+
+	ret = clk_prepare_enable(bdc->clk);
+	if (ret) {
+		dev_err(bdc->dev, "err enabling the clock\n");
+		return ret;
+	}
+	ret = bdc_reinit(bdc);
+	if (ret) {
+		dev_err(bdc->dev, "err in bdc reinit\n");
+		return ret;
+	}
 
 	return 0;
 }
 
+#endif /* CONFIG_PM_SLEEP */
+
+static SIMPLE_DEV_PM_OPS(bdc_pm_ops, bdc_suspend,
+		bdc_resume);
+
 static const struct of_device_id bdc_of_match[] = {
 	{ .compatible = "brcm,bdc-v0.16" },
 	{ .compatible = "brcm,bdc" },
@@ -543,6 +578,7 @@ static int bdc_remove(struct platform_device *pdev)
 	.driver		= {
 		.name	= BRCM_BDC_NAME,
 		.owner	= THIS_MODULE,
+		.pm = &bdc_pm_ops,
 		.of_match_table	= bdc_of_match,
 	},
 	.probe		= bdc_probe,
Signature · 6 lines
1.9.0.138.g2de3478

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
author maintainer
#8 lore raw

PATCH v2 7/9 usb: bdc: fix "xsf for ep not enabled" errror

In reply to Al Cooper

This patch essentially clears the port status change bits at the correct times. It is necessary because the driver was not handling the change bits correctly for events during device connection/disconnection and bus enumeration. So, one of them (PCC) was left stuck sometimes causing the "xsf for ep not enabled" error we get on first connection. This was found by the Android team. This was debugged and fixed by Sasi Kumar.

---
 drivers/usb/gadget/udc/bdc/bdc_udc.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/usb/gadget/udc/bdc/bdc_udc.c +4 -3
index aae7458..c843461 100644
@@ -249,6 +249,7 @@ void bdc_sr_uspc(struct bdc *bdc, struct bdc_sr *sreport)
 			disconn = true;
 		else if ((uspc & BDC_PCS) && !BDC_PST(uspc))
 			connected = true;
+		clear_flags |= BDC_PCC;
 	}
 
 	/* Change in VBus and VBus is present */
@@ -259,16 +260,16 @@ void bdc_sr_uspc(struct bdc *bdc, struct bdc_sr *sreport)
 			bdc_softconn(bdc);
 			usb_gadget_set_state(&bdc->gadget, USB_STATE_POWERED);
 		}
-		clear_flags = BDC_VBC;
+		clear_flags |= BDC_VBC;
 	} else if ((uspc & BDC_PRS) || (uspc & BDC_PRC) || disconn) {
 		/* Hot reset, warm reset, 2.0 bus reset or disconn */
 		dev_dbg(bdc->dev, "Port reset or disconn\n");
 		bdc_uspc_disconnected(bdc, disconn);
-		clear_flags = BDC_PCC|BDC_PCS|BDC_PRS|BDC_PRC;
+		clear_flags |= BDC_PRC;
 	} else if ((uspc & BDC_PSC) && (uspc & BDC_PCS)) {
 		/* Change in Link state */
 		handle_link_state_change(bdc, uspc);
-		clear_flags = BDC_PSC|BDC_PCS;
+		clear_flags |= BDC_PSC;
 	}
 
 	/*
Signature · 1 line
1.9.0.138.g2de3478
author maintainer
#9 lore raw

PATCH v2 8/9 usb: bdc: Enable in Kconfig for ARCH_BRCMSTB systems

In reply to Al Cooper

Many ARM based Broadcom STB SoC's have a USB BDC controller so enable this driver for these systems.

---
 drivers/usb/gadget/udc/bdc/Kconfig | 1 +
 1 file changed, 1 insertion(+)
drivers/usb/gadget/udc/bdc/Kconfig +1 -0
index eb8b553..c74ac25 100644
@@ -1,6 +1,7 @@
 config USB_BDC_UDC
 	tristate "Broadcom USB3.0 device controller IP driver(BDC)"
 	depends on USB_GADGET && HAS_DMA
+	default ARCH_BRCMSTB
 
 	help
 	BDC is Broadcom's USB3.0 device controller IP. If your SOC has a BDC IP
Signature · 1 line
1.9.0.138.g2de3478
author maintainer
#10 lore raw

PATCH v2 9/9 usb: bdc: Add support for USB phy

In reply to Al Cooper

If a phy is specified in the device tree node, get it and use it. This was based on a patch by:
"Srinath Mannam <[email protected]>"

---
 drivers/usb/gadget/udc/bdc/bdc.h      |  3 ++
 drivers/usb/gadget/udc/bdc/bdc_core.c | 74 ++++++++++++++++++++++++++++++++++-
 2 files changed, 75 insertions(+), 2 deletions(-)
drivers/usb/gadget/udc/bdc/bdc.h +3 -0
index 67c5f23..6df0352 100644
@@ -413,6 +413,9 @@ struct bdc {
 	/* device lock */
 	spinlock_t	lock;
 
+	/* generic phy */
+	struct phy      **phys;
+	int num_phys;
 	/* num of endpoints for a particular instantiation of IP */
 	unsigned int num_eps;
 	/*
drivers/usb/gadget/udc/bdc/bdc_core.c +72 -2

116 lines not on this page · raw message

Signature · 1 line
1.9.0.138.g2de3478
maintainer Acked-by on v2 2/9
#3 lore raw

Re: [PATCH V2 2/9] dt-bindings: usb: bdc: Add Device Tree binding for Broadcom UDC driver

In reply to Al Cooper
Quoted 8 lines · Al Cooper

Add Device Tree binding document for Broadcom USB Device Controller (BDC).

---
 Documentation/devicetree/bindings/usb/brcm,bdc.txt | 29 ++++++++++++++++++++++
 1 file changed, 29 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/usb/brcm,bdc.txt

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html