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 ;
@@ -1989,6 +1992,14 @@ extern void WL_MCI_WAKEUP0_DriverIRQHandler(void);
1989
1992
extern void WL_MCI_WAKEUP_DONE0_DriverIRQHandler (void );
1990
1993
#endif
1991
1994
1995
+ struct gpio_callback wakeup_callback ;
1996
+
1997
+ static void gpio_wakeup_callback (const struct device * port , struct gpio_callback * cb ,
1998
+ gpio_port_pins_t pins )
1999
+ {
2000
+ // TODO: Reserved for future use.
2001
+ }
2002
+
1992
2003
static int nxp_wifi_dev_init (const struct device * dev )
1993
2004
{
1994
2005
struct nxp_wifi_dev * nxp_wifi = & nxp_wifi0 ;
@@ -2000,11 +2011,49 @@ static int nxp_wifi_dev_init(const struct device *dev)
2000
2011
#ifdef CONFIG_NXP_RW610
2001
2012
IRQ_CONNECT (IMU_IRQ_N , IMU_IRQ_P , WL_MCI_WAKEUP0_DriverIRQHandler , 0 , 0 );
2002
2013
irq_enable (IMU_IRQ_N );
2003
- IRQ_CONNECT (IMU_WAKEUP_IRQ_N , IMU_WAKEUP_IRQ_P , WL_MCI_WAKEUP_DONE0_DriverIRQHandler , 0 , 0 );
2014
+ IRQ_CONNECT (IMU_WAKEUP_IRQ_N , IMU_WAKEUP_IRQ_P ,
2015
+ WL_MCI_WAKEUP_DONE0_DriverIRQHandler , 0 , 0 );
2004
2016
irq_enable (IMU_WAKEUP_IRQ_N );
2005
2017
#if (DT_INST_PROP (0 , wakeup_source ))
2006
2018
EnableDeepSleepIRQ (IMU_IRQ_N );
2007
2019
#endif
2020
+ #else
2021
+ #if DT_NODE_HAS_PROP (DT_DRV_INST (0 ), wakeup_gpios )
2022
+ int err = 0 ;
2023
+
2024
+ struct gpio_dt_spec wakeup = GPIO_DT_SPEC_GET (DT_DRV_INST (0 ), wakeup_gpios );
2025
+ if (!gpio_is_ready_dt (& wakeup )) {
2026
+ LOG_ERR ("Error: failed to configure wakeup %s pin %d" , wakeup .port -> name ,
2027
+ wakeup .pin );
2028
+ return - EIO ;
2029
+ }
2030
+
2031
+ /* Configure wakeup gpio as input */
2032
+ err = gpio_pin_configure_dt (& wakeup , GPIO_INPUT );
2033
+ if (err ) {
2034
+ LOG_ERR ("Error %d: failed to configure wakeup %s pin %d" , err ,
2035
+ wakeup .port -> name , wakeup .pin );
2036
+ return err ;
2037
+ }
2038
+
2039
+ err = gpio_pin_set_dt (& wakeup , 0 );
2040
+ if (err ) {
2041
+ return err ;
2042
+ }
2043
+
2044
+ /* Configure wakeup gpio interrupt */
2045
+ err = gpio_pin_interrupt_configure_dt (& wakeup , GPIO_INT_EDGE_FALLING );
2046
+ if (err ) {
2047
+ return err ;
2048
+ }
2049
+
2050
+ /* Set wakeup gpio callback function */
2051
+ gpio_init_callback (& wakeup_callback , gpio_wakeup_callback , BIT (wakeup .pin ));
2052
+ err = gpio_add_callback_dt (& wakeup , & wakeup_callback );
2053
+ if (err ) {
2054
+ return err ;
2055
+ }
2056
+ #endif
2008
2057
#endif
2009
2058
2010
2059
return 0 ;
@@ -2045,7 +2094,8 @@ static int nxp_wifi_set_config(const struct device *dev, enum ethernet_config_ty
2045
2094
return 0 ;
2046
2095
}
2047
2096
2048
- #if defined(CONFIG_PM_DEVICE ) && defined(CONFIG_NXP_RW610 )
2097
+ #ifdef CONFIG_PM_DEVICE
2098
+ #ifdef CONFIG_NXP_RW610
2049
2099
void device_pm_dump_wakeup_source (void )
2050
2100
{
2051
2101
if (POWER_GetWakeupStatus (IMU_IRQ_N )) {
@@ -2059,6 +2109,18 @@ void device_pm_dump_wakeup_source(void)
2059
2109
POWER_ClearWakeupStatus (32 );
2060
2110
}
2061
2111
}
2112
+ #endif
2113
+
2114
+ static bool nxp_wifi_wlan_wakeup (void )
2115
+ {
2116
+ #ifdef CONFIG_NXP_RW610
2117
+ return POWER_GetWakeupStatus (WL_MCI_WAKEUP0_IRQn );
2118
+ #elif CONFIG_NXP_IW610
2119
+ return GPC_GetIRQStatusFlag (GPC , GPIO1_Combined_0_15_IRQn );
2120
+ #else
2121
+ return false;
2122
+ #endif
2123
+ }
2062
2124
2063
2125
static int device_wlan_pm_action (const struct device * dev , enum pm_device_action pm_action )
2064
2126
{
@@ -2103,7 +2165,7 @@ static int device_wlan_pm_action(const struct device *dev, enum pm_device_action
2103
2165
/* If we are not woken up by WLAN, skip posting host sleep exit event.
2104
2166
* And skip host sleep handshake next time we are about to sleep.
2105
2167
*/
2106
- if (POWER_GetWakeupStatus ( WL_MCI_WAKEUP0_IRQn )) {
2168
+ if (nxp_wifi_wlan_wakeup ( )) {
2107
2169
ret = wlan_hs_send_event (HOST_SLEEP_EXIT , NULL );
2108
2170
if (ret != 0 ) {
2109
2171
return - EFAULT ;
@@ -2112,8 +2174,9 @@ static int device_wlan_pm_action(const struct device *dev, enum pm_device_action
2112
2174
} else {
2113
2175
wlan_hs_hanshake_cfg (true);
2114
2176
}
2115
-
2177
+ #ifdef CONFIG_NXP_RW610
2116
2178
device_pm_dump_wakeup_source ();
2179
+ #endif
2117
2180
if (wlan_host_sleep_state == HOST_SLEEP_ONESHOT ) {
2118
2181
wlan_host_sleep_state = HOST_SLEEP_DISABLE ;
2119
2182
wlan_hs_hanshake_cfg (false);
0 commit comments