linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/6] usb: dwc2/gadget: bugfixes for gadget driver
@ 2014-09-09  8:44 Robert Baldyga
  2014-09-09  8:44 ` [PATCH 1/6] usb: dwc2/gadget: fix phy disable sequence Robert Baldyga
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Robert Baldyga @ 2014-09-09  8:44 UTC (permalink / raw)
  To: Paul.Zimmerman; +Cc: gregkh, balbi, linux-usb, linux-kernel, Robert Baldyga

Hi,

I have splitted my patchset "usb: dwc2/gadget: fix series" into two series.
This patch series contains fixes for dwc2/gadget driver. It's intended
for 3.17-final. I will also send this patches backported for stable.

Best regard
Robert Baldyga

Kamil Debski (2):
  usb: dwc2/gadget: fix phy disable sequence
  usb: dwc2/gadget: fix phy initialization sequence

Marek Szyprowski (3):
  usb: dwc2/gadget: break infinite loop in endpoint disable code
  usb: dwc2/gadget: do not call disconnect method in pullup
  usb: dwc2/gadget: delay enabling irq once hardware is configured
    properly

Robert Baldyga (1):
  usb: dwc2/gadget: avoid disabling ep0

 drivers/usb/dwc2/gadget.c | 52 +++++++++++++++++++++++------------------------
 1 file changed, 25 insertions(+), 27 deletions(-)

-- 
1.9.1


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

* [PATCH 1/6] usb: dwc2/gadget: fix phy disable sequence
  2014-09-09  8:44 [PATCH 0/6] usb: dwc2/gadget: bugfixes for gadget driver Robert Baldyga
@ 2014-09-09  8:44 ` Robert Baldyga
  2014-09-09  8:44 ` [PATCH 2/6] usb: dwc2/gadget: fix phy initialization sequence Robert Baldyga
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Robert Baldyga @ 2014-09-09  8:44 UTC (permalink / raw)
  To: Paul.Zimmerman
  Cc: gregkh, balbi, linux-usb, linux-kernel, Kamil Debski,
	Marek Szyprowski, Robert Baldyga

From: Kamil Debski <k.debski@samsung.com>

When the driver is removed s3c_hsotg_phy_disable is called three times
instead of once. This results in decreasing of the phy reference counter
below zero and thus consecutive inserts of the module fails.

This patch removes calls to s3c_hsotg_phy_disable from s3c_hsotg_remove
and s3c_hsotg_udc_stop.

s3c_hsotg_udc_stop is called from udc-core.c only after
usb_gadget_disconnect, which in turn calls s3c_hsotg_pullup, which
already calls s3c_hsotg_phy_disable.

s3c_hsotg_remove must be called only after udc_stop, so there is no
point in disabling phy once again there.

Signed-off-by: Kamil Debski <k.debski@samsung.com>
Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
Signed-off-by: Robert Baldyga <r.baldyga@samsung.com>
---
 drivers/usb/dwc2/gadget.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
index 7c9618e..505d56e 100644
--- a/drivers/usb/dwc2/gadget.c
+++ b/drivers/usb/dwc2/gadget.c
@@ -2897,8 +2897,6 @@ static int s3c_hsotg_udc_stop(struct usb_gadget *gadget,
 
 	spin_lock_irqsave(&hsotg->lock, flags);
 
-	s3c_hsotg_phy_disable(hsotg);
-
 	if (!driver)
 		hsotg->driver = NULL;
 
@@ -3582,7 +3580,6 @@ static int s3c_hsotg_remove(struct platform_device *pdev)
 		usb_gadget_unregister_driver(hsotg->driver);
 	}
 
-	s3c_hsotg_phy_disable(hsotg);
 	if (hsotg->phy)
 		phy_exit(hsotg->phy);
 	clk_disable_unprepare(hsotg->clk);
-- 
1.9.1


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

* [PATCH 2/6] usb: dwc2/gadget: fix phy initialization sequence
  2014-09-09  8:44 [PATCH 0/6] usb: dwc2/gadget: bugfixes for gadget driver Robert Baldyga
  2014-09-09  8:44 ` [PATCH 1/6] usb: dwc2/gadget: fix phy disable sequence Robert Baldyga
