20
20
#include <zephyr/net/wifi_mgmt.h>
21
21
#ifdef CONFIG_PM_DEVICE
22
22
#include <zephyr/pm/device.h>
23
+ #ifdef CONFIG_NXP_IW610
24
+ #include <fsl_gpc.h>
25
+ #endif
23
26
#endif
24
27
#ifdef CONFIG_WIFI_NM
25
28
#include <zephyr/net/wifi_nm.h>
@@ -73,7 +76,7 @@ extern struct interface g_uap;
73
76
extern const rtos_wpa_supp_dev_ops wpa_supp_ops ;
74
77
#endif
75
78
76
- #if defined( CONFIG_PM_DEVICE ) && defined( CONFIG_NXP_RW610 )
79
+ #ifdef CONFIG_PM_DEVICE
77
80
extern int is_hs_handshake_done ;
78
81
extern int wlan_host_sleep_state ;
79
82
extern bool skip_hs_handshake ;
@@ -2010,6 +2013,18 @@ extern void WL_MCI_WAKEUP0_DriverIRQHandler(void);
2010
2013
extern void WL_MCI_WAKEUP_DONE0_DriverIRQHandler (void );
2011
2014
#endif
2012
2015
2016
+ #ifdef CONFIG_PM_DEVICE
2017
+ #ifdef CONFIG_NXP_IW610
2018
+ struct gpio_callback wakeup_callback ;
2019
+
2020
+ static void gpio_wakeup_callback (const struct device * port , struct gpio_callback * cb ,
2021
+ gpio_port_pins_t pins )
2022
+ {
2023
+ /* TODO: Reserved for future use. */
2024
+ }
2025
+ #endif
2026
+ #endif
2027
+
2013
2028
static int nxp_wifi_dev_init (const struct device * dev )
2014
2029
{
2015
2030
struct nxp_wifi_dev * nxp_wifi = & nxp_wifi0 ;
@@ -2021,13 +2036,52 @@ static int nxp_wifi_dev_init(const struct device *dev)
2021
2036
#ifdef CONFIG_NXP_RW610
2022
2037
IRQ_CONNECT (IMU_IRQ_N , IMU_IRQ_P , WL_MCI_WAKEUP0_DriverIRQHandler , 0 , 0 );
2023
2038
irq_enable (IMU_IRQ_N );
2024
- IRQ_CONNECT (IMU_WAKEUP_IRQ_N , IMU_WAKEUP_IRQ_P , WL_MCI_WAKEUP_DONE0_DriverIRQHandler , 0 , 0 );
2039
+ IRQ_CONNECT (IMU_WAKEUP_IRQ_N , IMU_WAKEUP_IRQ_P ,
2040
+ WL_MCI_WAKEUP_DONE0_DriverIRQHandler , 0 , 0 );
2025
2041
irq_enable (IMU_WAKEUP_IRQ_N );
2026
2042
#if (DT_INST_PROP (0 , wakeup_source ))
2027
2043
EnableDeepSleepIRQ (IMU_IRQ_N );
2028
2044
#endif
2029
- #endif
2045
+ #else
2046
+ #ifdef CONFIG_PM_DEVICE
2047
+ #if DT_NODE_HAS_PROP (DT_DRV_INST (0 ), wakeup_gpios )
2048
+ int err = 0 ;
2049
+ struct gpio_dt_spec wakeup = GPIO_DT_SPEC_GET (DT_DRV_INST (0 ), wakeup_gpios );
2050
+
2051
+ if (!gpio_is_ready_dt (& wakeup )) {
2052
+ LOG_ERR ("Error: failed to configure wakeup %s pin %d" , wakeup .port -> name ,
2053
+ wakeup .pin );
2054
+ return - EIO ;
2055
+ }
2056
+
2057
+ /* Configure wakeup gpio as input */
2058
+ err = gpio_pin_configure_dt (& wakeup , GPIO_INPUT );
2059
+ if (err ) {
2060
+ LOG_ERR ("Error %d: failed to configure wakeup %s pin %d" , err ,
2061
+ wakeup .port -> name , wakeup .pin );
2062
+ return err ;
2063
+ }
2064
+
2065
+ err = gpio_pin_set_dt (& wakeup , 0 );
2066
+ if (err ) {
2067
+ return err ;
2068
+ }
2030
2069
2070
+ /* Configure wakeup gpio interrupt */
2071
+ err = gpio_pin_interrupt_configure_dt (& wakeup , GPIO_INT_EDGE_FALLING );
2072
+ if (err ) {
2073
+ return err ;
2074
+ }
2075
+
2076
+ /* Set wakeup gpio callback function */
2077
+ gpio_init_callback (& wakeup_callback , gpio_wakeup_callback , BIT (wakeup .pin ));
2078
+ err = gpio_add_callback_dt (& wakeup , & wakeup_callback );
2079
+ if (err ) {
2080
+ return err ;
2081
+ }
2082
+ #endif
2083
+ #endif
2084
+ #endif
2031
2085
return 0 ;
2032
2086
}
2033
2087
@@ -2066,7 +2120,8 @@ static int nxp_wifi_set_config(const struct device *dev, enum ethernet_config_ty
2066
2120
return 0 ;
2067
2121
}
2068
2122
2069
- #if defined(CONFIG_PM_DEVICE ) && defined(CONFIG_NXP_RW610 )
2123
+ #ifdef CONFIG_PM_DEVICE
2124
+ #ifdef CONFIG_NXP_RW610
2070
2125
void device_pm_dump_wakeup_source (void )
2071
2126
{
2072
2127
if (POWER_GetWakeupStatus (IMU_IRQ_N )) {
@@ -2080,6 +2135,18 @@ void device_pm_dump_wakeup_source(void)
2080
2135
POWER_ClearWakeupStatus (32 );
2081
2136
}
2082
2137
}
2138
+ #endif
2139
+
2140
+ static bool nxp_wifi_wlan_wakeup (void )
2141
+ {
2142
+ #ifdef CONFIG_NXP_RW610
2143
+ return POWER_GetWakeupStatus (WL_MCI_WAKEUP0_IRQn );
2144
+ #elif CONFIG_NXP_IW610
2145
+ return GPC_GetIRQStatusFlag (GPC , GPIO1_Combined_0_15_IRQn );
2146
+ #else
2147
+ return false;
2148
+ #endif
2149
+ }
2083
2150
2084
2151
static int device_wlan_pm_action (const struct device * dev , enum pm_device_action pm_action )
2085
2152
{
@@ -2124,7 +2191,7 @@ static int device_wlan_pm_action(const struct device *dev, enum pm_device_action
2124
2191
/* If we are not woken up by WLAN, skip posting host sleep exit event.
2125
2192
* And skip host sleep handshake next time we are about to sleep.
2126
2193
*/
2127
- if (POWER_GetWakeupStatus ( WL_MCI_WAKEUP0_IRQn )) {
2194
+ if (nxp_wifi_wlan_wakeup ( )) {
2128
2195
ret = wlan_hs_send_event (HOST_SLEEP_EXIT , NULL );
2129
2196
if (ret != 0 ) {
2130
2197
return - EFAULT ;
@@ -2133,8 +2200,9 @@ static int device_wlan_pm_action(const struct device *dev, enum pm_device_action
2133
2200
} else {
2134
2201
wlan_hs_hanshake_cfg (true);
2135
2202
}
2136
-
2203
+ #ifdef CONFIG_NXP_RW610
2137
2204
device_pm_dump_wakeup_source ();
2205
+ #endif
2138
2206
if (wlan_host_sleep_state == HOST_SLEEP_ONESHOT ) {
2139
2207
wlan_host_sleep_state = HOST_SLEEP_DISABLE ;
2140
2208
wlan_hs_hanshake_cfg (false);
0 commit comments