usb: bdc: Updates and fixes to USB BDC driver
Subsystems (3)
Al Cooper
maintainercover usb: bdc: Updates and fixes to USB BDC driver
This is a series of updates and fixes to the Broadcom USB BDC driver
Al Cooper (6):
usb: bdc: driver runs out of buffer descriptors on large ADB transfers
usb: bdc: Cleanup clock support
usb: bdc: driver may fail to get USB PHY
usb: bdc: Fix bug causing crash after multiple disconnects
dt-bindings: usb: bdc: Update compatible strings
usb: bdc: Update compatible match strings
Documentation/devicetree/bindings/usb/brcm,bdc.txt | 4 ++-- drivers/usb/gadget/udc/bdc/bdc.h | 2 +- drivers/usb/gadget/udc/bdc/bdc_core.c | 26 ++++++++++++++++------ drivers/usb/gadget/udc/bdc/bdc_ep.c | 16 ++++++++----- 4 files changed, 32 insertions(+), 16 deletions(-)
Signature · 1 line
1.9.0.138.g2de3478
Al Cooper
maintainerPATCH 1/6 usb: bdc: driver runs out of buffer descriptors on large ADB transfers
Version v1.0.40 of the Android host ADB software increased maximum transfer sizes from 256K to 1M. Since the STB ADB gadget driver requests only 16K at a time, the BDC driver ran out of buffer descriptors (BDs) if the queuing happens faster than the incoming 16K transfers. This issue is fixed by doubling the number of BDs that can be queued so that the entire 1M request can be queued without running out of buffers.
--- drivers/usb/gadget/udc/bdc/bdc.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/gadget/udc/bdc/bdc.h +1 -1
@@ -44,7 +44,7 @@#define NUM_SR_ENTRIES 64/* Num of bds per table */ -#define NUM_BDS_PER_TABLE 32 +#define NUM_BDS_PER_TABLE 64/* Num of tables in bd list for control,bulk and Int ep */ #define NUM_TABLES 2
Signature · 1 line
1.9.0.138.g2de3478
Al Cooper
maintainerPATCH 2/6 usb: bdc: Cleanup clock support
In reply to Al Cooper- Fix driver to defer on clk_get defer
--- drivers/usb/gadget/udc/bdc/bdc_core.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)
drivers/usb/gadget/udc/bdc/bdc_core.c +9 -6
@@ -490,8 +490,14 @@ static int bdc_probe(struct platform_device *pdev)dev_dbg (dev,"%s()\n" , __func__); + bdc =devm_kzalloc (dev,sizeof (*bdc),GFP_KERNEL ); +if (!bdc) +return -ENOMEM ; + clk =devm_clk_get (dev,"sw_usbd" );if (IS_ERR (clk)) { +if (PTR_ERR (clk) == -EPROBE_DEFER ) +return -EPROBE_DEFER ;dev_info (dev,"Clock not found in Device Tree\n" ); clk =NULL ; }
@@ -501,11 +507,6 @@ static int bdc_probe(struct platform_device *pdev)dev_err (dev,"could not enable clock\n" );return ret; } - - bdc =devm_kzalloc (dev,sizeof (*bdc),GFP_KERNEL ); -if (!bdc) -return -ENOMEM ; - bdc->clk = clk; res =platform_get_resource (pdev,IORESOURCE_MEM ,0 );
@@ -551,7 +552,7 @@ static int bdc_probe(struct platform_device *pdev) ret =bdc_phy_init (bdc);if (ret) {dev_err (bdc->dev,"BDC phy init failure:%d\n" , ret); -return ret; + goto clk_cleanup; } temp =bdc_readl (bdc->regs,BDC_BDCCAP1 );
@@ -583,6 +584,8 @@ static int bdc_probe(struct platform_device *pdev)bdc_hw_exit (bdc); phycleanup:bdc_phy_exit (bdc); +clk_cleanup: +clk_disable_unprepare (bdc->clk);return ret; }
Signature · 1 line
1.9.0.138.g2de3478
Re: [PATCH 2/6] usb: bdc: Cleanup clock support
Quoted 13 lines · Al Cooper
- Fix driver to defer on
clk_getdeferSigned-off-by Al Cooper <[email protected]>--- drivers/usb/gadget/udc/bdc/bdc_core.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)drivers/usb/gadget/udc/bdc/bdc_core.c +0
-0@@ -490,8 +490,14 @@ static int bdc_probe(struct platform_device *pdev)
drivers/usb/gadget/udc/bdc/bdc_core.c static int bdc_probe(struct platform_device *pdev) · line 500
Quoted 10 lines
drivers/usb/gadget/udc/bdc/bdc_core.c +6
-0dev_dbg (dev,"%s()\n" , __func__); + bdc =devm_kzalloc (dev,sizeof (*bdc),GFP_KERNEL ); +if (!bdc) +return -ENOMEM ; + clk =devm_clk_get (dev,"sw_usbd" );if (IS_ERR (clk)) { +if (PTR_ERR (clk) == -EPROBE_DEFER ) +return -EPROBE_DEFER ;
what about using devm_clk_get_optional()?
Quoted 33 lines
drivers/usb/gadget/udc/bdc/bdc_core.c +3
-6dev_info (dev,"Clock not found in Device Tree\n" ); clk =NULL ; }@@ -501,11 +507,6 @@ static int bdc_probe(struct platform_device *pdev)dev_err (dev,"could not enable clock\n" );return ret; } - - bdc =devm_kzalloc (dev,sizeof (*bdc),GFP_KERNEL ); -if (!bdc) -return -ENOMEM ; - bdc->clk = clk; res =platform_get_resource (pdev,IORESOURCE_MEM ,0 );@@ -551,7 +552,7 @@ static int bdc_probe(struct platform_device *pdev) ret =bdc_phy_init (bdc);if (ret) {dev_err (bdc->dev,"BDC phy init failure:%d\n" , ret); -return ret; + goto clk_cleanup; } temp =bdc_readl (bdc->regs,BDC_BDCCAP1 );@@ -583,6 +584,8 @@ static int bdc_probe(struct platform_device *pdev)bdc_hw_exit (bdc); phycleanup:bdc_phy_exit (bdc); +clk_cleanup: +clk_disable_unprepare (bdc->clk);return ret; }
Alan Cooper
maintainerRe: [PATCH 2/6] usb: bdc: Cleanup clock support
Quoted 8 lines
Quoted 8 lines
drivers/usb/gadget/udc/bdc/bdc_core.c +0
-0@@ -490,8 +490,14 @@ static int bdc_probe(struct platform_device *pdev)dev_dbg (dev,"%s()\n" , __func__);
Quoted 9 lines
drivers/usb/gadget/udc/bdc/bdc_core.c static int bdc_probe(struct platform_device *pdev) · line 500
Quoted 8 lines
drivers/usb/gadget/udc/bdc/bdc_core.c +6
-0+ bdc =devm_kzalloc (dev,sizeof (*bdc),GFP_KERNEL ); +if (!bdc) +return -ENOMEM ; + clk =devm_clk_get (dev,"sw_usbd" );if (IS_ERR (clk)) { +if (PTR_ERR (clk) == -EPROBE_DEFER ) +return -EPROBE_DEFER ;what about using
devm_clk_get_optional()?
Good suggestion.
Thanks
Al
Quoted 62 lines · Chunfeng Yun
Quoted 13 lines · Al Cooper
drivers/usb/gadget/udc/bdc/bdc_core.c +0
-1- Fix driver to defer on clk_get deferSigned-off-by Al Cooper <[email protected]>--- drivers/usb/gadget/udc/bdc/bdc_core.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)drivers/usb/gadget/udc/bdc/bdc_core.c +0
-0@@ -490,8 +490,14 @@ static int bdc_probe(struct platform_device *pdev)drivers/usb/gadget/udc/bdc/bdc_core.c static int bdc_probe(struct platform_device *pdev) · line 500
Quoted 10 lines
drivers/usb/gadget/udc/bdc/bdc_core.c +6
-0dev_dbg (dev,"%s()\n" , __func__); + bdc =devm_kzalloc (dev,sizeof (*bdc),GFP_KERNEL ); +if (!bdc) +return -ENOMEM ; + clk =devm_clk_get (dev,"sw_usbd" );if (IS_ERR (clk)) { +if (PTR_ERR (clk) == -EPROBE_DEFER ) +return -EPROBE_DEFER ;what about using
devm_clk_get_optional()?Quoted 33 lines
drivers/usb/gadget/udc/bdc/bdc_core.c +3
-6dev_info (dev,"Clock not found in Device Tree\n" ); clk =NULL ; }@@ -501,11 +507,6 @@ static int bdc_probe(struct platform_device *pdev)dev_err (dev,"could not enable clock\n" );return ret; } - - bdc =devm_kzalloc (dev,sizeof (*bdc),GFP_KERNEL ); -if (!bdc) -return -ENOMEM ; - bdc->clk = clk; res =platform_get_resource (pdev,IORESOURCE_MEM ,0 );@@ -551,7 +552,7 @@ static int bdc_probe(struct platform_device *pdev) ret =bdc_phy_init (bdc);if (ret) {dev_err (bdc->dev,"BDC phy init failure:%d\n" , ret); -return ret; + goto clk_cleanup; } temp =bdc_readl (bdc->regs,BDC_BDCCAP1 );@@ -583,6 +584,8 @@ static int bdc_probe(struct platform_device *pdev)bdc_hw_exit (bdc); phycleanup:bdc_phy_exit (bdc); +clk_cleanup: +clk_disable_unprepare (bdc->clk);return ret; }
Al Cooper
maintainerPATCH 3/6 usb: bdc: driver may fail to get USB PHY
In reply to Al CooperInitialization order is important for the USB PHY and the PHY clients. The init order is based on the build order of the drivers in the makefiles and the PHY drivers are built early to help with dependencies, but the new SCMI based clock subsystem has the side effect of making some additional drivers DEFER until the clock is ready. This is causing the USB PHY driver to defer which is causing some PHY clients to fail when they try to get the PHY. The fix is to have the client driver return DEFER when it's "get phy" routine returns DEFER.
--- drivers/usb/gadget/udc/bdc/bdc_core.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/usb/gadget/udc/bdc/bdc_core.c +5 -1
@@ -543,9 +543,13 @@ static int bdc_probe(struct platform_device *pdev) dev, dev->of_node, phy_num);if (IS_ERR (bdc->phys[phy_num])) { ret =PTR_ERR (bdc->phys[phy_num]); +if (ret == -EPROBE_DEFER ) { +dev_dbg (bdc->dev,"DEFER, waiting for PHY\n" ); +return ret; + }dev_err (bdc->dev,"BDC phy specified but not found:%d\n" , ret); -return ret; + goto clk_cleanup; } }
Signature · 1 line
1.9.0.138.g2de3478
Re: [PATCH 3/6] usb: bdc: driver may fail to get USB PHY
Quoted 19 lines · Al Cooper
Initialization order is important for the USB PHY and the PHY clients. The init order is based on the build order of the drivers in the makefiles and the PHY drivers are built early to help with dependencies, but the new SCMI based clock subsystem has the side effect of making some additional drivers DEFER until the clock is ready. This is causing the USB PHY driver to defer which is causing some PHY clients to fail when they try to get the PHY. The fix is to have the client driver return DEFER when it's "get phy" routine returns DEFER.
Signed-off-by Al Cooper <[email protected]>--- drivers/usb/gadget/udc/bdc/bdc_core.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)drivers/usb/gadget/udc/bdc/bdc_core.c +0
-0
drivers/usb/gadget/udc/bdc/bdc_core.c static int bdc_probe(struct platform_device *pdev) · line 547
Quoted 5 lines
drivers/usb/gadget/udc/bdc/bdc_core.c +2
-0@@ -543,9 +543,13 @@ static int bdc_probe(struct platform_device *pdev) dev, dev->of_node, phy_num);if (IS_ERR (bdc->phys[phy_num])) { ret =PTR_ERR (bdc->phys[phy_num]); +if (ret == -EPROBE_DEFER ) { +dev_dbg (bdc->dev,"DEFER, waiting for PHY\n" );
why not disable clock here? when re-probe, will enable clock again. to me, no need check -EPROBE_DEFFER.
Quoted 10 lines
drivers/usb/gadget/udc/bdc/bdc_core.c +3
-1+return ret; + }dev_err (bdc->dev,"BDC phy specified but not found:%d\n" , ret); -return ret; + goto clk_cleanup; } }
Alan Cooper
maintainerRe: [PATCH 3/6] usb: bdc: driver may fail to get USB PHY
It's been very useful to have the DEFER debug message so I'd like to leave in the check for DEFER. I should not be skipping the clock disable, so I'll "goto clk_cleanup" for both cases.
Thanks
Al
Quoted 40 lines · Chunfeng Yun
Quoted 19 lines · Al Cooper
Initialization order is important for the USB PHY and the PHY clients. The init order is based on the build order of the drivers in the makefiles and the PHY drivers are built early to help with dependencies, but the new SCMI based clock subsystem has the side effect of making some additional drivers DEFER until the clock is ready. This is causing the USB PHY driver to defer which is causing some PHY clients to fail when they try to get the PHY. The fix is to have the client driver return DEFER when it's "get phy" routine returns DEFER.
Signed-off-by Al Cooper <[email protected]>--- drivers/usb/gadget/udc/bdc/bdc_core.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)drivers/usb/gadget/udc/bdc/bdc_core.c +0
-0drivers/usb/gadget/udc/bdc/bdc_core.c static int bdc_probe(struct platform_device *pdev) · line 547
Quoted 5 lines
drivers/usb/gadget/udc/bdc/bdc_core.c +2
-0@@ -543,9 +543,13 @@ static int bdc_probe(struct platform_device *pdev) dev, dev->of_node, phy_num);if (IS_ERR (bdc->phys[phy_num])) { ret =PTR_ERR (bdc->phys[phy_num]); +if (ret == -EPROBE_DEFER ) { +dev_dbg (bdc->dev,"DEFER, waiting for PHY\n" );why not disable clock here? when re-probe, will enable clock again. to me, no need check -EPROBE_DEFFER.
Quoted 10 lines
drivers/usb/gadget/udc/bdc/bdc_core.c +3
-1+return ret; + }dev_err (bdc->dev,"BDC phy specified but not found:%d\n" , ret); -return ret; + goto clk_cleanup; } }
Al Cooper
maintainerPATCH 4/6 usb: bdc: Fix bug causing crash after multiple disconnects
In reply to Al CooperMultiple connects/disconnects can cause a crash on the second disconnect. The driver had a problem where it would try to send endpoint commands after it was disconnected which is not allowed by the hardware. The fix is to only allow the endpoint commands when the endpoint is connected. This will also fix issues that showed up when using configfs to create gadgets.
--- drivers/usb/gadget/udc/bdc/bdc_core.c | 4 ++++ drivers/usb/gadget/udc/bdc/bdc_ep.c | 16 ++++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-)
drivers/usb/gadget/udc/bdc/bdc_core.c +4 -0
@@ -282,6 +282,7 @@ static void bdc_mem_init(struct bdc *bdc, bool reinit)* in that case reinit is passed as 1 */ if (reinit) { +int i;/* Enable interrupts */ temp =bdc_readl (bdc->regs,BDC_BDCSC ); temp |=BDC_GIE ;
@@ -291,6 +292,9 @@ static void bdc_mem_init(struct bdc *bdc, bool reinit)/* Initialize SRR to 0 */ memset (bdc->srr.sr_bds,0 ,NUM_SR_ENTRIES *sizeof (struct bdc_bd )); +/* clear ep flags to avoid post disconnect stops/deconfigs */ +for (i =1 ; i < bdc->num_eps; ++i) + bdc->bdc_ep_array[i]->flags =0 ; }else {/* One time initiaization only */ /* Enable status report function pointers */
drivers/usb/gadget/udc/bdc/bdc_ep.c +10 -6
@@ -615,7 +615,6 @@ int bdc_ep_enable(struct bdc_ep *ep) }bdc_dbg_bd_list (bdc, ep);/* only for ep0: config ep is called for ep0 from connect event */ - ep->flags |=BDC_EP_ENABLED ;if (ep->ep_num ==1 )return ret;
@@ -759,10 +758,13 @@ static int ep_dequeue(struct bdc_ep *ep, struct bdc_req *req) __func__, ep->name, start_bdi, end_bdi);dev_dbg (bdc->dev,"ep_dequeue ep=%p ep->desc=%p\n" , ep, (void *)ep->usb_ep.desc); -/* Stop the ep to see where the HW is ? */ - ret =bdc_stop_ep (bdc, ep->ep_num); -/* if there is an issue with stopping ep, then no need to go further */ -if (ret) +/* if still connected, stop the ep to see where the HW is ? */ +if (!(bdc_readl (bdc->regs,BDC_USPC ) &BDC_PST_MASK )) { + ret =bdc_stop_ep (bdc, ep->ep_num); +/* if there is an issue, then no need to go further */ +if (ret) +return 0 ; + }else return 0 ;/*
@@ -1911,7 +1913,9 @@ static int bdc_gadget_ep_disable(struct usb_ep *_ep) __func__, ep->name, ep->flags);if (!(ep->flags &BDC_EP_ENABLED )) { -dev_warn (bdc->dev,"%s is already disabled\n" , ep->name); +if (bdc->gadget.speed !=USB_SPEED_UNKNOWN ) +dev_warn (bdc->dev,"%s is already disabled\n" , + ep->name);return 0 ; }spin_lock_irqsave (&bdc->lock, flags);
Signature · 1 line
1.9.0.138.g2de3478
Al Cooper
maintainerPATCH 5/6 dt-bindings: usb: bdc: Update compatible strings
In reply to Al CooperRemove "brcm,bdc-v0.16" because it was never used on any system. Add "brcm,bdc-udc-v3.1" which exists for any STB system with BDC.
--- Documentation/devicetree/bindings/usb/brcm,bdc.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Documentation/devicetree/bindings/usb/brcm,bdc.txt +2 -2
@@ -4,7 +4,7 @@ Broadcom USB Device Controller (BDC) Required properties: - compatible: must be one of: - "brcm,bdc-v0.16" + "brcm,bdc-udc-v3.1" "brcm,bdc" - reg: the base register address and length - interrupts: the interrupt line for this controller
@@ -21,7 +21,7 @@ On Broadcom STB platforms, these properties are required: Example: bdc@f0b02000 { - compatible = "brcm,bdc-v0.16"; + compatible = "brcm,bdc-udc-v3.1"; reg = <0xf0b02000 0xfc4>; interrupts = <0x0 0x60 0x0>; phys = <&usbphy_0 0x0>;
Signature · 1 line
1.9.0.138.g2de3478
Re: [PATCH 5/6] dt-bindings: usb: bdc: Update compatible strings
Quoted 8 lines · Al Cooper
Remove "brcm,bdc-v0.16" because it was never used on any system. Add "brcm,bdc-udc-v3.1" which exists for any STB system with BDC.
Signed-off-by Al Cooper <[email protected]>--- Documentation/devicetree/bindings/usb/brcm,bdc.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Al Cooper
maintainerPATCH 6/6 usb: bdc: Update compatible match strings
In reply to Al CooperRemove "brcm,bdc-v0.16" because it was never used on any system. Add "brcm,bdc-udc-v3.1" which exists for any STB system with BDC.
--- drivers/usb/gadget/udc/bdc/bdc_core.c | 1 + 1 file changed, 1 insertion(+)
drivers/usb/gadget/udc/bdc/bdc_core.c +1 -0
@@ -644,6 +644,7 @@ static SIMPLE_DEV_PM_OPS(bdc_pm_ops, bdc_suspend, bdc_resume);static const struct of_device_id bdc_of_match[] = { + { .compatible ="brcm,bdc-udc-v3.1" }, { .compatible ="brcm,bdc-v0.16" }, { .compatible ="brcm,bdc" }, {/* sentinel */ }
Signature · 1 line
1.9.0.138.g2de3478
Re: [PATCH 6/6] usb: bdc: Update compatible match strings
Hello!
Quoted 1 line · Al Cooper
Remove "brcm,bdc-v0.16" because it was never used on any system.
You're not really removing it, are you?
Quoted 12 lines
Add "brcm,bdc-udc-v3.1" which exists for any STB system with BDC.
Signed-off-by Al Cooper <[email protected]>--- drivers/usb/gadget/udc/bdc/bdc_core.c | 1 + 1 file changed, 1 insertion(+)drivers/usb/gadget/udc/bdc/bdc_core.c +0
-0
drivers/usb/gadget/udc/bdc/bdc_core.c static SIMPLE_DEV_PM_OPS(bdc_pm_ops, bdc_suspend, · line 650
Quoted 7 lines
drivers/usb/gadget/udc/bdc/bdc_core.c +1
-0@@ -644,6 +644,7 @@ static SIMPLE_DEV_PM_OPS(bdc_pm_ops, bdc_suspend, bdc_resume);static const struct of_device_id bdc_of_match[] = { + { .compatible ="brcm,bdc-udc-v3.1" }, { .compatible ="brcm,bdc-v0.16" }, { .compatible ="brcm,bdc" }, {/* sentinel */ }
MBR, Sergei
Alan Cooper
maintainerRe: [PATCH 6/6] usb: bdc: Update compatible match strings
Quoted 3 lines
Quoted 1 line
Remove "brcm,bdc-v0.16" because it was never used on any system.
You're not really removing it, are you?
Whoops, it was supposed to be removed.
Thanks
Al
Quoted 30 lines · Sergei Shtylyov
Hello!
Quoted 1 line · Al Cooper
Remove "brcm,bdc-v0.16" because it was never used on any system.
You're not really removing it, are you?
Quoted 12 lines
Add "brcm,bdc-udc-v3.1" which exists for any STB system with BDC.
Signed-off-by Al Cooper <[email protected]>--- drivers/usb/gadget/udc/bdc/bdc_core.c | 1 + 1 file changed, 1 insertion(+)drivers/usb/gadget/udc/bdc/bdc_core.c +0
-0drivers/usb/gadget/udc/bdc/bdc_core.c static SIMPLE_DEV_PM_OPS(bdc_pm_ops, bdc_suspend, · line 650
Quoted 7 lines
drivers/usb/gadget/udc/bdc/bdc_core.c +1
-0@@ -644,6 +644,7 @@ static SIMPLE_DEV_PM_OPS(bdc_pm_ops, bdc_suspend, bdc_resume);static const struct of_device_id bdc_of_match[] = { + { .compatible ="brcm,bdc-udc-v3.1" }, { .compatible ="brcm,bdc-v0.16" }, { .compatible ="brcm,bdc" }, {/* sentinel */ }MBR, Sergei