Skip to content

drivers: wifi: Add WLAN wakeup for MIMXRT1060-EVK #92067

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions boards/shields/nxp_m2_wifi_bt/nxp_m2_2ll_wifi_bt.overlay
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
&m2_wifi_sdio {
nxp_wifi {
compatible = "nxp,wifi";
wakeup-gpios = <&gpio1 0 GPIO_ACTIVE_LOW>;
status = "okay";
};
};
4 changes: 2 additions & 2 deletions drivers/wifi/nxp/Kconfig.nxp
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ menu "Wi-Fi driver Stack configurations"

config NXP_WIFI_MON_TASK_STACK_SIZE
int "Mon thread stack size"
depends on NXP_RW610
depends on NXP_RW610 || NXP_IW610
default 3072
help
This option specifies the size of the stack used by the mon task.
Expand Down Expand Up @@ -444,7 +444,7 @@ menu "Wi-Fi thread priority configurations"

config NXP_WIFI_MON_TASK_PRIO
int "Mon task priority"
depends on NXP_RW610
depends on NXP_RW610 || NXP_IW610
default 4
help
This option specifies the priority of the mon task.
Expand Down
80 changes: 74 additions & 6 deletions drivers/wifi/nxp/nxp_wifi_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
#include <zephyr/net/wifi_mgmt.h>
#ifdef CONFIG_PM_DEVICE
#include <zephyr/pm/device.h>
#ifdef CONFIG_NXP_IW610
#include <fsl_gpc.h>
#endif
#endif
#ifdef CONFIG_WIFI_NM
#include <zephyr/net/wifi_nm.h>
Expand Down Expand Up @@ -73,7 +76,7 @@ extern struct interface g_uap;
extern const rtos_wpa_supp_dev_ops wpa_supp_ops;
#endif

#if defined(CONFIG_PM_DEVICE) && defined(CONFIG_NXP_RW610)
#ifdef CONFIG_PM_DEVICE
extern int is_hs_handshake_done;
extern int wlan_host_sleep_state;
extern bool skip_hs_handshake;
Expand Down Expand Up @@ -1989,6 +1992,18 @@ extern void WL_MCI_WAKEUP0_DriverIRQHandler(void);
extern void WL_MCI_WAKEUP_DONE0_DriverIRQHandler(void);
#endif

#ifdef CONFIG_PM_DEVICE
#ifdef CONFIG_NXP_IW610
struct gpio_callback wakeup_callback;

static void gpio_wakeup_callback(const struct device *port, struct gpio_callback *cb,
gpio_port_pins_t pins)
{
/* TODO: Reserved for future use. */
}
Comment on lines +1999 to +2003
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is causing a build failure in twister testing of the PR for not being used

#endif
#endif

static int nxp_wifi_dev_init(const struct device *dev)
{
struct nxp_wifi_dev *nxp_wifi = &nxp_wifi0;
Expand All @@ -2000,13 +2015,52 @@ static int nxp_wifi_dev_init(const struct device *dev)
#ifdef CONFIG_NXP_RW610
IRQ_CONNECT(IMU_IRQ_N, IMU_IRQ_P, WL_MCI_WAKEUP0_DriverIRQHandler, 0, 0);
irq_enable(IMU_IRQ_N);
IRQ_CONNECT(IMU_WAKEUP_IRQ_N, IMU_WAKEUP_IRQ_P, WL_MCI_WAKEUP_DONE0_DriverIRQHandler, 0, 0);
IRQ_CONNECT(IMU_WAKEUP_IRQ_N, IMU_WAKEUP_IRQ_P,
WL_MCI_WAKEUP_DONE0_DriverIRQHandler, 0, 0);
irq_enable(IMU_WAKEUP_IRQ_N);
#if (DT_INST_PROP(0, wakeup_source))
EnableDeepSleepIRQ(IMU_IRQ_N);
#endif
#endif
#else
#ifdef CONFIG_PM_DEVICE
#if DT_NODE_HAS_PROP(DT_DRV_INST(0), wakeup_gpios)
int err = 0;
struct gpio_dt_spec wakeup = GPIO_DT_SPEC_GET(DT_DRV_INST(0), wakeup_gpios);

if (!gpio_is_ready_dt(&wakeup)) {
LOG_ERR("Error: failed to configure wakeup %s pin %d", wakeup.port->name,
wakeup.pin);
return -EIO;
}

/* Configure wakeup gpio as input */
err = gpio_pin_configure_dt(&wakeup, GPIO_INPUT);
if (err) {
LOG_ERR("Error %d: failed to configure wakeup %s pin %d", err,
wakeup.port->name, wakeup.pin);
return err;
}

err = gpio_pin_set_dt(&wakeup, 0);
if (err) {
return err;
}

/* Configure wakeup gpio interrupt */
err = gpio_pin_interrupt_configure_dt(&wakeup, GPIO_INT_EDGE_FALLING);
if (err) {
return err;
}

/* Set wakeup gpio callback function */
gpio_init_callback(&wakeup_callback, gpio_wakeup_callback, BIT(wakeup.pin));
err = gpio_add_callback_dt(&wakeup, &wakeup_callback);
if (err) {
return err;
}
#endif
#endif
#endif
return 0;
}

