Skip to content

Commit bc785e0

Browse files
decsnyaescolar
authored andcommitted
drivers: nxp_enet: Add NET DEVICE PM function
Add functionality for when NET_POWER_MANAGEMENT (ie PM_DEVICE) is enabled. This function code originally comes from the old eth_mcux driver which was only tested on kinetis family SOCs, so that family kconfig is a dependency for this feature for now. Signed-off-by: Declan Snyder <[email protected]>
1 parent fe3aefe commit bc785e0

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

drivers/ethernet/Kconfig.nxp_enet

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ menuconfig ETH_NXP_ENET
1010
select NOCACHE_MEMORY if HAS_MCUX_CACHE
1111
select ARM_MPU if CPU_CORTEX_M7
1212
select MDIO if DT_HAS_NXP_ENET_MDIO_ENABLED
13+
select NET_POWER_MANAGEMENT if (PM_DEVICE && SOC_FAMILY_KINETIS)
1314
select EXPERIMENTAL
1415
help
1516
Enable NXP ENET Ethernet driver.

drivers/ethernet/eth_nxp_enet.c

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME);
4242
#include <zephyr/net/dsa.h>
4343
#endif
4444

45+
#if defined(CONFIG_NET_POWER_MANAGEMENT) && defined(CONFIG_PM_DEVICE)
46+
#include <zephyr/pm/device.h>
47+
#endif
48+
4549
#include <zephyr/drivers/ethernet/eth_nxp_enet.h>
4650
#include <zephyr/dt-bindings/ethernet/nxp_enet.h>
4751
#include <fsl_enet.h>
@@ -629,6 +633,50 @@ static int eth_nxp_enet_init(const struct device *dev)
629633
return 0;
630634
}
631635

636+
#if defined(CONFIG_NET_POWER_MANAGEMENT)
637+
static int eth_nxp_enet_device_pm_action(const struct device *dev, enum pm_device_action action)
638+
{
639+
const struct nxp_enet_mac_config *config = dev->config;
640+
struct nxp_enet_mac_data *data = dev->data;
641+
int ret;
642+
643+
if (!device_is_ready(config->clock_dev)) {
644+
return -ENODEV;
645+
}
646+
647+
if (action == PM_DEVICE_ACTION_SUSPEND) {
648+
LOG_DBG("Suspending");
649+
650+
ret = net_if_suspend(data->iface);
651+
if (ret) {
652+
return ret;
653+
}
654+
655+
ENET_Reset(config->base);
656+
ENET_Down(config->base);
657+
clock_control_off(config->clock_dev, (clock_control_subsys_t)config->clock_subsys);
658+
} else if (action == PM_DEVICE_ACTION_RESUME) {
659+
LOG_DBG("Resuming");
660+
661+
clock_control_on(config->clock_dev, (clock_control_subsys_t)config->clock_subsys);
662+
eth_nxp_enet_init(dev);
663+
net_if_resume(data->iface);
664+
} else {
665+
return -ENOTSUP;
666+
}
667+
668+
return 0;
669+
}
670+
671+
#define ETH_NXP_ENET_PM_DEVICE_INIT(n) \
672+
PM_DEVICE_DT_INST_DEFINE(n, eth_nxp_enet_device_pm_action);
673+
#define ETH_NXP_ENET_PM_DEVICE_GET(n) PM_DEVICE_DT_INST_GET(n)
674+
675+
#else
676+
#define ETH_NXP_ENET_PM_DEVICE_INIT(n)
677+
#define ETH_NXP_ENET_PM_DEVICE_GET(n) NULL
678+
#endif /* CONFIG_NET_POWER_MANAGEMENT */
679+
632680
#ifdef CONFIG_NET_DSA
633681
#define NXP_ENET_SEND_FUNC dsa_tx
634682
#else
@@ -842,7 +890,10 @@ static const struct ethernet_api api_funcs = {
842890
.rx_frame_buf = nxp_enet_##n##_rx_frame_buf, \
843891
}; \
844892
\
845-
ETH_NET_DEVICE_DT_INST_DEFINE(n, eth_nxp_enet_init, NULL, \
893+
ETH_NXP_ENET_PM_DEVICE_INIT(n) \
894+
\
895+
ETH_NET_DEVICE_DT_INST_DEFINE(n, eth_nxp_enet_init, \
896+
ETH_NXP_ENET_PM_DEVICE_GET(n), \
846897
&nxp_enet_##n##_data, &nxp_enet_##n##_config, \
847898
CONFIG_ETH_INIT_PRIORITY, \
848899
&api_funcs, NET_ETH_MTU);

0 commit comments

Comments
 (0)