Skip to content

Commit 70cd0ab

Browse files
tmon-nordickartben
authored andcommitted
drivers: udc_dwc2: Use spin lock for synchronization
Replace irq_lock() with spin lock which is proper synchronization primitive that should be used. Because non-SMP implementations are allowed to optimize spin lock to just locking interrupts the resulting code is the same on all currently supported DWC2 targets. Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
1 parent c237253 commit 70cd0ab

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

drivers/usb/udc/udc_dwc2.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ struct dwc2_reg_backup {
102102

103103
/* Driver private data per instance */
104104
struct udc_dwc2_data {
105+
struct k_spinlock lock;
105106
struct k_thread thread_data;
106107
/* Main events the driver thread waits for */
107108
struct k_event drv_evt;
@@ -462,7 +463,7 @@ static int dwc2_tx_fifo_write(const struct device *dev,
462463
uint32_t max_xfersize, max_pktcnt, pktcnt;
463464
const uint32_t addnl = USB_MPS_ADDITIONAL_TRANSACTIONS(cfg->mps);
464465
const size_t d = sizeof(uint32_t);
465-
unsigned int key;
466+
k_spinlock_key_t key;
466467
uint32_t len;
467468
const bool is_periodic = dwc2_ep_is_periodic(cfg);
468469
const bool is_iso = dwc2_ep_is_iso(cfg);
@@ -537,7 +538,7 @@ static int dwc2_tx_fifo_write(const struct device *dev,
537538
priv->tx_len[ep_idx] = len;
538539

539540
/* Lock and write to endpoint FIFO */
540-
key = irq_lock();
541+
key = k_spin_lock(&priv->lock);
541542

542543
/* Set number of packets and transfer size */
543544
sys_write32((is_periodic ? usb_dwc2_set_dieptsizn_mc(1 + addnl) : 0) |
@@ -549,7 +550,7 @@ static int dwc2_tx_fifo_write(const struct device *dev,
549550
/* Cannot continue unless buffer is bounced. Device will
550551
* cease to function. Is fatal error appropriate here?
551552
*/
552-
irq_unlock(key);
553+
k_spin_unlock(&priv->lock, key);
553554
return -ENOTSUP;
554555
}
555556

@@ -565,7 +566,7 @@ static int dwc2_tx_fifo_write(const struct device *dev,
565566
* no fifo is assigned to inactive endpoint and therefore it is
566567
* possible that the write will corrupt other endpoint fifo.
567568
*/
568-
irq_unlock(key);
569+
k_spin_unlock(&priv->lock, key);
569570
return -ENOENT;
570571
}
571572

@@ -615,7 +616,7 @@ static int dwc2_tx_fifo_write(const struct device *dev,
615616
}
616617
}
617618

618-
irq_unlock(key);
619+
k_spin_unlock(&priv->lock, key);
619620

620621
return 0;
621622
}

0 commit comments

Comments
 (0)