drivers: clock_control: nrf: Move USB part to the USB driver

Removed all nrf_power/USB related stuff from clock control
driver to USB driver.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
This commit is contained in:
Krzysztof Chruscinski 2020-08-10 13:50:26 +02:00 committed by Carles Cufí
commit 701e9befe4
4 changed files with 41 additions and 67 deletions

View file

@ -11,7 +11,6 @@
#include <drivers/clock_control/nrf_clock_control.h>
#include "nrf_clock_calibration.h"
#include <nrfx_clock.h>
#include <nrfx_power.h>
#include <logging/log.h>
#include <shell/shell.h>
@ -504,29 +503,6 @@ static void clock_event_handler(nrfx_clock_evt_type_t event)
}
}
#if defined(CONFIG_USB_NRFX)
static void usb_event_handler(nrfx_power_usb_evt_t event)
{
extern void usb_dc_nrfx_power_event_callback(nrf_power_event_t evt);
switch (event) {
case NRFX_POWER_USB_EVT_DETECTED:
usb_dc_nrfx_power_event_callback(NRF_POWER_EVENT_USBDETECTED);
break;
case NRFX_POWER_USB_EVT_REMOVED:
usb_dc_nrfx_power_event_callback(NRF_POWER_EVENT_USBREMOVED);
break;
case NRFX_POWER_USB_EVT_READY:
usb_dc_nrfx_power_event_callback(NRF_POWER_EVENT_USBPWRRDY);
break;
default:
__ASSERT_NO_MSG(0);
break;
}
}
#endif
static int clk_init(struct device *dev)
{
nrfx_err_t nrfx_err;
@ -540,15 +516,6 @@ static int clk_init(struct device *dev)
nrfx_isr, nrfx_power_clock_irq_handler, 0);
irq_enable(DT_INST_IRQN(0));
#if defined(CONFIG_USB_NRFX) && defined(CONFIG_SOC_SERIES_NRF53X)
/* Use CLOCK/POWER priority for compatibility with other series where
* USB events are handled by CLOCK interrupt handler.
*/
IRQ_CONNECT(USBREGULATOR_IRQn, DT_INST_IRQ(0, priority),
nrfx_usbreg_irq_handler, 0, 0);
irq_enable(USBREGULATOR_IRQn);
#endif
nrfx_err = nrfx_clock_init(clock_event_handler);
if (nrfx_err != NRFX_SUCCESS) {
return -EIO;
@ -562,12 +529,6 @@ static int clk_init(struct device *dev)
nrfx_clock_enable();
static const nrfx_power_usbevt_config_t config = {
.handler = usb_event_handler
};
nrfx_power_usbevt_init(&config);
for (enum clock_control_nrf_type i = 0;
i < CLOCK_CONTROL_NRF_TYPE_COUNT; i++) {
struct nrf_clock_control_sub_data *subdata =
@ -614,17 +575,6 @@ DEVICE_AND_API_INIT(clock_nrf, DT_INST_LABEL(0),
CONFIG_KERNEL_INIT_PRIORITY_DEVICE,
&clock_control_api);
#ifdef CONFIG_USB_NRFX
void nrf5_power_usb_power_int_enable(bool enable)
{
if (enable) {
nrfx_power_usbevt_enable();
} else {
nrfx_power_usbevt_disable();
}
}
#endif
static int cmd_status(const struct shell *shell, size_t argc, char **argv)
{
nrf_clock_hfclk_t hfclk_src;

View file

@ -54,6 +54,7 @@ menuconfig USB_NRFX
select USB_DEVICE_DRIVER
select NRFX_USBD
select USB_DEVICE_DISABLE_ZLP_EPIN_HANDLING
select NRFX_USBREG if SOC_SERIES_NRF53X
help
nRF USB Device Controller Driver

View file

@ -20,9 +20,9 @@
#include <drivers/usb/usb_dc.h>
#include <usb/usb_device.h>
#include <drivers/clock_control.h>
#include <hal/nrf_power.h>
#include <drivers/clock_control/nrf_clock_control.h>
#include <nrfx_usbd.h>
#include <nrfx_power.h>
#define LOG_LEVEL CONFIG_USB_DRIVER_LOG_LEVEL
@ -493,22 +493,22 @@ static inline struct usbd_event *usbd_evt_alloc(void)
return ev;
}
void usb_dc_nrfx_power_event_callback(nrf_power_event_t event)
static void usb_dc_power_event_handler(nrfx_power_usb_evt_t event)
{
enum usbd_periph_state new_state;
switch (event) {
case NRF_POWER_EVENT_USBDETECTED:
case NRFX_POWER_USB_EVT_DETECTED:
new_state = USBD_ATTACHED;
break;
case NRF_POWER_EVENT_USBPWRRDY:
case NRFX_POWER_USB_EVT_READY:
new_state = USBD_POWERED;
break;
case NRF_POWER_EVENT_USBREMOVED:
case NRFX_POWER_USB_EVT_REMOVED:
new_state = USBD_DETACHED;
break;
default:
LOG_ERR("Unknown USB power event");
LOG_ERR("Unknown USB power event %d", event);
return;
}
@ -1205,19 +1205,20 @@ static inline void usbd_reinit(void)
int ret;
nrfx_err_t err;
nrf5_power_usb_power_int_enable(false);
nrfx_power_usbevt_disable();
nrfx_usbd_disable();
nrfx_usbd_uninit();
usbd_evt_flush();
ret = eps_ctx_init();
__ASSERT_NO_MSG(ret == 0);
nrf5_power_usb_power_int_enable(true);
nrfx_power_usbevt_enable();
err = nrfx_usbd_init(usbd_event_handler);
if (err != NRFX_SUCCESS) {
LOG_DBG("nRF USBD driver reinit failed. Code: %d", (uint32_t)err);
LOG_DBG("nRF USBD driver reinit failed. Code: %d", err);
__ASSERT_NO_MSG(0);
}
}
@ -1351,7 +1352,7 @@ int usb_dc_attach(void)
LOG_DBG("nRF USBD driver init failed. Code: %d", (uint32_t)err);
return -EIO;
}
nrf5_power_usb_power_int_enable(true);
nrfx_power_usbevt_enable();
ret = eps_ctx_init();
if (ret == 0) {
@ -1362,7 +1363,7 @@ int usb_dc_attach(void)
usbd_work_schedule();
}
if (nrf_power_usbregstatus_vbusdet_get(NRF_POWER)) {
if (nrfx_power_usbstatus_get() != NRFX_POWER_USB_STATE_DISCONNECTED) {
/* USBDETECTED event is be generated on cable attachment and
* when cable is already attached during reset, but not when
* the peripheral is re-enabled.
@ -1370,7 +1371,7 @@ int usb_dc_attach(void)
* will not receive this event and it needs to be generated
* again here.
*/
usb_dc_nrfx_power_event_callback(NRF_POWER_EVENT_USBDETECTED);
usb_dc_power_event_handler(NRFX_POWER_USB_EVT_DETECTED);
}
return ret;
@ -1394,7 +1395,7 @@ int usb_dc_detach(void)
}
(void)hfxo_stop(ctx);
nrf5_power_usb_power_int_enable(false);
nrfx_power_usbevt_disable();
ctx->attached = false;
k_mutex_unlock(&ctx->drv_lock);
@ -1923,3 +1924,29 @@ int usb_dc_wakeup_request(void)
}
return 0;
}
static int usb_init(struct device *arg)
{
#ifdef CONFIG_SOC_SERIES_NRF53X
#undef DT_DRV_COMPAT
#define DT_DRV_COMPAT nordic_nrf_clock
/* Use CLOCK/POWER priority for compatibility with other series where
* USB events are handled by CLOCK interrupt handler.
*/
IRQ_CONNECT(USBREGULATOR_IRQn, DT_INST_IRQ(0, priority),
nrfx_usbreg_irq_handler, 0, 0);
irq_enable(USBREGULATOR_IRQn);
#endif
static const nrfx_power_usbevt_config_t config = {
.handler = usb_dc_power_event_handler
};
nrfx_power_usbevt_init(&config);
return 0;
}
SYS_INIT(usb_init, PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_DEVICE);

View file

@ -80,10 +80,6 @@ enum nrf_lfclk_start_mode {
#define CLOCK_CONTROL_NRF_K32SRC_ACCURACY 7
#endif
#if defined(CONFIG_USB_NRFX)
void nrf5_power_usb_power_int_enable(bool enable);
#endif
/** @brief Force LF clock calibration. */
void z_nrf_clock_calibration_force_start(void);