drivers: nxp_enet: simplify driver header

Simplify the driver header implementation, so that there are not
structs and unions different per each situtaion, and make just one
function for the enet module drivers to call on each other. Also,
capitalize existing enums.

Signed-off-by: Declan Snyder <declan.snyder@nxp.com>
This commit is contained in:
Declan Snyder 2023-11-30 16:13:44 -06:00 committed by Henrik Brix Andersen
parent 07e3869809
commit 213471f2ad
4 changed files with 55 additions and 36 deletions

View file

@ -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

View file

@ -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:

View file

@ -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;
}
}

View file

@ -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
}