usb/gadget/pch_udc: Fix disconnect issue
PATCH v2 1/6 usb/gadget/pch_udc: Fix disconnect issue
ISSUE:
When the driver notifies a gadget of a disconnect event, a system rarely freezes.
CAUSE:
When the driver calls dev->driver->disconnect(), it is not calling spinlock().
---
V2: Divide into 6 patches
--- drivers/usb/gadget/pch_udc.c | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-)
drivers/usb/gadget/pch_udc.c +4 -1
@@ -2340,8 +2340,11 @@ static void pch_udc_svc_ur_interrupt(struct pch_udc_dev *dev)/* Complete request queue */ empty_req_queue (ep); } -if (dev->driver && dev->driver->disconnect) +if (dev->driver && dev->driver->disconnect) { +spin_unlock (&dev->lock); dev->driver->disconnect (&dev->gadget); +spin_lock (&dev->lock); + } }/**
Signature · 1 line
1.7.4.4
PATCH v2 2/6 usb/gadget/pch_udc: Fix wrong return value
ISSUE:
If the return value of pch_udc_pcd_init() is False, the return value of this function is unsettled. Since pch_udc_pcd_init() always returns 0, there is not actually the issue.
CAUSE:
If pch_udc_pcd_init() is True, the variable, retval, is not set for an appropriate value.
---
V2: Divide into 6 patches
--- drivers/usb/gadget/pch_udc.c | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-)
drivers/usb/gadget/pch_udc.c +3 -1
@@ -2920,8 +2920,10 @@ static int pch_udc_probe(struct pci_dev *pdev, } pch_udc = dev;/* initialize the hardware */ -if (pch_udc_pcd_init (dev)) +if (pch_udc_pcd_init (dev)) { + retval = -ENODEV ; goto finished; + }if (request_irq (pdev->irq, pch_udc_isr,IRQF_SHARED ,KBUILD_MODNAME , dev)) { dev_err(&pdev->dev, "%s: request_irq(%d) fail\n", __func__,
Signature · 1 line
1.7.4.4
PATCH v2 3/6 usb/gadget/pch_udc: Fix USB suspend issue
In reply to Tomoya MORINAGAISSUE:
After USB Suspend, a system rarely freezes.
CAUSE:
When USB Suspend occurred, the driver is not notifying a gadget of the event.
---
V2: Divide into 6 patches
--- drivers/usb/gadget/pch_udc.c | 9 ++++++++- 1 files changed, 8 insertions(+), 1 deletions(-)
drivers/usb/gadget/pch_udc.c +8 -1
@@ -2480,8 +2480,15 @@ static void pch_udc_dev_isr(struct pch_udc_dev *dev, u32 dev_intr)if (dev_intr &UDC_DEVINT_SC )pch_udc_svc_cfg_interrupt (dev);/* USB Suspend interrupt */ -if (dev_intr &UDC_DEVINT_US ) +if (dev_intr &UDC_DEVINT_US ) { +if (dev->driver + && dev->driver->suspend) { +spin_unlock (&dev->lock); + dev->driver->suspend (&dev->gadget); +spin_lock (&dev->lock); + }dev_dbg (&dev->pdev->dev,"USB_SUSPEND\n" ); + }/* Clear the SOF interrupt, if enabled */ if (dev_intr &UDC_DEVINT_SOF )dev_dbg (&dev->pdev->dev,"SOF\n" );
Signature · 1 line
1.7.4.4
PATCH v2 4/6 usb/gadget/pch_udc: Fix usb/gadget/pch_udc: Fix ether gadget connect/disconnect issue
In reply to Tomoya MORINAGAISSUE:
After a USB cable is connect/disconnected, the system rarely freezes.
CAUSE:
Since the USB device controller cannot know to disconnect the USB cable, when it is used without detecting VBUS by GPIO, the UDC driver does not notify to USB Gadget.
Since USB Gadget cannot know to disconnect, a false setting occurred when the USB cable is connected/disconnect repeatedly.
---
V2: Divide into 6 patches
--- drivers/usb/gadget/pch_udc.c | 70 +++++++++++++++++++++++++++++++++++++++-- 1 files changed, 66 insertions(+), 4 deletions(-)
drivers/usb/gadget/pch_udc.c +66 -4
@@ -320,6 +320,7 @@ struct pch_udc_ep {* @registered: driver regsitered with system * @suspended: driver in suspended state * @connected: gadget driver associated +* @vbus_session: required vbus_session state * @set_cfg_not_acked: pending acknowledgement 4 setup * @waiting_zlp_ack: pending acknowledgement 4 ZLP * @data_requests: DMA pool for data requests
@@ -346,6 +347,7 @@ struct pch_udc_dev { registered:1, suspended:1, connected:1, + vbus_session:1, set_cfg_not_acked:1, waiting_zlp_ack:1;struct pci_pool *data_requests;
@@ -563,6 +565,31 @@ static void pch_udc_clear_disconnect(struct pch_udc_dev *dev) }/** +* pch_udc_reconnect() - This API initializes usb device controller, +* and clear the disconnect status. +* @dev: Reference to pch_udc_regs structure +*/ +static void pch_udc_init (struct pch_udc_dev *dev); +static void pch_udc_reconnect (struct pch_udc_dev *dev) +{ +pch_udc_init (dev); + +/* enable device interrupts */ +/* pch_udc_enable_interrupts() */ +pch_udc_bit_clr (dev,UDC_DEVIRQMSK_ADDR , +UDC_DEVINT_UR |UDC_DEVINT_US | +UDC_DEVINT_ENUM | +UDC_DEVINT_SI |UDC_DEVINT_SC ); + +/* Clear the disconnect */ +pch_udc_bit_set (dev,UDC_DEVCTL_ADDR ,UDC_DEVCTL_RES ); +pch_udc_bit_clr (dev,UDC_DEVCTL_ADDR ,UDC_DEVCTL_SD ); +mdelay (1 ); +/* Resume USB signalling */ +pch_udc_bit_clr (dev,UDC_DEVCTL_ADDR ,UDC_DEVCTL_RES ); +} + +/** * pch_udc_vbus_session() - set or clearr the disconnect status. * @dev: Reference to pch_udc_regs structure * @is_active: Parameter specifying the action
@@ -572,10 +599,18 @@ static void pch_udc_clear_disconnect(struct pch_udc_dev *dev)static inline void pch_udc_vbus_session (struct pch_udc_dev *dev,int is_active) { -if (is_active) -pch_udc_clear_disconnect (dev); -else +if (is_active) { +pch_udc_reconnect (dev); + dev->vbus_session =1 ; + }else { +if (dev->driver && dev->driver->disconnect) { +spin_unlock (&dev->lock); + dev->driver->disconnect (&dev->gadget); +spin_lock (&dev->lock); + }pch_udc_set_disconnect (dev); + dev->vbus_session =0 ; + } }/**
@@ -1135,7 +1170,17 @@ static int pch_udc_pcd_pullup(struct usb_gadget *gadget, int is_on)if (!gadget)return -EINVAL ; dev = container_of(gadget, struct pch_udc_dev, gadget); -pch_udc_vbus_session (dev, is_on); +if (is_on) { +pch_udc_reconnect (dev); + }else { +if (dev->driver && dev->driver->disconnect) { +spin_unlock (&dev->lock); + dev->driver->disconnect (&dev->gadget); +spin_lock (&dev->lock); + } +pch_udc_set_disconnect (dev); + } +return 0 ; }
@@ -2487,6 +2532,15 @@ static void pch_udc_dev_isr(struct pch_udc_dev *dev, u32 dev_intr) dev->driver->suspend (&dev->gadget);spin_lock (&dev->lock); } + +if (dev->vbus_session ==0 ) { +if (dev->driver && dev->driver->disconnect) { +spin_unlock (&dev->lock); + dev->driver->disconnect (&dev->gadget); +spin_lock (&dev->lock); + } +pch_udc_reconnect (dev); + }dev_dbg (&dev->pdev->dev,"USB_SUSPEND\n" ); }/* Clear the SOF interrupt, if enabled */
@@ -2514,6 +2568,14 @@ static irqreturn_t pch_udc_isr(int irq, void *pdev) dev_intr =pch_udc_read_device_interrupts (dev); ep_intr =pch_udc_read_ep_interrupts (dev); +/* For a hot plug, this find that the controller is hung up. */ +if (dev_intr == ep_intr) +if (dev_intr ==pch_udc_readl (dev,UDC_DEVCFG_ADDR )) { +dev_dbg (&dev->pdev->dev,"UDC: Hung up\n" ); +/* The controller is reset */ +pch_udc_writel (dev,UDC_SRST ,UDC_SRST_ADDR ); +return IRQ_HANDLED ; + }if (dev_intr)/* Clear device interrupts */ pch_udc_write_device_interrupts (dev, dev_intr);
Signature · 1 line
1.7.4.4
PATCH v2 5/6 usb/gadget/pch_udc: Reduce redundant interrupt
In reply to Tomoya MORINAGAISSUE:
USB Suspend interrupts occur frequently.
CAUSE:
When it is called pch_udc_reconnect() in USB Suspend, it repeats reset and Suspend.
SOLUTION:pch_udc_reconnect() does not enable all interrupts.
When an enumeration event occurred the driver enables all interrupts.
---
V2: Divide into 6 patches
--- drivers/usb/gadget/pch_udc.c | 9 ++++++--- 1 files changed, 6 insertions(+), 3 deletions(-)
drivers/usb/gadget/pch_udc.c +6 -3
@@ -577,9 +577,7 @@ static void pch_udc_reconnect(struct pch_udc_dev *dev)/* enable device interrupts */ /* pch_udc_enable_interrupts() */ pch_udc_bit_clr (dev,UDC_DEVIRQMSK_ADDR , -UDC_DEVINT_UR |UDC_DEVINT_US | -UDC_DEVINT_ENUM | -UDC_DEVINT_SI |UDC_DEVINT_SC ); +UDC_DEVINT_UR |UDC_DEVINT_ENUM );/* Clear the disconnect */ pch_udc_bit_set (dev,UDC_DEVCTL_ADDR ,UDC_DEVCTL_RES );
@@ -2424,6 +2422,11 @@ static void pch_udc_svc_enum_interrupt(struct pch_udc_dev *dev)pch_udc_set_dma (dev,DMA_DIR_TX );pch_udc_set_dma (dev,DMA_DIR_RX );pch_udc_ep_set_rrdy (&(dev->ep[UDC_EP0OUT_IDX ])); + +/* enable device interrupts */ +pch_udc_enable_interrupts (dev,UDC_DEVINT_UR |UDC_DEVINT_US | +UDC_DEVINT_ES |UDC_DEVINT_ENUM | +UDC_DEVINT_SI |UDC_DEVINT_SC ); }/**
Signature · 1 line
1.7.4.4
PATCH v2 6/6 usb/gadget/pch_udc: Add debug message
In reply to Tomoya MORINAGAISSUE:
Adding debugging messages.
CAUSE:
The debugging messages are added to make sure of that major interrupt events are occurring.
---
V2: Divide into 6 patches
--- drivers/usb/gadget/pch_udc.c | 8 ++++++-- 1 files changed, 6 insertions(+), 2 deletions(-)
drivers/usb/gadget/pch_udc.c +6 -2
@@ -2516,11 +2516,15 @@ static void pch_udc_svc_cfg_interrupt(struct pch_udc_dev *dev)static void pch_udc_dev_isr (struct pch_udc_dev *dev,u32 dev_intr) {/* USB Reset Interrupt */ -if (dev_intr &UDC_DEVINT_UR ) +if (dev_intr &UDC_DEVINT_UR ) {pch_udc_svc_ur_interrupt (dev); +dev_dbg (&dev->pdev->dev,"USB_RESET\n" ); + }/* Enumeration Done Interrupt */ -if (dev_intr &UDC_DEVINT_ENUM ) +if (dev_intr &UDC_DEVINT_ENUM ) {pch_udc_svc_enum_interrupt (dev); +dev_dbg (&dev->pdev->dev,"USB_ENUM\n" ); + }/* Set Interface Interrupt */ if (dev_intr &UDC_DEVINT_SI )pch_udc_svc_intf_interrupt (dev);
Signature · 1 line
1.7.4.4
Hello.
Quoted 5 lines · Tomoya MORINAGA
ISSUE:
When the driver notifies a gadget of a disconnect event, a system rarely freezes.CAUSE:
When the driver callsdev->driver->disconnect(), it is not callingspinlock().
spin_unlock(), you mean?
Quoted 12 lines
Signed-off-by Tomoya MORINAGA<[email protected]>---
V2: Divide into 6 patches--- drivers/usb/gadget/pch_udc.c | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-)drivers/usb/gadget/pch_udc.c +0
-0
drivers/usb/gadget/pch_udc.c static void pch_udc_svc_ur_interrupt(struct pch_udc_dev *dev) · line 2347
Quoted 9 lines
drivers/usb/gadget/pch_udc.c +4
-1@@ -2340,8 +2340,11 @@ static void pch_udc_svc_ur_interrupt(struct pch_udc_dev *dev)/* Complete request queue */ empty_req_queue (ep); } -if (dev->driver&& dev->driver->disconnect) +if (dev->driver&& dev->driver->disconnect) { +spin_unlock (&dev->lock); dev->driver->disconnect (&dev->gadget); +spin_lock (&dev->lock); + }
WBR, Sergei
Hi Sergei
2012/1/12 Sergei Shtylyov <[email protected]>:
Quoted 6 lines
Quoted 3 lines
CAUSE:
When the driver callsdev->driver->disconnect(), it is not callingspinlock().
spin_unlock(), you mean?
It means that there is not the following sentence in the previous source. I think this is a cause of system freeze.
Quoted 2 lines
+
spin_unlock(&dev->lock);
+spin_lock(&dev->lock);
I correct myself below.
CAUSE:
The driver calls dev->driver->disconnect() without calling spin_unlock(&dev->lock).
thanks,
tomoya
Quoted 7 lines · Tomoya MORINAGA
ISSUE:
When the driver notifies a gadget of a disconnect event, a system rarely freezes.CAUSE:
When the driver callsdev->driver->disconnect(), it is not callingspinlock().Signed-off-by Tomoya MORINAGA <[email protected]>
applied all 6 patches
Signature · 1 line
balbi