@@ -42,6 +42,10 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME);
42
42
#include <zephyr/net/dsa.h>
43
43
#endif
44
44
45
+ #if defined(CONFIG_NET_POWER_MANAGEMENT ) && defined(CONFIG_PM_DEVICE )
46
+ #include <zephyr/pm/device.h>
47
+ #endif
48
+
45
49
#include <zephyr/drivers/ethernet/eth_nxp_enet.h>
46
50
#include <zephyr/dt-bindings/ethernet/nxp_enet.h>
47
51
#include <fsl_enet.h>
@@ -629,6 +633,50 @@ static int eth_nxp_enet_init(const struct device *dev)
629
633
return 0 ;
630
634
}
631
635
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
+
632
680
#ifdef CONFIG_NET_DSA
633
681
#define NXP_ENET_SEND_FUNC dsa_tx
634
682
#else
@@ -842,7 +890,10 @@ static const struct ethernet_api api_funcs = {
842
890
.rx_frame_buf = nxp_enet_##n##_rx_frame_buf, \
843
891
}; \
844
892
\
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), \
846
897
&nxp_enet_##n##_data, &nxp_enet_##n##_config, \
847
898
CONFIG_ETH_INIT_PRIORITY, \
848
899
&api_funcs, NET_ETH_MTU);
0 commit comments