diff --git a/drivers/ethernet/eth_nxp_enet.c b/drivers/ethernet/eth_nxp_enet.c index 6620049fcb..6537ea1c84 100644 --- a/drivers/ethernet/eth_nxp_enet.c +++ b/drivers/ethernet/eth_nxp_enet.c @@ -116,13 +116,6 @@ struct nxp_enet_mac_data { ******************** */ -extern void nxp_enet_mdio_callback(const struct device *mdio_dev, - enum nxp_enet_callback_reason event); - -extern void nxp_enet_ptp_clock_callback(const struct device *dev, - enum nxp_enet_callback_reason event, - union nxp_enet_ptp_data *ptp_data); - static inline struct net_if *get_iface(struct nxp_enet_mac_data *data, uint16_t vlan_tag) { #if defined(CONFIG_NET_VLAN) @@ -632,6 +625,22 @@ static int nxp_enet_phy_init(const struct device *dev) **************************** */ +void nxp_enet_driver_cb(const struct device *dev, + enum nxp_enet_driver dev_type, + enum nxp_enet_callback_reason event, + void *data) +{ + if (dev_type == NXP_ENET_MDIO) { + nxp_enet_mdio_callback(dev, event, data); + } + +#ifdef CONFIG_PTP_CLOCK_NXP_ENET + if (dev_type == NXP_ENET_PTP_CLOCK) { + nxp_enet_ptp_clock_callback(dev, event, data); + } +#endif +} + static void eth_callback(ENET_Type *base, enet_handle_t *handle, #if FSL_FEATURE_ENET_QUEUE > 1 uint32_t ringId, @@ -704,7 +713,7 @@ static void eth_nxp_enet_isr(const struct device *dev) if (eir & ENET_EIR_MII_MASK) { /* Callback to MDIO driver for relevant interrupt */ - nxp_enet_mdio_callback(config->mdio, nxp_enet_interrupt); + nxp_enet_driver_cb(config->mdio, NXP_ENET_MDIO, NXP_ENET_INTERRUPT, NULL); } irq_unlock(irq_lock_key); @@ -798,13 +807,11 @@ static int eth_nxp_enet_init(const struct device *dev) data->mac_addr, enet_module_clock_rate); - nxp_enet_mdio_callback(config->mdio, nxp_enet_module_reset); + nxp_enet_driver_cb(config->mdio, NXP_ENET_MDIO, NXP_ENET_MODULE_RESET, NULL); #if defined(CONFIG_PTP_CLOCK_NXP_ENET) - union nxp_enet_ptp_data ptp_data; - - nxp_enet_ptp_clock_callback(config->ptp_clock, nxp_enet_module_reset, &ptp_data); - data->ptp_mutex = ptp_data.for_mac.ptp_mutex; + nxp_enet_driver_cb(config->ptp_clock, NXP_ENET_PTP_CLOCK, + NXP_ENET_MODULE_RESET, &data->ptp_mutex); ENET_SetTxReclaim(&data->enet_handle, true, 0); #endif diff --git a/drivers/mdio/mdio_nxp_enet.c b/drivers/mdio/mdio_nxp_enet.c index 2ea43e4842..88a25f8c98 100644 --- a/drivers/mdio/mdio_nxp_enet.c +++ b/drivers/mdio/mdio_nxp_enet.c @@ -228,18 +228,20 @@ static void nxp_enet_mdio_post_module_reset_init(const struct device *dev) } void nxp_enet_mdio_callback(const struct device *dev, - enum nxp_enet_callback_reason event) + enum nxp_enet_callback_reason event, void *cb_data) { struct nxp_enet_mdio_data *data = dev->data; + ARG_UNUSED(cb_data); + switch (event) { - case nxp_enet_module_reset: + case NXP_ENET_MODULE_RESET: nxp_enet_mdio_post_module_reset_init(dev); break; - case nxp_enet_interrupt: + case NXP_ENET_INTERRUPT: nxp_enet_mdio_isr_cb(dev); break; - case nxp_enet_interrupt_enabled: + case NXP_ENET_INTERRUPT_ENABLED: data->interrupt_up = true; break; default: diff --git a/drivers/ptp_clock/ptp_clock_nxp_enet.c b/drivers/ptp_clock/ptp_clock_nxp_enet.c index 67f561e9bc..821557cf79 100644 --- a/drivers/ptp_clock/ptp_clock_nxp_enet.c +++ b/drivers/ptp_clock/ptp_clock_nxp_enet.c @@ -153,12 +153,12 @@ static int ptp_clock_nxp_enet_rate_adjust(const struct device *dev, void nxp_enet_ptp_clock_callback(const struct device *dev, enum nxp_enet_callback_reason event, - union nxp_enet_ptp_data *ptp_data) + void *data) { const struct ptp_clock_nxp_enet_config *config = dev->config; struct ptp_clock_nxp_enet_data *data = dev->data; - if (event == nxp_enet_module_reset) { + if (event == NXP_ENET_MODULE_RESET) { enet_ptp_config_t ptp_config; uint32_t enet_ref_pll_rate; uint8_t ptp_multicast[6] = { 0x01, 0x1B, 0x19, 0x00, 0x00, 0x00 }; @@ -181,9 +181,9 @@ void nxp_enet_ptp_clock_callback(const struct device *dev, &ptp_config); } - if (ptp_data != NULL) { + if (data != NULL) { /* Share the mutex with mac driver */ - ptp_data->for_mac.ptp_mutex = &data->ptp_mutex; + *(struct k_mutex *)data = &data->ptp_mutex; } } diff --git a/include/zephyr/drivers/ethernet/eth_nxp_enet.h b/include/zephyr/drivers/ethernet/eth_nxp_enet.h index 8dcb5f31c0..5fc5564b32 100644 --- a/include/zephyr/drivers/ethernet/eth_nxp_enet.h +++ b/include/zephyr/drivers/ethernet/eth_nxp_enet.h @@ -29,27 +29,37 @@ extern "C" { * Interrupt enable: The driver's relevant interrupt was enabled in NVIC */ enum nxp_enet_callback_reason { - nxp_enet_module_reset, - nxp_enet_interrupt, - nxp_enet_interrupt_enabled, + NXP_ENET_MODULE_RESET, + NXP_ENET_INTERRUPT, + NXP_ENET_INTERRUPT_ENABLED, }; -struct nxp_enet_ptp_data_for_mac { - struct k_mutex *ptp_mutex; +enum nxp_enet_driver { + NXP_ENET_MAC, + NXP_ENET_MDIO, + NXP_ENET_PTP_CLOCK, }; -union nxp_enet_ptp_data { - struct nxp_enet_ptp_data_for_mac for_mac; -}; - -/* Calback for mdio device called from mac driver */ -void nxp_enet_mdio_callback(const struct device *mdio_dev, - enum nxp_enet_callback_reason event); - -void nxp_enet_ptp_clock_callback(const struct device *dev, +extern void nxp_enet_mdio_callback(const struct device *mdio_dev, enum nxp_enet_callback_reason event, - union nxp_enet_ptp_data *ptp_data); + void *data); +extern void nxp_enet_ptp_clock_callback(const struct device *dev, + enum nxp_enet_callback_reason event, + void *data); + +/* + * Internal implementation, inter-driver communication function + * + * dev: target device to call back + * dev_type: which driver to call back + * event: reason/cause of callback + * data: opaque data, will be interpreted based on reason and target driver + */ +extern void nxp_enet_driver_cb(const struct device *dev, + enum nxp_enet_driver dev_type, + enum nxp_enet_callback_reason event, + void *data); #ifdef __cplusplus }