From 338e1f465738acec2d2ca5f9ef2d390456a5d752 Mon Sep 17 00:00:00 2001 From: Chih-Wei Huang Date: Wed, 7 Sep 2016 02:44:44 +0800 Subject: [PATCH] Unload/reload wifi driver on suspend/resume --- Android.mk | 2 +- power.c | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/Android.mk b/Android.mk index 7dd518b..469a4ee 100644 --- a/Android.mk +++ b/Android.mk @@ -15,7 +15,7 @@ include $(CLEAR_VARS) LOCAL_MODULE := power.x86 LOCAL_MODULE_RELATIVE_PATH := hw LOCAL_SRC_FILES := power.c -LOCAL_SHARED_LIBRARIES := liblog +LOCAL_SHARED_LIBRARIES := liblog libcutils LOCAL_MODULE_TAGS := optional include $(BUILD_SHARED_LIBRARY) diff --git a/power.c b/power.c index 845e0a2..328a2e0 100644 --- a/power.c +++ b/power.c @@ -21,6 +21,10 @@ #include #include +#include +#include + +extern int delete_module(const char *, unsigned int); #define SYS_CPU "/sys/devices/system/cpu" #define CPU_ONLINE "1" @@ -51,6 +55,24 @@ static void power_init(struct power_module *module) static void power_set_interactive(struct power_module *module, int on) { + char mod[PROPERTY_VALUE_MAX]; + if ((!property_get("wlan.no-unload-driver", mod, NULL) || strcmp(mod, "1")) + && property_get("wlan.modname", mod, NULL)) { + if (on) { + if (insmod_by_dep(mod, "", NULL, 0, NULL)) { + ALOGE("insmod %s failed", mod); + } else { + ALOGD("reload %s OK", mod); + } + } else { + if (delete_module(mod, O_NONBLOCK)) { + ALOGE("rmmod %s failed", mod); + } else { + ALOGD("unload %s OK", mod); + } + } + } + set_nonboot_cpu_state(on ? CPU_ONLINE : CPU_OFFLINE); } -- 2.11.0