@ 2014-09-09  8:44 ` Robert Baldyga
  2014-09-09  8:44 ` [PATCH 3/6] usb: dwc2/gadget: break infinite loop in endpoint disable code Robert Baldyga
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Robert Baldyga @ 2014-09-09  8:44 UTC (permalink / raw)
  To: Paul.Zimmerman
  Cc: gregkh, balbi, linux-usb, linux-kernel, Kamil Debski,
	Marek Szyprowski, Robert Baldyga

From: Kamil Debski <k.debski@samsung.com>

In the Generic PHY Framework a NULL phy is considered to be a valid phy
thus the "if (hsotg->phy)" check does not give us the information whether
the Generic PHY Framework is used.

In addition to the above this patch also removes phy_init from probe and
phy_exit from remove. This is not necessary when init/exit is done in the
s3c_hsotg_phy_enable/disable functions.

Signed-off-by: Kamil Debski <k.debski@samsung.com>
Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
Signed-off-by: Robert Baldyga <r.baldyga@samsung.com>
---
 drivers/usb/dwc2/gadget.c | 27 ++++++++++++---------------
 1 file changed, 12 insertions(+), 15 deletions(-)

diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
index 505d56e..fd556e0 100644
--- a/drivers/usb/dwc2/gadget.c
+++ b/drivers/usb/dwc2/gadget.c
@@ -2747,13 +2747,14 @@ static void s3c_hsotg_phy_enable(struct s3c_hsotg *hsotg)
 
 	dev_dbg(hsotg->dev, "pdev 0x%p\n", pdev);
 
-	if (hsotg->phy) {
-		phy_init(hsotg->phy);
-		phy_power_on(hsotg->phy);
-	} else if (hsotg->uphy)
+	if (hsotg->uphy)
 		usb_phy_init(hsotg->uphy);
-	else if (hsotg->plat->phy_init)
+	else if (hsotg->plat && hsotg->plat->phy_init)
 		hsotg->plat->phy_init(pdev, hsotg->plat->phy_type);
+	else {
+		phy_init(hsotg->phy);
+		phy_power_on(hsotg->phy);
+	}
 }
 
 /**
@@ -2767,13 +2768,14 @@ static void s3c_hsotg_phy_disable(struct s3c_hsotg *hsotg)
 {
 	struct platform_device *pdev = to_platform_device(hsotg->dev);
 
-	if (hsotg->phy) {
-		phy_power_off(hsotg->phy);
-		phy_exit(hsotg->phy);
-	} else if (hsotg->uphy)
+	if (hsotg->uphy)
 		usb_phy_shutdown(hsotg->uphy);
-	else if (hsotg->plat->phy_exit)
+	else if (hsotg->plat && hsotg->plat->phy_exit)
 		hsotg->plat->phy_exit(pdev, hsotg->plat->phy_type);
+	else {
+		phy_power_off(hsotg->phy);
+		phy_exit(hsotg->phy);
+	}
 }
 
 /**
@@ -3486,9 +3488,6 @@ static int s3c_hsotg_probe(struct platform_device *pdev)
 	if (hsotg->phy && (phy_get_bus_width(phy) == 8))
 		hsotg->phyif = GUSBCFG_PHYIF8;
 
-	if (hsotg->phy)
-		phy_init(hsotg->phy);
-
 	/* usb phy enable */
 	s3c_hsotg_phy_enable(hsotg);
 
@@ -3580,8 +3579,6 @@ static int s3c_hsotg_remove(struct platform_device *pdev)
 		usb_gadget_unregister_driver(hsotg->driver);
 	}
 
-	if (hsotg->phy)
-		phy_exit(hsotg->phy);
 	clk_disable_unprepare(hsotg->clk);
 
 	return 0;
-- 
1.9.1


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

* [PATCH 3/6] usb: dwc2/gadget: break infinite loop in endpoint disable code
  2014-09-09  8:44 [PATCH 0/6] usb: dwc2/gadget: bugfixes for gadget driver Robert Baldyga
  2014-09-09  8:44 ` [PATCH 1/6] usb: dwc2/gadget: fix phy disable sequence Robert Baldyga
  2014-09-09  8:44 ` [PATCH 2/6] usb: dwc2/gadget: fix phy initialization sequence Robert Baldyga
