wlan: Modify wlan driver to support msm-4.9 kernel

Upgrade wlan driver to support msm-4.9 kernel and also
maintain backward compatibility with previous kernel versions.

Change-Id: Iaae91fe559bfba05b1da4be9b9ef9a12d6f9df28
CRs-Fixed: 2180168
diff --git a/Android.mk b/Android.mk
index de0c735..179d4cb 100644
--- a/Android.mk
+++ b/Android.mk
@@ -48,7 +48,11 @@
     WLAN_BLD_DIR := vendor/qcom/proprietary/wlan
 else
 ifneq ($(TARGET_SUPPORTS_WEARABLES),true)
+ifneq ($(ANDROID_BUILD_TOP),)
+    WLAN_BLD_DIR := $(ANDROID_BUILD_TOP)/vendor/qcom/opensource/wlan
+else
     WLAN_BLD_DIR := vendor/qcom/opensource/wlan
+endif
 else
     WLAN_BLD_DIR := device/qcom/msm8909w/opensource/wlan
 endif
@@ -115,7 +119,17 @@
 ###########################################################
 
 # This is set once per LOCAL_PATH, not per (kernel) module
+
+ifneq ($(TARGET_SUPPORTS_WEARABLES),true)
+ifneq ($(ANDROID_BUILD_TOP),)
+KBUILD_OPTIONS := WLAN_ROOT=$(WLAN_BLD_DIR)/prima
+endif
+endif
+
+ifeq ($(KBUILD_OPTIONS),)
 KBUILD_OPTIONS := WLAN_ROOT=$(KERNEL_TO_BUILD_ROOT_OFFSET)$(WLAN_BLD_DIR)/prima
+endif
+
 # We are actually building wlan.ko here, as per the
 # requirement we are specifying <chipset>_wlan.ko as LOCAL_MODULE.
 # This means we need to rename the module to <chipset>_wlan.ko
@@ -125,8 +139,13 @@
 KBUILD_OPTIONS += $(WLAN_SELECT)
 
 
+ifeq ($(KERNEL_TO_BUILD_ROOT_OFFSET),../../)
+VERSION=$(shell grep -w "VERSION =" $(TOP)/kernel/msm-$(TARGET_KERNEL_VERSION)/Makefile | sed 's/^VERSION = //' )
+PATCHLEVEL=$(shell grep -w "PATCHLEVEL =" $(TOP)/kernel/msm-$(TARGET_KERNEL_VERSION)/Makefile | sed 's/^PATCHLEVEL = //' )
+else
 VERSION=$(shell grep -w "VERSION =" $(TOP)/kernel/Makefile | sed 's/^VERSION = //' )
 PATCHLEVEL=$(shell grep -w "PATCHLEVEL =" $(TOP)/kernel/Makefile | sed 's/^PATCHLEVEL = //' )
+endif
 
 include $(CLEAR_VARS)
 LOCAL_MODULE              := $(WLAN_CHIPSET)_wlan.ko