Expand Down Expand Up @@ -2045,7 +2099,8 @@ static int nxp_wifi_set_config(const struct device *dev, enum ethernet_config_ty
return 0;
}

#if defined(CONFIG_PM_DEVICE) && defined(CONFIG_NXP_RW610)
#ifdef CONFIG_PM_DEVICE
#ifdef CONFIG_NXP_RW610
void device_pm_dump_wakeup_source(void)
{
if (POWER_GetWakeupStatus(IMU_IRQ_N)) {
Expand All @@ -2059,6 +2114,18 @@ void device_pm_dump_wakeup_source(void)
POWER_ClearWakeupStatus(32);
}
}
#endif

static bool nxp_wifi_wlan_wakeup(void)
{
#ifdef CONFIG_NXP_RW610
return POWER_GetWakeupStatus(WL_MCI_WAKEUP0_IRQn);
#elif CONFIG_NXP_IW610
return GPC_GetIRQStatusFlag(GPC, GPIO1_Combined_0_15_IRQn);
#else
return false;
#endif
}

static int device_wlan_pm_action(const struct device *dev, enum pm_device_action pm_action)
{
Expand Down Expand Up @@ -2103,7 +2170,7 @@ static int device_wlan_pm_action(const struct device *dev, enum pm_device_action
/* If we are not woken up by WLAN, skip posting host sleep exit event.
* And skip host sleep handshake next time we are about to sleep.
*/
if (POWER_GetWakeupStatus(WL_MCI_WAKEUP0_IRQn)) {
if (nxp_wifi_wlan_wakeup()) {
ret = wlan_hs_send_event(HOST_SLEEP_EXIT, NULL);
if (ret != 0) {
return -EFAULT;
Expand All @@ -2112,8 +2179,9 @@ static int device_wlan_pm_action(const struct device *dev, enum pm_device_action
} else {
wlan_hs_hanshake_cfg(true);
}

#ifdef CONFIG_NXP_RW610
device_pm_dump_wakeup_source();
#endif
if (wlan_host_sleep_state == HOST_SLEEP_ONESHOT) {
wlan_host_sleep_state = HOST_SLEEP_DISABLE;
wlan_hs_hanshake_cfg(false);
Expand Down
9 changes: 9 additions & 0 deletions dts/bindings/wifi/nxp,wifi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,12 @@ description: |
compatible: "nxp,wifi"

include: [base.yaml, pinctrl-device.yaml]

properties:
wakeup-gpios:
type: phandle-array
description: |
WLAN wakeup host pin
This pin defaults to active low when consumed by the SDK card. The
property value should ensure the flags properly describ the signal
that is presendted to the driver.
6 changes: 6 additions & 0 deletions samples/net/wifi/shell/nxp/overlay_iw610.conf
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,9 @@ CONFIG_ETH_DRIVER=n
CONFIG_NET_TC_TX_SKIP_FOR_HIGH_PRIO=y
CONFIG_NET_MGMT_THREAD_PRIORITY=3
CONFIG_NXP_WIFI_DRIVER_TASK_PRIO=2

# power mgmt
CONFIG_PM=y
CONFIG_PM_DEVICE=y
CONFIG_PM_LOG_LEVEL_OFF=y
CONFIG_PM_DEVICE_LOG_LEVEL_OFF=y
2 changes: 1 addition & 1 deletion west.yml
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ manifest:
groups:
- hal
- name: hal_nxp
revision: 111f568bda6f119cd896f38ae5843ecde92039bd
revision: pull/566/head
path: modules/hal/nxp
groups:
- hal
Expand Down
Loading