@ 2014-09-09  8:44 ` Robert Baldyga
  2014-09-09  8:44 ` [PATCH 4/6] usb: dwc2/gadget: do not call disconnect method in pullup Robert Baldyga
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Robert Baldyga @ 2014-09-09  8:44 UTC (permalink / raw)
  To: Paul.Zimmerman
  Cc: gregkh, balbi, linux-usb, linux-kernel, Marek Szyprowski, Robert Baldyga

From: Marek Szyprowski <m.szyprowski@samsung.com>

This patch fixes possible freeze caused by infinite loop in interrupt
context.

Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
Signed-off-by: Robert Baldyga <r.baldyga@samsung.com>
---
 drivers/usb/dwc2/gadget.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
index fd556e0..a451eef 100644
--- a/drivers/usb/dwc2/gadget.c
+++ b/drivers/usb/dwc2/gadget.c
@@ -1649,6 +1649,7 @@ static void s3c_hsotg_txfifo_flush(struct s3c_hsotg *hsotg, unsigned int idx)
 			dev_err(hsotg->dev,
 				"%s: timeout flushing fifo (GRSTCTL=%08x)\n",
 				__func__, val);
+			break;
 		}
 
 		udelay(1);
-- 
1.9.1


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

* [PATCH 4/6] usb: dwc2/gadget: do not call disconnect method in pullup
  2014-09-09  8:44 [PATCH 0/6] usb: dwc2/gadget: bugfixes for gadget driver Robert Baldyga
                   ` (2 preceding siblings ...)
  2014-09-09  8:44 ` [PATCH 3/6] usb: dwc2/gadget: break infinite loop in endpoint disable code Robert Baldyga
@ 2014-09-09  8:44 ` Robert Baldyga
  2014-09-09  8:44 ` [PATCH 5/6] usb: dwc2/gadget: delay enabling irq once hardware is configured properly Robert Baldyga
  2014-09-09  8:44 ` [PATCH 6/6] usb: dwc2/gadget: avoid disabling ep0 Robert Baldyga
  5 siblings, 0 replies; 7+ messages in thread
From: Robert Baldyga @ 2014-09-09  8:44 UTC (permalink / raw)
  To: Paul.Zimmerman
  Cc: gregkh, balbi, linux-usb, linux-kernel, Marek Szyprowski, Robert Baldyga

From: Marek Szyprowski <m.szyprowski@samsung.com>

This leads to potential spinlock recursion in composite framework, other
udc drivers also don't call it directly from pullup method.

Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
Signed-off-by: Robert Baldyga <r.baldyga@samsung.com>
---
 drivers/usb/dwc2/gadget.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
index a451eef..474eae2 100644
--- a/drivers/usb/dwc2/gadget.c
+++ b/drivers/usb/dwc2/gadget.c
@@ -2942,7 +2942,6 @@ static int s3c_hsotg_pullup(struct usb_gadget *gadget, int is_on)
 		s3c_hsotg_phy_enable(hsotg);
 		s3c_hsotg_core_init(hsotg);
 	} else {
-		s3c_hsotg_disconnect(hsotg);
 		s3c_hsotg_phy_disable(hsotg);
 	}
 
-- 
1.9.1


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

* [PATCH 5/6] usb: dwc2/gadget: delay enabling irq once hardware is configured properly
  2014-09-09  8:44 [PATCH 0/6] usb: dwc2/gadget: bugfixes for gadget driver Robert Baldyga
                   ` (3 preceding siblings ...)
  2014-09-09  8:44 ` [PATCH 4/6] usb: dwc2/gadget: do not call disconnect method in pullup Robert Baldyga
@ 2014-09-09  8:44 ` Robert Baldyga
  2014-09-09  8:44 ` [PATCH 6/6] usb: dwc2/gadget: avoid disabling ep0 Robert Baldyga
  5 siblings, 0 replies; 7+ messages in thread
From: Robert Baldyga @ 2014-09-09  8:44 UTC (permalink / raw)
  To: Paul.Zimmerman
  Cc: gregkh, balbi, linux-usb, linux-kernel, Marek Szyprowski, Robert Baldyga

From: Marek Szyprowski <m.szyprowski@samsung.com>

This patch fixes kernel panic/interrupt storm/etc issues if bootloader
left s3c-hsotg module in enabled state. Now interrupt handler is enabled
only after proper configuration of hardware registers.

Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
Signed-off-by: Robert Baldyga <r.baldyga@samsung.com>
---
 drivers/usb/dwc2/gadget.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
index 474eae2..43fd3d5 100644
--- a/drivers/usb/dwc2/gadget.c
+++ b/drivers/usb/dwc2/gadget.c
@@ -3441,13 +3441,6 @@ static int s3c_hsotg_probe(struct platform_device *pdev)
 
 	hsotg->irq = ret;
 
-	ret = devm_request_irq(&pdev->dev, hsotg->irq, s3c_hsotg_irq, 0,
-				dev_name(dev), hsotg);
-	if (ret < 0) {
-		dev_err(dev, "cannot claim IRQ\n");
-		goto err_clk;
-	}
-
 	dev_info(dev, "regs %p, irq %d\n", hsotg->regs, hsotg->irq);
 
 	hsotg->gadget.max_speed = USB_SPEED_HIGH;
@@ -3495,6 +3488,17 @@ static int s3c_hsotg_probe(struct platform_device *pdev)
 	s3c_hsotg_init(hsotg);
 	s3c_hsotg_hw_cfg(hsotg);
 
+	ret = devm_request_irq(&pdev->dev, hsotg->irq, s3c_hsotg_irq, 0,
+				dev_name(dev), hsotg);
+	if (ret < 0) {
+		s3c_hsotg_phy_disable(hsotg);
+		clk_disable_unprepare(hsotg->clk);
+		regulator_bulk_disable(ARRAY_SIZE(hsotg->supplies),
+				       hsotg->supplies);
+		dev_err(dev, "cannot claim IRQ\n");
+		goto err_clk;
+	}
+
 	/* hsotg->num_of_eps holds number of EPs other than ep0 */
 
 	if (hsotg->num_of_eps == 0) {
-- 
1.9.1


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

* [PATCH 6/6] usb: dwc2/gadget: avoid disabling ep0
  2014-09-09  8:44 [PATCH 0/6] usb: dwc2/gadget: bugfixes for gadget driver Robert Baldyga
                   ` (4 preceding siblings ...)
  2014-09-09  8:44 ` [PATCH 5/6] usb: dwc2/gadget: delay enabling irq once hardware is configured properly Robert Baldyga
@ 2014-09-09  8:44 ` Robert Baldyga
  5 siblings, 0 replies; 7+ messages in thread
From: Robert Baldyga @ 2014-09-09  8:44 UTC (permalink / raw)
  To: Paul.Zimmerman; +Cc: gregkh, balbi, linux-usb, linux-kernel, Robert Baldyga

Endpoint 0 should not be disabled, so we start loop counter from number 1.

Signed-off-by: Robert Baldyga <r.baldyga@samsung.com>
---
 drivers/usb/dwc2/gadget.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
index 43fd3d5..ce6071d 100644
--- a/drivers/usb/dwc2/gadget.c
+++ b/drivers/usb/dwc2/gadget.c
@@ -2895,7 +2895,7 @@ static int s3c_hsotg_udc_stop(struct usb_gadget *gadget,
 		return -ENODEV;
 
 	/* all endpoints should be shutdown */
-	for (ep = 0; ep < hsotg->num_of_eps; ep++)
+	for (ep = 1; ep < hsotg->num_of_eps; ep++)
 		s3c_hsotg_ep_disable(&hsotg->eps[ep].ep);
 
 	spin_lock_irqsave(&hsotg->lock, flags);
-- 
1.9.1


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

end of thread, other threads:[~2014-09-09  8:52 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-09  8:44 [PATCH 0/6] usb: dwc2/gadget: bugfixes for gadget driver Robert Baldyga
2014-09-09  8:44 ` [PATCH 1/6] usb: dwc2/gadget: fix phy disable sequence Robert Baldyga
2014-09-09  8:44 ` [PATCH 2/6] usb: dwc2/gadget: fix phy initialization sequence Robert Baldyga
2014-09-09  8:44 ` [PATCH 3/6] usb: dwc2/gadget: break infinite loop in endpoint disable code Robert Baldyga
2014-09-09  8:44 ` [PATCH 4/6] usb: dwc2/gadget: do not call disconnect method in pullup Robert Baldyga
2014-09-09  8:44 ` [PATCH 5/6] usb: dwc2/gadget: delay enabling irq once hardware is configured properly Robert Baldyga
2014-09-09  8:44 ` [PATCH 6/6] usb: dwc2/gadget: avoid disabling ep0 Robert Baldyga

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).