Commit 4f4c5e36 authored by Harro Haan's avatar Harro Haan Committed by Russell King
parent 7e27d6e7
...@@ -77,10 +77,10 @@ static const char driver_name [] = "at91_udc"; ...@@ -77,10 +77,10 @@ static const char driver_name [] = "at91_udc";
static const char ep0name[] = "ep0"; static const char ep0name[] = "ep0";
#define at91_udp_read(dev, reg) \ #define at91_udp_read(udc, reg) \
__raw_readl((dev)->udp_baseaddr + (reg)) __raw_readl((udc)->udp_baseaddr + (reg))
#define at91_udp_write(dev, reg, val) \ #define at91_udp_write(udc, reg, val) \
__raw_writel((val), (dev)->udp_baseaddr + (reg)) __raw_writel((val), (udc)->udp_baseaddr + (reg))
/*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/
...@@ -102,8 +102,9 @@ static void proc_ep_show(struct seq_file *s, struct at91_ep *ep) ...@@ -102,8 +102,9 @@ static void proc_ep_show(struct seq_file *s, struct at91_ep *ep)
u32 csr; u32 csr;
struct at91_request *req; struct at91_request *req;
unsigned long flags; unsigned long flags;
struct at91_udc *udc = ep->udc;
local_irq_save(flags); spin_lock_irqsave(&udc->lock, flags);
csr = __raw_readl(ep->creg); csr = __raw_readl(ep->creg);
...@@ -147,7 +148,7 @@ static void proc_ep_show(struct seq_file *s, struct at91_ep *ep) ...@@ -147,7 +148,7 @@ static void proc_ep_show(struct seq_file *s, struct at91_ep *ep)
&req->req, length, &req->req, length,
req->req.length, req->req.buf); req->req.length, req->req.buf);
} }
local_irq_restore(flags); spin_unlock_irqrestore(&udc->lock, flags);
} }
static void proc_irq_show(struct seq_file *s, const char *label, u32 mask) static void proc_irq_show(struct seq_file *s, const char *label, u32 mask)
...@@ -272,7 +273,9 @@ static void done(struct at91_ep *ep, struct at91_request *req, int status) ...@@ -272,7 +273,9 @@ static void done(struct at91_ep *ep, struct at91_request *req, int status)
VDBG("%s done %p, status %d\n", ep->ep.name, req, status); VDBG("%s done %p, status %d\n", ep->ep.name, req, status);
ep->stopped = 1; ep->stopped = 1;
spin_unlock(&udc->lock);
req->req.complete(&ep->ep, &req->req); req->req.complete(&ep->ep, &req->req);
spin_lock(&udc->lock);
ep->stopped = stopped; ep->stopped = stopped;
/* ep0 is always ready; other endpoints need a non-empty queue */ /* ep0 is always ready; other endpoints need a non-empty queue */
...@@ -472,7 +475,7 @@ static int at91_ep_enable(struct usb_ep *_ep, ...@@ -472,7 +475,7 @@ static int at91_ep_enable(struct usb_ep *_ep,
const struct usb_endpoint_descriptor *desc) const struct usb_endpoint_descriptor *desc)
{ {
struct at91_ep *ep = container_of(_ep, struct at91_ep, ep); struct at91_ep *ep = container_of(_ep, struct at91_ep, ep);
struct at91_udc *dev = ep->udc; struct at91_udc *udc = ep->udc;
u16 maxpacket; u16 maxpacket;
u32 tmp; u32 tmp;
unsigned long flags; unsigned long flags;
...@@ -487,7 +490,7 @@ static int at91_ep_enable(struct usb_ep *_ep, ...@@ -487,7 +490,7 @@ static int at91_ep_enable(struct usb_ep *_ep,
return -EINVAL; return -EINVAL;
} }
if (!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN) { if (!udc->driver || udc->gadget.speed == USB_SPEED_UNKNOWN) {
DBG("bogus device state\n"); DBG("bogus device state\n");
return -ESHUTDOWN; return -ESHUTDOWN;
} }
...@@ -521,7 +524,7 @@ static int at91_ep_enable(struct usb_ep *_ep, ...@@ -521,7 +524,7 @@ static int at91_ep_enable(struct usb_ep *_ep,
} }
ok: ok:
local_irq_save(flags); spin_lock_irqsave(&udc->lock, flags);
/* initialize endpoint to match this descriptor */ /* initialize endpoint to match this descriptor */
ep->is_in = usb_endpoint_dir_in(desc); ep->is_in = usb_endpoint_dir_in(desc);
...@@ -540,10 +543,10 @@ static int at91_ep_enable(struct usb_ep *_ep, ...@@ -540,10 +543,10 @@ static int at91_ep_enable(struct usb_ep *_ep,
* reset/init endpoint fifo. NOTE: leaves fifo_bank alone, * reset/init endpoint fifo. NOTE: leaves fifo_bank alone,
* since endpoint resets don't reset hw pingpong state. * since endpoint resets don't reset hw pingpong state.
*/ */
at91_udp_write(dev, AT91_UDP_RST_EP, ep->int_mask); at91_udp_write(udc, AT91_UDP_RST_EP, ep->int_mask);
at91_udp_write(dev, AT91_UDP_RST_EP, 0); at91_udp_write(udc, AT91_UDP_RST_EP, 0);
local_irq_restore(flags); spin_unlock_irqrestore(&udc->lock, flags);
return 0; return 0;
} }
...@@ -556,7 +559,7 @@ static int at91_ep_disable (struct usb_ep * _ep) ...@@ -556,7 +559,7 @@ static int at91_ep_disable (struct usb_ep * _ep)
if (ep == &ep->udc->ep[0]) if (ep == &ep->udc->ep[0])
return -EINVAL; return -EINVAL;
local_irq_save(flags); spin_lock_irqsave(&udc->lock, flags);
nuke(ep, -ESHUTDOWN); nuke(ep, -ESHUTDOWN);
...@@ -571,7 +574,7 @@ static int at91_ep_disable (struct usb_ep * _ep) ...@@ -571,7 +574,7 @@ static int at91_ep_disable (struct usb_ep * _ep)
__raw_writel(0, ep->creg); __raw_writel(0, ep->creg);
} }
local_irq_restore(flags); spin_unlock_irqrestore(&udc->lock, flags);
return 0; return 0;
} }
...@@ -607,7 +610,7 @@ static int at91_ep_queue(struct usb_ep *_ep, ...@@ -607,7 +610,7 @@ static int at91_ep_queue(struct usb_ep *_ep,
{ {
struct at91_request *req; struct at91_request *req;
struct at91_ep *ep; struct at91_ep *ep;
struct at91_udc *dev; struct at91_udc *udc;
int status; int status;
unsigned long flags; unsigned long flags;
...@@ -625,9 +628,9 @@ static int at91_ep_queue(struct usb_ep *_ep, ...@@ -625,9 +628,9 @@ static int at91_ep_queue(struct usb_ep *_ep,
return -EINVAL; return -EINVAL;
} }
dev = ep->udc; udc = ep->udc;
if (!dev || !dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN) { if (!udc || !udc->driver || udc->gadget.speed == USB_SPEED_UNKNOWN) {
DBG("invalid device\n"); DBG("invalid device\n");
return -EINVAL; return -EINVAL;
} }
...@@ -635,7 +638,7 @@ static int at91_ep_queue(struct usb_ep *_ep, ...@@ -635,7 +638,7 @@ static int at91_ep_queue(struct usb_ep *_ep,
_req->status = -EINPROGRESS; _req->status = -EINPROGRESS;
_req->actual = 0; _req->actual = 0;
local_irq_save(flags); spin_lock_irqsave(&udc->lock, flags);
/* try to kickstart any empty and idle queue */ /* try to kickstart any empty and idle queue */
if (list_empty(&ep->queue) && !ep->stopped) { if (list_empty(&ep->queue) && !ep->stopped) {
...@@ -653,7 +656,7 @@ static int at91_ep_queue(struct usb_ep *_ep, ...@@ -653,7 +656,7 @@ static int at91_ep_queue(struct usb_ep *_ep,
if (is_ep0) { if (is_ep0) {
u32 tmp; u32 tmp;
if (!dev->req_pending) { if (!udc->req_pending) {
status = -EINVAL; status = -EINVAL;
goto done; goto done;
} }
...@@ -662,11 +665,11 @@ static int at91_ep_queue(struct usb_ep *_ep, ...@@ -662,11 +665,11 @@ static int at91_ep_queue(struct usb_ep *_ep,
* defer changing CONFG until after the gadget driver * defer changing CONFG until after the gadget driver
* reconfigures the endpoints. * reconfigures the endpoints.
*/ */
if (dev->wait_for_config_ack) { if (udc->wait_for_config_ack) {
tmp = at91_udp_read(dev, AT91_UDP_GLB_STAT); tmp = at91_udp_read(udc, AT91_UDP_GLB_STAT);
tmp ^= AT91_UDP_CONFG; tmp ^= AT91_UDP_CONFG;
VDBG("toggle config\n"); VDBG("toggle config\n");
at91_udp_write(dev, AT91_UDP_GLB_STAT, tmp); at91_udp_write(udc, AT91_UDP_GLB_STAT, tmp);
} }
if (req->req.length == 0) { if (req->req.length == 0) {
ep0_in_status: ep0_in_status:
...@@ -676,7 +679,7 @@ static int at91_ep_queue(struct usb_ep *_ep, ...@@ -676,7 +679,7 @@ static int at91_ep_queue(struct usb_ep *_ep,
tmp &= ~SET_FX; tmp &= ~SET_FX;
tmp |= CLR_FX | AT91_UDP_TXPKTRDY; tmp |= CLR_FX | AT91_UDP_TXPKTRDY;
__raw_writel(tmp, ep->creg); __raw_writel(tmp, ep->creg);
dev->req_pending = 0; udc->req_pending = 0;
goto done; goto done;
} }
} }
...@@ -695,10 +698,10 @@ static int at91_ep_queue(struct usb_ep *_ep, ...@@ -695,10 +698,10 @@ static int at91_ep_queue(struct usb_ep *_ep,
if (req && !status) { if (req && !status) {
list_add_tail (&req->queue, &ep->queue); list_add_tail (&req->queue, &ep->queue);
at91_udp_write(dev, AT91_UDP_IER, ep->int_mask); at91_udp_write(udc, AT91_UDP_IER, ep->int_mask);
} }
done: done:
local_irq_restore(flags); spin_unlock_irqrestore(&udc->lock, flags);
return (status < 0) ? status : 0; return (status < 0) ? status : 0;
} }
...@@ -706,20 +709,29 @@ static int at91_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req) ...@@ -706,20 +709,29 @@ static int at91_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req)
{ {
struct at91_ep *ep; struct at91_ep *ep;
struct at91_request *req; struct at91_request *req;
unsigned long flags;
struct at91_udc *udc;
ep = container_of(_ep, struct at91_ep, ep); ep = container_of(_ep, struct at91_ep, ep);
if (!_ep || ep->ep.name == ep0name) if (!_ep || ep->ep.name == ep0name)
return -EINVAL; return -EINVAL;
udc = ep->udc;
spin_lock_irqsave(&udc->lock, flags);
/* make sure it's actually queued on this endpoint */ /* make sure it's actually queued on this endpoint */
list_for_each_entry (req, &ep->queue, queue) { list_for_each_entry (req, &ep->queue, queue) {
if (&req->req == _req) if (&req->req == _req)
break; break;
} }
if (&req->req != _req) if (&req->req != _req) {
spin_unlock_irqrestore(&udc->lock, flags);
return -EINVAL; return -EINVAL;
}
done(ep, req, -ECONNRESET); done(ep, req, -ECONNRESET);
spin_unlock_irqrestore(&udc->lock, flags);
return 0; return 0;
} }
...@@ -736,7 +748,7 @@ static int at91_ep_set_halt(struct usb_ep *_ep, int value) ...@@ -736,7 +748,7 @@ static int at91_ep_set_halt(struct usb_ep *_ep, int value)
return -EINVAL; return -EINVAL;
creg = ep->creg; creg = ep->creg;
local_irq_save(flags); spin_lock_irqsave(&udc->lock, flags);
csr = __raw_readl(creg); csr = __raw_readl(creg);
...@@ -761,7 +773,7 @@ static int at91_ep_set_halt(struct usb_ep *_ep, int value) ...@@ -761,7 +773,7 @@ static int at91_ep_set_halt(struct usb_ep *_ep, int value)
__raw_writel(csr, creg); __raw_writel(csr, creg);
} }
local_irq_restore(flags); spin_unlock_irqrestore(&udc->lock, flags);
return status; return status;
} }
...@@ -795,7 +807,7 @@ static int at91_wakeup(struct usb_gadget *gadget) ...@@ -795,7 +807,7 @@ static int at91_wakeup(struct usb_gadget *gadget)
unsigned long flags; unsigned long flags;
DBG("%s\n", __func__ ); DBG("%s\n", __func__ );
local_irq_save(flags); spin_lock_irqsave(&udc->lock, flags);
if (!udc->clocked || !udc->suspended) if (!udc->clocked || !udc->suspended)
goto done; goto done;
...@@ -809,7 +821,7 @@ static int at91_wakeup(struct usb_gadget *gadget) ...@@ -809,7 +821,7 @@ static int at91_wakeup(struct usb_gadget *gadget)
at91_udp_write(udc, AT91_UDP_GLB_STAT, glbstate); at91_udp_write(udc, AT91_UDP_GLB_STAT, glbstate);
done: done:
local_irq_restore(flags); spin_unlock_irqrestore(&udc->lock, flags);
return status; return status;
} }
...@@ -851,8 +863,11 @@ static void stop_activity(struct at91_udc *udc) ...@@ -851,8 +863,11 @@ static void stop_activity(struct at91_udc *udc)
ep->stopped = 1; ep->stopped = 1;
nuke(ep, -ESHUTDOWN); nuke(ep, -ESHUTDOWN);
} }
if (driver) if (driver) {
spin_unlock(&udc->lock);
driver->disconnect(&udc->gadget); driver->disconnect(&udc->gadget);
spin_lock(&udc->lock);
}
udc_reinit(udc); udc_reinit(udc);
} }
...@@ -935,13 +950,13 @@ static int at91_vbus_session(struct usb_gadget *gadget, int is_active) ...@@ -935,13 +950,13 @@ static int at91_vbus_session(struct usb_gadget *gadget, int is_active)
unsigned long flags; unsigned long flags;
// VDBG("vbus %s\n", is_active ? "on" : "off"); // VDBG("vbus %s\n", is_active ? "on" : "off");
local_irq_save(flags); spin_lock_irqsave(&udc->lock, flags);
udc->vbus = (is_active != 0); udc->vbus = (is_active != 0);
if (udc->driver) if (udc->driver)
pullup(udc, is_active); pullup(udc, is_active);
else else
pullup(udc, 0); pullup(udc, 0);
local_irq_restore(flags); spin_unlock_irqrestore(&udc->lock, flags);
return 0; return 0;
} }
...@@ -950,10 +965,10 @@ static int at91_pullup(struct usb_gadget *gadget, int is_on) ...@@ -950,10 +965,10 @@ static int at91_pullup(struct usb_gadget *gadget, int is_on)
struct at91_udc *udc = to_udc(gadget); struct at91_udc *udc = to_udc(gadget);
unsigned long flags; unsigned long flags;
local_irq_save(flags); spin_lock_irqsave(&udc->lock, flags);
udc->enabled = is_on = !!is_on; udc->enabled = is_on = !!is_on;
pullup(udc, is_on); pullup(udc, is_on);
local_irq_restore(flags); spin_unlock_irqrestore(&udc->lock, flags);
return 0; return 0;
} }
...@@ -962,9 +977,9 @@ static int at91_set_selfpowered(struct usb_gadget *gadget, int is_on) ...@@ -962,9 +977,9 @@ static int at91_set_selfpowered(struct usb_gadget *gadget, int is_on)
struct at91_udc *udc = to_udc(gadget); struct at91_udc *udc = to_udc(gadget);
unsigned long flags; unsigned long flags;
local_irq_save(flags); spin_lock_irqsave(&udc->lock, flags);
udc->selfpowered = (is_on != 0); udc->selfpowered = (is_on != 0);
local_irq_restore(flags); spin_unlock_irqrestore(&udc->lock, flags);
return 0; return 0;
} }
...@@ -1226,8 +1241,11 @@ static void handle_setup(struct at91_udc *udc, struct at91_ep *ep, u32 csr) ...@@ -1226,8 +1241,11 @@ static void handle_setup(struct at91_udc *udc, struct at91_ep *ep, u32 csr)
#undef w_length #undef w_length
/* pass request up to the gadget driver */ /* pass request up to the gadget driver */
if (udc->driver) if (udc->driver) {
spin_unlock(&udc->lock);
status = udc->driver->setup(&udc->gadget, &pkt.r); status = udc->driver->setup(&udc->gadget, &pkt.r);
spin_lock(&udc->lock);
}
else else
status = -ENODEV; status = -ENODEV;
if (status < 0) { if (status < 0) {
...@@ -1378,6 +1396,9 @@ static irqreturn_t at91_udc_irq (int irq, void *_udc) ...@@ -1378,6 +1396,9 @@ static irqreturn_t at91_udc_irq (int irq, void *_udc)
struct at91_udc *udc = _udc; struct at91_udc *udc = _udc;
u32 rescans = 5; u32 rescans = 5;
int disable_clock = 0; int disable_clock = 0;
unsigned long flags;
spin_lock_irqsave(&udc->lock, flags);
if (!udc->clocked) { if (!udc->clocked) {
clk_on(udc); clk_on(udc);
...@@ -1433,8 +1454,11 @@ static irqreturn_t at91_udc_irq (int irq, void *_udc) ...@@ -1433,8 +1454,11 @@ static irqreturn_t at91_udc_irq (int irq, void *_udc)
* and then into standby to avoid drawing more than * and then into standby to avoid drawing more than
* 500uA power (2500uA for some high-power configs). * 500uA power (2500uA for some high-power configs).
*/ */
if (udc->driver && udc->driver->suspend) if (udc->driver && udc->driver->suspend) {
spin_unlock(&udc->lock);
udc->driver->suspend(&udc->gadget); udc->driver->suspend(&udc->gadget);
spin_lock(&udc->lock);
}
/* host initiated resume */ /* host initiated resume */
} else if (status & AT91_UDP_RXRSM) { } else if (status & AT91_UDP_RXRSM) {
...@@ -1451,8 +1475,11 @@ static irqreturn_t at91_udc_irq (int irq, void *_udc) ...@@ -1451,8 +1475,11 @@ static irqreturn_t at91_udc_irq (int irq, void *_udc)
* would normally want to switch out of slow clock * would normally want to switch out of slow clock
* mode into normal mode. * mode into normal mode.
*/ */
if (udc->driver && udc->driver->resume) if (udc->driver && udc->driver->resume) {
spin_unlock(&udc->lock);
udc->driver->resume(&udc->gadget); udc->driver->resume(&udc->gadget);
spin_lock(&udc->lock);
}
/* endpoint IRQs are cleared by handling them */ /* endpoint IRQs are cleared by handling them */
} else { } else {
...@@ -1474,6 +1501,8 @@ static irqreturn_t at91_udc_irq (int irq, void *_udc) ...@@ -1474,6 +1501,8 @@ static irqreturn_t at91_udc_irq (int irq, void *_udc)
if (disable_clock) if (disable_clock)
clk_off(udc); clk_off(udc);
spin_unlock_irqrestore(&udc->lock, flags);
return IRQ_HANDLED; return IRQ_HANDLED;
} }
...@@ -1574,6 +1603,7 @@ int usb_gadget_register_driver (struct usb_gadget_driver *driver) ...@@ -1574,6 +1603,7 @@ int usb_gadget_register_driver (struct usb_gadget_driver *driver)
{ {
struct at91_udc *udc = &controller; struct at91_udc *udc = &controller;
int retval; int retval;
unsigned long flags;
if (!driver if (!driver
|| driver->speed < USB_SPEED_FULL || driver->speed < USB_SPEED_FULL
...@@ -1605,9 +1635,9 @@ int usb_gadget_register_driver (struct usb_gadget_driver *driver) ...@@ -1605,9 +1635,9 @@ int usb_gadget_register_driver (struct usb_gadget_driver *driver)
return retval; return retval;
} }
local_irq_disable(); spin_lock_irqsave(&udc->lock, flags);
pullup(udc, 1); pullup(udc, 1);
local_irq_enable(); spin_unlock_irqrestore(&udc->lock, flags);
DBG("bound to %s\n", driver->driver.name); DBG("bound to %s\n", driver->driver.name);
return 0; return 0;
...@@ -1617,15 +1647,16 @@ EXPORT_SYMBOL (usb_gadget_register_driver); ...@@ -1617,15 +1647,16 @@ EXPORT_SYMBOL (usb_gadget_register_driver);
int usb_gadget_unregister_driver (struct usb_gadget_driver *driver) int usb_gadget_unregister_driver (struct usb_gadget_driver *driver)
{ {
struct at91_udc *udc = &controller; struct at91_udc *udc = &controller;
unsigned long flags;
if (!driver || driver != udc->driver || !driver->unbind) if (!driver || driver != udc->driver || !driver->unbind)
return -EINVAL; return -EINVAL;
local_irq_disable(); spin_lock_irqsave(&udc->lock, flags);
udc->enabled = 0; udc->enabled = 0;
at91_udp_write(udc, AT91_UDP_IDR, ~0); at91_udp_write(udc, AT91_UDP_IDR, ~0);
pullup(udc, 0); pullup(udc, 0);
local_irq_enable(); spin_unlock_irqrestore(&udc->lock, flags);
driver->unbind(&udc->gadget); driver->unbind(&udc->gadget);
udc->gadget.dev.driver = NULL; udc->gadget.dev.driver = NULL;
...@@ -1641,8 +1672,13 @@ EXPORT_SYMBOL (usb_gadget_unregister_driver); ...@@ -1641,8 +1672,13 @@ EXPORT_SYMBOL (usb_gadget_unregister_driver);
static void at91udc_shutdown(struct platform_device *dev) static void at91udc_shutdown(struct platform_device *dev)
{ {
struct at91_udc *udc = platform_get_drvdata(dev);
unsigned long flags;
/* force disconnect on reboot */ /* force disconnect on reboot */
spin_lock_irqsave(&udc->lock, flags);
pullup(platform_get_drvdata(dev), 0); pullup(platform_get_drvdata(dev), 0);
spin_unlock_irqrestore(&udc->lock, flags);
} }
static int __init at91udc_probe(struct platform_device *pdev) static int __init at91udc_probe(struct platform_device *pdev)
...@@ -1683,6 +1719,7 @@ static int __init at91udc_probe(struct platform_device *pdev) ...@@ -1683,6 +1719,7 @@ static int __init at91udc_probe(struct platform_device *pdev)
udc->board = *(struct at91_udc_data *) dev->platform_data; udc->board = *(struct at91_udc_data *) dev->platform_data;
udc->pdev = pdev; udc->pdev = pdev;
udc->enabled = 0; udc->enabled = 0;
spin_lock_init(&udc->lock);
/* rm9200 needs manual D+ pullup; off by default */ /* rm9200 needs manual D+ pullup; off by default */
if (cpu_is_at91rm9200()) { if (cpu_is_at91rm9200()) {
...@@ -1804,13 +1841,16 @@ static int __exit at91udc_remove(struct platform_device *pdev) ...@@ -1804,13 +1841,16 @@ static int __exit at91udc_remove(struct platform_device *pdev)
{ {
struct at91_udc *udc = platform_get_drvdata(pdev); struct at91_udc *udc = platform_get_drvdata(pdev);
struct resource *res; struct resource *res;
unsigned long flags;
DBG("remove\n"); DBG("remove\n");
if (udc->driver) if (udc->driver)
return -EBUSY; return -EBUSY;
spin_lock_irqsave(&udc->lock, flags);
pullup(udc, 0); pullup(udc, 0);
spin_unlock_irqrestore(&udc->lock, flags);
device_init_wakeup(&pdev->dev, 0); device_init_wakeup(&pdev->dev, 0);
remove_debug_file(udc); remove_debug_file(udc);
...@@ -1840,6 +1880,7 @@ static int at91udc_suspend(struct platform_device *pdev, pm_message_t mesg) ...@@ -1840,6 +1880,7 @@ static int at91udc_suspend(struct platform_device *pdev, pm_message_t mesg)
{ {
struct at91_udc *udc = platform_get_drvdata(pdev); struct at91_udc *udc = platform_get_drvdata(pdev);
int wake = udc->driver && device_may_wakeup(&pdev->dev); int wake = udc->driver && device_may_wakeup(&pdev->dev);
unsigned long flags;
/* Unless we can act normally to the host (letting it wake us up /* Unless we can act normally to the host (letting it wake us up
* whenever it has work for us) force disconnect. Wakeup requires * whenever it has work for us) force disconnect. Wakeup requires
...@@ -1849,8 +1890,10 @@ static int at91udc_suspend(struct platform_device *pdev, pm_message_t mesg) ...@@ -1849,8 +1890,10 @@ static int at91udc_suspend(struct platform_device *pdev, pm_message_t mesg)
if ((!udc->suspended && udc->addr) if ((!udc->suspended && udc->addr)
|| !wake || !wake
|| at91_suspend_entering_slow_clock()) { || at91_suspend_entering_slow_clock()) {
spin_lock_irqsave(&udc->lock, flags);
pullup(udc, 0); pullup(udc, 0);
wake = 0; wake = 0;
spin_unlock_irqrestore(&udc->lock, flags);
} else } else
enable_irq_wake(udc->udp_irq); enable_irq_wake(udc->udp_irq);
...@@ -1863,6 +1906,7 @@ static int at91udc_suspend(struct platform_device *pdev, pm_message_t mesg) ...@@ -1863,6 +1906,7 @@ static int at91udc_suspend(struct platform_device *pdev, pm_message_t mesg)
static int at91udc_resume(struct platform_device *pdev) static int at91udc_resume(struct platform_device *pdev)
{ {
struct at91_udc *udc = platform_get_drvdata(pdev); struct at91_udc *udc = platform_get_drvdata(pdev);
unsigned long flags;
if (udc->board.vbus_pin > 0 && udc->active_suspend) if (udc->board.vbus_pin > 0 && udc->active_suspend)
disable_irq_wake(udc->board.vbus_pin); disable_irq_wake(udc->board.vbus_pin);
...@@ -1870,8 +1914,11 @@ static int at91udc_resume(struct platform_device *pdev) ...@@ -1870,8 +1914,11 @@ static int at91udc_resume(struct platform_device *pdev)
/* maybe reconnect to host; if so, clocks on */ /* maybe reconnect to host; if so, clocks on */
if (udc->active_suspend) if (udc->active_suspend)
disable_irq_wake(udc->udp_irq); disable_irq_wake(udc->udp_irq);
else else {
spin_lock_irqsave(&udc->lock, flags);
pullup(udc, 1); pullup(udc, 1);
spin_unlock_irqrestore(&udc->lock, flags);
}
return 0; return 0;
} }
#else #else
......
...@@ -144,6 +144,7 @@ struct at91_udc { ...@@ -144,6 +144,7 @@ struct at91_udc {
struct proc_dir_entry *pde; struct proc_dir_entry *pde;
void __iomem *udp_baseaddr; void __iomem *udp_baseaddr;
int udp_irq; int udp_irq;
spinlock_t lock;
}; };
static inline struct at91_udc *to_udc(struct usb_gadget *g) static inline struct at91_udc *to_udc(struct usb_gadget *g)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment