Skip to content

Commit 4cc21ef

Browse files
committed
drivers: udc: disable SOF interrupt by default
Add Kconfig option to enable SOF interrupts. Disable SOF interrupt in drivers that are maintainable and do not obfuscate how interrupts are enabled. If the new Kconfig option is disabled, no SOF events are passed to the higher layer. Signed-off-by: Johann Fischer <[email protected]>
1 parent f3a3ad3 commit 4cc21ef

File tree

20 files changed

+69
-23
lines changed

20 files changed

+69
-23
lines changed

drivers/usb/udc/Kconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ config UDC_BUF_FORCE_NOCACHE
3232
Place the buffer pools in the nocache memory region if the driver
3333
cannot handle buffers in cached memory.
3434

35+
config UDC_ENABLE_SOF
36+
bool "SOF interrupt processing"
37+
help
38+
Enabled SoF interrupts can cause a very high CPU load on high-speed
39+
controllers because the interrupt rate would be 125 µs.
40+
3541
config UDC_WORKQUEUE
3642
bool "Use a dedicate work queue for UDC drivers"
3743
help

drivers/usb/udc/udc_ambiq.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,9 @@ static void udc_ambiq_evt_callback(const struct device *dev, am_hal_usb_dev_even
157157
case AM_HAL_USB_DEV_EVT_BUS_RESET:
158158
/* enable usb bus interrupts */
159159
am_hal_usb_intr_usb_enable(priv->usb_handle,
160-
USB_CFG2_SOFE_Msk | USB_CFG2_ResumeE_Msk |
161-
USB_CFG2_SuspendE_Msk | USB_CFG2_ResetE_Msk);
160+
IF_ENABLED(CONFIG_UDC_ENABLE_SOF, (USB_CFG2_SOFE_Msk |))
161+
USB_CFG2_ResumeE_Msk |
162+
USB_CFG2_SuspendE_Msk | USB_CFG2_ResetE_Msk);
162163
/* init the endpoint */
163164
am_hal_usb_ep_init(priv->usb_handle, 0, 0, EP0_MPS);
164165
/* Set USB device speed to HAL */
@@ -175,7 +176,7 @@ static void udc_ambiq_evt_callback(const struct device *dev, am_hal_usb_dev_even
175176
udc_submit_event(dev, UDC_EVT_RESUME, 0);
176177
break;
177178
case AM_HAL_USB_DEV_EVT_SOF:
178-
udc_submit_event(dev, UDC_EVT_SOF, 0);
179+
udc_submit_sof_event(dev, 0);
179180
break;
180181
case AM_HAL_USB_DEV_EVT_SUSPEND:
181182
/* Handle USB Suspend event, then set device state to suspended */

drivers/usb/udc/udc_common.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,24 @@ int udc_submit_event(const struct device *dev,
180180
return data->event_cb(dev, &drv_evt);
181181
}
182182

183+
void udc_submit_sof_event(const struct device *dev,
184+
const int frame)
185+
{
186+
#if defined(CONFIG_UDC_ENABLE_SOF)
187+
struct udc_data *data = dev->data;
188+
struct udc_event drv_evt = {
189+
.type = UDC_EVT_SOF,
190+
.status = frame,
191+
.dev = dev,
192+
};
193+
194+
(void)data->event_cb(dev, &drv_evt);
195+
#else
196+
ARG_UNUSED(dev);
197+
ARG_UNUSED(frame);
198+
#endif
199+
}
200+
183201
int udc_submit_ep_event(const struct device *dev,
184202
struct net_buf *const buf,
185203
const int err)

drivers/usb/udc/udc_common.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,18 @@ int udc_submit_event(const struct device *dev,
156156
int udc_submit_ep_event(const struct device *dev,
157157
struct net_buf *const buf,
158158
const int err);
159+
160+
/**
161+
* @brief Helper function to send UDC SOF event to a higher level.
162+
*
163+
* Type of this event is hardcoded to UDC_EVT_SOF.
164+
*
165+
* @param[in] dev Pointer to device struct of the driver instance
166+
* @param[in] frame Frame number
167+
*/
168+
void udc_submit_sof_event(const struct device *dev,
169+
const int frame);
170+
159171
/**
160172
* @brief Helper function to enable endpoint.
161173
*

drivers/usb/udc/udc_dwc2.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2154,8 +2154,8 @@ static int udc_dwc2_init_controller(const struct device *dev)
21542154
sys_write32(USB_DWC2_GINTSTS_OEPINT | USB_DWC2_GINTSTS_IEPINT |
21552155
USB_DWC2_GINTSTS_ENUMDONE | USB_DWC2_GINTSTS_USBRST |
21562156
USB_DWC2_GINTSTS_WKUPINT | USB_DWC2_GINTSTS_USBSUSP |
2157-
USB_DWC2_GINTSTS_INCOMPISOOUT | USB_DWC2_GINTSTS_INCOMPISOIN |
2158-
USB_DWC2_GINTSTS_SOF,
2157+
IF_ENABLED(CONFIG_UDC_ENABLE_SOF, (USB_DWC2_GINTSTS_SOF |))
2158+
USB_DWC2_GINTSTS_INCOMPISOOUT | USB_DWC2_GINTSTS_INCOMPISOIN,
21592159
(mem_addr_t)&base->gintmsk);
21602160

21612161
return 0;
@@ -2890,7 +2890,7 @@ static void udc_dwc2_isr_handler(const struct device *dev)
28902890

28912891
dsts = sys_read32((mem_addr_t)&base->dsts);
28922892
priv->sof_num = usb_dwc2_get_dsts_soffn(dsts);
2893-
udc_submit_event(dev, UDC_EVT_SOF, 0);
2893+
udc_submit_sof_event(dev, 0);
28942894
}
28952895

28962896
if (int_status & USB_DWC2_GINTSTS_USBRST) {

drivers/usb/udc/udc_it82xx2.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ LOG_MODULE_REGISTER(udc_it82xx2, CONFIG_UDC_DRIVER_LOG_LEVEL);
1717

1818
#define DT_DRV_COMPAT ite_it82xx2_usb
1919

20-
/* TODO: Replace this definition by Kconfig option */
21-
#define USB_DEVICE_CONFIG_SOF_NOTIFICATIONS (0U)
22-
2320
#define IT8XXX2_IS_EXTEND_ENDPOINT(n) (USB_EP_GET_IDX(n) >= 4)
2421

2522
#define IT82xx2_STATE_OUT_SHARED_FIFO_BUSY 0
@@ -1357,11 +1354,11 @@ static void it82xx2_usb_dc_isr(const void *arg)
13571354

13581355
/* sof received */
13591356
if (status & DC_SOF_RECEIVED) {
1360-
if (!USB_DEVICE_CONFIG_SOF_NOTIFICATIONS) {
1357+
if (!IS_ENABLED(CONFIG_UDC_ENABLE_SOF)) {
13611358
it82xx2_enable_sof_int(dev, false);
13621359
} else {
13631360
usb_regs->dc_interrupt_status = DC_SOF_RECEIVED;
1364-
udc_submit_event(dev, UDC_EVT_SOF, 0);
1361+
udc_submit_sof_event(dev, 0);
13651362
}
13661363
it82xx2_enable_resume_int(dev, false);
13671364
emit_resume_event(dev);
@@ -1411,7 +1408,7 @@ static void suspended_handler(struct k_work *item)
14111408

14121409
it82xx2_enable_resume_int(dev, true);
14131410

1414-
if (!USB_DEVICE_CONFIG_SOF_NOTIFICATIONS) {
1411+
if (!IS_ENABLED(CONFIG_UDC_ENABLE_SOF)) {
14151412
it82xx2_enable_sof_int(dev, true);
14161413
}
14171414

drivers/usb/udc/udc_kinetis.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ static void usbfsotg_isr_handler(const struct device *dev)
653653
}
654654

655655
if (istatus == USB_ISTAT_SOFTOK_MASK) {
656-
udc_submit_event(dev, UDC_EVT_SOF, 0);
656+
udc_submit_sof_event(dev, 0);
657657
}
658658

659659
if (istatus == USB_ISTAT_ERROR_MASK) {
@@ -1016,7 +1016,7 @@ static int usbfsotg_init(const struct device *dev)
10161016
base->INTEN = (USB_INTEN_SLEEPEN_MASK |
10171017
USB_INTEN_STALLEN_MASK |
10181018
USB_INTEN_TOKDNEEN_MASK |
1019-
USB_INTEN_SOFTOKEN_MASK |
1019+
IF_ENABLED(CONFIG_UDC_ENABLE_SOF, (USB_INTEN_SOFTOKEN_MASK |))
10201020
USB_INTEN_ERROREN_MASK |
10211021
USB_INTEN_USBRSTEN_MASK);
10221022

drivers/usb/udc/udc_mcux_ehci.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ usb_status_t USB_DeviceNotificationTrigger(void *handle, void *msg)
531531
udc_submit_event(dev, UDC_EVT_VBUS_READY, 0);
532532
break;
533533
case kUSB_DeviceNotifySOF:
534-
udc_submit_event(dev, UDC_EVT_SOF, 0);
534+
udc_submit_sof_event(dev, 0);
535535
break;
536536
default:
537537
udc_mcux_event_submit(dev, mcux_msg);

drivers/usb/udc/udc_mcux_ip3511.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ usb_status_t USB_DeviceNotificationTrigger(void *handle, void *msg)
531531
udc_submit_event(dev, UDC_EVT_VBUS_READY, 0);
532532
break;
533533
case kUSB_DeviceNotifySOF:
534-
udc_submit_event(dev, UDC_EVT_SOF, 0);
534+
udc_submit_sof_event(dev, 0);
535535
break;
536536
default:
537537
udc_mcux_event_submit(dev, mcux_msg);

drivers/usb/udc/udc_nrf.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ static void usbd_event_handler(nrf_usbd_common_evt_t const *const hal_evt)
526526
udc_submit_event(udc_nrf_dev, UDC_EVT_RESET, 0);
527527
break;
528528
case NRF_USBD_COMMON_EVT_SOF:
529-
udc_submit_event(udc_nrf_dev, UDC_EVT_SOF, 0);
529+
udc_submit_sof_event(udc_nrf_dev, 0);
530530
udc_sof_check_iso_out(udc_nrf_dev);
531531
break;
532532
case NRF_USBD_COMMON_EVT_SUSPEND:
@@ -559,7 +559,7 @@ static void udc_nrf_power_handler(nrfx_power_usb_evt_t pwr_evt)
559559
break;
560560
case NRFX_POWER_USB_EVT_READY:
561561
LOG_DBG("POWER event ready");
562-
nrf_usbd_common_start(true);
562+
nrf_usbd_common_start(IS_ENABLED(CONFIG_UDC_ENABLE_SOF));
563563
break;
564564
case NRFX_POWER_USB_EVT_REMOVED:
565565
LOG_DBG("POWER event removed");

0 commit comments

Comments
 (0)