diff --git a/arch/arm/src/lc823450/lc823450_usbdev.c b/arch/arm/src/lc823450/lc823450_usbdev.c index facacbc43c..7929c9195f 100644 --- a/arch/arm/src/lc823450/lc823450_usbdev.c +++ b/arch/arm/src/lc823450/lc823450_usbdev.c @@ -122,6 +122,7 @@ struct lc823450_usbdev_s struct usbdev_s usbdev; struct usbdevclass_driver_s *driver; struct lc823450_ep_s eplist[LC823450_NPHYSENDPOINTS]; + spinlock_t lock; /* Spinlock */ int bufoffset; uint8_t used; /* used phyep */ #ifdef CONFIG_WAKELOCK @@ -477,7 +478,7 @@ static int lc823450_epclearreq(struct usbdev_ep_s *ep) struct lc823450_ep_s *privep = (struct lc823450_ep_s *)ep; irqstate_t flags; - flags = spin_lock_irqsave(NULL); + flags = spin_lock_irqsave(&g_usbdev.lock); while (privep->req_q.tail) { struct usbdev_req_s *req; @@ -494,7 +495,7 @@ static int lc823450_epclearreq(struct usbdev_ep_s *ep) req->callback(ep, req); } - spin_unlock_irqrestore(NULL, flags); + spin_unlock_irqrestore(&g_usbdev.lock, flags); return 0; } @@ -659,27 +660,27 @@ static int lc823450_epsubmit(struct usbdev_ep_s *ep, if (privep->epphy == 0) { - flags = spin_lock_irqsave(NULL); + flags = spin_lock_irqsave(&g_usbdev.lock); req->xfrd = epbuf_write(privep->epphy, req->buf, req->len); - spin_unlock_irqrestore(NULL, flags); + spin_unlock_irqrestore(&g_usbdev.lock, flags); req->callback(ep, req); } else if (privep->in) { /* Send packet request from function driver */ - flags = spin_lock_irqsave(NULL); + flags = spin_lock_irqsave(&g_usbdev.lock); if ((getreg32(USB_EPCOUNT(privep->epphy * 2)) & USB_EPCOUNT_PHYCNT_MASK) >> USB_EPCOUNT_PHYCNT_SHIFT || privep->req_q.tail) { sq_addfirst(&privreq->q_ent, &privep->req_q); /* non block */ - spin_unlock_irqrestore(NULL, flags); + spin_unlock_irqrestore(&g_usbdev.lock, flags); } else { - spin_unlock_irqrestore(NULL, flags); + spin_unlock_irqrestore(&g_usbdev.lock, flags); req->xfrd = epbuf_write(privep->epphy, req->buf, req->len); req->callback(ep, req); } @@ -688,9 +689,9 @@ static int lc823450_epsubmit(struct usbdev_ep_s *ep, { /* receive packet buffer from function driver */ - flags = spin_lock_irqsave(NULL); + flags = spin_lock_irqsave(&g_usbdev.lock); sq_addfirst(&privreq->q_ent, &privep->req_q); /* non block */ - spin_unlock_irqrestore(NULL, flags); + spin_unlock_irqrestore(&g_usbdev.lock, flags); lc823450_epack(privep->epphy, 1); } @@ -714,9 +715,9 @@ static int lc823450_epcancel(struct usbdev_ep_s *ep, /* Remove request from req_queue */ - flags = spin_lock_irqsave(NULL); + flags = spin_lock_irqsave(&g_usbdev.lock); sq_remafter(&privreq->q_ent, &privep->req_q); - spin_unlock_irqrestore(NULL, flags); + spin_unlock_irqrestore(&g_usbdev.lock, flags); return 0; } @@ -735,7 +736,7 @@ static int lc823450_epstall(struct usbdev_ep_s *ep, bool resume) /* STALL or RESUME the endpoint */ - flags = spin_lock_irqsave(NULL); + flags = spin_lock_irqsave(&g_usbdev.lock); usbtrace(resume ? TRACE_EPRESUME : TRACE_EPSTALL, privep->epphy); if (resume) @@ -749,7 +750,7 @@ static int lc823450_epstall(struct usbdev_ep_s *ep, bool resume) epcmd_write(privep->epphy, USB_EPCMD_STALL_SET | USB_EPCMD_TGL_SET); } - spin_unlock_irqrestore(NULL, flags); + spin_unlock_irqrestore(&g_usbdev.lock, flags); return OK; } @@ -758,11 +759,11 @@ void up_epignore_clear_stall(struct usbdev_ep_s *ep, bool ignore) { struct lc823450_ep_s *privep = (struct lc823450_ep_s *)ep; irqstate_t flags; - flags = spin_lock_irqsave(NULL); + flags = spin_lock_irqsave(&g_usbdev.lock); privep->ignore_clear_stall = ignore; - spin_unlock_irqrestore(NULL, flags); + spin_unlock_irqrestore(&g_usbdev.lock, flags); } #endif /* CONFIG_USBMSC_IGNORE_CLEAR_STALL */ @@ -919,7 +920,7 @@ static void usb_suspend_work_func(void *arg) } #endif - flags = spin_lock_irqsave(NULL); + flags = spin_lock_irqsave(&g_usbdev.lock); if (getreg32(USB_DEVS) & USB_DEVS_SUSPEND) { uinfo("USB BUS SUSPEND\n"); @@ -934,7 +935,7 @@ static void usb_suspend_work_func(void *arg) wake_unlock(&priv->wlock); } - spin_unlock_irqrestore(NULL, flags); + spin_unlock_irqrestore(&g_usbdev.lock, flags); } #endif @@ -1252,7 +1253,7 @@ static void subintr_epin(uint8_t epnum, struct lc823450_ep_s *privep) /* Send packet done */ irqstate_t flags; - flags = spin_lock_irqsave(NULL); + flags = spin_lock_irqsave(&g_usbdev.lock); if (privep->req_q.tail) { @@ -1263,7 +1264,7 @@ static void subintr_epin(uint8_t epnum, struct lc823450_ep_s *privep) q_ent = sq_remlast(&privep->req_q); - spin_unlock_irqrestore(NULL, flags); + spin_unlock_irqrestore(&g_usbdev.lock, flags); req = &container_of(q_ent, struct lc823450_req_s, q_ent)->req; @@ -1279,7 +1280,7 @@ static void subintr_epin(uint8_t epnum, struct lc823450_ep_s *privep) } else { - spin_unlock_irqrestore(NULL, flags); + spin_unlock_irqrestore(&g_usbdev.lock, flags); epcmd_write(epnum, USB_EPCMD_EMPTY_CLR); } } @@ -1297,7 +1298,7 @@ static void subintr_epout(uint8_t epnum, struct lc823450_ep_s *privep) /* Packet receive from host */ irqstate_t flags; - flags = spin_lock_irqsave(NULL); + flags = spin_lock_irqsave(&g_usbdev.lock); if (privep->req_q.tail) { @@ -1316,7 +1317,7 @@ static void subintr_epout(uint8_t epnum, struct lc823450_ep_s *privep) lc823450_epack(epnum, 0); } - spin_unlock_irqrestore(NULL, flags); + spin_unlock_irqrestore(&g_usbdev.lock, flags); /* PIO */ @@ -1329,7 +1330,7 @@ static void subintr_epout(uint8_t epnum, struct lc823450_ep_s *privep) } else { - spin_unlock_irqrestore(NULL, flags); + spin_unlock_irqrestore(&g_usbdev.lock, flags); uinfo("REQ Buffer Exhault\n"); epcmd_write(epnum, USB_EPCMD_READY_CLR); } @@ -1430,6 +1431,7 @@ void arm_usbinitialize(void) memset(&g_usbdev, 0, sizeof(g_usbdev)); g_usbdev.usbdev.ops = &g_devops; g_usbdev.usbdev.ep0 = &g_usbdev.eplist[0].ep; + spin_lock_init(&g_usbdev.lock); for (i = 0; i < LC823450_NPHYSENDPOINTS; i++) { @@ -1647,7 +1649,7 @@ int usbdev_unregister(struct usbdevclass_driver_s *driver) * canceled while the class driver is still bound. */ - flags = spin_lock_irqsave(NULL); + flags = spin_lock_irqsave(&g_usbdev.lock); #ifdef CONFIG_WAKELOCK /* cancel USB suspend work */ @@ -1683,7 +1685,7 @@ int usbdev_unregister(struct usbdevclass_driver_s *driver) pm_unregister(&g_pm_cb); #endif /* CONFIG_PM */ - spin_unlock_irqrestore(NULL, flags); + spin_unlock_irqrestore(&g_usbdev.lock, flags); #ifdef CONFIG_LC823450_LSISTBY /* disable USB */ @@ -1933,7 +1935,7 @@ static void usbdev_pmnotify(struct pm_callback_s *cb, { irqstate_t flags; - flags = spin_lock_irqsave(NULL); + flags = spin_lock_irqsave(&g_usbdev.lock); switch (pmstate) { @@ -1956,6 +1958,6 @@ static void usbdev_pmnotify(struct pm_callback_s *cb, break; } - spin_unlock_irqrestore(NULL, flags); + spin_unlock_irqrestore(&g_usbdev.lock, flags); } #endif