more dwc2/gadget fixes
Subsystems (3)
v2 cover more dwc2/gadget fixes
Hi!
This patchset contains a set of fixes to solve vaious minor issues related to cable connect/disconnect events, pull-up control, soft-disconnect mode, proper usb phy operation and restoring gadget state after suspend/resume cycle.
Changes since v1 (http://www.spinics.net/lists/linux-samsung-soc/msg37842.html):
- fixed issues spotted by Felipe Balbi
Best regards
Marek Szyprowski, PhD
Samsung R&D Institute Poland
Marek Szyprowski (10):
usb: dwc2/gadget: report disconnect event from 'end session' irq
usb: dwc2/gadget: fix enumeration issues
usb: dwc2/gadget: fix gadget unregistration in udc_stop() function
usb: dwc2/gadget: disable phy before turning off power regulators
usb: dwc2/gadget: move setting last reset time to s3c_hsotg_core_init
usb: dwc2/gadget: decouple setting soft-disconnect from
s3c_hsotg_core_init
usb: dwc2/gadget: move phy control calls out of pullup() method
usb: dwc2/gadget: use soft-disconnect udc feature in pullup() method
usb: dwc2/gadget: fix calls to phy control functions in suspend/resume
code
usb: dwc2/gadget: rework suspend/resume code to correctly restore
gadget state
drivers/usb/dwc2/core.h | 4 +- drivers/usb/dwc2/gadget.c | 95 ++++++++++++++++++++++++++++++++--------------- 2 files changed, 69 insertions(+), 30 deletions(-)
Signature · 1 line
1.9.2
A message that is not in the archive (sent off-list or not yet received): 1413801940-31086-1-git-send-email-m.szyprowski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org
PATCH v2 2/10 usb: dwc2/gadget: fix enumeration issues
Excessive debug messages might cause timing issues that prevent correct usb enumeration. This patch hides information about USB bus reset to let driver enumerate fast enough to avoid making host angry. This fixes endless enumeration and usb reset loop observed with some Linux hosts.
--- drivers/usb/dwc2/gadget.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/dwc2/gadget.c +1 -1
@@ -2333,7 +2333,7 @@ irq_retry:u32 usb_status =readl (hsotg->regs +GOTGCTL ); -dev_info (hsotg->dev,"%s: USBRst\n" , __func__); +dev_dbg (hsotg->dev,"%s: USBRst\n" , __func__);dev_dbg (hsotg->dev,"GNPTXSTS=%08x\n" ,readl (hsotg->regs +GNPTXSTS ));
Signature · 6 lines
1.9.2 -- 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
A message that is not in the archive (sent off-list or not yet received): 1413801940-31086-3-git-send-email-m.szyprowski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org
Paul Zimmerman
Acked-byRE: [PATCH v2 02/10] usb: dwc2/gadget: fix enumeration issues
Quoted 22 lines
-----Original Message-----
From: Marek Szyprowski [mailto:[email protected]]
Sent: Monday, October 20, 2014 3:46 AMExcessive debug messages might cause timing issues that prevent correct usb enumeration. This patch hides information about USB bus reset to let driver enumerate fast enough to avoid making host angry. This fixes endless enumeration and usb reset loop observed with some Linux hosts.
Signed-off-by Marek Szyprowski <[email protected]>Reviewed-by Felipe Balbi <[email protected]>--- drivers/usb/dwc2/gadget.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/usb/dwc2/gadget.c +0
-0
drivers/usb/dwc2/gadget.c irq_retry: · line 2339
Quoted 8 lines
drivers/usb/dwc2/gadget.c +1
-1@@ -2333,7 +2333,7 @@ irq_retry:u32 usb_status =readl (hsotg->regs +GOTGCTL ); -dev_info (hsotg->dev,"%s: USBRst\n" , __func__); +dev_dbg (hsotg->dev,"%s: USBRst\n" , __func__);dev_dbg (hsotg->dev,"GNPTXSTS=%08x\n" ,readl (hsotg->regs +GNPTXSTS ));
--
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
PATCH v2 3/10 usb: dwc2/gadget: fix gadget unregistration in udc_stop() function
In reply to a message not in the archiveudc_stop() should clear ->driver pointer unconditionally to let the UDC framework to work correctly with both registering/unregistering gadgets and enabling/disabling gadgets by writing to /sys/class/udc/*hsotg/soft_connect interface.
--- drivers/usb/dwc2/gadget.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/usb/dwc2/gadget.c +0 -2
@@ -2940,9 +2940,7 @@ static int s3c_hsotg_udc_stop(struct usb_gadget *gadget,spin_lock_irqsave (&hsotg->lock, flags); -if (!driver) - hsotg->driver =NULL ;
A message that is not in the archive (sent off-list or not yet received): 1413801940-31086-4-git-send-email-m.szyprowski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org
Re: [PATCH v2 03/10] usb: dwc2/gadget: fix gadget unregistration in udc_stop() function
Quoted 6 lines · Marek Szyprowski
udc_stop()should clear ->driver pointer unconditionally to let the UDC framework to work correctly with both registering/unregistering gadgets and enabling/disabling gadgets by writing to/sys/class/udc/*hsotg/soft_connectinterface.Signed-off-by Marek Szyprowski <[email protected]>
Also here. In fact, this is much more important :-)
Signature · 1 line
balbi
Paul Zimmerman
Acked-byRE: [PATCH v2 03/10] usb: dwc2/gadget: fix gadget unregistration in udc_stop() function
Quoted 4 lines
From: Felipe Balbi [mailto:[email protected]]
Sent: Thursday, October 23, 2014 8:02 AMOn Mon, Oct 20, 2014 at 12:45:33PM +0200, Marek Szyprowski wrote:
Quoted 8 lines
Quoted 6 lines
udc_stop()should clear ->driver pointer unconditionally to let the UDC framework to work correctly with both registering/unregistering gadgets and enabling/disabling gadgets by writing to/sys/class/udc/*hsotg/soft_connectinterface.Signed-off-by Marek Szyprowski <[email protected]>Also here. In fact, this is much more important :-)
Are there any more patches in this series that need immediate attention? Otherwise I plan to finish reviewing the series on Friday or so.
Signature · 1 line
Paul
A message that is not in the archive (sent off-list or not yet received): A2CA0424C0A6F04399FB9E1CD98E0304844E5483-Yu2iAY70zvrYN67daEjeMPufCSb+aD3WLzEdoUbNIic@public.gmane.org
Re: [PATCH v2 03/10] usb: dwc2/gadget: fix gadget unregistration in udc_stop() function
Quoted 9 lines · Paul Zimmerman
Quoted 9 lines
From: Felipe Balbi [mailto:[email protected]]
Sent: Thursday, October 23, 2014 8:02 AMQuoted 5 lines · Marek Szyprowski
udc_stop()should clear ->driver pointer unconditionally to let the UDC framework to work correctly with both registering/unregistering gadgets and enabling/disabling gadgets by writing to/sys/class/udc/*hsotg/soft_connectinterface.
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
Signed-off-by Marek Szyprowski <[email protected]>Also here. In fact, this is much more important :-)
Are there any more patches in this series that need immediate attention? Otherwise I plan to finish reviewing the series on Friday or so.
no, this is the most important one. Everything else can wait until Friday, thanks.
Signature · 1 line
balbi
PATCH v2 4/10 usb: dwc2/gadget: disable phy before turning off power regulators
In reply to a message not in the archiveThis patch fixes probe function to match the pattern used elsewhere in the driver, where power regulators are turned off as the last element in the device shutdown procedure.
--- drivers/usb/dwc2/gadget.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/usb/dwc2/gadget.c +1 -1
@@ -3571,6 +3571,7 @@ static int s3c_hsotg_probe(struct platform_device *pdev)s3c_hsotg_initep (hsotg, &hsotg->eps[epnum], epnum);/* disable power and clock */ +s3c_hsotg_phy_disable (hsotg); ret =regulator_bulk_disable (ARRAY_SIZE (hsotg->supplies), hsotg->supplies);
@@ -3579,8 +3580,6 @@ static int s3c_hsotg_probe(struct platform_device *pdev) goto err_ep_mem; } -s3c_hsotg_phy_disable (hsotg);
A message that is not in the archive (sent off-list or not yet received): 1413801940-31086-5-git-send-email-m.szyprowski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org
Re: [PATCH v2 04/10] usb: dwc2/gadget: disable phy before turning off power regulators
Quoted 5 lines · Marek Szyprowski
This patch fixes probe function to match the pattern used elsewhere in the driver, where power regulators are turned off as the last element in the device shutdown procedure.
Signed-off-by Marek Szyprowski <[email protected]>
Paul, can I have your Acked-by here so I can send this to v3.18-rc1 ?
Signature · 1 line
balbi
Paul Zimmerman
Acked-byRE: [PATCH v2 04/10] usb: dwc2/gadget: disable phy before turning off power regulators
Quoted 11 lines
From: Felipe Balbi [mailto:[email protected]]
Sent: Thursday, October 23, 2014 8:01 AMQuoted 5 lines · Marek Szyprowski
This patch fixes probe function to match the pattern used elsewhere in the driver, where power regulators are turned off as the last element in the device shutdown procedure.
Signed-off-by Marek Szyprowski <[email protected]>Paul, can I have your Acked-by here so I can send this to v3.18-rc1 ?
Sorry, I've been working on a really hot issue at $work and didn't have time yet to review this series.
Re: [PATCH v2 04/10] usb: dwc2/gadget: disable phy before turning off power regulators
Quoted 8 lines · Paul Zimmerman
Quoted 8 lines
From: Felipe Balbi [mailto:[email protected]]
Sent: Thursday, October 23, 2014 8:01 AMQuoted 4 lines · Marek Szyprowski
This patch fixes probe function to match the pattern used elsewhere in the driver, where power regulators are turned off as the last element in the device shutdown procedure.
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
Signed-off-by Marek Szyprowski <[email protected]>Paul, can I have your Acked-by here so I can send this to v3.18-rc1 ?
Sorry, I've been working on a really hot issue at $work and didn't have time yet to review this series.
don't worry, we've all been there :-)
thanks
Signature · 1 line
balbi
PATCH v2 6/10 usb: dwc2/gadget: decouple setting soft-disconnect from s3c_hsotg_core_init
In reply to a message not in the archiveThis patch changes s3c_hsotg_core_init function to leave hardware in soft disconnect mode, so the moment of coupling the hardware to the usb bus can be later controlled by the separate functions for enabling and disabling soft disconnect mode. This patch is a preparation to rework pullup() method.
--- drivers/usb/dwc2/gadget.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-)
drivers/usb/dwc2/gadget.c +17 -5
@@ -2124,7 +2124,7 @@ static int s3c_hsotg_corereset(struct s3c_hsotg *hsotg)* * Issue a soft reset to the core, and await the core finishing it. */ -static void s3c_hsotg_core_init (struct s3c_hsotg *hsotg) +static void s3c_hsotg_core_init_disconnected (struct s3c_hsotg *hsotg) {s3c_hsotg_corereset (hsotg);
@@ -2241,14 +2241,23 @@ static void s3c_hsotg_core_init(struct s3c_hsotg *hsotg) readl(hsotg->regs + DOEPCTL0));/* clear global NAKs */ -writel (DCTL_CGOUTNAK |DCTL_CGNPINNAK , +writel (DCTL_CGOUTNAK |DCTL_CGNPINNAK |DCTL_SFTDISCON , hsotg->regs +DCTL );/* must be at-least 3ms to allow bus to see disconnect */ mdelay (3 ); hsotg->last_rst = jiffies; +} + +static void s3c_hsotg_core_disconnect (struct s3c_hsotg *hsotg) +{ +/* set the soft-disconnect bit */ +__orr32 (hsotg->regs +DCTL ,DCTL_SFTDISCON ); +} +static void s3c_hsotg_core_connect (struct s3c_hsotg *hsotg) +{/* remove the soft-disconnect and let's go */ __bic32 (hsotg->regs +DCTL ,DCTL_SFTDISCON ); }
@@ -2348,7 +2357,8 @@ irq_retry:kill_all_requests (hsotg, &hsotg->eps[0 ], -ECONNRESET , true); -s3c_hsotg_core_init (hsotg); +s3c_hsotg_core_init_disconnected (hsotg); +s3c_hsotg_core_connect (hsotg); } } }
@@ -2981,7 +2991,8 @@ static int s3c_hsotg_pullup(struct usb_gadget *gadget, int is_on)if (is_on) {s3c_hsotg_phy_enable (hsotg);clk_enable (hsotg->clk); -s3c_hsotg_core_init (hsotg); +s3c_hsotg_core_init_disconnected (hsotg); +s3c_hsotg_core_connect (hsotg); }else {clk_disable (hsotg->clk);s3c_hsotg_phy_disable (hsotg);
@@ -3668,7 +3679,8 @@ static int s3c_hsotg_resume(struct platform_device *pdev)spin_lock_irqsave (&hsotg->lock, flags);s3c_hsotg_phy_enable (hsotg); -s3c_hsotg_core_init (hsotg); +s3c_hsotg_core_init_disconnected (hsotg); +s3c_hsotg_core_connect (hsotg);spin_unlock_irqrestore (&hsotg->lock, flags);return ret;
Signature · 6 lines
1.9.2 -- 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
RE: [PATCH v2 06/10] usb: dwc2/gadget: decouple setting soft-disconnect from s3c_hsotg_core_init
Quoted 35 lines
From: Marek Szyprowski [mailto:[email protected]]
Sent: Monday, October 20, 2014 3:46 AMThis patch changes
s3c_hsotg_core_initfunction to leave hardware in soft disconnect mode, so the moment of coupling the hardware to the usb bus can be later controlled by the separate functions for enabling and disabling soft disconnect mode. This patch is a preparation to reworkpullup()method.Signed-off-by Marek Szyprowski <[email protected]>--- drivers/usb/dwc2/gadget.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-)drivers/usb/dwc2/gadget.c +2
-2@@ -2124,7 +2124,7 @@ static int s3c_hsotg_corereset(struct s3c_hsotg *hsotg)* * Issue a soft reset to the core, and await the core finishing it. */ -static void s3c_hsotg_core_init (struct s3c_hsotg *hsotg) +static void s3c_hsotg_core_init_disconnected (struct s3c_hsotg *hsotg) {s3c_hsotg_corereset (hsotg);@@ -2241,14 +2241,23 @@ static void s3c_hsotg_core_init(struct s3c_hsotg *hsotg) readl(hsotg->regs + DOEPCTL0));/* clear global NAKs */ -writel (DCTL_CGOUTNAK |DCTL_CGNPINNAK , +writel (DCTL_CGOUTNAK |DCTL_CGNPINNAK |DCTL_SFTDISCON , hsotg->regs +DCTL );
drivers/usb/dwc2/gadget.c static void s3c_hsotg_core_init(struct s3c_hsotg *hsotg) · line 2256
Quoted 10 lines
drivers/usb/dwc2/gadget.c +6
-0/* must be at-least 3ms to allow bus to see disconnect */ mdelay (3 ); hsotg->last_rst = jiffies; +} + +static void s3c_hsotg_core_disconnect (struct s3c_hsotg *hsotg) +{ +/* set the soft-disconnect bit */ +__orr32 (hsotg->regs +DCTL ,DCTL_SFTDISCON );
I'm not really happy with adding more uses of these __orr32, __bic32 functions. When I first saw those, I went 'wtf?", because with the assembly-sounding names, they look like some special ARM instruction or something.
But I guess cleaning that up can wait for a future patch series, so OK.
Quoted 28 lines
drivers/usb/dwc2/gadget.c +7
-2+} +static void s3c_hsotg_core_connect (struct s3c_hsotg *hsotg) +{/* remove the soft-disconnect and let's go */ __bic32 (hsotg->regs +DCTL ,DCTL_SFTDISCON ); }@@ -2348,7 +2357,8 @@ irq_retry:kill_all_requests (hsotg, &hsotg->eps[0 ], -ECONNRESET , true); -s3c_hsotg_core_init (hsotg); +s3c_hsotg_core_init_disconnected (hsotg); +s3c_hsotg_core_connect (hsotg); } } }@@ -2981,7 +2991,8 @@ static int s3c_hsotg_pullup(struct usb_gadget *gadget, int is_on)if (is_on) {s3c_hsotg_phy_enable (hsotg);clk_enable (hsotg->clk); -s3c_hsotg_core_init (hsotg); +s3c_hsotg_core_init_disconnected (hsotg); +s3c_hsotg_core_connect (hsotg); }else {clk_disable (hsotg->clk);s3c_hsotg_phy_disable (hsotg);
drivers/usb/dwc2/gadget.c static int s3c_hsotg_resume(struct platform_device *pdev) · line 3686
Quoted 9 lines
drivers/usb/dwc2/gadget.c +2
-1@@ -3668,7 +3679,8 @@ static int s3c_hsotg_resume(struct platform_device *pdev)spin_lock_irqsave (&hsotg->lock, flags);s3c_hsotg_phy_enable (hsotg); -s3c_hsotg_core_init (hsotg); +s3c_hsotg_core_init_disconnected (hsotg); +s3c_hsotg_core_connect (hsotg);spin_unlock_irqrestore (&hsotg->lock, flags);return ret;
Re: [PATCH v2 06/10] usb: dwc2/gadget: decouple setting soft-disconnect from s3c_hsotg_core_init
Hello,
Quoted 50 lines · Paul Zimmerman
Quoted 35 lines
From: Marek Szyprowski [mailto:[email protected]]
Sent: Monday, October 20, 2014 3:46 AMThis patch changes
s3c_hsotg_core_initfunction to leave hardware in soft disconnect mode, so the moment of coupling the hardware to the usb bus can be later controlled by the separate functions for enabling and disabling soft disconnect mode. This patch is a preparation to reworkpullup()method.Signed-off-by Marek Szyprowski <[email protected]>--- drivers/usb/dwc2/gadget.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-)drivers/usb/dwc2/gadget.c +2
-2@@ -2124,7 +2124,7 @@ static int s3c_hsotg_corereset(struct s3c_hsotg *hsotg)* * Issue a soft reset to the core, and await the core finishing it. */ -static void s3c_hsotg_core_init (struct s3c_hsotg *hsotg) +static void s3c_hsotg_core_init_disconnected (struct s3c_hsotg *hsotg) {s3c_hsotg_corereset (hsotg);@@ -2241,14 +2241,23 @@ static void s3c_hsotg_core_init(struct s3c_hsotg *hsotg) readl(hsotg->regs + DOEPCTL0));/* clear global NAKs */ -writel (DCTL_CGOUTNAK |DCTL_CGNPINNAK , +writel (DCTL_CGOUTNAK |DCTL_CGNPINNAK |DCTL_SFTDISCON , hsotg->regs +DCTL );drivers/usb/dwc2/gadget.c static void s3c_hsotg_core_init(struct s3c_hsotg *hsotg) · line 2256
Quoted 10 lines
drivers/usb/dwc2/gadget.c +6
-0/* must be at-least 3ms to allow bus to see disconnect */ mdelay (3 ); hsotg->last_rst = jiffies; +} + +static void s3c_hsotg_core_disconnect (struct s3c_hsotg *hsotg) +{ +/* set the soft-disconnect bit */ +__orr32 (hsotg->regs +DCTL ,DCTL_SFTDISCON );I'm not really happy with adding more uses of these
__orr32,__bic32functions. When I first saw those, I went 'wtf?", because with the assembly-sounding names, they look like some special ARM instruction or something.
Quoted 1 line
But I guess cleaning that up can wait for a future patch series, so OK.
Those functions are really convenient, but I agree we need a better names for them.
Quoted 36 lines
Quoted 36 lines
drivers/usb/dwc2/gadget.c +9
-3+} +static void s3c_hsotg_core_connect (struct s3c_hsotg *hsotg) +{/* remove the soft-disconnect and let's go */ __bic32 (hsotg->regs +DCTL ,DCTL_SFTDISCON ); }@@ -2348,7 +2357,8 @@ irq_retry:kill_all_requests (hsotg, &hsotg->eps[0 ], -ECONNRESET , true); -s3c_hsotg_core_init (hsotg); +s3c_hsotg_core_init_disconnected (hsotg); +s3c_hsotg_core_connect (hsotg); } } }@@ -2981,7 +2991,8 @@ static int s3c_hsotg_pullup(struct usb_gadget *gadget, int is_on)if (is_on) {s3c_hsotg_phy_enable (hsotg);clk_enable (hsotg->clk); -s3c_hsotg_core_init (hsotg); +s3c_hsotg_core_init_disconnected (hsotg); +s3c_hsotg_core_connect (hsotg); }else {clk_disable (hsotg->clk);s3c_hsotg_phy_disable (hsotg);@@ -3668,7 +3679,8 @@ static int s3c_hsotg_resume(struct platform_device *pdev)spin_lock_irqsave (&hsotg->lock, flags);s3c_hsotg_phy_enable (hsotg); -s3c_hsotg_core_init (hsotg); +s3c_hsotg_core_init_disconnected (hsotg); +s3c_hsotg_core_connect (hsotg);spin_unlock_irqrestore (&hsotg->lock, flags);
Quoted 2 lines
drivers/usb/dwc2/gadget.c static int s3c_hsotg_resume(struct platform_device *pdev) · line 3686
Quoted 1 line
drivers/usb/dwc2/gadget.c +0
-0return ret;Acked-by Paul Zimmerman <[email protected]>
Best regards
Signature · 2 lines
Marek Szyprowski, PhD Samsung R&D Institute Poland
PATCH v2 9/10 usb: dwc2/gadget: fix calls to phy control functions in suspend/resume code
In reply to a message not in the archiveThis patch moves calls to phy enable/disable out of spinlock protected blocks in device suspend/resume to fix incorrect caller context. Phy related functions must not be called from atomic context. To protect device internal state from a race during suspend, a call to s3c_hsotg_core_disconnect() is added under a spinlock, what prevents any further activity on the usb bus.
--- drivers/usb/dwc2/gadget.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/usb/dwc2/gadget.c +5 -2
@@ -3653,11 +3653,13 @@ static int s3c_hsotg_suspend(struct platform_device *pdev, pm_message_t state) hsotg->driver->driver.name);spin_lock_irqsave (&hsotg->lock, flags); +s3c_hsotg_core_disconnect (hsotg);s3c_hsotg_disconnect (hsotg); -s3c_hsotg_phy_disable (hsotg); hsotg->gadget.speed =USB_SPEED_UNKNOWN ;spin_unlock_irqrestore (&hsotg->lock, flags); +s3c_hsotg_phy_disable (hsotg); +if (hsotg->driver) {int ep;for (ep =0 ; ep < hsotg->num_of_eps; ep++)
@@ -3686,8 +3688,9 @@ static int s3c_hsotg_resume(struct platform_device *pdev) hsotg->supplies); } -spin_lock_irqsave (&hsotg->lock, flags);s3c_hsotg_phy_enable (hsotg); + +spin_lock_irqsave (&hsotg->lock, flags);s3c_hsotg_core_init_disconnected (hsotg);s3c_hsotg_core_connect (hsotg);spin_unlock_irqrestore (&hsotg->lock, flags);
Signature · 6 lines
1.9.2 -- 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
RE: [PATCH v2 09/10] usb: dwc2/gadget: fix calls to phy control functions in suspend/resume code
Quoted 35 lines
From: Marek Szyprowski [mailto:[email protected]]
Sent: Monday, October 20, 2014 3:46 AMThis patch moves calls to phy enable/disable out of spinlock protected blocks in device suspend/resume to fix incorrect caller context. Phy related functions must not be called from atomic context. To protect device internal state from a race during suspend, a call to
s3c_hsotg_core_disconnect()is added under a spinlock, what prevents any further activity on the usb bus.Signed-off-by Marek Szyprowski <[email protected]>--- drivers/usb/dwc2/gadget.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)drivers/usb/dwc2/gadget.c +3
-1@@ -3653,11 +3653,13 @@ static int s3c_hsotg_suspend(struct platform_device *pdev, pm_message_t state) hsotg->driver->driver.name);spin_lock_irqsave (&hsotg->lock, flags); +s3c_hsotg_core_disconnect (hsotg);s3c_hsotg_disconnect (hsotg); -s3c_hsotg_phy_disable (hsotg); hsotg->gadget.speed =USB_SPEED_UNKNOWN ;spin_unlock_irqrestore (&hsotg->lock, flags); +s3c_hsotg_phy_disable (hsotg); +if (hsotg->driver) {int ep;for (ep =0 ; ep < hsotg->num_of_eps; ep++)
drivers/usb/dwc2/gadget.c static int s3c_hsotg_resume(struct platform_device *pdev) · line 3696
Quoted 10 lines
drivers/usb/dwc2/gadget.c +2
-1@@ -3686,8 +3688,9 @@ static int s3c_hsotg_resume(struct platform_device *pdev) hsotg->supplies); } -spin_lock_irqsave (&hsotg->lock, flags);s3c_hsotg_phy_enable (hsotg); + +spin_lock_irqsave (&hsotg->lock, flags);s3c_hsotg_core_init_disconnected (hsotg);s3c_hsotg_core_connect (hsotg);spin_unlock_irqrestore (&hsotg->lock, flags);
PATCH v2 10/10 usb: dwc2/gadget: rework suspend/resume code to correctly restore gadget state
In reply to a message not in the archiveSuspend/resume code assumed that the gadget was always enabled and connected to usb bus. This means that the actual state of the gadget (soft-enabled/disabled or connected/disconnected) was not correctly preserved on suspend/resume cycle. This patch fixes this issue.
--- drivers/usb/dwc2/core.h | 4 +++- drivers/usb/dwc2/gadget.c | 43 +++++++++++++++++++++++++++---------------- 2 files changed, 30 insertions(+), 17 deletions(-)
drivers/usb/dwc2/core.h +3 -1
@@ -210,7 +210,9 @@ struct s3c_hsotg {u8 ctrl_buff[8 ];struct usb_gadget gadget; -unsigned int setup; + unsigned int setup:1; + unsigned int connected:1; + unsigned int enabled:1;unsigned long last_rst;struct s3c_hsotg_ep *eps; };
drivers/usb/dwc2/gadget.c +27 -16
87 lines not on this page · raw message
Signature · 6 lines
1.9.2 -- 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
RE: [PATCH v2 10/10] usb: dwc2/gadget: rework suspend/resume code to correctly restore gadget state
Quoted 67 lines
From: Marek Szyprowski [mailto:[email protected]]
Sent: Monday, October 20, 2014 3:46 AMSuspend/resume code assumed that the gadget was always enabled and connected to usb bus. This means that the actual state of the gadget (soft-enabled/disabled or connected/disconnected) was not correctly preserved on suspend/resume cycle. This patch fixes this issue.
Signed-off-by Marek Szyprowski <[email protected]>--- drivers/usb/dwc2/core.h | 4 +++- drivers/usb/dwc2/gadget.c | 43 +++++++++++++++++++++++++++---------------- 2 files changed, 30 insertions(+), 17 deletions(-)drivers/usb/dwc2/core.h +3
-1@@ -210,7 +210,9 @@ struct s3c_hsotg {u8 ctrl_buff[8 ];struct usb_gadget gadget; -unsigned int setup; + unsigned int setup:1; + unsigned int connected:1; + unsigned int enabled:1;unsigned long last_rst;struct s3c_hsotg_ep *eps; };drivers/usb/dwc2/gadget.c +7
-0@@ -2925,6 +2925,8 @@ static int s3c_hsotg_udc_start(struct usb_gadget *gadget,spin_lock_irqsave (&hsotg->lock, flags);s3c_hsotg_init (hsotg);s3c_hsotg_core_init_disconnected (hsotg); + hsotg->enabled =1 ; + hsotg->connected =0 ;spin_unlock_irqrestore (&hsotg->lock, flags);dev_info (hsotg->dev,"bound driver %s\n" , driver->driver.name);@@ -2961,6 +2963,8 @@ static int s3c_hsotg_udc_stop(struct usb_gadget *gadget, hsotg->driver =NULL ; hsotg->gadget.speed =USB_SPEED_UNKNOWN ; + hsotg->enabled =0 ; + hsotg->connected =0 ;spin_unlock_irqrestore (&hsotg->lock, flags);@@ -2999,11 +3003,14 @@ static int s3c_hsotg_pullup(struct usb_gadget *gadget, int is_on)dev_dbg (hsotg->dev,"%s: is_on: %d\n" , __func__, is_on);spin_lock_irqsave (&hsotg->lock, flags); +if (is_on) {clk_enable (hsotg->clk); + hsotg->connected =1 ;s3c_hsotg_core_connect (hsotg); }else {s3c_hsotg_core_disconnect (hsotg); + hsotg->connected =0 ;clk_disable (hsotg->clk); }
drivers/usb/dwc2/gadget.c static int s3c_hsotg_suspend(struct platform_device *pdev, pm_message_t state) · line 3662
Quoted 9 lines
drivers/usb/dwc2/gadget.c +1
-5@@ -3652,16 +3659,18 @@ static int s3c_hsotg_suspend(struct platform_device *pdev, pm_message_t state)dev_info (hsotg->dev,"suspending usb gadget %s\n" , hsotg->driver->driver.name); -spin_lock_irqsave (&hsotg->lock, flags); -s3c_hsotg_core_disconnect (hsotg); -s3c_hsotg_disconnect (hsotg); - hsotg->gadget.speed =USB_SPEED_UNKNOWN ; -spin_unlock_irqrestore (&hsotg->lock, flags); +if (hsotg->enabled) {
Hmm. Are you sure it's safe to check ->enabled outside of the spinlock? What happens if s3c_hsotg_udc_stop() runs right after this, before the spinlock is taken, and disables stuff? Sure, it's a tiny window, but still...
Signature · 1 line
Paul
Quoted 49 lines
drivers/usb/dwc2/gadget.c +19
-11+int ep; -s3c_hsotg_phy_disable (hsotg); +spin_lock_irqsave (&hsotg->lock, flags); +if (hsotg->connected) +s3c_hsotg_core_disconnect (hsotg); +s3c_hsotg_disconnect (hsotg); + hsotg->gadget.speed =USB_SPEED_UNKNOWN ; +spin_unlock_irqrestore (&hsotg->lock, flags); + +s3c_hsotg_phy_disable (hsotg); -if (hsotg->driver) { -int ep;for (ep =0 ; ep < hsotg->num_of_eps; ep++)s3c_hsotg_ep_disable (&hsotg->eps[ep].ep);@@ -3679,21 +3688,23 @@ static int s3c_hsotg_resume(struct platform_device *pdev)unsigned long flags;int ret =0 ; -if (hsotg->driver) { +if (hsotg->driver)dev_info (hsotg->dev,"resuming usb gadget %s\n" , hsotg->driver->driver.name); +if (hsotg->enabled) {clk_enable (hsotg->clk); ret =regulator_bulk_enable (ARRAY_SIZE (hsotg->supplies), - hsotg->supplies); - } + hsotg->supplies); -s3c_hsotg_phy_enable (hsotg); +s3c_hsotg_phy_enable (hsotg); -spin_lock_irqsave (&hsotg->lock, flags); -s3c_hsotg_core_init_disconnected (hsotg); -s3c_hsotg_core_connect (hsotg); -spin_unlock_irqrestore (&hsotg->lock, flags); +spin_lock_irqsave (&hsotg->lock, flags); +s3c_hsotg_core_init_disconnected (hsotg); +if (hsotg->connected) +s3c_hsotg_core_connect (hsotg); +spin_unlock_irqrestore (&hsotg->lock, flags); + }return ret; }
Re: [PATCH v2 10/10] usb: dwc2/gadget: rework suspend/resume code to correctly restore gadget state
Hello,
Quoted 70 lines · Paul Zimmerman
Quoted 70 lines
From: Marek Szyprowski [mailto:[email protected]]
Sent: Monday, October 20, 2014 3:46 AMSuspend/resume code assumed that the gadget was always enabled and connected to usb bus. This means that the actual state of the gadget (soft-enabled/disabled or connected/disconnected) was not correctly preserved on suspend/resume cycle. This patch fixes this issue.
Signed-off-by Marek Szyprowski <[email protected]>--- drivers/usb/dwc2/core.h | 4 +++- drivers/usb/dwc2/gadget.c | 43 +++++++++++++++++++++++++++---------------- 2 files changed, 30 insertions(+), 17 deletions(-)drivers/usb/dwc2/core.h +3
-1@@ -210,7 +210,9 @@ struct s3c_hsotg {u8 ctrl_buff[8 ];struct usb_gadget gadget; -unsigned int setup; + unsigned int setup:1; + unsigned int connected:1; + unsigned int enabled:1;unsigned long last_rst;struct s3c_hsotg_ep *eps; };drivers/usb/dwc2/gadget.c +7
-0@@ -2925,6 +2925,8 @@ static int s3c_hsotg_udc_start(struct usb_gadget *gadget,spin_lock_irqsave (&hsotg->lock, flags);s3c_hsotg_init (hsotg);s3c_hsotg_core_init_disconnected (hsotg); + hsotg->enabled =1 ; + hsotg->connected =0 ;spin_unlock_irqrestore (&hsotg->lock, flags);dev_info (hsotg->dev,"bound driver %s\n" , driver->driver.name);@@ -2961,6 +2963,8 @@ static int s3c_hsotg_udc_stop(struct usb_gadget *gadget, hsotg->driver =NULL ; hsotg->gadget.speed =USB_SPEED_UNKNOWN ; + hsotg->enabled =0 ; + hsotg->connected =0 ;spin_unlock_irqrestore (&hsotg->lock, flags);@@ -2999,11 +3003,14 @@ static int s3c_hsotg_pullup(struct usb_gadget *gadget, int is_on)dev_dbg (hsotg->dev,"%s: is_on: %d\n" , __func__, is_on);spin_lock_irqsave (&hsotg->lock, flags); +if (is_on) {clk_enable (hsotg->clk); + hsotg->connected =1 ;s3c_hsotg_core_connect (hsotg); }else {s3c_hsotg_core_disconnect (hsotg); + hsotg->connected =0 ;clk_disable (hsotg->clk); }@@ -3652,16 +3659,18 @@ static int s3c_hsotg_suspend(struct platform_device *pdev, pm_message_t state)dev_info (hsotg->dev,"suspending usb gadget %s\n" , hsotg->driver->driver.name);
Quoted 10 lines
drivers/usb/dwc2/gadget.c static int s3c_hsotg_suspend(struct platform_device *pdev, pm_message_t state) · line 3662
Quoted 6 lines
drivers/usb/dwc2/gadget.c +1
-5-spin_lock_irqsave (&hsotg->lock, flags); -s3c_hsotg_core_disconnect (hsotg); -s3c_hsotg_disconnect (hsotg); - hsotg->gadget.speed =USB_SPEED_UNKNOWN ; -spin_unlock_irqrestore (&hsotg->lock, flags); +if (hsotg->enabled) {Hmm. Are you sure it's safe to check ->enabled outside of the spinlock? What happens if
s3c_hsotg_udc_stop()runs right after this, before the spinlock is taken, and disables stuff? Sure, it's a tiny window, but still...
This code is called only in system suspend path, when userspace has been already frozen. udc_stop() can be called only as a result of userspace action, so it is imho safe to assume that the above code doesn't need additional locking.
Best regards
Signature · 2 lines
Marek Szyprowski, PhD Samsung R&D Institute Poland
Re: [PATCH v2 10/10] usb: dwc2/gadget: rework suspend/resume code to correctly restore gadget state
Hello,
Quoted 88 lines · Marek Szyprowski
Quoted 75 lines · Paul Zimmerman
Quoted 75 lines
From: Marek Szyprowski [mailto:[email protected]]
Sent: Monday, October 20, 2014 3:46 AMSuspend/resume code assumed that the gadget was always enabled and connected to usb bus. This means that the actual state of the gadget (soft-enabled/disabled or connected/disconnected) was not correctly preserved on suspend/resume cycle. This patch fixes this issue.
Signed-off-by Marek Szyprowski <[email protected]>--- drivers/usb/dwc2/core.h | 4 +++- drivers/usb/dwc2/gadget.c | 43 +++++++++++++++++++++++++++---------------- 2 files changed, 30 insertions(+), 17 deletions(-)drivers/usb/dwc2/core.h +3
-1@@ -210,7 +210,9 @@ struct s3c_hsotg {u8 ctrl_buff[8 ];struct usb_gadget gadget; -unsigned int setup; + unsigned int setup:1; + unsigned int connected:1; + unsigned int enabled:1;unsigned long last_rst;struct s3c_hsotg_ep *eps; };drivers/usb/dwc2/gadget.c +2
-0@@ -2925,6 +2925,8 @@ static int s3c_hsotg_udc_start(struct usb_gadget *gadget,spin_lock_irqsave (&hsotg->lock, flags);s3c_hsotg_init (hsotg);s3c_hsotg_core_init_disconnected (hsotg); + hsotg->enabled =1 ; + hsotg->connected =0 ;spin_unlock_irqrestore (&hsotg->lock, flags);dev_info(hsotg->dev, "bound driver %s\n", driver->driver.name);drivers/usb/dwc2/gadget.c +5
-0@@ -2961,6 +2963,8 @@ static int s3c_hsotg_udc_stop(struct usb_gadget *gadget, hsotg->driver =NULL ; hsotg->gadget.speed =USB_SPEED_UNKNOWN ; + hsotg->enabled =0 ; + hsotg->connected =0 ;spin_unlock_irqrestore (&hsotg->lock, flags);@@ -2999,11 +3003,14 @@ static int s3c_hsotg_pullup(struct usb_gadget *gadget, int is_on) dev_dbg(hsotg->dev, "%s: is_on: %d\n", __func__, is_on);spin_lock_irqsave (&hsotg->lock, flags); +if (is_on) {clk_enable (hsotg->clk); + hsotg->connected =1 ;s3c_hsotg_core_connect (hsotg); }else {s3c_hsotg_core_disconnect (hsotg); + hsotg->connected =0 ;clk_disable (hsotg->clk); }@@ -3652,16 +3659,18 @@ static int s3c_hsotg_suspend(struct platform_device *pdev, pm_message_t state) dev_info(hsotg->dev, "suspending usb gadget %s\n", hsotg->driver->driver.name);Quoted 10 lines
drivers/usb/dwc2/gadget.c static int s3c_hsotg_suspend(struct platform_device *pdev, pm_message_t state) · line 3662
Quoted 6 lines
drivers/usb/dwc2/gadget.c +1
-5-spin_lock_irqsave (&hsotg->lock, flags); -s3c_hsotg_core_disconnect (hsotg); -s3c_hsotg_disconnect (hsotg); - hsotg->gadget.speed =USB_SPEED_UNKNOWN ; -spin_unlock_irqrestore (&hsotg->lock, flags); +if (hsotg->enabled) {Hmm. Are you sure it's safe to check ->enabled outside of the spinlock? What happens if
s3c_hsotg_udc_stop()runs right after this, before the spinlock is taken, and disables stuff? Sure, it's a tiny window, but still...
Quoted 3 lines
This code is called only in system suspend path, when userspace has been already frozen.
udc_stop()can be called only as a result of userspace action, so it is imho safe to assume that the above code doesn't need additional locking.
However if you prefer the version with explicit locking, I will send v3 in a few minutes.
Best regards
Signature · 2 lines
Marek Szyprowski, PhD Samsung R&D Institute Poland
PATCH v3 1/2 usb: dwc2/gadget: add mutex to serialize init/deinit calls
This patch adds mutex, which protects initialization and deinitialization procedures against suspend/resume methods.
--- drivers/usb/dwc2/core.h | 1 + drivers/usb/dwc2/gadget.c | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+)
drivers/usb/dwc2/core.h +1 -0
@@ -187,6 +187,7 @@ struct s3c_hsotg {struct s3c_hsotg_plat *plat;spinlock_t lock; +struct mutex init_mutex;void __iomem *regs;int irq;
drivers/usb/dwc2/gadget.c +20 -0
@@ -21,6 +21,7 @@#include <linux/platform_device.h> #include <linux/dma-mapping.h> #include <linux/debugfs.h> +#include <linux/mutex.h> #include <linux/seq_file.h> #include <linux/delay.h> #include <linux/io.h>
@@ -2908,6 +2909,7 @@ static int s3c_hsotg_udc_start(struct usb_gadget *gadget,return -EINVAL ; } +mutex_lock (&hsotg->init_mutex);WARN_ON (hsotg->driver); driver->driver.bus =NULL ;
@@ -2933,9 +2935,12 @@ static int s3c_hsotg_udc_start(struct usb_gadget *gadget,dev_info (hsotg->dev,"bound driver %s\n" , driver->driver.name); +mutex_unlock (&hsotg->init_mutex); +return 0 ; err: +mutex_unlock (&hsotg->init_mutex); hsotg->driver =NULL ;return ret; }
@@ -2957,6 +2962,8 @@ static int s3c_hsotg_udc_stop(struct usb_gadget *gadget,if (!hsotg)return -ENODEV ; +mutex_lock (&hsotg->init_mutex); +/* all endpoints should be shutdown */ for (ep =1 ; ep < hsotg->num_of_eps; ep++)s3c_hsotg_ep_disable (&hsotg->eps[ep].ep);
@@ -2974,6 +2981,8 @@ static int s3c_hsotg_udc_stop(struct usb_gadget *gadget,clk_disable (hsotg->clk); +mutex_unlock (&hsotg->init_mutex); +return 0 ; }
@@ -3002,6 +3011,7 @@ static int s3c_hsotg_pullup(struct usb_gadget *gadget, int is_on)dev_dbg (hsotg->dev,"%s: is_on: %d\n" , __func__, is_on); +mutex_lock (&hsotg->init_mutex);spin_lock_irqsave (&hsotg->lock, flags);if (is_on) {clk_enable (hsotg->clk);
@@ -3013,6 +3023,7 @@ static int s3c_hsotg_pullup(struct usb_gadget *gadget, int is_on) hsotg->gadget.speed =USB_SPEED_UNKNOWN ;spin_unlock_irqrestore (&hsotg->lock, flags); +mutex_unlock (&hsotg->init_mutex);return 0 ; }
@@ -3507,6 +3518,7 @@ static int s3c_hsotg_probe(struct platform_device *pdev) }spin_lock_init (&hsotg->lock); +mutex_init (&hsotg->init_mutex); hsotg->irq = ret;
@@ -3652,6 +3664,8 @@ static int s3c_hsotg_suspend(struct platform_device *pdev, pm_message_t state)unsigned long flags;int ret =0 ; +mutex_lock (&hsotg->init_mutex); +if (hsotg->driver)dev_info (hsotg->dev,"suspending usb gadget %s\n" , hsotg->driver->driver.name);
@@ -3674,6 +3688,8 @@ static int s3c_hsotg_suspend(struct platform_device *pdev, pm_message_t state)clk_disable (hsotg->clk); } +mutex_unlock (&hsotg->init_mutex); +return ret; }
@@ -3683,7 +3699,9 @@ static int s3c_hsotg_resume(struct platform_device *pdev)unsigned long flags;int ret =0 ; +mutex_lock (&hsotg->init_mutex);if (hsotg->driver) { +dev_info (hsotg->dev,"resuming usb gadget %s\n" , hsotg->driver->driver.name);
@@ -3699,6 +3717,8 @@ static int s3c_hsotg_resume(struct platform_device *pdev)s3c_hsotg_core_connect (hsotg);spin_unlock_irqrestore (&hsotg->lock, flags); +mutex_unlock (&hsotg->init_mutex); +return ret; }
Signature · 1 line
1.9.2
PATCH v3 2/2 usb: dwc2/gadget: rework suspend/resume code to correctly restore gadget state
Suspend/resume code assumed that the gadget was always enabled and connected to usb bus. This means that the actual state of the gadget (soft-enabled/disabled or connected/disconnected) was not correctly preserved on suspend/resume cycle. This patch fixes this issue.
--- drivers/usb/dwc2/core.h | 4 +++- drivers/usb/dwc2/gadget.c | 41 +++++++++++++++++++++++++---------------- 2 files changed, 28 insertions(+), 17 deletions(-)
drivers/usb/dwc2/core.h +3 -1
@@ -211,7 +211,9 @@ struct s3c_hsotg {u8 ctrl_buff[8 ];struct usb_gadget gadget; -unsigned int setup; + unsigned int setup:1; + unsigned int connected:1; + unsigned int enabled:1;unsigned long last_rst;unsigned int address;struct s3c_hsotg_ep *eps;
drivers/usb/dwc2/gadget.c +25 -16
80 lines not on this page · raw message
Signature · 1 line
1.9.2
RE: [PATCH v3 1/2] usb: dwc2/gadget: add mutex to serialize init/deinit calls
In reply to Marek SzyprowskiQuoted 128 lines
From: Marek Szyprowski [mailto:[email protected]]
Sent: Friday, October 31, 2014 3:13 AMThis patch adds mutex, which protects initialization and deinitialization procedures against suspend/resume methods.
Signed-off-by Marek Szyprowski <[email protected]>--- drivers/usb/dwc2/core.h | 1 + drivers/usb/dwc2/gadget.c | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+)drivers/usb/dwc2/core.h +1
-0@@ -187,6 +187,7 @@ struct s3c_hsotg {struct s3c_hsotg_plat *plat;spinlock_t lock; +struct mutex init_mutex;void __iomem *regs;int irq;drivers/usb/dwc2/gadget.c +18
-0@@ -21,6 +21,7 @@#include <linux/platform_device.h> #include <linux/dma-mapping.h> #include <linux/debugfs.h> +#include <linux/mutex.h> #include <linux/seq_file.h> #include <linux/delay.h> #include <linux/io.h> @@ -2908,6 +2909,7 @@ static int s3c_hsotg_udc_start(struct usb_gadget *gadget,return -EINVAL ; } +mutex_lock (&hsotg->init_mutex);WARN_ON (hsotg->driver); driver->driver.bus =NULL ;@@ -2933,9 +2935,12 @@ static int s3c_hsotg_udc_start(struct usb_gadget *gadget,dev_info (hsotg->dev,"bound driver %s\n" , driver->driver.name); +mutex_unlock (&hsotg->init_mutex); +return 0 ; err: +mutex_unlock (&hsotg->init_mutex); hsotg->driver =NULL ;return ret; }@@ -2957,6 +2962,8 @@ static int s3c_hsotg_udc_stop(struct usb_gadget *gadget,if (!hsotg)return -ENODEV ; +mutex_lock (&hsotg->init_mutex); +/* all endpoints should be shutdown */ for (ep =1 ; ep < hsotg->num_of_eps; ep++)s3c_hsotg_ep_disable (&hsotg->eps[ep].ep);@@ -2974,6 +2981,8 @@ static int s3c_hsotg_udc_stop(struct usb_gadget *gadget,clk_disable (hsotg->clk); +mutex_unlock (&hsotg->init_mutex); +return 0 ; }@@ -3002,6 +3011,7 @@ static int s3c_hsotg_pullup(struct usb_gadget *gadget, int is_on)dev_dbg (hsotg->dev,"%s: is_on: %d\n" , __func__, is_on); +mutex_lock (&hsotg->init_mutex);spin_lock_irqsave (&hsotg->lock, flags);if (is_on) {clk_enable (hsotg->clk);@@ -3013,6 +3023,7 @@ static int s3c_hsotg_pullup(struct usb_gadget *gadget, int is_on) hsotg->gadget.speed =USB_SPEED_UNKNOWN ;spin_unlock_irqrestore (&hsotg->lock, flags); +mutex_unlock (&hsotg->init_mutex);return 0 ; }@@ -3507,6 +3518,7 @@ static int s3c_hsotg_probe(struct platform_device *pdev) }spin_lock_init (&hsotg->lock); +mutex_init (&hsotg->init_mutex); hsotg->irq = ret;@@ -3652,6 +3664,8 @@ static int s3c_hsotg_suspend(struct platform_device *pdev, pm_message_t state)unsigned long flags;int ret =0 ; +mutex_lock (&hsotg->init_mutex); +if (hsotg->driver)dev_info (hsotg->dev,"suspending usb gadget %s\n" , hsotg->driver->driver.name);@@ -3674,6 +3688,8 @@ static int s3c_hsotg_suspend(struct platform_device *pdev, pm_message_t state)clk_disable (hsotg->clk); } +mutex_unlock (&hsotg->init_mutex); +return ret; }@@ -3683,7 +3699,9 @@ static int s3c_hsotg_resume(struct platform_device *pdev)unsigned long flags;int ret =0 ; +mutex_lock (&hsotg->init_mutex);if (hsotg->driver) { +dev_info (hsotg->dev,"resuming usb gadget %s\n" , hsotg->driver->driver.name);
drivers/usb/dwc2/gadget.c static int s3c_hsotg_resume(struct platform_device *pdev) · line 3724
Quoted 8 lines
drivers/usb/dwc2/gadget.c +2
-0@@ -3699,6 +3717,8 @@ static int s3c_hsotg_resume(struct platform_device *pdev)s3c_hsotg_core_connect (hsotg);spin_unlock_irqrestore (&hsotg->lock, flags); +mutex_unlock (&hsotg->init_mutex); +return ret; }
Hmm. I can't find any other UDC driver that uses a mutex in its suspend/resume functions. Can you explain why this is needed only for dwc2?
Signature · 1 line
Paul
A message that is not in the archive (sent off-list or not yet received): A2CA0424C0A6F04399FB9E1CD98E0304844E7FDD-Yu2iAY70zvrYN67daEjeMPufCSb+aD3WLzEdoUbNIic@public.gmane.org
Re: [PATCH v3 1/2] usb: dwc2/gadget: add mutex to serialize init/deinit calls
Hello,
Quoted 131 lines · Paul Zimmerman
Quoted 131 lines
From: Marek Szyprowski [mailto:[email protected]]
Sent: Friday, October 31, 2014 3:13 AMThis patch adds mutex, which protects initialization and deinitialization procedures against suspend/resume methods.
Signed-off-by Marek Szyprowski <[email protected]>--- drivers/usb/dwc2/core.h | 1 + drivers/usb/dwc2/gadget.c | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+)drivers/usb/dwc2/core.h +1
-0@@ -187,6 +187,7 @@ struct s3c_hsotg {struct s3c_hsotg_plat *plat;spinlock_t lock; +struct mutex init_mutex;void __iomem *regs;int irq;drivers/usb/dwc2/gadget.c +18
-0@@ -21,6 +21,7 @@#include <linux/platform_device.h> #include <linux/dma-mapping.h> #include <linux/debugfs.h> +#include <linux/mutex.h> #include <linux/seq_file.h> #include <linux/delay.h> #include <linux/io.h> @@ -2908,6 +2909,7 @@ static int s3c_hsotg_udc_start(struct usb_gadget *gadget,return -EINVAL ; } +mutex_lock (&hsotg->init_mutex);WARN_ON (hsotg->driver); driver->driver.bus =NULL ;@@ -2933,9 +2935,12 @@ static int s3c_hsotg_udc_start(struct usb_gadget *gadget,dev_info (hsotg->dev,"bound driver %s\n" , driver->driver.name); +mutex_unlock (&hsotg->init_mutex); +return 0 ; err: +mutex_unlock (&hsotg->init_mutex); hsotg->driver =NULL ;return ret; }@@ -2957,6 +2962,8 @@ static int s3c_hsotg_udc_stop(struct usb_gadget *gadget,if (!hsotg)return -ENODEV ; +mutex_lock (&hsotg->init_mutex); +/* all endpoints should be shutdown */ for (ep =1 ; ep < hsotg->num_of_eps; ep++)s3c_hsotg_ep_disable (&hsotg->eps[ep].ep);@@ -2974,6 +2981,8 @@ static int s3c_hsotg_udc_stop(struct usb_gadget *gadget,clk_disable (hsotg->clk); +mutex_unlock (&hsotg->init_mutex); +return 0 ; }@@ -3002,6 +3011,7 @@ static int s3c_hsotg_pullup(struct usb_gadget *gadget, int is_on)dev_dbg (hsotg->dev,"%s: is_on: %d\n" , __func__, is_on); +mutex_lock (&hsotg->init_mutex);spin_lock_irqsave (&hsotg->lock, flags);if (is_on) {clk_enable (hsotg->clk);@@ -3013,6 +3023,7 @@ static int s3c_hsotg_pullup(struct usb_gadget *gadget, int is_on) hsotg->gadget.speed =USB_SPEED_UNKNOWN ;spin_unlock_irqrestore (&hsotg->lock, flags); +mutex_unlock (&hsotg->init_mutex);return 0 ; }@@ -3507,6 +3518,7 @@ static int s3c_hsotg_probe(struct platform_device *pdev) }spin_lock_init (&hsotg->lock); +mutex_init (&hsotg->init_mutex); hsotg->irq = ret;@@ -3652,6 +3664,8 @@ static int s3c_hsotg_suspend(struct platform_device *pdev, pm_message_t state)unsigned long flags;int ret =0 ; +mutex_lock (&hsotg->init_mutex); +if (hsotg->driver)dev_info (hsotg->dev,"suspending usb gadget %s\n" , hsotg->driver->driver.name);@@ -3674,6 +3688,8 @@ static int s3c_hsotg_suspend(struct platform_device *pdev, pm_message_t state)clk_disable (hsotg->clk); } +mutex_unlock (&hsotg->init_mutex); +return ret; }@@ -3683,7 +3699,9 @@ static int s3c_hsotg_resume(struct platform_device *pdev)unsigned long flags;int ret =0 ; +mutex_lock (&hsotg->init_mutex);if (hsotg->driver) { +dev_info (hsotg->dev,"resuming usb gadget %s\n" , hsotg->driver->driver.name);@@ -3699,6 +3717,8 @@ static int s3c_hsotg_resume(struct platform_device *pdev)s3c_hsotg_core_connect (hsotg);spin_unlock_irqrestore (&hsotg->lock, flags);
Quoted 8 lines
drivers/usb/dwc2/gadget.c static int s3c_hsotg_suspend(struct platform_device *pdev, pm_message_t state) · line 3695
Quoted 5 lines
drivers/usb/dwc2/gadget.c +2
-0+mutex_unlock (&hsotg->init_mutex); +return ret; }Hmm. I can't find any other UDC driver that uses a mutex in its suspend/resume functions. Can you explain why this is needed only for dwc2?
I've posted this version because I thought you were not convinced that the patch "usb: dwc2/gadget: rework suspend/resume code to correctly restore gadget state" can add code for initialization and deinitialization in suspend/resume paths.
Best regards
Signature · 7 lines
Marek Szyprowski, PhD Samsung R&D Institute Poland -- 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
RE: [PATCH v3 1/2] usb: dwc2/gadget: add mutex to serialize init/deinit calls
Quoted 146 lines
From: Marek Szyprowski [mailto:[email protected]]
Sent: Thursday, November 13, 2014 7:18 AMQuoted 94 lines · Paul Zimmerman
Quoted 94 lines
From: Marek Szyprowski [mailto:[email protected]]
Sent: Friday, October 31, 2014 3:13 AMThis patch adds mutex, which protects initialization and deinitialization procedures against suspend/resume methods.
Signed-off-by Marek Szyprowski <[email protected]>--- drivers/usb/dwc2/core.h | 1 + drivers/usb/dwc2/gadget.c | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+)drivers/usb/dwc2/core.h +1
-0@@ -187,6 +187,7 @@ struct s3c_hsotg {struct s3c_hsotg_plat *plat;spinlock_t lock; +struct mutex init_mutex;void __iomem *regs;int irq;drivers/usb/dwc2/gadget.c +11
-0@@ -21,6 +21,7 @@#include <linux/platform_device.h> #include <linux/dma-mapping.h> #include <linux/debugfs.h> +#include <linux/mutex.h> #include <linux/seq_file.h> #include <linux/delay.h> #include <linux/io.h> @@ -2908,6 +2909,7 @@ static int s3c_hsotg_udc_start(struct usb_gadget *gadget,return -EINVAL ; } +mutex_lock (&hsotg->init_mutex);WARN_ON (hsotg->driver); driver->driver.bus =NULL ;@@ -2933,9 +2935,12 @@ static int s3c_hsotg_udc_start(struct usb_gadget *gadget,dev_info (hsotg->dev,"bound driver %s\n" , driver->driver.name); +mutex_unlock (&hsotg->init_mutex); +return 0 ; err: +mutex_unlock (&hsotg->init_mutex); hsotg->driver =NULL ;return ret; }@@ -2957,6 +2962,8 @@ static int s3c_hsotg_udc_stop(struct usb_gadget *gadget,if (!hsotg)return -ENODEV ; +mutex_lock (&hsotg->init_mutex); +/* all endpoints should be shutdown */ for (ep =1 ; ep < hsotg->num_of_eps; ep++)s3c_hsotg_ep_disable (&hsotg->eps[ep].ep);@@ -2974,6 +2981,8 @@ static int s3c_hsotg_udc_stop(struct usb_gadget *gadget,clk_disable (hsotg->clk); +mutex_unlock (&hsotg->init_mutex); +return 0 ; }@@ -3002,6 +3011,7 @@ static int s3c_hsotg_pullup(struct usb_gadget *gadget, int is_on)dev_dbg (hsotg->dev,"%s: is_on: %d\n" , __func__, is_on); +mutex_lock (&hsotg->init_mutex);spin_lock_irqsave (&hsotg->lock, flags);if (is_on) {clk_enable (hsotg->clk);@@ -3013,6 +3023,7 @@ static int s3c_hsotg_pullup(struct usb_gadget *gadget, int is_on) hsotg->gadget.speed =USB_SPEED_UNKNOWN ;spin_unlock_irqrestore (&hsotg->lock, flags); +mutex_unlock (&hsotg->init_mutex);return 0 ; }@@ -3507,6 +3518,7 @@ static int s3c_hsotg_probe(struct platform_device *pdev) }Quoted 6 lines
drivers/usb/dwc2/gadget.c static int s3c_hsotg_suspend(struct platform_device *pdev, pm_message_t
Quoted 6 lines
drivers/usb/dwc2/gadget.c +1
-0spin_lock_init (&hsotg->lock); +mutex_init (&hsotg->init_mutex); hsotg->irq = ret;@@ -3652,6 +3664,8 @@ static int s3c_hsotg_suspend(struct platform_device *pdev, pm_message_tstate)
Quoted 9 lines
drivers/usb/dwc2/gadget.c static int s3c_hsotg_suspend(struct platform_device *pdev, pm_message_t
Quoted 9 lines
drivers/usb/dwc2/gadget.c +2
-0unsigned long flags;int ret =0 ; +mutex_lock (&hsotg->init_mutex); +if (hsotg->driver)dev_info (hsotg->dev,"suspending usb gadget %s\n" , hsotg->driver->driver.name);@@ -3674,6 +3688,8 @@ static int s3c_hsotg_suspend(struct platform_device *pdev, pm_message_tstate)
Quoted 22 lines
Quoted 22 lines
drivers/usb/dwc2/gadget.c +4
-0clk_disable (hsotg->clk); } +mutex_unlock (&hsotg->init_mutex); +return ret; }@@ -3683,7 +3699,9 @@ static int s3c_hsotg_resume(struct platform_device *pdev)unsigned long flags;int ret =0 ; +mutex_lock (&hsotg->init_mutex);if (hsotg->driver) { +dev_info (hsotg->dev,"resuming usb gadget %s\n" , hsotg->driver->driver.name);@@ -3699,6 +3717,8 @@ static int s3c_hsotg_resume(struct platform_device *pdev)s3c_hsotg_core_connect (hsotg);spin_unlock_irqrestore (&hsotg->lock, flags);Quoted 8 lines
drivers/usb/dwc2/gadget.c static int s3c_hsotg_suspend(struct platform_device *pdev, pm_message_t state) · line 3695
Quoted 5 lines
drivers/usb/dwc2/gadget.c +2
-0+mutex_unlock (&hsotg->init_mutex); +return ret; }Hmm. I can't find any other UDC driver that uses a mutex in its suspend/resume functions. Can you explain why this is needed only for dwc2?
Quoted 6 lines
I've posted this version because I thought you were not convinced that the patch
"usb: dwc2/gadget: rework suspend/resume code to correctly restore gadget state"
can add code for initialization and deinitialization in suspend/resume paths.
My problem with that patch was that you were checking the ->enabled flag outside of the spinlock. To address that, you only need to move the check inside of the spinlock. I don't see why a mutex is needed.
Signature · 1 line
Paul
Re: [PATCH v3 1/2] usb: dwc2/gadget: add mutex to serialize init/deinit calls
Hello,
Quoted 151 lines · Paul Zimmerman
Quoted 145 lines
From: Marek Szyprowski [mailto:[email protected]]
Sent: Thursday, November 13, 2014 7:18 AMQuoted 94 lines · Paul Zimmerman
Quoted 94 lines
From: Marek Szyprowski [mailto:[email protected]]
Sent: Friday, October 31, 2014 3:13 AMThis patch adds mutex, which protects initialization and deinitialization procedures against suspend/resume methods.
Signed-off-by Marek Szyprowski <[email protected]>--- drivers/usb/dwc2/core.h | 1 + drivers/usb/dwc2/gadget.c | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+)drivers/usb/dwc2/core.h +1
-0@@ -187,6 +187,7 @@ struct s3c_hsotg {struct s3c_hsotg_plat *plat;spinlock_t lock; +struct mutex init_mutex;void __iomem *regs;int irq;drivers/usb/dwc2/gadget.c +11
-0@@ -21,6 +21,7 @@#include <linux/platform_device.h> #include <linux/dma-mapping.h> #include <linux/debugfs.h> +#include <linux/mutex.h> #include <linux/seq_file.h> #include <linux/delay.h> #include <linux/io.h> @@ -2908,6 +2909,7 @@ static int s3c_hsotg_udc_start(struct usb_gadget *gadget,return -EINVAL ; } +mutex_lock (&hsotg->init_mutex);WARN_ON (hsotg->driver); driver->driver.bus =NULL ;@@ -2933,9 +2935,12 @@ static int s3c_hsotg_udc_start(struct usb_gadget *gadget,dev_info (hsotg->dev,"bound driver %s\n" , driver->driver.name); +mutex_unlock (&hsotg->init_mutex); +return 0 ; err: +mutex_unlock (&hsotg->init_mutex); hsotg->driver =NULL ;return ret; }@@ -2957,6 +2962,8 @@ static int s3c_hsotg_udc_stop(struct usb_gadget *gadget,if (!hsotg)return -ENODEV ; +mutex_lock (&hsotg->init_mutex); +/* all endpoints should be shutdown */ for (ep =1 ; ep < hsotg->num_of_eps; ep++)s3c_hsotg_ep_disable (&hsotg->eps[ep].ep);@@ -2974,6 +2981,8 @@ static int s3c_hsotg_udc_stop(struct usb_gadget *gadget,clk_disable (hsotg->clk); +mutex_unlock (&hsotg->init_mutex); +return 0 ; }@@ -3002,6 +3011,7 @@ static int s3c_hsotg_pullup(struct usb_gadget *gadget, int is_on)dev_dbg (hsotg->dev,"%s: is_on: %d\n" , __func__, is_on); +mutex_lock (&hsotg->init_mutex);spin_lock_irqsave (&hsotg->lock, flags);if (is_on) {clk_enable (hsotg->clk);@@ -3013,6 +3023,7 @@ static int s3c_hsotg_pullup(struct usb_gadget *gadget, int is_on) hsotg->gadget.speed =USB_SPEED_UNKNOWN ;spin_unlock_irqrestore (&hsotg->lock, flags); +mutex_unlock (&hsotg->init_mutex);return 0 ; }@@ -3507,6 +3518,7 @@ static int s3c_hsotg_probe(struct platform_device *pdev) }Quoted 6 lines
drivers/usb/dwc2/gadget.c static int s3c_hsotg_suspend(struct platform_device *pdev, pm_message_t
Quoted 6 lines
drivers/usb/dwc2/gadget.c +1
-0spin_lock_init (&hsotg->lock); +mutex_init (&hsotg->init_mutex); hsotg->irq = ret;@@ -3652,6 +3664,8 @@ static int s3c_hsotg_suspend(struct platform_device *pdev, pm_message_tstate)
Quoted 9 lines
drivers/usb/dwc2/gadget.c static int s3c_hsotg_suspend(struct platform_device *pdev, pm_message_t
Quoted 9 lines
drivers/usb/dwc2/gadget.c +2
-0unsigned long flags;int ret =0 ; +mutex_lock (&hsotg->init_mutex); +if (hsotg->driver)dev_info (hsotg->dev,"suspending usb gadget %s\n" , hsotg->driver->driver.name);@@ -3674,6 +3688,8 @@ static int s3c_hsotg_suspend(struct platform_device *pdev, pm_message_tstate)
Quoted 22 lines
Quoted 22 lines
drivers/usb/dwc2/gadget.c +4
-0clk_disable (hsotg->clk); } +mutex_unlock (&hsotg->init_mutex); +return ret; }@@ -3683,7 +3699,9 @@ static int s3c_hsotg_resume(struct platform_device *pdev)unsigned long flags;int ret =0 ; +mutex_lock (&hsotg->init_mutex);if (hsotg->driver) { +dev_info (hsotg->dev,"resuming usb gadget %s\n" , hsotg->driver->driver.name);@@ -3699,6 +3717,8 @@ static int s3c_hsotg_resume(struct platform_device *pdev)s3c_hsotg_core_connect (hsotg);spin_unlock_irqrestore (&hsotg->lock, flags);Quoted 8 lines
drivers/usb/dwc2/gadget.c static int s3c_hsotg_suspend(struct platform_device *pdev, pm_message_t state) · line 3695
Quoted 5 lines
drivers/usb/dwc2/gadget.c +2
-0+mutex_unlock (&hsotg->init_mutex); +return ret; }Hmm. I can't find any other UDC driver that uses a mutex in its suspend/resume functions. Can you explain why this is needed only for dwc2?
Quoted 6 lines
I've posted this version because I thought you were not convinced that the patch
"usb: dwc2/gadget: rework suspend/resume code to correctly restore gadget state"
can add code for initialization and deinitialization in suspend/resume paths.
Quoted 3 lines
My problem with that patch was that you were checking the ->enabled flag outside of the spinlock. To address that, you only need to move the check inside of the spinlock. I don't see why a mutex is needed.
It is not that simple. I can add spin_lock() before checking enabled, but then I would need to spin_unlock() to call regulator_bulk_enable() and phy_enable(), because both cannot be called from atomic context. This means that the spinlock in such case will not protect anything and is simply useless.
Best regards
Signature · 2 lines
Marek Szyprowski, PhD Samsung R&D Institute Poland
RE: [PATCH v3 1/2] usb: dwc2/gadget: add mutex to serialize init/deinit calls
Quoted 159 lines
From: Marek Szyprowski [mailto:[email protected]]
Sent: Friday, November 14, 2014 1:19 AMQuoted 151 lines · Paul Zimmerman
Quoted 145 lines
From: Marek Szyprowski [mailto:[email protected]]
Sent: Thursday, November 13, 2014 7:18 AMQuoted 94 lines · Paul Zimmerman
Quoted 94 lines
From: Marek Szyprowski [mailto:[email protected]]
Sent: Friday, October 31, 2014 3:13 AMThis patch adds mutex, which protects initialization and deinitialization procedures against suspend/resume methods.
Signed-off-by Marek Szyprowski <[email protected]>--- drivers/usb/dwc2/core.h | 1 + drivers/usb/dwc2/gadget.c | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+)drivers/usb/dwc2/core.h +1
-0@@ -187,6 +187,7 @@ struct s3c_hsotg {struct s3c_hsotg_plat *plat;spinlock_t lock; +struct mutex init_mutex;void __iomem *regs;int irq;drivers/usb/dwc2/gadget.c +11
-0@@ -21,6 +21,7 @@#include <linux/platform_device.h> #include <linux/dma-mapping.h> #include <linux/debugfs.h> +#include <linux/mutex.h> #include <linux/seq_file.h> #include <linux/delay.h> #include <linux/io.h> @@ -2908,6 +2909,7 @@ static int s3c_hsotg_udc_start(struct usb_gadget *gadget,return -EINVAL ; } +mutex_lock (&hsotg->init_mutex);WARN_ON (hsotg->driver); driver->driver.bus =NULL ;@@ -2933,9 +2935,12 @@ static int s3c_hsotg_udc_start(struct usb_gadget *gadget,dev_info (hsotg->dev,"bound driver %s\n" , driver->driver.name); +mutex_unlock (&hsotg->init_mutex); +return 0 ; err: +mutex_unlock (&hsotg->init_mutex); hsotg->driver =NULL ;return ret; }@@ -2957,6 +2962,8 @@ static int s3c_hsotg_udc_stop(struct usb_gadget *gadget,if (!hsotg)return -ENODEV ; +mutex_lock (&hsotg->init_mutex); +/* all endpoints should be shutdown */ for (ep =1 ; ep < hsotg->num_of_eps; ep++)s3c_hsotg_ep_disable (&hsotg->eps[ep].ep);@@ -2974,6 +2981,8 @@ static int s3c_hsotg_udc_stop(struct usb_gadget *gadget,clk_disable (hsotg->clk); +mutex_unlock (&hsotg->init_mutex); +return 0 ; }@@ -3002,6 +3011,7 @@ static int s3c_hsotg_pullup(struct usb_gadget *gadget, int is_on)dev_dbg (hsotg->dev,"%s: is_on: %d\n" , __func__, is_on); +mutex_lock (&hsotg->init_mutex);spin_lock_irqsave (&hsotg->lock, flags);if (is_on) {clk_enable (hsotg->clk);@@ -3013,6 +3023,7 @@ static int s3c_hsotg_pullup(struct usb_gadget *gadget, int is_on) hsotg->gadget.speed =USB_SPEED_UNKNOWN ;spin_unlock_irqrestore (&hsotg->lock, flags); +mutex_unlock (&hsotg->init_mutex);return 0 ; }@@ -3507,6 +3518,7 @@ static int s3c_hsotg_probe(struct platform_device *pdev) }Quoted 6 lines
drivers/usb/dwc2/gadget.c static int s3c_hsotg_suspend(struct platform_device *pdev, pm_message_t
Quoted 6 lines
drivers/usb/dwc2/gadget.c +1
-0spin_lock_init (&hsotg->lock); +mutex_init (&hsotg->init_mutex); hsotg->irq = ret;@@ -3652,6 +3664,8 @@ static int s3c_hsotg_suspend(struct platform_device *pdev, pm_message_tstate)
Quoted 9 lines
drivers/usb/dwc2/gadget.c static int s3c_hsotg_suspend(struct platform_device *pdev, pm_message_t
Quoted 9 lines
drivers/usb/dwc2/gadget.c +2
-0unsigned long flags;int ret =0 ; +mutex_lock (&hsotg->init_mutex); +if (hsotg->driver)dev_info (hsotg->dev,"suspending usb gadget %s\n" , hsotg->driver->driver.name);@@ -3674,6 +3688,8 @@ static int s3c_hsotg_suspend(struct platform_device *pdev, pm_message_tstate)
Quoted 22 lines
Quoted 22 lines
drivers/usb/dwc2/gadget.c +4
-0clk_disable (hsotg->clk); } +mutex_unlock (&hsotg->init_mutex); +return ret; }@@ -3683,7 +3699,9 @@ static int s3c_hsotg_resume(struct platform_device *pdev)unsigned long flags;int ret =0 ; +mutex_lock (&hsotg->init_mutex);if (hsotg->driver) { +dev_info (hsotg->dev,"resuming usb gadget %s\n" , hsotg->driver->driver.name);@@ -3699,6 +3717,8 @@ static int s3c_hsotg_resume(struct platform_device *pdev)s3c_hsotg_core_connect (hsotg);spin_unlock_irqrestore (&hsotg->lock, flags);Quoted 8 lines
drivers/usb/dwc2/gadget.c static int s3c_hsotg_suspend(struct platform_device *pdev, pm_message_t state) · line 3695
Quoted 5 lines
drivers/usb/dwc2/gadget.c +2
-0+mutex_unlock (&hsotg->init_mutex); +return ret; }Hmm. I can't find any other UDC driver that uses a mutex in its suspend/resume functions. Can you explain why this is needed only for dwc2?
Quoted 6 lines
I've posted this version because I thought you were not convinced that the patch
"usb: dwc2/gadget: rework suspend/resume code to correctly restore gadget state"
can add code for initialization and deinitialization in suspend/resume paths.Quoted 3 lines
My problem with that patch was that you were checking the ->enabled flag outside of the spinlock. To address that, you only need to move the check inside of the spinlock. I don't see why a mutex is needed.
Quoted 7 lines
It is not that simple. I can add
spin_lock()before checking enabled, but then
I would need tospin_unlock()to callregulator_bulk_enable()andphy_enable(),
because both cannot be called from atomic context. This means that the spinlock
in such case will not protect anything and is simply useless.
Ah, OK. So you're using the mutex instead of the ->enabled flag that you proposed in the "rework suspend/resume code" patch. So this patch is a replacement for that one. Somehow I was thinking this patch was on top of that one.
So I guess this is OK, but I would like to get Felipe's opinion about it before we apply this.
Felipe?
Signature · 1 line
Paul
Re: [PATCH v3 1/2] usb: dwc2/gadget: add mutex to serialize init/deinit calls
Hi,
Quoted 35 lines · Paul Zimmerman
Quoted 22 lines
Quoted 18 lines
Quoted 12 lines
Quoted 4 lines
Quoted 4 lines
(quoted diff) +0
-0@@ -3699,6 +3717,8 @@ static int s3c_hsotg_resume(struct platform_device *pdev) s3c_hsotg_core_connect(hsotg); spin_unlock_irqrestore(&hsotg->lock, flags);Quoted 8 lines
Review static int s3c_hsotg_resume(struct platform_device *pdev) · line 3724
Quoted 5 lines
(quoted diff) +2
-0+ mutex_unlock(&hsotg->init_mutex); + return ret; }Hmm. I can't find any other UDC driver that uses a mutex in its suspend/resume functions. Can you explain why this is needed only for dwc2?
Quoted 6 lines
I've posted this version because I thought you were not convinced that the patch
"usb: dwc2/gadget: rework suspend/resume code to correctly restore gadget state"
can add code for initialization and deinitialization in suspend/resume paths.Quoted 3 lines
My problem with that patch was that you were checking the ->enabled flag outside of the spinlock. To address that, you only need to move the check inside of the spinlock. I don't see why a mutex is needed.
Quoted 7 lines
It is not that simple. I can add
spin_lock()before checking enabled, but then
I would need tospin_unlock()to callregulator_bulk_enable()andphy_enable(),
because both cannot be called from atomic context. This means that the spinlock
in such case will not protect anything and is simply useless.Ah, OK. So you're using the mutex instead of the ->enabled flag that you proposed in the "rework suspend/resume code" patch. So this patch is a replacement for that one. Somehow I was thinking this patch was on top of that one.
Quoted 4 lines
So I guess this is OK, but I would like to get Felipe's opinion about it before we apply this.
Felipe?
I can't think of a better way, I'm afraid :-(
Signature · 1 line
balbi
A message that is not in the archive (sent off-list or not yet received): 1414750354-19571-1-git-send-email-m.szyprowski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org
Paul Zimmerman
Acked-byRE: [PATCH v3 1/2] usb: dwc2/gadget: add mutex to serialize init/deinit calls
Quoted 128 lines
From: Marek Szyprowski [mailto:[email protected]]
Sent: Friday, October 31, 2014 3:13 AMThis patch adds mutex, which protects initialization and deinitialization procedures against suspend/resume methods.
Signed-off-by Marek Szyprowski <[email protected]>--- drivers/usb/dwc2/core.h | 1 + drivers/usb/dwc2/gadget.c | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+)drivers/usb/dwc2/core.h +1
-0@@ -187,6 +187,7 @@ struct s3c_hsotg {struct s3c_hsotg_plat *plat;spinlock_t lock; +struct mutex init_mutex;void __iomem *regs;int irq;drivers/usb/dwc2/gadget.c +18
-0@@ -21,6 +21,7 @@#include <linux/platform_device.h> #include <linux/dma-mapping.h> #include <linux/debugfs.h> +#include <linux/mutex.h> #include <linux/seq_file.h> #include <linux/delay.h> #include <linux/io.h> @@ -2908,6 +2909,7 @@ static int s3c_hsotg_udc_start(struct usb_gadget *gadget,return -EINVAL ; } +mutex_lock (&hsotg->init_mutex);WARN_ON (hsotg->driver); driver->driver.bus =NULL ;@@ -2933,9 +2935,12 @@ static int s3c_hsotg_udc_start(struct usb_gadget *gadget,dev_info (hsotg->dev,"bound driver %s\n" , driver->driver.name); +mutex_unlock (&hsotg->init_mutex); +return 0 ; err: +mutex_unlock (&hsotg->init_mutex); hsotg->driver =NULL ;return ret; }@@ -2957,6 +2962,8 @@ static int s3c_hsotg_udc_stop(struct usb_gadget *gadget,if (!hsotg)return -ENODEV ; +mutex_lock (&hsotg->init_mutex); +/* all endpoints should be shutdown */ for (ep =1 ; ep < hsotg->num_of_eps; ep++)s3c_hsotg_ep_disable (&hsotg->eps[ep].ep);@@ -2974,6 +2981,8 @@ static int s3c_hsotg_udc_stop(struct usb_gadget *gadget,clk_disable (hsotg->clk); +mutex_unlock (&hsotg->init_mutex); +return 0 ; }@@ -3002,6 +3011,7 @@ static int s3c_hsotg_pullup(struct usb_gadget *gadget, int is_on)dev_dbg (hsotg->dev,"%s: is_on: %d\n" , __func__, is_on); +mutex_lock (&hsotg->init_mutex);spin_lock_irqsave (&hsotg->lock, flags);if (is_on) {clk_enable (hsotg->clk);@@ -3013,6 +3023,7 @@ static int s3c_hsotg_pullup(struct usb_gadget *gadget, int is_on) hsotg->gadget.speed =USB_SPEED_UNKNOWN ;spin_unlock_irqrestore (&hsotg->lock, flags); +mutex_unlock (&hsotg->init_mutex);return 0 ; }@@ -3507,6 +3518,7 @@ static int s3c_hsotg_probe(struct platform_device *pdev) }spin_lock_init (&hsotg->lock); +mutex_init (&hsotg->init_mutex); hsotg->irq = ret;@@ -3652,6 +3664,8 @@ static int s3c_hsotg_suspend(struct platform_device *pdev, pm_message_t state)unsigned long flags;int ret =0 ; +mutex_lock (&hsotg->init_mutex); +if (hsotg->driver)dev_info (hsotg->dev,"suspending usb gadget %s\n" , hsotg->driver->driver.name);@@ -3674,6 +3688,8 @@ static int s3c_hsotg_suspend(struct platform_device *pdev, pm_message_t state)clk_disable (hsotg->clk); } +mutex_unlock (&hsotg->init_mutex); +return ret; }@@ -3683,7 +3699,9 @@ static int s3c_hsotg_resume(struct platform_device *pdev)unsigned long flags;int ret =0 ; +mutex_lock (&hsotg->init_mutex);if (hsotg->driver) { +dev_info (hsotg->dev,"resuming usb gadget %s\n" , hsotg->driver->driver.name);
drivers/usb/dwc2/gadget.c static int s3c_hsotg_resume(struct platform_device *pdev) · line 3724
Quoted 8 lines
drivers/usb/dwc2/gadget.c +2
-0@@ -3699,6 +3717,8 @@ static int s3c_hsotg_resume(struct platform_device *pdev)s3c_hsotg_core_connect (hsotg);spin_unlock_irqrestore (&hsotg->lock, flags); +mutex_unlock (&hsotg->init_mutex); +return ret; }
--
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
Re: [PATCH v3 1/2] usb: dwc2/gadget: add mutex to serialize init/deinit calls
In reply to Marek SzyprowskiQuoted 4 lines · Marek Szyprowski
This patch adds mutex, which protects initialization and deinitialization procedures against suspend/resume methods.
Signed-off-by Marek Szyprowski <[email protected]>
doesn't apply either:
checking file drivers/usb/dwc2/core.h
Hunk #1 FAILED at 187.
1 out of 1 hunk FAILED
checking file drivers/usb/dwc2/gadget.c
Hunk #2 succeeded at 2863 (offset -46 lines). Hunk #3 succeeded at 2889 (offset -46 lines). Hunk #4 succeeded at 2915 (offset -47 lines). Hunk #5 succeeded at 2934 (offset -47 lines). Hunk #6 succeeded at 2964 (offset -47 lines). Hunk #7 succeeded at 2976 (offset -47 lines). Hunk #8 FAILED at 3518.
Hunk #9 succeeded at 3579 (offset -84 lines). Hunk #10 succeeded at 3603 with fuzz 1 (offset -84 lines). Hunk #11 succeeded at 3614 (offset -84 lines). Hunk #12 succeeded at 3632 with fuzz 1 (offset -84 lines). 1 out of 12 hunks FAILED
please rebase on testing/next. Also, add Paul's Ack when doing so ;-)
thanks
Signature · 1 line
balbi
PATCH v2 1/10 usb: dwc2/gadget: report disconnect event from 'end session' irq
In reply to Marek SzyprowskiThis patch adds a call to s3c_hsotg_disconnect() from 'end session' interrupt (GOTGINT_SES_END_DET) to correctly notify gadget subsystem about unplugged usb cable. 'disconnected' interrupt (DISCONNINT) might look a bit more suitable for this event, but it is asserted only in host mode, so in device mode we need to use something else.
--- drivers/usb/dwc2/gadget.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/usb/dwc2/gadget.c +6 -0
@@ -2279,6 +2279,12 @@ irq_retry:dev_info (hsotg->dev,"OTGInt: %08x\n" , otgint);writel (otgint, hsotg->regs +GOTGINT ); + +if (otgint &GOTGINT_SES_END_DET ) { +if (hsotg->gadget.speed !=USB_SPEED_UNKNOWN ) +s3c_hsotg_disconnect (hsotg); + hsotg->gadget.speed =USB_SPEED_UNKNOWN ; + } }if (gintsts &GINTSTS_SESSREQINT ) {
Signature · 1 line
1.9.2
A message that is not in the archive (sent off-list or not yet received): 1413801940-31086-2-git-send-email-m.szyprowski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org
RE: [PATCH v2 01/10] usb: dwc2/gadget: report disconnect event from 'end session' irq
Quoted 21 lines
From: Marek Szyprowski [mailto:[email protected]]
Sent: Monday, October 20, 2014 3:46 AMThis patch adds a call to
s3c_hsotg_disconnect()from 'end session' interrupt (GOTGINT_SES_END_DET) to correctly notify gadget subsystem about unplugged usb cable. 'disconnected' interrupt (DISCONNINT) might look a bit more suitable for this event, but it is asserted only in host mode, so in device mode we need to use something else.Signed-off-by Marek Szyprowski <[email protected]>--- drivers/usb/dwc2/gadget.c | 6 ++++++ 1 file changed, 6 insertions(+)drivers/usb/dwc2/gadget.c +0
-0@@ -2279,6 +2279,12 @@ irq_retry:dev_info (hsotg->dev,"OTGInt: %08x\n" , otgint);
drivers/usb/dwc2/gadget.c irq_retry: · line 2290
Quoted 10 lines
drivers/usb/dwc2/gadget.c +6
-0writel (otgint, hsotg->regs +GOTGINT ); + +if (otgint &GOTGINT_SES_END_DET ) { +if (hsotg->gadget.speed !=USB_SPEED_UNKNOWN ) +s3c_hsotg_disconnect (hsotg); + hsotg->gadget.speed =USB_SPEED_UNKNOWN ; + } }if (gintsts &GINTSTS_SESSREQINT ) {
Does this mean we can get rid of the call to s3c_hsotg_disconnect in s3c_hsotg_process_control after a SET_ADDRESS is received? If not, then s3c_hsotg_disconnect will be called twice, once here after the disconnect, and once again after the reconnect and SET_ADDRESS.
Signature · 6 lines
Paul -- 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
A message that is not in the archive (sent off-list or not yet received): A2CA0424C0A6F04399FB9E1CD98E0304844E5C19-Yu2iAY70zvrYN67daEjeMPufCSb+aD3WLzEdoUbNIic@public.gmane.org
Re: [PATCH v2 01/10] usb: dwc2/gadget: report disconnect event from 'end session' irq
Hello,
Quoted 30 lines · Paul Zimmerman
Quoted 30 lines
From: Marek Szyprowski [mailto:[email protected]]
Sent: Monday, October 20, 2014 3:46 AMThis patch adds a call to
s3c_hsotg_disconnect()from 'end session' interrupt (GOTGINT_SES_END_DET) to correctly notify gadget subsystem about unplugged usb cable. 'disconnected' interrupt (DISCONNINT) might look a bit more suitable for this event, but it is asserted only in host mode, so in device mode we need to use something else.Signed-off-by Marek Szyprowski <[email protected]>--- drivers/usb/dwc2/gadget.c | 6 ++++++ 1 file changed, 6 insertions(+)drivers/usb/dwc2/gadget.c +6
-0@@ -2279,6 +2279,12 @@ irq_retry:dev_info (hsotg->dev,"OTGInt: %08x\n" , otgint);writel (otgint, hsotg->regs +GOTGINT ); + +if (otgint &GOTGINT_SES_END_DET ) { +if (hsotg->gadget.speed !=USB_SPEED_UNKNOWN ) +s3c_hsotg_disconnect (hsotg); + hsotg->gadget.speed =USB_SPEED_UNKNOWN ; + } }
Quoted 5 lines
drivers/usb/dwc2/gadget.c irq_retry: · line 2290
Quoted 1 line
drivers/usb/dwc2/gadget.c +0
-0if (gintsts &GINTSTS_SESSREQINT ) {Does this mean we can get rid of the call to
s3c_hsotg_disconnectins3c_hsotg_process_controlafter aSET_ADDRESSis received? If not, thens3c_hsotg_disconnectwill be called twice, once here after the disconnect, and once again after the reconnect andSET_ADDRESS.
Nope, we cannot get rid of that call, because it is needed got get gadget operational when device has been re-enumerated. The simplest way to reproduce such case is to connect dwc2 to externally powered hub and then unplug cable between hub and usb host. In such case the 'end session' interrupt is not asserted, so the additional s3c_hsotg_disconnect() call before setting new address is needed. I will rework this patch and add a code to ensures that the gadget->disconnect() will be called only once.
Best regards
Signature · 7 lines
Marek Szyprowski, PhD Samsung R&D Institute Poland -- 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
PATCH v3 1/1 usb: dwc2/gadget: report disconnect event from 'end session' irq
In reply to Marek SzyprowskiThis patch adds a call to s3c_hsotg_disconnect() from 'end session' interrupt (GOTGINT_SES_END_DET) to correctly notify gadget subsystem about unplugged usb cable. 'disconnected' interrupt (DISCONNINT) might look a bit more suitable for this event, but it is asserted only in host mode, so in device mode we need to use something else.
Additional check has been added in s3c_hsotg_disconnect() function to ensure that the event is reported only once after successful device enumeration.
--- drivers/usb/dwc2/core.h | 1 + drivers/usb/dwc2/gadget.c | 10 ++++++++++ 2 files changed, 11 insertions(+)
drivers/usb/dwc2/core.h +1 -0
@@ -212,6 +212,7 @@ struct s3c_hsotg {struct usb_gadget gadget;unsigned int setup;unsigned long last_rst; +unsigned int address;struct s3c_hsotg_ep *eps; };
drivers/usb/dwc2/gadget.c +10 -0
@@ -1114,6 +1114,7 @@ static void s3c_hsotg_process_control(struct s3c_hsotg *hsotg, DCFG_DEVADDR_SHIFT) & DCFG_DEVADDR_MASK;writel (dcfg, hsotg->regs +DCFG ); + hsotg->address = ctrl->wValue;dev_info (hsotg->dev,"new address %d\n" , ctrl->wValue); ret =s3c_hsotg_send_reply (hsotg, ep0,NULL ,0 );
@@ -2031,6 +2032,10 @@ static void s3c_hsotg_disconnect(struct s3c_hsotg *hsotg) {unsigned ep; +if (!hsotg->address) +return ; + + hsotg->address =0 ;for (ep =0 ; ep < hsotg->num_of_eps; ep++)kill_all_requests (hsotg, &hsotg->eps[ep], -ESHUTDOWN , true);
@@ -2290,6 +2295,11 @@ irq_retry:dev_info (hsotg->dev,"OTGInt: %08x\n" , otgint);writel (otgint, hsotg->regs +GOTGINT ); + +if (otgint &GOTGINT_SES_END_DET ) { +s3c_hsotg_disconnect (hsotg); + hsotg->gadget.speed =USB_SPEED_UNKNOWN ; + } }if (gintsts &GINTSTS_SESSREQINT ) {
Signature · 1 line
1.9.2
RE: [PATCH v3] usb: dwc2/gadget: report disconnect event from 'end session' irq
Quoted 59 lines
From: Marek Szyprowski [mailto:[email protected]]
Sent: Friday, October 31, 2014 1:04 AM
To: [email protected]; [email protected]
Cc: Marek Szyprowski; Kyungmin Park; Robert Baldyga; Paul Zimmerman; Krzysztof Kozlowski; Felipe Balbi
Subject: [PATCH v3] usb: dwc2/gadget: report disconnect event from 'end session' irqThis patch adds a call to
s3c_hsotg_disconnect()from 'end session' interrupt (GOTGINT_SES_END_DET) to correctly notify gadget subsystem about unplugged usb cable. 'disconnected' interrupt (DISCONNINT) might look a bit more suitable for this event, but it is asserted only in host mode, so in device mode we need to use something else.Additional check has been added in
s3c_hsotg_disconnect()function to ensure that the event is reported only once after successful device enumeration.Signed-off-by Marek Szyprowski <[email protected]>--- drivers/usb/dwc2/core.h | 1 + drivers/usb/dwc2/gadget.c | 10 ++++++++++ 2 files changed, 11 insertions(+)drivers/usb/dwc2/core.h +1
-0@@ -212,6 +212,7 @@ struct s3c_hsotg {struct usb_gadget gadget;unsigned int setup;unsigned long last_rst; +unsigned int address;struct s3c_hsotg_ep *eps; };drivers/usb/dwc2/gadget.c +5
-0@@ -1114,6 +1114,7 @@ static void s3c_hsotg_process_control(struct s3c_hsotg *hsotg, DCFG_DEVADDR_SHIFT) & DCFG_DEVADDR_MASK;writel (dcfg, hsotg->regs +DCFG ); + hsotg->address = ctrl->wValue;dev_info (hsotg->dev,"new address %d\n" , ctrl->wValue); ret =s3c_hsotg_send_reply (hsotg, ep0,NULL ,0 );@@ -2031,6 +2032,10 @@ static void s3c_hsotg_disconnect(struct s3c_hsotg *hsotg) {unsigned ep; +if (!hsotg->address) +return ; + + hsotg->address =0 ;for (ep =0 ; ep < hsotg->num_of_eps; ep++)kill_all_requests (hsotg, &hsotg->eps[ep], -ESHUTDOWN , true);@@ -2290,6 +2295,11 @@ irq_retry:dev_info (hsotg->dev,"OTGInt: %08x\n" , otgint);
drivers/usb/dwc2/gadget.c irq_retry: · line 2305
Quoted 10 lines
drivers/usb/dwc2/gadget.c +5
-0writel (otgint, hsotg->regs +GOTGINT ); + +if (otgint &GOTGINT_SES_END_DET ) { +s3c_hsotg_disconnect (hsotg); + hsotg->gadget.speed =USB_SPEED_UNKNOWN ; + } }if (gintsts &GINTSTS_SESSREQINT ) {
I don't think this is right. The host can send control requests to the device before it sends a SetAddress to change from the default address of 0. So if a GOTGINT_SES_END_DET happens before the SetAddress, it will be ignored.
Or am I missing something?
Signature · 1 line
Paul
Re: [PATCH v3] usb: dwc2/gadget: report disconnect event from 'end session' irq
Hello,
Quoted 68 lines · Paul Zimmerman
Quoted 68 lines
From: Marek Szyprowski [mailto:[email protected]]
Sent: Friday, October 31, 2014 1:04 AM
To: [email protected]; [email protected]
Cc: Marek Szyprowski; Kyungmin Park; Robert Baldyga; Paul Zimmerman; Krzysztof Kozlowski; Felipe Balbi
Subject: [PATCH v3] usb: dwc2/gadget: report disconnect event from 'end session' irqThis patch adds a call to
s3c_hsotg_disconnect()from 'end session' interrupt (GOTGINT_SES_END_DET) to correctly notify gadget subsystem about unplugged usb cable. 'disconnected' interrupt (DISCONNINT) might look a bit more suitable for this event, but it is asserted only in host mode, so in device mode we need to use something else.Additional check has been added in
s3c_hsotg_disconnect()function to ensure that the event is reported only once after successful device enumeration.Signed-off-by Marek Szyprowski <[email protected]>--- drivers/usb/dwc2/core.h | 1 + drivers/usb/dwc2/gadget.c | 10 ++++++++++ 2 files changed, 11 insertions(+)drivers/usb/dwc2/core.h +1
-0@@ -212,6 +212,7 @@ struct s3c_hsotg {struct usb_gadget gadget;unsigned int setup;unsigned long last_rst; +unsigned int address;struct s3c_hsotg_ep *eps; };drivers/usb/dwc2/gadget.c +10
-0@@ -1114,6 +1114,7 @@ static void s3c_hsotg_process_control(struct s3c_hsotg *hsotg, DCFG_DEVADDR_SHIFT) & DCFG_DEVADDR_MASK;writel (dcfg, hsotg->regs +DCFG ); + hsotg->address = ctrl->wValue;dev_info (hsotg->dev,"new address %d\n" , ctrl->wValue); ret =s3c_hsotg_send_reply (hsotg, ep0,NULL ,0 );@@ -2031,6 +2032,10 @@ static void s3c_hsotg_disconnect(struct s3c_hsotg *hsotg) {unsigned ep; +if (!hsotg->address) +return ; + + hsotg->address =0 ;for (ep =0 ; ep < hsotg->num_of_eps; ep++)kill_all_requests (hsotg, &hsotg->eps[ep], -ESHUTDOWN , true);@@ -2290,6 +2295,11 @@ irq_retry:dev_info (hsotg->dev,"OTGInt: %08x\n" , otgint);writel (otgint, hsotg->regs +GOTGINT ); + +if (otgint &GOTGINT_SES_END_DET ) { +s3c_hsotg_disconnect (hsotg); + hsotg->gadget.speed =USB_SPEED_UNKNOWN ; + } }
Quoted 7 lines
drivers/usb/dwc2/gadget.c irq_retry: · line 2305
Quoted 1 line
drivers/usb/dwc2/gadget.c +0
-0if (gintsts &GINTSTS_SESSREQINT ) {I don't think this is right. The host can send control requests to the device before it sends a SetAddress to change from the default address of 0. So if a
GOTGINT_SES_END_DEThappens before the SetAddress, it will be ignored.Or am I missing something?
Well, right. However before finishing enumeration (setting the address) host usually only retrieves some usb descriptors what doesn't change the state of the gadget. Right now we always reported 'disconnected' event before setting the new address, what is a bit overkill (in some cases gadget driver got this even more than once). The above code handles all cases correctly and reports disconnect event only once.
Best regards
Signature · 2 lines
Marek Szyprowski, PhD Samsung R&D Institute Poland
A message that is not in the archive (sent off-list or not yet received): [email protected]
RE: [PATCH v3] usb: dwc2/gadget: report disconnect event from 'end session' irq
PiBGcm9tOiBNYXJlayBTenlwcm93c2tpIFttYWlsdG86bS5zenlwcm93c2tpQHNhbXN1bmcuY29t XQ0KPiBTZW50OiBUaHVyc2RheSwgTm92ZW1iZXIgMTMsIDIwMTQgNTo0MCBBTQ0KPiANCj4gT24g MjAxNC0xMC0zMSAxOToxNSwgUGF1bCBaaW1tZXJtYW4gd3JvdGU6DQo+ID4+IEZyb206IE1hcmVr IFN6eXByb3dza2kgW21haWx0bzptLnN6eXByb3dza2lAc2Ftc3VuZy5jb21dDQo+ID4+IFNlbnQ6 IEZyaWRheSwgT2N0b2JlciAzMSwgMjAxNCAxOjA0IEFNDQo+ID4+IFRvOiBsaW51eC11c2JAdmdl ci5rZXJuZWwub3JnOyBsaW51eC1zYW1zdW5nLXNvY0B2Z2VyLmtlcm5lbC5vcmcNCj4gPj4gQ2M6 IE1hcmVrIFN6eXByb3dza2k7IEt5dW5nbWluIFBhcms7IFJvYmVydCBCYWxkeWdhOyBQYXVsIFpp bW1lcm1hbjsgS3J6eXN6dG9mIEtvemxvd3NraTsgRmVsaXBlDQo+IEJhbGJpDQo+ID4+IFN1Ympl Y3Q6IFtQQVRDSCB2M10gdXNiOiBkd2MyL2dhZGdldDogcmVwb3J0IGRpc2Nvbm5lY3QgZXZlbnQg ZnJvbSAnZW5kIHNlc3Npb24nIGlycQ0KPiA+Pg0KPiA+PiBUaGlzIHBhdGNoIGFkZHMgYSBjYWxs IHRvIHMzY19oc290Z19kaXNjb25uZWN0KCkgZnJvbSAnZW5kIHNlc3Npb24nDQo+ID4+IGludGVy cnVwdCAoR09UR0lOVF9TRVNfRU5EX0RFVCkgdG8gY29ycmVjdGx5IG5vdGlmeSBnYWRnZXQgc3Vi c3lzdGVtDQo+ID4+IGFib3V0IHVucGx1Z2dlZCB1c2IgY2FibGUuICdkaXNjb25uZWN0ZWQnIGlu dGVycnVwdCAoRElTQ09OTklOVCkgbWlnaHQNCj4gPj4gbG9vayBhIGJpdCBtb3JlIHN1aXRhYmxl IGZvciB0aGlzIGV2ZW50LCBidXQgaXQgaXMgYXNzZXJ0ZWQgb25seSBpbg0KPiA+PiBob3N0IG1v ZGUsIHNvIGluIGRldmljZSBtb2RlIHdlIG5lZWQgdG8gdXNlIHNvbWV0aGluZyBlbHNlLg0KPiA+ Pg0KPiA+PiBBZGRpdGlvbmFsIGNoZWNrIGhhcyBiZWVuIGFkZGVkIGluIHMzY19oc290Z19kaXNj b25uZWN0KCkgZnVuY3Rpb24NCj4gPj4gdG8gZW5zdXJlIHRoYXQgdGhlIGV2ZW50IGlzIHJlcG9y dGVkIG9ubHkgb25jZSBhZnRlciBzdWNjZXNzZnVsIGRldmljZQ0KPiA+PiBlbnVtZXJhdGlvbi4N Cj4gPj4NCj4gPj4gU2lnbmVkLW9mZi1ieTogTWFyZWsgU3p5cHJvd3NraSA8bS5zenlwcm93c2tp QHNhbXN1bmcuY29tPg0KPiA+PiAtLS0NCj4gPj4gICBkcml2ZXJzL3VzYi9kd2MyL2NvcmUuaCAg IHwgIDEgKw0KPiA+PiAgIGRyaXZlcnMvdXNiL2R3YzIvZ2FkZ2V0LmMgfCAxMCArKysrKysrKysr DQo+ID4+ICAgMiBmaWxlcyBjaGFuZ2VkLCAxMSBpbnNlcnRpb25zKCspDQo+ID4+DQo+ID4+IGRp ZmYgLS1naXQgYS9kcml2ZXJzL3VzYi9kd2MyL2NvcmUuaCBiL2RyaXZlcnMvdXNiL2R3YzIvY29y ZS5oDQo+ID4+IGluZGV4IDU1YzkwYzUzZjJkNi4uYjQyZGYzMmU3NzM3IDEwMDY0NA0KPiA+PiAt LS0gYS9kcml2ZXJzL3VzYi9kd2MyL2NvcmUuaA0KPiA+PiArKysgYi9kcml2ZXJzL3VzYi9kd2My L2NvcmUuaA0KPiA+PiBAQCAtMjEyLDYgKzIxMiw3IEBAIHN0cnVjdCBzM2NfaHNvdGcgew0KPiA+ PiAgIAlzdHJ1Y3QgdXNiX2dhZGdldCAgICAgICBnYWRnZXQ7DQo+ID4+ICAgCXVuc2lnbmVkIGlu dCAgICAgICAgICAgIHNldHVwOw0KPiA+PiAgIAl1bnNpZ25lZCBsb25nICAgICAgICAgICBsYXN0 X3JzdDsNCj4gPj4gKwl1bnNpZ25lZCBpbnQJCWFkZHJlc3M7DQo+ID4+ICAgCXN0cnVjdCBzM2Nf aHNvdGdfZXAgICAgICplcHM7DQo+ID4+ICAgfTsNCj4gPj4NCj4gPj4gZGlmZiAtLWdpdCBhL2Ry aXZlcnMvdXNiL2R3YzIvZ2FkZ2V0LmMgYi9kcml2ZXJzL3VzYi9kd2MyL2dhZGdldC5jDQo+ID4+ IGluZGV4IGZjZDJiYjU1Y2NjYS4uNjMwNGVmYmExMWFhIDEwMDY0NA0KPiA+PiAtLS0gYS9kcml2 ZXJzL3VzYi9kd2MyL2dhZGdldC5jDQo+ID4+ICsrKyBiL2RyaXZlcnMvdXNiL2R3YzIvZ2FkZ2V0 LmMNCj4gPj4gQEAgLTExMTQsNiArMTExNCw3IEBAIHN0YXRpYyB2b2lkIHMzY19oc290Z19wcm9j ZXNzX2NvbnRyb2woc3RydWN0IHMzY19oc290ZyAqaHNvdGcsDQo+ID4+ICAgCQkJCSBEQ0ZHX0RF VkFERFJfU0hJRlQpICYgRENGR19ERVZBRERSX01BU0s7DQo+ID4+ICAgCQkJd3JpdGVsKGRjZmcs IGhzb3RnLT5yZWdzICsgRENGRyk7DQo+ID4+DQo+ID4+ICsJCQloc290Zy0+YWRkcmVzcyA9IGN0 cmwtPndWYWx1ZTsNCj4gPj4gICAJCQlkZXZfaW5mbyhoc290Zy0+ZGV2LCAibmV3IGFkZHJlc3Mg JWRcbiIsIGN0cmwtPndWYWx1ZSk7DQo+ID4+DQo+ID4+ICAgCQkJcmV0ID0gczNjX2hzb3RnX3Nl bmRfcmVwbHkoaHNvdGcsIGVwMCwgTlVMTCwgMCk7DQo+ID4+IEBAIC0yMDMxLDYgKzIwMzIsMTAg QEAgc3RhdGljIHZvaWQgczNjX2hzb3RnX2Rpc2Nvbm5lY3Qoc3RydWN0IHMzY19oc290ZyAqaHNv dGcpDQo+ID4+ICAgew0KPiA+PiAgIAl1bnNpZ25lZCBlcDsNCj4gPj4NCj4gPj4gKwlpZiAoIWhz b3RnLT5hZGRyZXNzKQ0KPiA+PiArCQlyZXR1cm47DQo+ID4+ICsNCj4gPj4gKwloc290Zy0+YWRk cmVzcyA9IDA7DQo+ID4+ICAgCWZvciAoZXAgPSAwOyBlcCA8IGhzb3RnLT5udW1fb2ZfZXBzOyBl cCsrKQ0KPiA+PiAgIAkJa2lsbF9hbGxfcmVxdWVzdHMoaHNvdGcsICZoc290Zy0+ZXBzW2VwXSwg LUVTSFVURE9XTiwgdHJ1ZSk7DQo+ID4+DQo+ID4+IEBAIC0yMjkwLDYgKzIyOTUsMTEgQEAgaXJx X3JldHJ5Og0KPiA+PiAgIAkJZGV2X2luZm8oaHNvdGctPmRldiwgIk9UR0ludDogJTA4eFxuIiwg b3RnaW50KTsNCj4gPj4NCj4gPj4gICAJCXdyaXRlbChvdGdpbnQsIGhzb3RnLT5yZWdzICsgR09U R0lOVCk7DQo+ID4+ICsNCj4gPj4gKwkJaWYgKG90Z2ludCAmIEdPVEdJTlRfU0VTX0VORF9ERVQp IHsNCj4gPj4gKwkJCXMzY19oc290Z19kaXNjb25uZWN0KGhzb3RnKTsNCj4gPj4gKwkJCWhzb3Rn LT5nYWRnZXQuc3BlZWQgPSBVU0JfU1BFRURfVU5LTk9XTjsNCj4gPj4gKwkJfQ0KPiA+PiAgIAl9 DQo+ID4+DQo+ID4+ICAgCWlmIChnaW50c3RzICYgR0lOVFNUU19TRVNTUkVRSU5UKSB7DQo+ID4g SSBkb24ndCB0aGluayB0aGlzIGlzIHJpZ2h0LiBUaGUgaG9zdCBjYW4gc2VuZCBjb250cm9sIHJl cXVlc3RzIHRvDQo+ID4gdGhlIGRldmljZSBiZWZvcmUgaXQgc2VuZHMgYSBTZXRBZGRyZXNzIHRv IGNoYW5nZSBmcm9tIHRoZSBkZWZhdWx0DQo+ID4gYWRkcmVzcyBvZiAwLiBTbyBpZiBhIEdPVEdJ TlRfU0VTX0VORF9ERVQgaGFwcGVucyBiZWZvcmUgdGhlDQo+ID4gU2V0QWRkcmVzcywgaXQgd2ls bCBiZSBpZ25vcmVkLg0KPiA+DQo+ID4gT3IgYW0gSSBtaXNzaW5nIHNvbWV0aGluZz8NCj4gDQo+ IFdlbGwsIHJpZ2h0LiBIb3dldmVyIGJlZm9yZSBmaW5pc2hpbmcgZW51bWVyYXRpb24gKHNldHRp bmcgdGhlIGFkZHJlc3MpDQo+IGhvc3QgdXN1YWxseQ0KPiBvbmx5IHJldHJpZXZlcyBzb21lIHVz YiBkZXNjcmlwdG9ycyB3aGF0IGRvZXNuJ3QgY2hhbmdlIHRoZSBzdGF0ZSBvZiB0aGUNCj4gZ2Fk Z2V0Lg0KPiBSaWdodCBub3cgd2UgYWx3YXlzIHJlcG9ydGVkICdkaXNjb25uZWN0ZWQnIGV2ZW50 IGJlZm9yZSBzZXR0aW5nIHRoZSBuZXcNCj4gYWRkcmVzcywNCj4gd2hhdCBpcyBhIGJpdCBvdmVy a2lsbCAoaW4gc29tZSBjYXNlcyBnYWRnZXQgZHJpdmVyIGdvdCB0aGlzIGV2ZW4gbW9yZQ0KPiB0 aGFuIG9uY2UpLg0KPiBUaGUgYWJvdmUgY29kZSBoYW5kbGVzIGFsbCBjYXNlcyBjb3JyZWN0bHkg YW5kIHJlcG9ydHMgZGlzY29ubmVjdCBldmVudA0KPiBvbmx5IG9uY2UuDQoNCldlbGwsIGlmIHRo ZSBkaXNjb25uZWN0IGhhcHBlbnMgYmVmb3JlIHRoZSBTZXRBZGRyZXNzLCB0aGUgZGlzY29ubmVj dA0Kd29uJ3QgYmUgcmVwb3J0ZWQgYXQgYWxsLiBVbmxlc3MgSSdtIHJlYWRpbmcgdGhlIGNvZGUg d3JvbmcuDQoNCi0tIA0KUGF1bA0KDQo=
--
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
Re: [PATCH v3] usb: dwc2/gadget: report disconnect event from 'end session' irq
Quoted 90 lines · Paul Zimmerman
Quoted 80 lines
From: Marek Szyprowski [mailto:[email protected]]
Sent: Thursday, November 13, 2014 5:40 AMQuoted 4 lines · Paul Zimmerman
Quoted 4 lines
From: Marek Szyprowski [mailto:[email protected]]
Sent: Friday, October 31, 2014 1:04 AM
To: [email protected]; [email protected]
Cc: Marek Szyprowski; Kyungmin Park; Robert Baldyga; Paul Zimmerman; Krzysztof Kozlowski; FelipeBalbi
Quoted 64 lines
Quoted 64 lines
Subject: [PATCH v3] usb: dwc2/gadget: report disconnect event from 'end session' irq
This patch adds a call to
s3c_hsotg_disconnect()from 'end session' interrupt (GOTGINT_SES_END_DET) to correctly notify gadget subsystem about unplugged usb cable. 'disconnected' interrupt (DISCONNINT) might look a bit more suitable for this event, but it is asserted only in host mode, so in device mode we need to use something else.Additional check has been added in
s3c_hsotg_disconnect()function to ensure that the event is reported only once after successful device enumeration.Signed-off-by Marek Szyprowski <[email protected]>--- drivers/usb/dwc2/core.h | 1 + drivers/usb/dwc2/gadget.c | 10 ++++++++++ 2 files changed, 11 insertions(+)drivers/usb/dwc2/core.h +1
-0@@ -212,6 +212,7 @@ struct s3c_hsotg {struct usb_gadget gadget;unsigned int setup;unsigned long last_rst; +unsigned int address;struct s3c_hsotg_ep *eps; };drivers/usb/dwc2/gadget.c +10
-0@@ -1114,6 +1114,7 @@ static void s3c_hsotg_process_control(struct s3c_hsotg *hsotg, DCFG_DEVADDR_SHIFT) & DCFG_DEVADDR_MASK;writel (dcfg, hsotg->regs +DCFG ); + hsotg->address = ctrl->wValue;dev_info (hsotg->dev,"new address %d\n" , ctrl->wValue); ret =s3c_hsotg_send_reply (hsotg, ep0,NULL ,0 );@@ -2031,6 +2032,10 @@ static void s3c_hsotg_disconnect(struct s3c_hsotg *hsotg) {unsigned ep; +if (!hsotg->address) +return ; + + hsotg->address =0 ;for (ep =0 ; ep < hsotg->num_of_eps; ep++)kill_all_requests (hsotg, &hsotg->eps[ep], -ESHUTDOWN , true);@@ -2290,6 +2295,11 @@ irq_retry:dev_info (hsotg->dev,"OTGInt: %08x\n" , otgint);writel (otgint, hsotg->regs +GOTGINT ); + +if (otgint &GOTGINT_SES_END_DET ) { +s3c_hsotg_disconnect (hsotg); + hsotg->gadget.speed =USB_SPEED_UNKNOWN ; + } }Quoted 7 lines
drivers/usb/dwc2/gadget.c irq_retry: · line 2305
Quoted 1 line
drivers/usb/dwc2/gadget.c +0
-0if (gintsts &GINTSTS_SESSREQINT ) {I don't think this is right. The host can send control requests to the device before it sends a SetAddress to change from the default address of 0. So if a
GOTGINT_SES_END_DEThappens before the SetAddress, it will be ignored.Or am I missing something?
Quoted 10 lines
Well, right. However before finishing enumeration (setting the address) host usually
only retrieves some usb descriptors what doesn't change the state of the gadget.
Right now we always reported 'disconnected' event before setting the new address,
what is a bit overkill (in some cases gadget driver got this even more than once).
The above code handles all cases correctly and reports disconnect event only once.
Quoted 2 lines
Well, if the disconnect happens before the SetAddress, the disconnect won't be reported at all. Unless I'm reading the code wrong.
Right, although this is not really an issue for any gadget driver. However if you prefer to report disconnect event more than once, I'm okay and I will remove the check based on the device address.
Best regards
Signature · 2 lines
Marek Szyprowski, PhD Samsung R&D Institute Poland
Re: [PATCH v3] usb: dwc2/gadget: report disconnect event from 'end session' irq
In reply to Paul ZimmermanHello,
Quoted 90 lines · Paul Zimmerman
Quoted 80 lines
From: Marek Szyprowski [mailto:[email protected]]
Sent: Thursday, November 13, 2014 5:40 AMQuoted 4 lines · Paul Zimmerman
Quoted 4 lines
From: Marek Szyprowski [mailto:[email protected]]
Sent: Friday, October 31, 2014 1:04 AM
To: [email protected]; [email protected]
Cc: Marek Szyprowski; Kyungmin Park; Robert Baldyga; Paul Zimmerman; Krzysztof Kozlowski; FelipeBalbi
Quoted 64 lines
Quoted 64 lines
Subject: [PATCH v3] usb: dwc2/gadget: report disconnect event from 'end session' irq
This patch adds a call to
s3c_hsotg_disconnect()from 'end session' interrupt (GOTGINT_SES_END_DET) to correctly notify gadget subsystem about unplugged usb cable. 'disconnected' interrupt (DISCONNINT) might look a bit more suitable for this event, but it is asserted only in host mode, so in device mode we need to use something else.Additional check has been added in
s3c_hsotg_disconnect()function to ensure that the event is reported only once after successful device enumeration.Signed-off-by Marek Szyprowski <[email protected]>--- drivers/usb/dwc2/core.h | 1 + drivers/usb/dwc2/gadget.c | 10 ++++++++++ 2 files changed, 11 insertions(+)drivers/usb/dwc2/core.h +1
-0@@ -212,6 +212,7 @@ struct s3c_hsotg {struct usb_gadget gadget;unsigned int setup;unsigned long last_rst; +unsigned int address;struct s3c_hsotg_ep *eps; };drivers/usb/dwc2/gadget.c +10
-0@@ -1114,6 +1114,7 @@ static void s3c_hsotg_process_control(struct s3c_hsotg *hsotg, DCFG_DEVADDR_SHIFT) & DCFG_DEVADDR_MASK;writel (dcfg, hsotg->regs +DCFG ); + hsotg->address = ctrl->wValue;dev_info (hsotg->dev,"new address %d\n" , ctrl->wValue); ret =s3c_hsotg_send_reply (hsotg, ep0,NULL ,0 );@@ -2031,6 +2032,10 @@ static void s3c_hsotg_disconnect(struct s3c_hsotg *hsotg) {unsigned ep; +if (!hsotg->address) +return ; + + hsotg->address =0 ;for (ep =0 ; ep < hsotg->num_of_eps; ep++)kill_all_requests (hsotg, &hsotg->eps[ep], -ESHUTDOWN , true);@@ -2290,6 +2295,11 @@ irq_retry:dev_info (hsotg->dev,"OTGInt: %08x\n" , otgint);writel (otgint, hsotg->regs +GOTGINT ); + +if (otgint &GOTGINT_SES_END_DET ) { +s3c_hsotg_disconnect (hsotg); + hsotg->gadget.speed =USB_SPEED_UNKNOWN ; + } }Quoted 7 lines
drivers/usb/dwc2/gadget.c irq_retry: · line 2305
Quoted 1 line
drivers/usb/dwc2/gadget.c +0
-0if (gintsts &GINTSTS_SESSREQINT ) {I don't think this is right. The host can send control requests to the device before it sends a SetAddress to change from the default address of 0. So if a
GOTGINT_SES_END_DEThappens before the SetAddress, it will be ignored.Or am I missing something?
Quoted 10 lines
Well, right. However before finishing enumeration (setting the address) host usually
only retrieves some usb descriptors what doesn't change the state of the gadget.
Right now we always reported 'disconnected' event before setting the new address,
what is a bit overkill (in some cases gadget driver got this even more than once).
The above code handles all cases correctly and reports disconnect event only once.
Quoted 2 lines
Well, if the disconnect happens before the SetAddress, the disconnect won't be reported at all. Unless I'm reading the code wrong.
Ok, I found other way to ensure that disconnect event is reported only once. I will post a patch in a few minutes.
Best regards
Signature · 2 lines
Marek Szyprowski, PhD Samsung R&D Institute Poland
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH v4 1/1 usb: dwc2/gadget: rework disconnect event handling
This patch adds a call to s3c_hsotg_disconnect() from 'end session' interrupt (GOTGINT_SES_END_DET) to correctly notify gadget subsystem about unplugged usb cable. DISCONNINT interrupt cannot be used for this purpose, because it is asserted only in host mode.
To avoid reporting disconnect event more than once, a disconnect call has been moved from USB_REQ_SET_ADDRESS handling function to SESSREQINT interrupt. This way driver ensures that disconnect event is reported either when usb cable is unplugged or every time the host starts a new session.
--- drivers/usb/dwc2/core.h | 1 + drivers/usb/dwc2/gadget.c | 13 +++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-)
drivers/usb/dwc2/core.h +1 -0
@@ -210,6 +210,7 @@ struct s3c_hsotg {u8 ctrl_buff[8 ];struct usb_gadget gadget; + unsigned int session:1;unsigned int setup;unsigned long last_rst;struct s3c_hsotg_ep *eps;
drivers/usb/dwc2/gadget.c +11 -2
@@ -1029,7 +1029,6 @@ static int s3c_hsotg_process_req_feature(struct s3c_hsotg *hsotg, }static void s3c_hsotg_enqueue_setup (struct s3c_hsotg *hsotg); -static void s3c_hsotg_disconnect (struct s3c_hsotg *hsotg);/** * s3c_hsotg_stall_ep0 - stall ep0
@@ -1107,7 +1106,6 @@ static void s3c_hsotg_process_control(struct s3c_hsotg *hsotg,if ((ctrl->bRequestType &USB_TYPE_MASK ) ==USB_TYPE_STANDARD ) {switch (ctrl->bRequest) {case USB_REQ_SET_ADDRESS : -s3c_hsotg_disconnect (hsotg); dcfg =readl (hsotg->regs +DCFG ); dcfg &= ~DCFG_DEVADDR_MASK ; dcfg |= (le16_to_cpu(ctrl->wValue) <<
@@ -2031,6 +2029,10 @@ static void s3c_hsotg_disconnect(struct s3c_hsotg *hsotg) {unsigned ep; +if (!hsotg->session) +return ; + + hsotg->session =0 ;for (ep =0 ; ep < hsotg->num_of_eps; ep++)kill_all_requests (hsotg, &hsotg->eps[ep], -ESHUTDOWN , true);
@@ -2290,11 +2292,18 @@ irq_retry:dev_info (hsotg->dev,"OTGInt: %08x\n" , otgint);writel (otgint, hsotg->regs +GOTGINT ); + +if (otgint &GOTGINT_SES_END_DET ) { +s3c_hsotg_disconnect (hsotg); + hsotg->gadget.speed =USB_SPEED_UNKNOWN ; + } }if (gintsts &GINTSTS_SESSREQINT ) {dev_dbg (hsotg->dev,"%s: SessReqInt\n" , __func__);writel (GINTSTS_SESSREQINT , hsotg->regs +GINTSTS ); +s3c_hsotg_disconnect (hsotg); + hsotg->session =1 ; }if (gintsts &GINTSTS_ENUMDONE ) {
Signature · 6 lines
1.9.2 -- 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
A message that is not in the archive (sent off-list or not yet received): 1415967607-6174-1-git-send-email-m.szyprowski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org
RE: [PATCH v4] usb: dwc2/gadget: rework disconnect event handling
Quoted 65 lines
-----Original Message-----
From: Marek Szyprowski [mailto:[email protected]]
Sent: Friday, November 14, 2014 4:20 AMThis patch adds a call to
s3c_hsotg_disconnect()from 'end session' interrupt (GOTGINT_SES_END_DET) to correctly notify gadget subsystem about unplugged usb cable. DISCONNINT interrupt cannot be used for this purpose, because it is asserted only in host mode.To avoid reporting disconnect event more than once, a disconnect call has been moved from
USB_REQ_SET_ADDRESShandling function to SESSREQINT interrupt. This way driver ensures that disconnect event is reported either when usb cable is unplugged or every time the host starts a new session.Signed-off-by Marek Szyprowski <[email protected]>--- drivers/usb/dwc2/core.h | 1 + drivers/usb/dwc2/gadget.c | 13 +++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-)drivers/usb/dwc2/core.h +1
-0@@ -210,6 +210,7 @@ struct s3c_hsotg {u8 ctrl_buff[8 ];struct usb_gadget gadget; + unsigned int session:1;unsigned int setup;unsigned long last_rst;struct s3c_hsotg_ep *eps;drivers/usb/dwc2/gadget.c +4
-2@@ -1029,7 +1029,6 @@ static int s3c_hsotg_process_req_feature(struct s3c_hsotg *hsotg, }static void s3c_hsotg_enqueue_setup (struct s3c_hsotg *hsotg); -static void s3c_hsotg_disconnect (struct s3c_hsotg *hsotg);/** * s3c_hsotg_stall_ep0 - stall ep0 @@ -1107,7 +1106,6 @@ static void s3c_hsotg_process_control(struct s3c_hsotg *hsotg,if ((ctrl->bRequestType &USB_TYPE_MASK ) ==USB_TYPE_STANDARD ) {switch (ctrl->bRequest) {case USB_REQ_SET_ADDRESS : -s3c_hsotg_disconnect (hsotg); dcfg =readl (hsotg->regs +DCFG ); dcfg &= ~DCFG_DEVADDR_MASK ; dcfg |= (le16_to_cpu(ctrl->wValue) <<@@ -2031,6 +2029,10 @@ static void s3c_hsotg_disconnect(struct s3c_hsotg *hsotg) {unsigned ep; +if (!hsotg->session) +return ; + + hsotg->session =0 ;for (ep =0 ; ep < hsotg->num_of_eps; ep++)kill_all_requests (hsotg, &hsotg->eps[ep], -ESHUTDOWN , true);
drivers/usb/dwc2/gadget.c irq_retry: · line 2297
Quoted 6 lines
drivers/usb/dwc2/gadget.c +3
-0@@ -2290,11 +2292,18 @@ irq_retry:dev_info (hsotg->dev,"OTGInt: %08x\n" , otgint);writel (otgint, hsotg->regs +GOTGINT ); + +if (otgint &GOTGINT_SES_END_DET ) { +s3c_hsotg_disconnect (hsotg);
I think you should clear hsotg->session here, shouldn't you? Otherwise I think s3c_hsotg_disconnect() will be called twice, once here and once when the next GINTSTS_SESSREQINT comes.
Signature · 1 line
Paul
Quoted 13 lines
drivers/usb/dwc2/gadget.c +4
-1+ hsotg->gadget.speed =USB_SPEED_UNKNOWN ; + } }if (gintsts &GINTSTS_SESSREQINT ) {dev_dbg (hsotg->dev,"%s: SessReqInt\n" , __func__);writel (GINTSTS_SESSREQINT , hsotg->regs +GINTSTS ); +s3c_hsotg_disconnect (hsotg); + hsotg->session =1 ; }if (gintsts &GINTSTS_ENUMDONE ) { --
Quoted 1 line
1.9.2
--
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
Re: [PATCH v4] usb: dwc2/gadget: rework disconnect event handling
Quoted 67 lines · Paul Zimmerman
Quoted 67 lines
-----Original Message-----
From: Marek Szyprowski [mailto:[email protected]]
Sent: Friday, November 14, 2014 4:20 AMThis patch adds a call to
s3c_hsotg_disconnect()from 'end session' interrupt (GOTGINT_SES_END_DET) to correctly notify gadget subsystem about unplugged usb cable. DISCONNINT interrupt cannot be used for this purpose, because it is asserted only in host mode.To avoid reporting disconnect event more than once, a disconnect call has been moved from
USB_REQ_SET_ADDRESShandling function to SESSREQINT interrupt. This way driver ensures that disconnect event is reported either when usb cable is unplugged or every time the host starts a new session.Signed-off-by Marek Szyprowski <[email protected]>--- drivers/usb/dwc2/core.h | 1 + drivers/usb/dwc2/gadget.c | 13 +++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-)drivers/usb/dwc2/core.h +1
-0@@ -210,6 +210,7 @@ struct s3c_hsotg {u8 ctrl_buff[8 ];struct usb_gadget gadget; + unsigned int session:1;unsigned int setup;unsigned long last_rst;struct s3c_hsotg_ep *eps;drivers/usb/dwc2/gadget.c +4
-2@@ -1029,7 +1029,6 @@ static int s3c_hsotg_process_req_feature(struct s3c_hsotg *hsotg, }static void s3c_hsotg_enqueue_setup (struct s3c_hsotg *hsotg); -static void s3c_hsotg_disconnect (struct s3c_hsotg *hsotg);/** * s3c_hsotg_stall_ep0 - stall ep0 @@ -1107,7 +1106,6 @@ static void s3c_hsotg_process_control(struct s3c_hsotg *hsotg,if ((ctrl->bRequestType &USB_TYPE_MASK ) ==USB_TYPE_STANDARD ) {switch (ctrl->bRequest) {case USB_REQ_SET_ADDRESS : -s3c_hsotg_disconnect (hsotg); dcfg =readl (hsotg->regs +DCFG ); dcfg &= ~DCFG_DEVADDR_MASK ; dcfg |= (le16_to_cpu(ctrl->wValue) <<@@ -2031,6 +2029,10 @@ static void s3c_hsotg_disconnect(struct s3c_hsotg *hsotg) {unsigned ep; +if (!hsotg->session) +return ; + + hsotg->session =0 ;for (ep =0 ; ep < hsotg->num_of_eps; ep++)kill_all_requests (hsotg, &hsotg->eps[ep], -ESHUTDOWN , true);@@ -2290,11 +2292,18 @@ irq_retry:dev_info (hsotg->dev,"OTGInt: %08x\n" , otgint);
Quoted 8 lines
drivers/usb/dwc2/gadget.c irq_retry: · line 2297
Quoted 4 lines
drivers/usb/dwc2/gadget.c +3
-0writel (otgint, hsotg->regs +GOTGINT ); + +if (otgint &GOTGINT_SES_END_DET ) { +s3c_hsotg_disconnect (hsotg);I think you should clear
hsotg->sessionhere, shouldn't you? Otherwise I thinks3c_hsotg_disconnect()will be called twice, once here and once when the nextGINTSTS_SESSREQINTcomes.
the best way to avoid that would be fiddle with hsotg->session inside s3c_hsotg_disconnect() only.
Signature · 1 line
balbi
Paul Zimmerman
Acked-byRE: [PATCH v4] usb: dwc2/gadget: rework disconnect event handling
Quoted 80 lines
From: [email protected] [mailto:[email protected]] On Behalf Of Felipe Balbi
Sent: Friday, November 14, 2014 11:05 AMQuoted 67 lines · Paul Zimmerman
Quoted 67 lines
-----Original Message-----
From: Marek Szyprowski [mailto:[email protected]]
Sent: Friday, November 14, 2014 4:20 AMThis patch adds a call to
s3c_hsotg_disconnect()from 'end session' interrupt (GOTGINT_SES_END_DET) to correctly notify gadget subsystem about unplugged usb cable. DISCONNINT interrupt cannot be used for this purpose, because it is asserted only in host mode.To avoid reporting disconnect event more than once, a disconnect call has been moved from
USB_REQ_SET_ADDRESShandling function to SESSREQINT interrupt. This way driver ensures that disconnect event is reported either when usb cable is unplugged or every time the host starts a new session.Signed-off-by Marek Szyprowski <[email protected]>--- drivers/usb/dwc2/core.h | 1 + drivers/usb/dwc2/gadget.c | 13 +++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-)drivers/usb/dwc2/core.h +1
-0@@ -210,6 +210,7 @@ struct s3c_hsotg {u8 ctrl_buff[8 ];struct usb_gadget gadget; + unsigned int session:1;unsigned int setup;unsigned long last_rst;struct s3c_hsotg_ep *eps;drivers/usb/dwc2/gadget.c +4
-2@@ -1029,7 +1029,6 @@ static int s3c_hsotg_process_req_feature(struct s3c_hsotg *hsotg, }static void s3c_hsotg_enqueue_setup (struct s3c_hsotg *hsotg); -static void s3c_hsotg_disconnect (struct s3c_hsotg *hsotg);/** * s3c_hsotg_stall_ep0 - stall ep0 @@ -1107,7 +1106,6 @@ static void s3c_hsotg_process_control(struct s3c_hsotg *hsotg,if ((ctrl->bRequestType &USB_TYPE_MASK ) ==USB_TYPE_STANDARD ) {switch (ctrl->bRequest) {case USB_REQ_SET_ADDRESS : -s3c_hsotg_disconnect (hsotg); dcfg =readl (hsotg->regs +DCFG ); dcfg &= ~DCFG_DEVADDR_MASK ; dcfg |= (le16_to_cpu(ctrl->wValue) <<@@ -2031,6 +2029,10 @@ static void s3c_hsotg_disconnect(struct s3c_hsotg *hsotg) {unsigned ep; +if (!hsotg->session) +return ; + + hsotg->session =0 ;for (ep =0 ; ep < hsotg->num_of_eps; ep++)kill_all_requests (hsotg, &hsotg->eps[ep], -ESHUTDOWN , true);@@ -2290,11 +2292,18 @@ irq_retry:dev_info (hsotg->dev,"OTGInt: %08x\n" , otgint);Quoted 8 lines
drivers/usb/dwc2/gadget.c irq_retry: · line 2297
Quoted 4 lines
drivers/usb/dwc2/gadget.c +3
-0writel (otgint, hsotg->regs +GOTGINT ); + +if (otgint &GOTGINT_SES_END_DET ) { +s3c_hsotg_disconnect (hsotg);I think you should clear
hsotg->sessionhere, shouldn't you? Otherwise I thinks3c_hsotg_disconnect()will be called twice, once here and once when the nextGINTSTS_SESSREQINTcomes.
Quoted 2 lines
the best way to avoid that would be fiddle with
hsotg->sessioninsides3c_hsotg_disconnect()only.
Whoops, I just noticed that hsotg->session *is* cleared inside of s3c_hsotg_disconnect(). So I think the patch is good as-is.
RE: [PATCH v4] usb: dwc2/gadget: rework disconnect event handling
In reply to Felipe BalbiQuoted 83 lines
From: Paul Zimmerman
Sent: Friday, November 14, 2014 1:21 PMQuoted 80 lines
From: [email protected] [mailto:[email protected]] On Behalf Of Felipe Balbi
Sent: Friday, November 14, 2014 11:05 AMQuoted 75 lines · Paul Zimmerman
Quoted 65 lines
-----Original Message-----
From: Marek Szyprowski [mailto:[email protected]]
Sent: Friday, November 14, 2014 4:20 AMThis patch adds a call to
s3c_hsotg_disconnect()from 'end session' interrupt (GOTGINT_SES_END_DET) to correctly notify gadget subsystem about unplugged usb cable. DISCONNINT interrupt cannot be used for this purpose, because it is asserted only in host mode.To avoid reporting disconnect event more than once, a disconnect call has been moved from
USB_REQ_SET_ADDRESShandling function to SESSREQINT interrupt. This way driver ensures that disconnect event is reported either when usb cable is unplugged or every time the host starts a new session.Signed-off-by Marek Szyprowski <[email protected]>--- drivers/usb/dwc2/core.h | 1 + drivers/usb/dwc2/gadget.c | 13 +++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-)drivers/usb/dwc2/core.h +1
-0@@ -210,6 +210,7 @@ struct s3c_hsotg {u8 ctrl_buff[8 ];struct usb_gadget gadget; + unsigned int session:1;unsigned int setup;unsigned long last_rst;struct s3c_hsotg_ep *eps;drivers/usb/dwc2/gadget.c +4
-2@@ -1029,7 +1029,6 @@ static int s3c_hsotg_process_req_feature(struct s3c_hsotg *hsotg, }static void s3c_hsotg_enqueue_setup (struct s3c_hsotg *hsotg); -static void s3c_hsotg_disconnect (struct s3c_hsotg *hsotg);/** * s3c_hsotg_stall_ep0 - stall ep0 @@ -1107,7 +1106,6 @@ static void s3c_hsotg_process_control(struct s3c_hsotg *hsotg,if ((ctrl->bRequestType &USB_TYPE_MASK ) ==USB_TYPE_STANDARD ) {switch (ctrl->bRequest) {case USB_REQ_SET_ADDRESS : -s3c_hsotg_disconnect (hsotg); dcfg =readl (hsotg->regs +DCFG ); dcfg &= ~DCFG_DEVADDR_MASK ; dcfg |= (le16_to_cpu(ctrl->wValue) <<@@ -2031,6 +2029,10 @@ static void s3c_hsotg_disconnect(struct s3c_hsotg *hsotg) {unsigned ep; +if (!hsotg->session) +return ; + + hsotg->session =0 ;for (ep =0 ; ep < hsotg->num_of_eps; ep++)kill_all_requests (hsotg, &hsotg->eps[ep], -ESHUTDOWN , true);drivers/usb/dwc2/gadget.c irq_retry: · line 2297
Quoted 6 lines
drivers/usb/dwc2/gadget.c +3
-0@@ -2290,11 +2292,18 @@ irq_retry:dev_info (hsotg->dev,"OTGInt: %08x\n" , otgint);writel (otgint, hsotg->regs +GOTGINT ); + +if (otgint &GOTGINT_SES_END_DET ) { +s3c_hsotg_disconnect (hsotg);I think you should clear
hsotg->sessionhere, shouldn't you? Otherwise I thinks3c_hsotg_disconnect()will be called twice, once here and once when the nextGINTSTS_SESSREQINTcomes.
Quoted 7 lines
Quoted 2 lines
the best way to avoid that would be fiddle with
hsotg->sessioninsides3c_hsotg_disconnect()only.Whoops, I just noticed that
hsotg->session*is* cleared inside ofs3c_hsotg_disconnect(). So I think the patch is good as-is.Acked-by Paul Zimmerman <[email protected]>
I'm having second thoughts about this. Currently, the GINTSTS_SESSREQINT interrupt in the gadget does nothing except print a debug message. So I'm not sure that all versions of the controller actually assert this interrupt when a connection is made. If they don't, then this patch would break the disconnect handling, since hsotg->session would never get set.
In particular, I'm thinking that a core which is synthesized without SRP support may not implement the GINTSTS_SESSREQINT interrupt. The databook seems to imply that:
"SessReqInt: In Device mode, this interrupt is asserted when the utmisrp_bvalid signal goes high."
And in the section which describes the utmisrp_bvalid signal, there is a note that says:
"This interface is present only when parameter OTG_MODE specifies an SRP-capable configuration."
So Marek, can you try moving the line which sets hsotg->session = 1 into s3c_hsotg_irq_enumdone() instead? Then we will be sure it gets set to one after a connect. Probably it should be renamed from 'session' to 'connect' in that case.
Signature · 1 line
Paul
Re: [PATCH v4] usb: dwc2/gadget: rework disconnect event handling
Hello,
Quoted 104 lines · Paul Zimmerman
Quoted 81 lines
From: Paul Zimmerman
Sent: Friday, November 14, 2014 1:21 PMQuoted 78 lines
From: [email protected] [mailto:[email protected]] On Behalf Of Felipe Balbi
Sent: Friday, November 14, 2014 11:05 AMQuoted 74 lines · Paul Zimmerman
Quoted 65 lines
-----Original Message-----
From: Marek Szyprowski [mailto:[email protected]]
Sent: Friday, November 14, 2014 4:20 AMThis patch adds a call to
s3c_hsotg_disconnect()from 'end session' interrupt (GOTGINT_SES_END_DET) to correctly notify gadget subsystem about unplugged usb cable. DISCONNINT interrupt cannot be used for this purpose, because it is asserted only in host mode.To avoid reporting disconnect event more than once, a disconnect call has been moved from
USB_REQ_SET_ADDRESShandling function to SESSREQINT interrupt. This way driver ensures that disconnect event is reported either when usb cable is unplugged or every time the host starts a new session.Signed-off-by Marek Szyprowski <[email protected]>--- drivers/usb/dwc2/core.h | 1 + drivers/usb/dwc2/gadget.c | 13 +++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-)drivers/usb/dwc2/core.h +1
-0@@ -210,6 +210,7 @@ struct s3c_hsotg {u8 ctrl_buff[8 ];struct usb_gadget gadget; + unsigned int session:1;unsigned int setup;unsigned long last_rst;struct s3c_hsotg_ep *eps;drivers/usb/dwc2/gadget.c +4
-2@@ -1029,7 +1029,6 @@ static int s3c_hsotg_process_req_feature(struct s3c_hsotg *hsotg, }static void s3c_hsotg_enqueue_setup (struct s3c_hsotg *hsotg); -static void s3c_hsotg_disconnect (struct s3c_hsotg *hsotg);/** * s3c_hsotg_stall_ep0 - stall ep0 @@ -1107,7 +1106,6 @@ static void s3c_hsotg_process_control(struct s3c_hsotg *hsotg,if ((ctrl->bRequestType &USB_TYPE_MASK ) ==USB_TYPE_STANDARD ) {switch (ctrl->bRequest) {case USB_REQ_SET_ADDRESS : -s3c_hsotg_disconnect (hsotg); dcfg =readl (hsotg->regs +DCFG ); dcfg &= ~DCFG_DEVADDR_MASK ; dcfg |= (le16_to_cpu(ctrl->wValue) <<@@ -2031,6 +2029,10 @@ static void s3c_hsotg_disconnect(struct s3c_hsotg *hsotg) {unsigned ep; +if (!hsotg->session) +return ; + + hsotg->session =0 ;for (ep =0 ; ep < hsotg->num_of_eps; ep++)kill_all_requests (hsotg, &hsotg->eps[ep], -ESHUTDOWN , true);drivers/usb/dwc2/gadget.c irq_retry: · line 2297
Quoted 6 lines
drivers/usb/dwc2/gadget.c +3
-0@@ -2290,11 +2292,18 @@ irq_retry:dev_info (hsotg->dev,"OTGInt: %08x\n" , otgint);writel (otgint, hsotg->regs +GOTGINT ); + +if (otgint &GOTGINT_SES_END_DET ) { +s3c_hsotg_disconnect (hsotg);I think you should clear
hsotg->sessionhere, shouldn't you? Otherwise I thinks3c_hsotg_disconnect()will be called twice, once here and once when the nextGINTSTS_SESSREQINTcomes.Quoted 6 lines
Quoted 2 lines
the best way to avoid that would be fiddle with
hsotg->sessioninsides3c_hsotg_disconnect()only.Whoops, I just noticed that
hsotg->session*is* cleared inside ofs3c_hsotg_disconnect(). So I think the patch is good as-is.Acked-by Paul Zimmerman <[email protected]>I'm having second thoughts about this. Currently, the
GINTSTS_SESSREQINTinterrupt in the gadget does nothing except print a debug message. So I'm not sure that all versions of the controller actually assert this interrupt when a connection is made. If they don't, then this patch would break the disconnect handling, sincehsotg->sessionwould never get set.In particular, I'm thinking that a core which is synthesized without SRP support may not implement the
GINTSTS_SESSREQINTinterrupt. The databook seems to imply that:"SessReqInt: In Device mode, this interrupt is asserted when the
utmisrp_bvalidsignal goes high."And in the section which describes the
utmisrp_bvalidsignal, there is a note that says:
Quoted 7 lines
"This interface is present only when parameter
OTG_MODEspecifies an SRP-capable configuration."So Marek, can you try moving the line which sets
hsotg->session= 1 intos3c_hsotg_irq_enumdone()instead? Then we will be sure it gets set to one after a connect. Probably it should be renamed from 'session' to 'connect' in that case.
Well... ok, but this will work exactly the same way as v3, which you were not keen of. I think the best way will be to keep it set both in SESSREQINT and enumdone, I will send a patch in a few minutes.
Best regards
Signature · 2 lines
Marek Szyprowski, PhD Samsung R&D Institute Poland
PATCH v5 1/1 usb: dwc2/gadget: rework disconnect event handling
This patch adds a call to s3c_hsotg_disconnect() from 'end session' interrupt (GOTGINT_SES_END_DET) to correctly notify gadget subsystem about unplugged usb cable. DISCONNINT interrupt cannot be used for this purpose, because it is asserted only in host mode.
To avoid reporting disconnect event more than once, a disconnect call has been moved from USB_REQ_SET_ADDRESS handling function to SESSREQINT interrupt. This way driver ensures that disconnect event is reported either when usb cable is unplugged or every time the host starts a new session. To handle devices which has been synthesized without SRP support, connected state is set in ENUMDONE interrupt.
--- drivers/usb/dwc2/core.h | 1 + drivers/usb/dwc2/gadget.c | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-)
drivers/usb/dwc2/core.h +1 -0
@@ -210,6 +210,7 @@ struct s3c_hsotg {u8 ctrl_buff[8 ];struct usb_gadget gadget; + unsigned int connected:1;unsigned int setup;unsigned long last_rst;struct s3c_hsotg_ep *eps;
drivers/usb/dwc2/gadget.c +14 -2
@@ -1029,7 +1029,6 @@ static int s3c_hsotg_process_req_feature(struct s3c_hsotg *hsotg, }static void s3c_hsotg_enqueue_setup (struct s3c_hsotg *hsotg); -static void s3c_hsotg_disconnect (struct s3c_hsotg *hsotg);/** * s3c_hsotg_stall_ep0 - stall ep0
@@ -1107,7 +1106,6 @@ static void s3c_hsotg_process_control(struct s3c_hsotg *hsotg,if ((ctrl->bRequestType &USB_TYPE_MASK ) ==USB_TYPE_STANDARD ) {switch (ctrl->bRequest) {case USB_REQ_SET_ADDRESS : -s3c_hsotg_disconnect (hsotg); dcfg =readl (hsotg->regs +DCFG ); dcfg &= ~DCFG_DEVADDR_MASK ; dcfg |= (le16_to_cpu(ctrl->wValue) <<
@@ -2031,6 +2029,10 @@ static void s3c_hsotg_disconnect(struct s3c_hsotg *hsotg) {unsigned ep; +if (!hsotg->connected) +return ; + + hsotg->connected =0 ;for (ep =0 ; ep < hsotg->num_of_eps; ep++)kill_all_requests (hsotg, &hsotg->eps[ep], -ESHUTDOWN , true);
@@ -2290,17 +2292,27 @@ irq_retry:dev_info (hsotg->dev,"OTGInt: %08x\n" , otgint);writel (otgint, hsotg->regs +GOTGINT ); + +if (otgint &GOTGINT_SES_END_DET ) { +s3c_hsotg_disconnect (hsotg); + hsotg->gadget.speed =USB_SPEED_UNKNOWN ; + } }if (gintsts &GINTSTS_SESSREQINT ) {dev_dbg (hsotg->dev,"%s: SessReqInt\n" , __func__);writel (GINTSTS_SESSREQINT , hsotg->regs +GINTSTS ); +/* +* Report disconnect if there is any previous session established +*/ +s3c_hsotg_disconnect (hsotg); }if (gintsts &GINTSTS_ENUMDONE ) {writel (GINTSTS_ENUMDONE , hsotg->regs +GINTSTS );s3c_hsotg_irq_enumdone (hsotg); + hsotg->connected =1 ; }if (gintsts &GINTSTS_CONIDSTSCHNG ) {
Signature · 1 line
1.9.2
A message that is not in the archive (sent off-list or not yet received): 1416214782-13911-1-git-send-email-m.szyprowski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org
Paul Zimmerman
Acked-byRE: [PATCH v5] usb: dwc2/gadget: rework disconnect event handling
Quoted 82 lines
From: Marek Szyprowski [mailto:[email protected]]
Sent: Monday, November 17, 2014 1:00 AMThis patch adds a call to
s3c_hsotg_disconnect()from 'end session' interrupt (GOTGINT_SES_END_DET) to correctly notify gadget subsystem about unplugged usb cable. DISCONNINT interrupt cannot be used for this purpose, because it is asserted only in host mode.To avoid reporting disconnect event more than once, a disconnect call has been moved from
USB_REQ_SET_ADDRESShandling function to SESSREQINT interrupt. This way driver ensures that disconnect event is reported either when usb cable is unplugged or every time the host starts a new session. To handle devices which has been synthesized without SRP support, connected state is set in ENUMDONE interrupt.Signed-off-by Marek Szyprowski <[email protected]>--- drivers/usb/dwc2/core.h | 1 + drivers/usb/dwc2/gadget.c | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-)drivers/usb/dwc2/core.h +1
-0@@ -210,6 +210,7 @@ struct s3c_hsotg {u8 ctrl_buff[8 ];struct usb_gadget gadget; + unsigned int connected:1;unsigned int setup;unsigned long last_rst;struct s3c_hsotg_ep *eps;drivers/usb/dwc2/gadget.c +13
-2@@ -1029,7 +1029,6 @@ static int s3c_hsotg_process_req_feature(struct s3c_hsotg *hsotg, }static void s3c_hsotg_enqueue_setup (struct s3c_hsotg *hsotg); -static void s3c_hsotg_disconnect (struct s3c_hsotg *hsotg);/** * s3c_hsotg_stall_ep0 - stall ep0 @@ -1107,7 +1106,6 @@ static void s3c_hsotg_process_control(struct s3c_hsotg *hsotg,if ((ctrl->bRequestType &USB_TYPE_MASK ) ==USB_TYPE_STANDARD ) {switch (ctrl->bRequest) {case USB_REQ_SET_ADDRESS : -s3c_hsotg_disconnect (hsotg); dcfg =readl (hsotg->regs +DCFG ); dcfg &= ~DCFG_DEVADDR_MASK ; dcfg |= (le16_to_cpu(ctrl->wValue) <<@@ -2031,6 +2029,10 @@ static void s3c_hsotg_disconnect(struct s3c_hsotg *hsotg) {unsigned ep; +if (!hsotg->connected) +return ; + + hsotg->connected =0 ;for (ep =0 ; ep < hsotg->num_of_eps; ep++)kill_all_requests (hsotg, &hsotg->eps[ep], -ESHUTDOWN , true);@@ -2290,17 +2292,27 @@ irq_retry:dev_info (hsotg->dev,"OTGInt: %08x\n" , otgint);writel (otgint, hsotg->regs +GOTGINT ); + +if (otgint &GOTGINT_SES_END_DET ) { +s3c_hsotg_disconnect (hsotg); + hsotg->gadget.speed =USB_SPEED_UNKNOWN ; + } }if (gintsts &GINTSTS_SESSREQINT ) {dev_dbg (hsotg->dev,"%s: SessReqInt\n" , __func__);writel (GINTSTS_SESSREQINT , hsotg->regs +GINTSTS ); +/* +* Report disconnect if there is any previous session established +*/ +s3c_hsotg_disconnect (hsotg);
drivers/usb/dwc2/gadget.c irq_retry: · line 2318
Quoted 10 lines
drivers/usb/dwc2/gadget.c +1
-0}if (gintsts &GINTSTS_ENUMDONE ) {writel (GINTSTS_ENUMDONE , hsotg->regs +GINTSTS );s3c_hsotg_irq_enumdone (hsotg); + hsotg->connected =1 ; }if (gintsts &GINTSTS_CONIDSTSCHNG ) {
--
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
Re: [PATCH v5] usb: dwc2/gadget: rework disconnect event handling
In reply to Marek SzyprowskiQuoted 5 lines · Marek Szyprowski
This patch adds a call to
s3c_hsotg_disconnect()from 'end session' interrupt (GOTGINT_SES_END_DET) to correctly notify gadget subsystem about unplugged usb cable. DISCONNINT interrupt cannot be used for this purpose, because it is asserted only in host mode.
Quoted 8 lines
To avoid reporting disconnect event more than once, a disconnect call has been moved from
USB_REQ_SET_ADDRESShandling function to SESSREQINT interrupt. This way driver ensures that disconnect event is reported either when usb cable is unplugged or every time the host starts a new session. To handle devices which has been synthesized without SRP support, connected state is set in ENUMDONE interrupt.Signed-off-by Marek Szyprowski <[email protected]>
doesn't apply, please rebase on my testing/next:
checking file drivers/usb/dwc2/core.h
Hunk #1 FAILED at 210.
1 out of 1 hunk FAILED
checking file drivers/usb/dwc2/gadget.c
Hunk #1 FAILED at 1029.
Hunk #2 succeeded at 1108 (offset 1 line).
Hunk #3 succeeded at 2031 (offset 1 line).
Hunk #4 FAILED at 2293.
2 out of 4 hunks FAILED
thanks
Signature · 1 line
balbi
PATCH v2 5/10 usb: dwc2/gadget: move setting last reset time to s3c_hsotg_core_init
In reply to Marek SzyprowskiThis patch removes duplicated code and sets last_rst variable in the function which does the hardware reset.
--- drivers/usb/dwc2/gadget.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/usb/dwc2/gadget.c +2 -3
@@ -2247,6 +2247,8 @@ static void s3c_hsotg_core_init(struct s3c_hsotg *hsotg)/* must be at-least 3ms to allow bus to see disconnect */ mdelay (3 ); + hsotg->last_rst = jiffies; +/* remove the soft-disconnect and let's go */ __bic32 (hsotg->regs +DCTL ,DCTL_SFTDISCON ); }
@@ -2347,7 +2349,6 @@ irq_retry: -ECONNRESET, true);s3c_hsotg_core_init (hsotg); - hsotg->last_rst = jiffies; } } }
@@ -2908,7 +2909,6 @@ static int s3c_hsotg_udc_start(struct usb_gadget *gadget, goto err; } - hsotg->last_rst = jiffies;dev_info (hsotg->dev,"bound driver %s\n" , driver->driver.name);return 0 ;
@@ -3667,7 +3667,6 @@ static int s3c_hsotg_resume(struct platform_device *pdev) }spin_lock_irqsave (&hsotg->lock, flags); - hsotg->last_rst = jiffies;s3c_hsotg_phy_enable (hsotg);s3c_hsotg_core_init (hsotg);spin_unlock_irqrestore (&hsotg->lock, flags);
Signature · 1 line
1.9.2
A message that is not in the archive (sent off-list or not yet received): 1413801940-31086-6-git-send-email-m.szyprowski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org
Paul Zimmerman
Acked-byRE: [PATCH v2 05/10] usb: dwc2/gadget: move setting last reset time to s3c_hsotg_core_init
Quoted 41 lines
From: Marek Szyprowski [mailto:[email protected]]
Sent: Monday, October 20, 2014 3:46 AMThis patch removes duplicated code and sets
last_rstvariable in the function which does the hardware reset.Signed-off-by Marek Szyprowski <[email protected]>--- drivers/usb/dwc2/gadget.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)drivers/usb/dwc2/gadget.c +2
-2@@ -2247,6 +2247,8 @@ static void s3c_hsotg_core_init(struct s3c_hsotg *hsotg)/* must be at-least 3ms to allow bus to see disconnect */ mdelay (3 ); + hsotg->last_rst = jiffies; +/* remove the soft-disconnect and let's go */ __bic32 (hsotg->regs +DCTL ,DCTL_SFTDISCON ); }@@ -2347,7 +2349,6 @@ irq_retry: -ECONNRESET, true);s3c_hsotg_core_init (hsotg); - hsotg->last_rst = jiffies; } } }@@ -2908,7 +2909,6 @@ static int s3c_hsotg_udc_start(struct usb_gadget *gadget, goto err; } - hsotg->last_rst = jiffies;dev_info (hsotg->dev,"bound driver %s\n" , driver->driver.name);return 0 ;
drivers/usb/dwc2/gadget.c static int s3c_hsotg_resume(struct platform_device *pdev) · line 3672
Quoted 7 lines
drivers/usb/dwc2/gadget.c +0
-1@@ -3667,7 +3667,6 @@ static int s3c_hsotg_resume(struct platform_device *pdev) }spin_lock_irqsave (&hsotg->lock, flags); - hsotg->last_rst = jiffies;s3c_hsotg_phy_enable (hsotg);s3c_hsotg_core_init (hsotg);spin_unlock_irqrestore (&hsotg->lock, flags);
--
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
PATCH v2 7/10 usb: dwc2/gadget: move phy control calls out of pullup() method
In reply to Marek SzyprowskiThis patch moves phy enable/disable calls from pullup() method to udc_start/stop functions. This solves the issue related to limited caller context for PHY functions, because they cannot be called from non-sleeping context. This is also a preparation for using soft-disconnect feature of udc controller in pullup() method.
--- drivers/usb/dwc2/gadget.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/usb/dwc2/gadget.c +4 -2
@@ -2919,6 +2919,8 @@ static int s3c_hsotg_udc_start(struct usb_gadget *gadget, goto err; } +s3c_hsotg_phy_enable (hsotg); +dev_info (hsotg->dev,"bound driver %s\n" , driver->driver.name);return 0 ;
@@ -2955,6 +2957,8 @@ static int s3c_hsotg_udc_stop(struct usb_gadget *gadget,spin_unlock_irqrestore (&hsotg->lock, flags); +s3c_hsotg_phy_disable (hsotg); +regulator_bulk_disable (ARRAY_SIZE (hsotg->supplies), hsotg->supplies);clk_disable (hsotg->clk);
@@ -2989,13 +2993,11 @@ static int s3c_hsotg_pullup(struct usb_gadget *gadget, int is_on)spin_lock_irqsave (&hsotg->lock, flags);if (is_on) { -s3c_hsotg_phy_enable (hsotg);clk_enable (hsotg->clk);s3c_hsotg_core_init_disconnected (hsotg);s3c_hsotg_core_connect (hsotg); }else {clk_disable (hsotg->clk); -s3c_hsotg_phy_disable (hsotg); } hsotg->gadget.speed =USB_SPEED_UNKNOWN ;
Signature · 1 line
1.9.2
RE: [PATCH v2 07/10] usb: dwc2/gadget: move phy control calls out of pullup() method
Quoted 40 lines
From: Marek Szyprowski [mailto:[email protected]]
Sent: Monday, October 20, 2014 3:46 AMThis patch moves phy enable/disable calls from
pullup()method to udc_start/stop functions. This solves the issue related to limited caller context for PHY functions, because they cannot be called from non-sleeping context. This is also a preparation for using soft-disconnect feature of udc controller inpullup()method.Signed-off-by Marek Szyprowski <[email protected]>--- drivers/usb/dwc2/gadget.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)drivers/usb/dwc2/gadget.c +4
-0@@ -2919,6 +2919,8 @@ static int s3c_hsotg_udc_start(struct usb_gadget *gadget, goto err; } +s3c_hsotg_phy_enable (hsotg); +dev_info (hsotg->dev,"bound driver %s\n" , driver->driver.name);return 0 ;@@ -2955,6 +2957,8 @@ static int s3c_hsotg_udc_stop(struct usb_gadget *gadget,spin_unlock_irqrestore (&hsotg->lock, flags); +s3c_hsotg_phy_disable (hsotg); +regulator_bulk_disable (ARRAY_SIZE (hsotg->supplies), hsotg->supplies);clk_disable (hsotg->clk);@@ -2989,13 +2993,11 @@ static int s3c_hsotg_pullup(struct usb_gadget *gadget, int is_on)spin_lock_irqsave (&hsotg->lock, flags);if (is_on) {
drivers/usb/dwc2/gadget.c static int s3c_hsotg_pullup(struct usb_gadget *gadget, int is_on) · line 3003
Quoted 10 lines
drivers/usb/dwc2/gadget.c +0
-2-s3c_hsotg_phy_enable (hsotg);clk_enable (hsotg->clk);s3c_hsotg_core_init_disconnected (hsotg);s3c_hsotg_core_connect (hsotg); }else {clk_disable (hsotg->clk); -s3c_hsotg_phy_disable (hsotg); } hsotg->gadget.speed =USB_SPEED_UNKNOWN ;
PATCH v2 8/10 usb: dwc2/gadget: use soft-disconnect udc feature in pullup() method
In reply to Marek SzyprowskiThis patch moves udc initialization from pullup() method to s3c_hsotg_udc_start(), so that method ends with hardware fully initialized and left in soft-disconnected state. After this change, the pullup() method simply clears soft-disconnect start() when called with is_on=1. For completeness, a call to s3c_hsotg_core_disconnect() has been added when pullup() method is called with is_on=0, what puts the udc hardware back to soft-disconnected state.
--- drivers/usb/dwc2/gadget.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/usb/dwc2/gadget.c +8 -1
@@ -2883,6 +2883,7 @@ static int s3c_hsotg_udc_start(struct usb_gadget *gadget, struct usb_gadget_driver *driver) {struct s3c_hsotg *hsotg =to_hsotg (gadget); +unsigned long flags;int ret;if (!hsotg) {
@@ -2921,7 +2922,13 @@ static int s3c_hsotg_udc_start(struct usb_gadget *gadget,s3c_hsotg_phy_enable (hsotg); +spin_lock_irqsave (&hsotg->lock, flags); +s3c_hsotg_init (hsotg); +s3c_hsotg_core_init_disconnected (hsotg); +spin_unlock_irqrestore (&hsotg->lock, flags); +dev_info (hsotg->dev,"bound driver %s\n" , driver->driver.name); +return 0 ; err:
@@ -2994,9 +3001,9 @@ static int s3c_hsotg_pullup(struct usb_gadget *gadget, int is_on)spin_lock_irqsave (&hsotg->lock, flags);if (is_on) {clk_enable (hsotg->clk); -s3c_hsotg_core_init_disconnected (hsotg);s3c_hsotg_core_connect (hsotg); }else { +s3c_hsotg_core_disconnect (hsotg);clk_disable (hsotg->clk); }
Signature · 1 line
1.9.2
RE: [PATCH v2 08/10] usb: dwc2/gadget: use soft-disconnect udc feature in pullup() method
Quoted 43 lines
From: Marek Szyprowski [mailto:[email protected]]
Sent: Monday, October 20, 2014 3:46 AMThis patch moves udc initialization from
pullup()method tos3c_hsotg_udc_start(), so that method ends with hardware fully initialized and left in soft-disconnected state. After this change, thepullup()method simply clears soft-disconnectstart()when called with is_on=1. For completeness, a call tos3c_hsotg_core_disconnect()has been added whenpullup()method is called with is_on=0, what puts the udc hardware back to soft-disconnected state.Signed-off-by Marek Szyprowski <[email protected]>--- drivers/usb/dwc2/gadget.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)drivers/usb/dwc2/gadget.c +7
-0@@ -2883,6 +2883,7 @@ static int s3c_hsotg_udc_start(struct usb_gadget *gadget, struct usb_gadget_driver *driver) {struct s3c_hsotg *hsotg =to_hsotg (gadget); +unsigned long flags;int ret;if (!hsotg) {@@ -2921,7 +2922,13 @@ static int s3c_hsotg_udc_start(struct usb_gadget *gadget,s3c_hsotg_phy_enable (hsotg); +spin_lock_irqsave (&hsotg->lock, flags); +s3c_hsotg_init (hsotg); +s3c_hsotg_core_init_disconnected (hsotg); +spin_unlock_irqrestore (&hsotg->lock, flags); +dev_info (hsotg->dev,"bound driver %s\n" , driver->driver.name); +return 0 ; err:
drivers/usb/dwc2/gadget.c static int s3c_hsotg_pullup(struct usb_gadget *gadget, int is_on) · line 3009
Quoted 10 lines
drivers/usb/dwc2/gadget.c +1
-1@@ -2994,9 +3001,9 @@ static int s3c_hsotg_pullup(struct usb_gadget *gadget, int is_on)spin_lock_irqsave (&hsotg->lock, flags);if (is_on) {clk_enable (hsotg->clk); -s3c_hsotg_core_init_disconnected (hsotg);s3c_hsotg_core_connect (hsotg); }else { +s3c_hsotg_core_disconnect (hsotg);clk_disable (hsotg->clk); }