diff --git a/Makefile b/Makefile index 8bf2624..fc2ec07 100755 --- a/Makefile +++ b/Makefile @@ -42,9 +42,6 @@ CONFIG_RTL8723D = n CONFIG_RTL8821C = n ######################### Interface ########################### CONFIG_USB_HCI = y -CONFIG_PCI_HCI = n -CONFIG_SDIO_HCI = n -CONFIG_GSPI_HCI = n ########################## Features ########################### CONFIG_MP_INCLUDED = y CONFIG_POWER_SAVING = y @@ -157,22 +154,8 @@ endif export TopDIR ?= $(shell pwd) ########### COMMON ################################# -ifeq ($(CONFIG_GSPI_HCI), y) -HCI_NAME = gspi -endif -ifeq ($(CONFIG_SDIO_HCI), y) -HCI_NAME = sdio -endif - -ifeq ($(CONFIG_USB_HCI), y) HCI_NAME = usb -endif - -ifeq ($(CONFIG_PCI_HCI), y) -HCI_NAME = pci -endif - _OS_INTFS_FILES := os_dep/osdep_service.o \ os_dep/os_intfs.o \ @@ -192,17 +175,6 @@ ifeq ($(CONFIG_MP_INCLUDED), y) _OS_INTFS_FILES += os_dep/ioctl_mp.o endif -ifeq ($(CONFIG_SDIO_HCI), y) -_OS_INTFS_FILES += os_dep/custom_gpio_linux.o -_OS_INTFS_FILES += os_dep/$(HCI_NAME)_ops_linux.o -endif - -ifeq ($(CONFIG_GSPI_HCI), y) -_OS_INTFS_FILES += os_dep/custom_gpio_linux.o -_OS_INTFS_FILES += os_dep/$(HCI_NAME)_ops_linux.o -endif - - _HAL_INTFS_FILES := hal/hal_intf.o \ hal/hal_com.o \ hal/hal_com_phycfg.o \ @@ -248,47 +220,11 @@ EXTRA_CFLAGS += -I$(src)/platform _PLATFORM_FILES := platform/platform_ops.o EXTRA_CFLAGS += -I$(src)/hal/btc -_OUTSRC_FILES += hal/btc/halbtc8723bwifionly.o \ - hal/btc/halbtc8822bwifionly.o \ - hal/btc/halbtc8821cwifionly.o -ifeq ($(CONFIG_BT_COEXIST), y) -_OUTSRC_FILES += hal/btc/halbtc8192e1ant.o \ - hal/btc/halbtc8192e2ant.o \ - hal/btc/halbtc8723b1ant.o \ - hal/btc/halbtc8723b2ant.o \ - hal/btc/halbtc8812a1ant.o \ - hal/btc/halbtc8812a2ant.o \ - hal/btc/halbtc8821a1ant.o \ - hal/btc/halbtc8821a2ant.o \ - hal/btc/halbtc8703b1ant.o \ - hal/btc/halbtc8723d1ant.o \ - hal/btc/halbtc8723d2ant.o \ - hal/btc/halbtc8822b1ant.o \ - hal/btc/halbtc8822b2ant.o \ - hal/btc/halbtc8821c1ant.o \ - hal/btc/halbtc8821c2ant.o -endif - - -########### HAL_RTL8188E ################################# -ifeq ($(CONFIG_RTL8188E), y) RTL871X = rtl8188e -ifeq ($(CONFIG_SDIO_HCI), y) -MODULE_NAME = 8189es -endif -ifeq ($(CONFIG_GSPI_HCI), y) -MODULE_NAME = 8189es -endif - -ifeq ($(CONFIG_USB_HCI), y) MODULE_NAME = 8188eu -endif -ifeq ($(CONFIG_PCI_HCI), y) -MODULE_NAME = 8188ee -endif EXTRA_CFLAGS += -DCONFIG_RTL8188E _HAL_INTFS_FILES += hal/HalPwrSeqCmd.o \ @@ -309,25 +245,9 @@ _HAL_INTFS_FILES += hal/$(RTL871X)_hal_init.o \ hal/rtl$(MODULE_NAME)_xmit.o \ hal/rtl$(MODULE_NAME)_recv.o -ifeq ($(CONFIG_SDIO_HCI), y) -_HAL_INTFS_FILES += hal/$(HCI_NAME)_ops.o -else -ifeq ($(CONFIG_GSPI_HCI), y) -_HAL_INTFS_FILES += hal/$(HCI_NAME)_ops.o -else _HAL_INTFS_FILES += hal/$(HCI_NAME)_ops_linux.o -endif -endif -ifeq ($(CONFIG_USB_HCI), y) _HAL_INTFS_FILES +=hal/HalEfuseMask8188E_USB.o -endif -ifeq ($(CONFIG_PCI_HCI), y) -_HAL_INTFS_FILES +=hal/HalEfuseMask8188E_PCIE.o -endif -ifeq ($(CONFIG_SDIO_HCI), y) -_HAL_INTFS_FILES +=hal/HalEfuseMask8188E_SDIO.o -endif #hal/OUTSRC/Hal8188EFWImg_CE.o _OUTSRC_FILES += hal/phydm/halhwimg8188e_mac.o\ @@ -338,521 +258,21 @@ _OUTSRC_FILES += hal/phydm/halhwimg8188e_mac.o\ hal/phydm/hal8188erateadaptive.o\ hal/phydm/phydm_rtl8188e.o -endif - -########### HAL_RTL8192E ################################# -ifeq ($(CONFIG_RTL8192E), y) - -RTL871X = rtl8192e -ifeq ($(CONFIG_SDIO_HCI), y) -MODULE_NAME = 8192es -endif - -ifeq ($(CONFIG_USB_HCI), y) -MODULE_NAME = 8192eu -endif - -ifeq ($(CONFIG_PCI_HCI), y) -MODULE_NAME = 8192ee -endif -EXTRA_CFLAGS += -DCONFIG_RTL8192E -_HAL_INTFS_FILES += hal/HalPwrSeqCmd.o \ - hal/Hal8192EPwrSeq.o\ - hal/$(RTL871X)_xmit.o\ - hal/$(RTL871X)_sreset.o - -_HAL_INTFS_FILES += hal/$(RTL871X)_hal_init.o \ - hal/$(RTL871X)_phycfg.o \ - hal/$(RTL871X)_rf6052.o \ - hal/$(RTL871X)_dm.o \ - hal/$(RTL871X)_rxdesc.o \ - hal/$(RTL871X)_cmd.o \ - hal/hal8192e_fw.o \ - hal/$(HCI_NAME)_halinit.o \ - hal/rtl$(MODULE_NAME)_led.o \ - hal/rtl$(MODULE_NAME)_xmit.o \ - hal/rtl$(MODULE_NAME)_recv.o - -ifeq ($(CONFIG_SDIO_HCI), y) -_HAL_INTFS_FILES += hal/$(HCI_NAME)_ops.o -else -ifeq ($(CONFIG_GSPI_HCI), y) -_HAL_INTFS_FILES += hal/$(HCI_NAME)_ops.o -else -_HAL_INTFS_FILES += hal/$(HCI_NAME)_ops_linux.o -endif -endif - -ifeq ($(CONFIG_USB_HCI), y) -_HAL_INTFS_FILES +=hal/HalEfuseMask8192E_USB.o -endif -ifeq ($(CONFIG_PCI_HCI), y) -_HAL_INTFS_FILES +=hal/HalEfuseMask8192E_PCIE.o -endif - -#hal/OUTSRC/HalHWImg8188E_FW.o -_OUTSRC_FILES += hal/phydm/halhwimg8192e_mac.o\ - hal/phydm/halhwimg8192e_bb.o\ - hal/phydm/halhwimg8192e_rf.o\ - hal/phydm/halphyrf_8192e_ce.o\ - hal/phydm/phydm_regconfig8192e.o\ - hal/phydm/phydm_rtl8192e.o - -endif - -########### HAL_RTL8812A_RTL8821A ################################# - -ifneq ($(CONFIG_RTL8812A)_$(CONFIG_RTL8821A), n_n) - -RTL871X = rtl8812a -ifeq ($(CONFIG_USB_HCI), y) -MODULE_NAME = 8812au -endif -ifeq ($(CONFIG_PCI_HCI), y) -MODULE_NAME = 8812ae -endif -ifeq ($(CONFIG_SDIO_HCI), y) -MODULE_NAME = 8812as -endif - -_HAL_INTFS_FILES += hal/HalPwrSeqCmd.o \ - hal/Hal8812PwrSeq.o \ - hal/Hal8821APwrSeq.o\ - hal/$(RTL871X)_xmit.o\ - hal/$(RTL871X)_sreset.o - -_HAL_INTFS_FILES += hal/$(RTL871X)_hal_init.o \ - hal/$(RTL871X)_phycfg.o \ - hal/$(RTL871X)_rf6052.o \ - hal/$(RTL871X)_dm.o \ - hal/$(RTL871X)_rxdesc.o \ - hal/$(RTL871X)_cmd.o \ - hal/$(HCI_NAME)_halinit.o \ - hal/rtl$(MODULE_NAME)_led.o \ - hal/rtl$(MODULE_NAME)_xmit.o \ - hal/rtl$(MODULE_NAME)_recv.o - -ifeq ($(CONFIG_SDIO_HCI), y) -_HAL_INTFS_FILES += hal/$(HCI_NAME)_ops.o -else -ifeq ($(CONFIG_GSPI_HCI), y) -_HAL_INTFS_FILES += hal/$(HCI_NAME)_ops.o -else -_HAL_INTFS_FILES += hal/$(HCI_NAME)_ops_linux.o -endif -endif - -ifeq ($(CONFIG_RTL8812A), y) -ifeq ($(CONFIG_USB_HCI), y) -_HAL_INTFS_FILES +=hal/HalEfuseMask8812A_USB.o -endif -ifeq ($(CONFIG_PCI_HCI), y) -_HAL_INTFS_FILES +=hal/HalEfuseMask8812A_PCIE.o -endif -endif -ifeq ($(CONFIG_RTL8821A), y) -ifeq ($(CONFIG_USB_HCI), y) -_HAL_INTFS_FILES +=hal/HalEfuseMask8821A_USB.o -endif -ifeq ($(CONFIG_PCI_HCI), y) -_HAL_INTFS_FILES +=hal/HalEfuseMask8821A_PCIE.o -endif -endif - -ifeq ($(CONFIG_RTL8812A), y) -EXTRA_CFLAGS += -DCONFIG_RTL8812A -_HAL_INTFS_FILES += hal/rtl8812a/hal8812a_fw.o - -_OUTSRC_FILES += hal/phydm/halhwimg8812a_mac.o\ - hal/phydm/halhwimg8812a_bb.o\ - hal/phydm/halhwimg8812a_rf.o\ - hal/phydm/halphyrf_8812a_ce.o\ - hal/phydm/phydm_regconfig8812a.o\ - hal/phydm/phydm_rtl8812a.o\ - hal/phydm/txbf/haltxbfjaguar.o -endif - -ifeq ($(CONFIG_RTL8821A), y) - -ifeq ($(CONFIG_RTL8812A), n) - -RTL871X = rtl8821a -ifeq ($(CONFIG_USB_HCI), y) -ifeq ($(CONFIG_BT_COEXIST), y) -MODULE_NAME := 8821au -else -MODULE_NAME := 8811au -endif -endif -ifeq ($(CONFIG_PCI_HCI), y) -MODULE_NAME := 8821ae -endif -ifeq ($(CONFIG_SDIO_HCI), y) -MODULE_NAME := 8821as -endif - -endif - -EXTRA_CFLAGS += -DCONFIG_RTL8821A - -_HAL_INTFS_FILES += hal/rtl8812a/hal8821a_fw.o -_OUTSRC_FILES += hal/phydm/rtl8821a/halhwimg8821a_mac.o\ - hal/phydm/rtl8821a/halhwimg8821a_bb.o\ - hal/phydm/rtl8821a/halhwimg8821a_rf.o\ - hal/phydm/rtl8812a/halphyrf_8812a_ce.o\ - hal/phydm/rtl8821a/halphyrf_8821a_ce.o\ - hal/phydm/rtl8821a/phydm_regconfig8821a.o\ - hal/phydm/rtl8821a/phydm_rtl8821a.o\ - hal/phydm/rtl8821a/phydm_iqk_8821a_ce.o\ - hal/phydm/txbf/haltxbfjaguar.o - -endif - -endif - -########### HAL_RTL8723B ################################# -ifeq ($(CONFIG_RTL8723B), y) - -RTL871X = rtl8723b -ifeq ($(CONFIG_USB_HCI), y) -MODULE_NAME = 8723bu -endif -ifeq ($(CONFIG_PCI_HCI), y) -MODULE_NAME = 8723be -endif -ifeq ($(CONFIG_SDIO_HCI), y) -MODULE_NAME = 8723bs -endif - -EXTRA_CFLAGS += -DCONFIG_RTL8723B - -_HAL_INTFS_FILES += hal/HalPwrSeqCmd.o \ - hal/Hal8723BPwrSeq.o\ - hal/$(RTL871X)_sreset.o - -_HAL_INTFS_FILES += hal/$(RTL871X)_hal_init.o \ - hal/$(RTL871X)_phycfg.o \ - hal/$(RTL871X)_rf6052.o \ - hal/$(RTL871X)_dm.o \ - hal/$(RTL871X)_rxdesc.o \ - hal/$(RTL871X)_cmd.o \ - hal/hal8723b_fw.o - -_HAL_INTFS_FILES += \ - hal/$(HCI_NAME)_halinit.o \ - hal/rtl$(MODULE_NAME)_led.o \ - hal/rtl$(MODULE_NAME)_xmit.o \ - hal/rtl$(MODULE_NAME)_recv.o - -ifeq ($(CONFIG_PCI_HCI), y) -_HAL_INTFS_FILES += hal/$(HCI_NAME)_ops_linux.o -else -_HAL_INTFS_FILES += hal/$(HCI_NAME)_ops.o -endif - -ifeq ($(CONFIG_USB_HCI), y) -_HAL_INTFS_FILES +=hal/HalEfuseMask8723B_USB.o -endif -ifeq ($(CONFIG_PCI_HCI), y) -_HAL_INTFS_FILES +=hal/HalEfuseMask8723B_PCIE.o -endif - -_OUTSRC_FILES += hal/phydm/halhwimg8723b_bb.o\ - hal/phydm/halhwimg8723b_mac.o\ - hal/phydm/halhwimg8723b_rf.o\ - hal/phydm/halhwimg8723b_mp.o\ - hal/phydm/phydm_regconfig8723b.o\ - hal/phydm/halphyrf_8723b_ce.o\ - hal/phydm/phydm_rtl8723b.o - -endif - -########### HAL_RTL8814A ################################# -ifeq ($(CONFIG_RTL8814A), y) -## ADD NEW VHT MP HW TX MODE ## -#EXTRA_CFLAGS += -DCONFIG_MP_VHT_HW_TX_MODE -#CONFIG_MP_VHT_HW_TX_MODE = y -########################################## -RTL871X = rtl8814a -ifeq ($(CONFIG_USB_HCI), y) -MODULE_NAME = 8814au -endif -ifeq ($(CONFIG_PCI_HCI), y) -MODULE_NAME = 8814ae -endif -ifeq ($(CONFIG_SDIO_HCI), y) -MODULE_NAME = 8814as -endif - -EXTRA_CFLAGS += -DCONFIG_RTL8814A - -_HAL_INTFS_FILES += hal/HalPwrSeqCmd.o \ - hal/Hal8814PwrSeq.o \ - hal/$(RTL871X)_xmit.o\ - hal/$(RTL871X)_sreset.o - -_HAL_INTFS_FILES += hal/$(RTL871X)_hal_init.o \ - hal/$(RTL871X)_phycfg.o \ - hal/$(RTL871X)_rf6052.o \ - hal/$(RTL871X)_dm.o \ - hal/$(RTL871X)_rxdesc.o \ - hal/$(RTL871X)_cmd.o \ - hal/hal8814a_fw.o - - -_HAL_INTFS_FILES += \ - hal/$(HCI_NAME)_halinit.o \ - hal/rtl$(MODULE_NAME)_led.o \ - hal/rtl$(MODULE_NAME)_xmit.o \ - hal/rtl$(MODULE_NAME)_recv.o - -ifeq ($(CONFIG_SDIO_HCI), y) -_HAL_INTFS_FILES += hal/$(HCI_NAME)_ops.o -else -ifeq ($(CONFIG_GSPI_HCI), y) -_HAL_INTFS_FILES += hal/$(HCI_NAME)_ops.o -else -_HAL_INTFS_FILES += hal/$(HCI_NAME)_ops_linux.o -endif -endif - -ifeq ($(CONFIG_USB_HCI), y) -_HAL_INTFS_FILES +=hal/HalEfuseMask8814A_USB.o -endif -ifeq ($(CONFIG_PCI_HCI), y) -_HAL_INTFS_FILES +=hal/HalEfuseMask8814A_PCIE.o -endif - -_OUTSRC_FILES += hal/phydm/halhwimg8814a_bb.o\ - hal/phydm/halhwimg8814a_mac.o\ - hal/phydm/halhwimg8814a_rf.o\ - hal/phydm/phydm_iqk_8814a.o\ - hal/phydm/phydm_regconfig8814a.o\ - hal/phydm/halphyrf_8814a_ce.o\ - hal/phydm/phydm_rtl8814a.o\ - hal/phydm/txbf/haltxbf8814a.o - -endif - -########### HAL_RTL8723C ################################# -ifeq ($(CONFIG_RTL8723C), y) - -RTL871X = rtl8703b -ifeq ($(CONFIG_USB_HCI), y) -MODULE_NAME = 8723cu -MODULE_SUB_NAME = 8703bu -endif -ifeq ($(CONFIG_PCI_HCI), y) -MODULE_NAME = 8723ce -MODULE_SUB_NAME = 8703be -endif -ifeq ($(CONFIG_SDIO_HCI), y) -MODULE_NAME = 8723cs -MODULE_SUB_NAME = 8703bs -endif - -EXTRA_CFLAGS += -DCONFIG_RTL8703B - -_HAL_INTFS_FILES += hal/HalPwrSeqCmd.o \ - hal/Hal8703BPwrSeq.o\ - hal/$(RTL871X)_sreset.o - -_HAL_INTFS_FILES += hal/$(RTL871X)_hal_init.o \ - hal/$(RTL871X)_phycfg.o \ - hal/$(RTL871X)_rf6052.o \ - hal/$(RTL871X)_dm.o \ - hal/$(RTL871X)_rxdesc.o \ - hal/$(RTL871X)_cmd.o \ - hal/hal8703b_fw.o - -_HAL_INTFS_FILES += \ - hal/$(HCI_NAME)_halinit.o \ - hal/rtl$(MODULE_SUB_NAME)_led.o \ - hal/rtl$(MODULE_SUB_NAME)_xmit.o \ - hal/rtl$(MODULE_SUB_NAME)_recv.o - -ifeq ($(CONFIG_PCI_HCI), y) -_HAL_INTFS_FILES += hal/$(HCI_NAME)_ops_linux.o -else -_HAL_INTFS_FILES += hal/$(HCI_NAME)_ops.o -endif - -ifeq ($(CONFIG_USB_HCI), y) -_HAL_INTFS_FILES +=hal/HalEfuseMask8703B_USB.o -endif -ifeq ($(CONFIG_PCI_HCI), y) -_HAL_INTFS_FILES +=hal/HalEfuseMask8703B_PCIE.o -endif - -_OUTSRC_FILES += hal/phydm/halhwimg8703b_bb.o\ - hal/phydm/halhwimg8703b_mac.o\ - hal/phydm/halhwimg8703b_rf.o\ - hal/phydm/phydm_regconfig8703b.o\ - hal/phydm/halphyrf_8703b.o -endif - -########### HAL_RTL8723D ################################# -ifeq ($(CONFIG_RTL8723D), y) - -RTL871X = rtl8723d -ifeq ($(CONFIG_USB_HCI), y) -MODULE_NAME = 8723du -MODULE_SUB_NAME = 8723du -endif -ifeq ($(CONFIG_PCI_HCI), y) -MODULE_NAME = 8723de -MODULE_SUB_NAME = 8723de -endif -ifeq ($(CONFIG_SDIO_HCI), y) -MODULE_NAME = 8723ds -MODULE_SUB_NAME = 8723ds -endif - -EXTRA_CFLAGS += -DCONFIG_RTL8723D - -_HAL_INTFS_FILES += hal/HalPwrSeqCmd.o \ - hal/Hal8723DPwrSeq.o\ - hal/$(RTL871X)_sreset.o - -_HAL_INTFS_FILES += hal/$(RTL871X)_hal_init.o \ - hal/$(RTL871X)_phycfg.o \ - hal/$(RTL871X)_rf6052.o \ - hal/$(RTL871X)_dm.o \ - hal/$(RTL871X)_rxdesc.o \ - hal/$(RTL871X)_cmd.o \ - hal/hal8723d_fw.o \ - hal/$(RTL871X)_lps_poff.o - - -_HAL_INTFS_FILES += \ - hal/$(HCI_NAME)_halinit.o \ - hal/rtl$(MODULE_SUB_NAME)_led.o \ - hal/rtl$(MODULE_SUB_NAME)_xmit.o \ - hal/rtl$(MODULE_SUB_NAME)_recv.o - -ifeq ($(CONFIG_PCI_HCI), y) -_HAL_INTFS_FILES += hal/$(HCI_NAME)_ops_linux.o -else -_HAL_INTFS_FILES += hal/$(HCI_NAME)_ops.o -endif - -ifeq ($(CONFIG_USB_HCI), y) -_HAL_INTFS_FILES +=hal/HalEfuseMask8723D_USB.o -endif -ifeq ($(CONFIG_PCI_HCI), y) -_HAL_INTFS_FILES +=hal/HalEfuseMask8723D_PCIE.o -endif - -_OUTSRC_FILES += hal/phydm/halhwimg8723d_bb.o\ - hal/phydm/halhwimg8723d_mac.o\ - hal/phydm/halhwimg8723d_rf.o\ - hal/phydm/phydm_regconfig8723d.o\ - hal/phydm/phydm_rtl8723d.o\ - hal/phydm/halphyrf_8723d.o -endif - -########### HAL_RTL8188F ################################# -ifeq ($(CONFIG_RTL8188F), y) - -RTL871X = rtl8188f -ifeq ($(CONFIG_USB_HCI), y) -MODULE_NAME = 8188fu -endif -ifeq ($(CONFIG_PCI_HCI), y) -MODULE_NAME = 8188fe -endif -ifeq ($(CONFIG_SDIO_HCI), y) -MODULE_NAME = 8189fs -endif - -EXTRA_CFLAGS += -DCONFIG_RTL8188F - -_HAL_INTFS_FILES += hal/HalPwrSeqCmd.o \ - hal/Hal8188FPwrSeq.o\ - hal/$(RTL871X)_sreset.o - -_HAL_INTFS_FILES += hal/$(RTL871X)_hal_init.o \ - hal/$(RTL871X)_phycfg.o \ - hal/$(RTL871X)_rf6052.o \ - hal/$(RTL871X)_dm.o \ - hal/$(RTL871X)_rxdesc.o \ - hal/$(RTL871X)_cmd.o \ - hal/hal8188f_fw.o - -_HAL_INTFS_FILES += \ - hal/$(HCI_NAME)_halinit.o \ - hal/rtl$(MODULE_NAME)_led.o \ - hal/rtl$(MODULE_NAME)_xmit.o \ - hal/rtl$(MODULE_NAME)_recv.o - -ifeq ($(CONFIG_PCI_HCI), y) -_HAL_INTFS_FILES += hal/$(HCI_NAME)_ops_linux.o -else -_HAL_INTFS_FILES += hal/$(HCI_NAME)_ops.o -endif - -ifeq ($(CONFIG_USB_HCI), y) -_HAL_INTFS_FILES +=hal/HalEfuseMask8188F_USB.o -endif - -ifeq ($(CONFIG_SDIO_HCI), y) -_HAL_INTFS_FILES +=hal/HalEfuseMask8188F_SDIO.o -endif - -_OUTSRC_FILES += hal/phydm/halhwimg8188f_bb.o\ - hal/phydm/halhwimg8188f_mac.o\ - hal/phydm/halhwimg8188f_rf.o\ - hal/phydm/phydm_regconfig8188f.o\ - hal/phydm/halphyrf_8188f.o \ - hal/phydm/phydm_rtl8188f.o - -endif - -########### HAL_RTL8822B ################################# -ifeq ($(CONFIG_RTL8822B), y) -include $(TopDIR)/rtl8822b.mk -endif - -########### HAL_RTL8821C ################################# -ifeq ($(CONFIG_RTL8821C), y) -include $(TopDIR)/rtl8821c.mk - -_OUTSRC_FILES += hal/phydm/rtl8821c/halhwimg8821c_bb.o \ - hal/phydm/rtl8821c/halhwimg8821c_mac.o \ - hal/phydm/rtl8821c/halhwimg8821c_rf.o \ - hal/phydm/rtl8821c/phydm_hal_api8821c.o \ - hal/phydm/rtl8821c/phydm_regconfig8821c.o\ - hal/phydm/rtl8821c/halphyrf_8821c.o\ - hal/phydm/rtl8821c/phydm_iqk_8821c.o -endif - ########### AUTO_CFG ################################# ifeq ($(CONFIG_AUTOCFG_CP), y) ifeq ($(CONFIG_MULTIDRV), y) $(shell cp $(TopDIR)/autoconf_multidrv_$(HCI_NAME)_linux.h $(TopDIR)/include/autoconf.h) -else -ifeq ($(CONFIG_RTL8188E)$(CONFIG_SDIO_HCI),yy) -$(shell cp $(TopDIR)/autoconf_rtl8189e_$(HCI_NAME)_linux.h $(TopDIR)/include/autoconf.h) -else ifeq ($(CONFIG_RTL8188F)$(CONFIG_SDIO_HCI),yy) -$(shell cp $(TopDIR)/autoconf_rtl8189f_$(HCI_NAME)_linux.h $(TopDIR)/include/autoconf.h) -else ifeq ($(CONFIG_RTL8723C),y) -$(shell cp $(TopDIR)/autoconf_rtl8723c_$(HCI_NAME)_linux.h $(TopDIR)/include/autoconf.h) -else -$(shell cp $(TopDIR)/autoconf_$(RTL871X)_$(HCI_NAME)_linux.h $(TopDIR)/include/autoconf.h) -endif endif endif ########### END OF PATH ################################# -ifeq ($(CONFIG_USB_HCI), y) ifeq ($(CONFIG_USB_AUTOSUSPEND), y) EXTRA_CFLAGS += -DCONFIG_USB_AUTOSUSPEND endif -endif ifeq ($(CONFIG_MP_INCLUDED), y) #MODULE_NAME := $(MODULE_NAME)_mp @@ -970,9 +390,6 @@ endif ifeq ($(CONFIG_WOWLAN), y) EXTRA_CFLAGS += -DCONFIG_WOWLAN -ifeq ($(CONFIG_SDIO_HCI), y) -EXTRA_CFLAGS += -DCONFIG_RTW_SDIO_PM_KEEP_POWER -endif ifeq ($(CONFIG_DEFAULT_PATTERNS_EN), y) EXTRA_CFLAGS += -DCONFIG_DEFAULT_PATTERNS_EN endif @@ -980,9 +397,6 @@ endif ifeq ($(CONFIG_AP_WOWLAN), y) EXTRA_CFLAGS += -DCONFIG_AP_WOWLAN -ifeq ($(CONFIG_SDIO_HCI), y) -EXTRA_CFLAGS += -DCONFIG_RTW_SDIO_PM_KEEP_POWER -endif endif ifeq ($(CONFIG_PNO_SUPPORT), y) @@ -1005,12 +419,6 @@ ifneq ($(CONFIG_WAKEUP_GPIO_IDX), default) EXTRA_CFLAGS += -DWAKEUP_GPIO_IDX=$(CONFIG_WAKEUP_GPIO_IDX) endif -ifeq ($(CONFIG_RTW_SDIO_PM_KEEP_POWER), y) -ifeq ($(CONFIG_SDIO_HCI), y) -EXTRA_CFLAGS += -DCONFIG_RTW_SDIO_PM_KEEP_POWER -endif -endif - ifeq ($(CONFIG_REDUCE_TX_CPU_LOADING), y) EXTRA_CFLAGS += -DCONFIG_REDUCE_TX_CPU_LOADING endif @@ -1119,11 +527,6 @@ EXTRA_CFLAGS += -DCONFIG_IOCTL_CFG80211 -DRTW_USE_CFG80211_STA_EVENT # Enable this for Android 5.0 EXTRA_CFLAGS += -DCONFIG_RADIO_WORK -ifeq ($(CONFIG_SDIO_HCI), y) -EXTRA_CFLAGS += -DCONFIG_PLATFORM_OPS -_PLATFORM_FILES += platform/platform_arm_act_sdio.o -endif - ARCH := arm CROSS_COMPILE := /opt/arm-2011.09/bin/arm-none-linux-gnueabi- KSRC := /home/android_sdk/Action-semi/705a_android_L/android/kernel @@ -1141,13 +544,8 @@ EXTRA_CFLAGS += -DCONFIG_PLATFORM_OPS # Enable this for Android 5.0 EXTRA_CFLAGS += -DCONFIG_RADIO_WORK -ifeq ($(CONFIG_USB_HCI), y) EXTRA_CFLAGS += -DCONFIG_USE_USB_BUFFER_ALLOC_TX _PLATFORM_FILES += platform/platform_ARM_SUNxI_usb.o -endif -ifeq ($(CONFIG_SDIO_HCI), y) -_PLATFORM_FILES += platform/platform_ARM_SUN50IW1P1_sdio.o -endif ARCH := arm64 # ===Cross compile setting for Android 5.1(64) SDK === @@ -1210,9 +608,6 @@ EXTRA_CFLAGS += -DCONFIG_PLATFORM_ANDROID EXTRA_CFLAGS += -DCONFIG_CONCURRENT_MODE EXTRA_CFLAGS += -DCONFIG_IOCTL_CFG80211 -DRTW_USE_CFG80211_STA_EVENT EXTRA_CFLAGS += -DCONFIG_SKIP_SIGNAL_SCALE_MAPPING -ifeq ($(CONFIG_SDIO_HCI), y) -EXTRA_CFLAGS += -DCONFIG_RESUME_IN_WORKQUEUE -endif endif ifeq ($(CONFIG_PLATFORM_JB_X86), y) @@ -1293,9 +688,7 @@ endif ifeq ($(CONFIG_PLATFORM_RTK_DMP), y) EXTRA_CFLAGS += -DRTK_DMP_PLATFORM -DCONFIG_WIRELESS_EXT EXTRA_CFLAGS += -DCONFIG_PLATFORM_OPS -ifeq ($(CONFIG_USB_HCI), y) _PLATFORM_FILES += platform/platform_RTK_DMP_usb.o -endif ARCH:=mips CROSS_COMPILE:=mipsel-linux- KVER:= @@ -1430,9 +823,6 @@ EXTRA_CFLAGS += -DCONFIG_PLATFORM_ARM_RK3066 EXTRA_CFLAGS += -DRTW_ENABLE_WIFI_CONTROL_FUNC EXTRA_CFLAGS += -DCONFIG_CONCURRENT_MODE EXTRA_CFLAGS += -DCONFIG_IOCTL_CFG80211 -ifeq ($(CONFIG_SDIO_HCI), y) -EXTRA_CFLAGS += -DRTW_SUPPORT_PLATFORM_SHUTDOWN -endif EXTRA_CFLAGS += -fno-pic ARCH := arm CROSS_COMPILE := /home/android_sdk/Rockchip/rk3066_20130607/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.6/bin/arm-linux-androideabi- @@ -1489,15 +879,8 @@ EXTRA_CFLAGS += -DCONFIG_CONCURRENT_MODE EXTRA_CFLAGS += -DCONFIG_IOCTL_CFG80211 -DRTW_USE_CFG80211_STA_EVENT EXTRA_CFLAGS += -DCONFIG_PLATFORM_OPS -ifeq ($(CONFIG_USB_HCI), y) EXTRA_CFLAGS += -DCONFIG_USE_USB_BUFFER_ALLOC_TX _PLATFORM_FILES += platform/platform_ARM_SUNxI_usb.o -endif -ifeq ($(CONFIG_SDIO_HCI), y) -# default setting for A10-EVB mmc0 -#EXTRA_CFLAGS += -DCONFIG_WITS_EVB_V13 -_PLATFORM_FILES += platform/platform_ARM_SUNxI_sdio.o -endif ARCH := arm #CROSS_COMPILE := arm-none-linux-gnueabi- @@ -1516,23 +899,10 @@ EXTRA_CFLAGS += -DCONFIG_IOCTL_CFG80211 -DRTW_USE_CFG80211_STA_EVENT EXTRA_CFLAGS += -DCONFIG_QOS_OPTIMIZATION EXTRA_CFLAGS += -DCONFIG_PLATFORM_OPS -ifeq ($(CONFIG_USB_HCI), y) EXTRA_CFLAGS += -DCONFIG_USE_USB_BUFFER_ALLOC_TX _PLATFORM_FILES += platform/platform_ARM_SUNxI_usb.o -endif -ifeq ($(CONFIG_SDIO_HCI), y) -# default setting for A31-EVB mmc0 -EXTRA_CFLAGS += -DCONFIG_A31_EVB -_PLATFORM_FILES += platform/platform_ARM_SUNnI_sdio.o -endif ARCH := arm -#Android-JB42 -#CROSS_COMPILE := /home/android_sdk/Allwinner/a31/android-jb42/lichee/buildroot/output/external-toolchain/bin/arm-linux-gnueabi- -#KSRC :=/home/android_sdk/Allwinner/a31/android-jb42/lichee/linux-3.3 -#ifeq ($(CONFIG_USB_HCI), y) -#MODULE_NAME := 8188eu_sw -#endif # ==== Cross compile setting for kitkat-a3x_v4.5 ===== CROSS_COMPILE := /home/android_sdk/Allwinner/a31/kitkat-a3x_v4.5/lichee/buildroot/output/external-toolchain/bin/arm-linux-gnueabi- KSRC :=/home/android_sdk/Allwinner/a31/kitkat-a3x_v4.5/lichee/linux-3.3 @@ -1547,13 +917,8 @@ EXTRA_CFLAGS += -DCONFIG_IOCTL_CFG80211 -DRTW_USE_CFG80211_STA_EVENT EXTRA_CFLAGS += -DCONFIG_QOS_OPTIMIZATION EXTRA_CFLAGS += -DCONFIG_PLATFORM_OPS -ifeq ($(CONFIG_USB_HCI), y) EXTRA_CFLAGS += -DCONFIG_USE_USB_BUFFER_ALLOC_TX _PLATFORM_FILES += platform/platform_ARM_SUNxI_usb.o -endif -ifeq ($(CONFIG_SDIO_HCI), y) -_PLATFORM_FILES += platform/platform_ARM_SUNnI_sdio.o -endif ARCH := arm # ===Cross compile setting for Android 4.2 SDK === @@ -1576,13 +941,8 @@ EXTRA_CFLAGS += -DCONFIG_CONCURRENT_MODE EXTRA_CFLAGS += -DCONFIG_IOCTL_CFG80211 -DRTW_USE_CFG80211_STA_EVENT EXTRA_CFLAGS += -DCONFIG_PLATFORM_OPS -ifeq ($(CONFIG_USB_HCI), y) EXTRA_CFLAGS += -DCONFIG_USE_USB_BUFFER_ALLOC_TX _PLATFORM_FILES += platform/platform_ARM_SUNxI_usb.o -endif -ifeq ($(CONFIG_SDIO_HCI), y) -_PLATFORM_FILES += platform/platform_ARM_SUNnI_sdio.o -endif ARCH := arm # ===Cross compile setting for Android 4.2 SDK === @@ -1605,13 +965,8 @@ EXTRA_CFLAGS += -DCONFIG_IOCTL_CFG80211 -DRTW_USE_CFG80211_STA_EVENT EXTRA_CFLAGS += -DCONFIG_RADIO_WORK EXTRA_CFLAGS += -DCONFIG_PLATFORM_OPS -ifeq ($(CONFIG_USB_HCI), y) EXTRA_CFLAGS += -DCONFIG_USE_USB_BUFFER_ALLOC_TX _PLATFORM_FILES += platform/platform_ARM_SUNxI_usb.o -endif -ifeq ($(CONFIG_SDIO_HCI), y) -_PLATFORM_FILES += platform/platform_ARM_SUNnI_sdio.o -endif ARCH := arm # ===Cross compile setting for Android L SDK === @@ -1666,10 +1021,6 @@ EXTRA_CFLAGS += -DPLATFORM_SPREADTRUM_6820 ifeq ($(RTL871X), rtl8188e) EXTRA_CFLAGS += -DSOFTAP_PS_DURATION=50 endif -ifeq ($(CONFIG_SDIO_HCI), y) -EXTRA_CFLAGS += -DCONFIG_PLATFORM_OPS -_PLATFORM_FILES += platform/platform_sprd_sdio.o -endif endif ifeq ($(CONFIG_PLATFORM_ARM_SPREADTRUM_8810), y) @@ -1681,19 +1032,12 @@ EXTRA_CFLAGS += -DPLATFORM_SPREADTRUM_8810 ifeq ($(RTL871X), rtl8188e) EXTRA_CFLAGS += -DSOFTAP_PS_DURATION=50 endif -ifeq ($(CONFIG_SDIO_HCI), y) -EXTRA_CFLAGS += -DCONFIG_PLATFORM_OPS -_PLATFORM_FILES += platform/platform_sprd_sdio.o -endif endif ifeq ($(CONFIG_PLATFORM_ARM_WMT), y) EXTRA_CFLAGS += -DCONFIG_CONCURRENT_MODE EXTRA_CFLAGS += -DCONFIG_IOCTL_CFG80211 -DRTW_USE_CFG80211_STA_EVENT EXTRA_CFLAGS += -DCONFIG_PLATFORM_OPS -ifeq ($(CONFIG_SDIO_HCI), y) -_PLATFORM_FILES += platform/platform_ARM_WMT_sdio.o -endif ARCH := arm CROSS_COMPILE := /home/android_sdk/WonderMedia/wm8880-android4.4/toolchain/arm_201103_gcc4.5.2/mybin/arm_1103_le- KSRC := /home/android_sdk/WonderMedia/wm8880-android4.4/kernel4.4/ @@ -1710,14 +1054,7 @@ EXTRA_CFLAGS += -DCONFIG_IOCTL_CFG80211 -DRTW_USE_CFG80211_STA_EVENT #EXTRA_CFLAGS += -DCONFIG_QOS_OPTIMIZATION EXTRA_CFLAGS += -DCONFIG_QOS_OPTIMIZATION -#EXTRA_CFLAGS += -DCONFIG_#PLATFORM_OPS -ifeq ($(CONFIG_USB_HCI), y) EXTRA_CFLAGS += -DCONFIG_USE_USB_BUFFER_ALLOC_TX -#_PLATFORM_FILES += platform/platform_ARM_SUNxI_usb.o -endif -ifeq ($(CONFIG_SDIO_HCI), y) -_PLATFORM_FILES += platform/platform_ARM_SUNnI_sdio.o -endif ARCH := arm @@ -1745,14 +1082,7 @@ EXTRA_CFLAGS += -Wno-error=date-time ifeq ($(RTK_ANDROID_VERSION), nougat) EXTRA_CFLAGS += -DRTW_P2P_GROUP_INTERFACE=1 endif -#EXTRA_CFLAGS += -DCONFIG_#PLATFORM_OPS -ifeq ($(CONFIG_USB_HCI), y) EXTRA_CFLAGS += -DCONFIG_USE_USB_BUFFER_ALLOC_TX -#_PLATFORM_FILES += platform/platform_ARM_SUNxI_usb.o -endif -ifeq ($(CONFIG_SDIO_HCI), y) -_PLATFORM_FILES += platform/platform_ARM_SUNnI_sdio.o -endif ARCH := arm64 @@ -1789,18 +1119,8 @@ endif ifeq ($(CONFIG_MULTIDRV), y) -ifeq ($(CONFIG_SDIO_HCI), y) -MODULE_NAME := rtw_sdio -endif -ifeq ($(CONFIG_USB_HCI), y) MODULE_NAME := rtw_usb -endif - -ifeq ($(CONFIG_PCI_HCI), y) -MODULE_NAME := rtw_pci -endif - endif @@ -1840,10 +1160,6 @@ rtk_core := core/rtw_cmd.o \ core/rtw_odm.o \ core/rtw_efuse.o -ifeq ($(CONFIG_SDIO_HCI), y) -rtk_core += core/rtw_sdio.o -endif - $(MODULE_NAME)-y += $(rtk_core) $(MODULE_NAME)-$(CONFIG_INTEL_WIDI) += core/rtw_intel_widi.o diff --git a/core/rtw_bt_mp.c b/core/rtw_bt_mp.c deleted file mode 100644 index f2ef924..0000000 --- a/core/rtw_bt_mp.c +++ /dev/null @@ -1,25 +0,0 @@ -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of version 2 of the GNU General Public License as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA - * - * - ******************************************************************************/ - - -#include -#include - - diff --git a/core/rtw_eeprom.c b/core/rtw_eeprom.c deleted file mode 100644 index e887810..0000000 --- a/core/rtw_eeprom.c +++ /dev/null @@ -1,329 +0,0 @@ -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of version 2 of the GNU General Public License as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA - * - * - ******************************************************************************/ -#define _RTW_EEPROM_C_ - -#include -#include -#include - -void up_clk(_adapter *padapter, u16 *x) -{ - *x = *x | _EESK; - rtw_write8(padapter, EE_9346CR, (u8)*x); - rtw_udelay_os(CLOCK_RATE); - - -} - -void down_clk(_adapter *padapter, u16 *x) -{ - *x = *x & ~_EESK; - rtw_write8(padapter, EE_9346CR, (u8)*x); - rtw_udelay_os(CLOCK_RATE); -} - -void shift_out_bits(_adapter *padapter, u16 data, u16 count) -{ - u16 x, mask; - - if (rtw_is_surprise_removed(padapter)) { - goto out; - } - mask = 0x01 << (count - 1); - x = rtw_read8(padapter, EE_9346CR); - - x &= ~(_EEDO | _EEDI); - - do { - x &= ~_EEDI; - if (data & mask) - x |= _EEDI; - if (rtw_is_surprise_removed(padapter)) { - goto out; - } - rtw_write8(padapter, EE_9346CR, (u8)x); - rtw_udelay_os(CLOCK_RATE); - up_clk(padapter, &x); - down_clk(padapter, &x); - mask = mask >> 1; - } while (mask); - if (rtw_is_surprise_removed(padapter)) { - goto out; - } - x &= ~_EEDI; - rtw_write8(padapter, EE_9346CR, (u8)x); -out: - return; -} - -u16 shift_in_bits(_adapter *padapter) -{ - u16 x, d = 0, i; - if (rtw_is_surprise_removed(padapter)) { - goto out; - } - x = rtw_read8(padapter, EE_9346CR); - - x &= ~(_EEDO | _EEDI); - d = 0; - - for (i = 0; i < 16; i++) { - d = d << 1; - up_clk(padapter, &x); - if (rtw_is_surprise_removed(padapter)) { - goto out; - } - x = rtw_read8(padapter, EE_9346CR); - - x &= ~(_EEDI); - if (x & _EEDO) - d |= 1; - - down_clk(padapter, &x); - } -out: - - return d; -} - -void standby(_adapter *padapter) -{ - u8 x; - x = rtw_read8(padapter, EE_9346CR); - - x &= ~(_EECS | _EESK); - rtw_write8(padapter, EE_9346CR, x); - - rtw_udelay_os(CLOCK_RATE); - x |= _EECS; - rtw_write8(padapter, EE_9346CR, x); - rtw_udelay_os(CLOCK_RATE); -} - -u16 wait_eeprom_cmd_done(_adapter *padapter) -{ - u8 x; - u16 i, res = _FALSE; - standby(padapter); - for (i = 0; i < 200; i++) { - x = rtw_read8(padapter, EE_9346CR); - if (x & _EEDO) { - res = _TRUE; - goto exit; - } - rtw_udelay_os(CLOCK_RATE); - } -exit: - return res; -} - -void eeprom_clean(_adapter *padapter) -{ - u16 x; - if (rtw_is_surprise_removed(padapter)) { - goto out; - } - x = rtw_read8(padapter, EE_9346CR); - if (rtw_is_surprise_removed(padapter)) { - goto out; - } - x &= ~(_EECS | _EEDI); - rtw_write8(padapter, EE_9346CR, (u8)x); - if (rtw_is_surprise_removed(padapter)) { - goto out; - } - up_clk(padapter, &x); - if (rtw_is_surprise_removed(padapter)) { - goto out; - } - down_clk(padapter, &x); -out: - return; -} - -void eeprom_write16(_adapter *padapter, u16 reg, u16 data) -{ - u8 x; - - x = rtw_read8(padapter, EE_9346CR); - - x &= ~(_EEDI | _EEDO | _EESK | _EEM0); - x |= _EEM1 | _EECS; - rtw_write8(padapter, EE_9346CR, x); - - shift_out_bits(padapter, EEPROM_EWEN_OPCODE, 5); - - if (padapter->EepromAddressSize == 8) /* CF+ and SDIO */ - shift_out_bits(padapter, 0, 6); - else /* USB */ - shift_out_bits(padapter, 0, 4); - - standby(padapter); - - /* Commented out by rcnjko, 2004.0 - * Erase this particular word. Write the erase opcode and register - * number in that order. The opcode is 3bits in length; reg is 6 bits long. */ -/* shift_out_bits(Adapter, EEPROM_ERASE_OPCODE, 3); - * shift_out_bits(Adapter, reg, Adapter->EepromAddressSize); - * - * if (wait_eeprom_cmd_done(Adapter ) == FALSE) - * { - * return; - * } */ - - - standby(padapter); - - /* write the new word to the EEPROM */ - - /* send the write opcode the EEPORM */ - shift_out_bits(padapter, EEPROM_WRITE_OPCODE, 3); - - /* select which word in the EEPROM that we are writing to. */ - shift_out_bits(padapter, reg, padapter->EepromAddressSize); - - /* write the data to the selected EEPROM word. */ - shift_out_bits(padapter, data, 16); - - if (wait_eeprom_cmd_done(padapter) == _FALSE) - - goto exit; - - standby(padapter); - - shift_out_bits(padapter, EEPROM_EWDS_OPCODE, 5); - shift_out_bits(padapter, reg, 4); - - eeprom_clean(padapter); -exit: - return; -} - -u16 eeprom_read16(_adapter *padapter, u16 reg) /* ReadEEprom */ -{ - - u16 x; - u16 data = 0; - - if (rtw_is_surprise_removed(padapter)) { - goto out; - } - /* select EEPROM, reset bits, set _EECS */ - x = rtw_read8(padapter, EE_9346CR); - - if (rtw_is_surprise_removed(padapter)) { - goto out; - } - - x &= ~(_EEDI | _EEDO | _EESK | _EEM0); - x |= _EEM1 | _EECS; - rtw_write8(padapter, EE_9346CR, (unsigned char)x); - - /* write the read opcode and register number in that order */ - /* The opcode is 3bits in length, reg is 6 bits long */ - shift_out_bits(padapter, EEPROM_READ_OPCODE, 3); - shift_out_bits(padapter, reg, padapter->EepromAddressSize); - - /* Now read the data (16 bits) in from the selected EEPROM word */ - data = shift_in_bits(padapter); - - eeprom_clean(padapter); -out: - return data; -} - -/* From even offset */ -void eeprom_read_sz(_adapter *padapter, u16 reg, u8 *data, u32 sz) -{ - - u16 x, data16; - u32 i; - if (rtw_is_surprise_removed(padapter)) { - goto out; - } - /* select EEPROM, reset bits, set _EECS */ - x = rtw_read8(padapter, EE_9346CR); - - if (rtw_is_surprise_removed(padapter)) { - goto out; - } - - x &= ~(_EEDI | _EEDO | _EESK | _EEM0); - x |= _EEM1 | _EECS; - rtw_write8(padapter, EE_9346CR, (unsigned char)x); - - /* write the read opcode and register number in that order */ - /* The opcode is 3bits in length, reg is 6 bits long */ - shift_out_bits(padapter, EEPROM_READ_OPCODE, 3); - shift_out_bits(padapter, reg, padapter->EepromAddressSize); - - - for (i = 0; i < sz; i += 2) { - data16 = shift_in_bits(padapter); - data[i] = data16 & 0xff; - data[i + 1] = data16 >> 8; - } - - eeprom_clean(padapter); -out: - return; -} - - -/* addr_off : address offset of the entry in eeprom (not the tuple number of eeprom (reg); that is addr_off !=reg) */ -u8 eeprom_read(_adapter *padapter, u32 addr_off, u8 sz, u8 *rbuf) -{ - u8 quotient, remainder, addr_2align_odd; - u16 reg, stmp , i = 0, idx = 0; - reg = (u16)(addr_off >> 1); - addr_2align_odd = (u8)(addr_off & 0x1); - - if (addr_2align_odd) { /* read that start at high part: e.g 1,3,5,7,9,... */ - stmp = eeprom_read16(padapter, reg); - rbuf[idx++] = (u8)((stmp >> 8) & 0xff); /* return hogh-part of the short */ - reg++; - sz--; - } - - quotient = sz >> 1; - remainder = sz & 0x1; - - for (i = 0 ; i < quotient; i++) { - stmp = eeprom_read16(padapter, reg + i); - rbuf[idx++] = (u8)(stmp & 0xff); - rbuf[idx++] = (u8)((stmp >> 8) & 0xff); - } - - reg = reg + i; - if (remainder) { /* end of read at lower part of short : 0,2,4,6,... */ - stmp = eeprom_read16(padapter, reg); - rbuf[idx] = (u8)(stmp & 0xff); - } - return _TRUE; -} - - - -VOID read_eeprom_content(_adapter *padapter) -{ - - - -} diff --git a/core/rtw_ioctl_rtl.c b/core/rtw_ioctl_rtl.c deleted file mode 100644 index ab4a387..0000000 --- a/core/rtw_ioctl_rtl.c +++ /dev/null @@ -1,904 +0,0 @@ -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of version 2 of the GNU General Public License as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA - * - * - ******************************************************************************/ -#define _RTW_IOCTL_RTL_C_ - -#include - -#ifdef CONFIG_MP_INCLUDED - #include -#endif - -struct oid_obj_priv oid_rtl_seg_01_01[] = { - {1, &oid_null_function}, /* 0x80 */ - {1, &oid_null_function}, /* 0x81 */ - {1, &oid_null_function}, /* 0x82 */ - {1, &oid_null_function}, /* 0x83 */ /* OID_RT_SET_SNIFFER_MODE */ - {1, &oid_rt_get_signal_quality_hdl}, /* 0x84 */ - {1, &oid_rt_get_small_packet_crc_hdl}, /* 0x85 */ - {1, &oid_rt_get_middle_packet_crc_hdl}, /* 0x86 */ - {1, &oid_rt_get_large_packet_crc_hdl}, /* 0x87 */ - {1, &oid_rt_get_tx_retry_hdl}, /* 0x88 */ - {1, &oid_rt_get_rx_retry_hdl}, /* 0x89 */ - {1, &oid_rt_pro_set_fw_dig_state_hdl}, /* 0x8A */ - {1, &oid_rt_pro_set_fw_ra_state_hdl} , /* 0x8B */ - {1, &oid_null_function}, /* 0x8C */ - {1, &oid_null_function}, /* 0x8D */ - {1, &oid_null_function}, /* 0x8E */ - {1, &oid_null_function}, /* 0x8F */ - {1, &oid_rt_get_rx_total_packet_hdl}, /* 0x90 */ - {1, &oid_rt_get_tx_beacon_ok_hdl}, /* 0x91 */ - {1, &oid_rt_get_tx_beacon_err_hdl}, /* 0x92 */ - {1, &oid_rt_get_rx_icv_err_hdl}, /* 0x93 */ - {1, &oid_rt_set_encryption_algorithm_hdl}, /* 0x94 */ - {1, &oid_null_function}, /* 0x95 */ - {1, &oid_rt_get_preamble_mode_hdl}, /* 0x96 */ - {1, &oid_null_function}, /* 0x97 */ - {1, &oid_rt_get_ap_ip_hdl}, /* 0x98 */ - {1, &oid_rt_get_channelplan_hdl}, /* 0x99 */ - {1, &oid_rt_set_preamble_mode_hdl}, /* 0x9A */ - {1, &oid_rt_set_bcn_intvl_hdl}, /* 0x9B */ - {1, &oid_null_function}, /* 0x9C */ - {1, &oid_rt_dedicate_probe_hdl}, /* 0x9D */ - {1, &oid_null_function}, /* 0x9E */ - {1, &oid_null_function}, /* 0x9F */ - {1, &oid_null_function}, /* 0xA0 */ - {1, &oid_null_function}, /* 0xA1 */ - {1, &oid_null_function}, /* 0xA2 */ - {1, &oid_null_function}, /* 0xA3 */ - {1, &oid_null_function}, /* 0xA4 */ - {1, &oid_null_function}, /* 0xA5 */ - {1, &oid_null_function}, /* 0xA6 */ - {1, &oid_rt_get_total_tx_bytes_hdl}, /* 0xA7 */ - {1, &oid_rt_get_total_rx_bytes_hdl}, /* 0xA8 */ - {1, &oid_rt_current_tx_power_level_hdl}, /* 0xA9 */ - {1, &oid_rt_get_enc_key_mismatch_count_hdl}, /* 0xAA */ - {1, &oid_rt_get_enc_key_match_count_hdl}, /* 0xAB */ - {1, &oid_rt_get_channel_hdl}, /* 0xAC */ - {1, &oid_rt_set_channelplan_hdl}, /* 0xAD */ - {1, &oid_rt_get_hardware_radio_off_hdl}, /* 0xAE */ - {1, &oid_null_function}, /* 0xAF */ - {1, &oid_null_function}, /* 0xB0 */ - {1, &oid_null_function}, /* 0xB1 */ - {1, &oid_null_function}, /* 0xB2 */ - {1, &oid_null_function}, /* 0xB3 */ - {1, &oid_rt_get_key_mismatch_hdl}, /* 0xB4 */ - {1, &oid_null_function}, /* 0xB5 */ - {1, &oid_null_function}, /* 0xB6 */ - {1, &oid_null_function}, /* 0xB7 */ - {1, &oid_null_function}, /* 0xB8 */ - {1, &oid_null_function}, /* 0xB9 */ - {1, &oid_null_function}, /* 0xBA */ - {1, &oid_rt_supported_wireless_mode_hdl}, /* 0xBB */ - {1, &oid_rt_get_channel_list_hdl}, /* 0xBC */ - {1, &oid_rt_get_scan_in_progress_hdl}, /* 0xBD */ - {1, &oid_null_function}, /* 0xBE */ - {1, &oid_null_function}, /* 0xBF */ - {1, &oid_null_function}, /* 0xC0 */ - {1, &oid_rt_forced_data_rate_hdl}, /* 0xC1 */ - {1, &oid_rt_wireless_mode_for_scan_list_hdl}, /* 0xC2 */ - {1, &oid_rt_get_bss_wireless_mode_hdl}, /* 0xC3 */ - {1, &oid_rt_scan_with_magic_packet_hdl}, /* 0xC4 */ - {1, &oid_null_function}, /* 0xC5 */ - {1, &oid_null_function}, /* 0xC6 */ - {1, &oid_null_function}, /* 0xC7 */ - {1, &oid_null_function}, /* 0xC8 */ - {1, &oid_null_function}, /* 0xC9 */ - {1, &oid_null_function}, /* 0xCA */ - {1, &oid_null_function}, /* 0xCB */ - {1, &oid_null_function}, /* 0xCC */ - {1, &oid_null_function}, /* 0xCD */ - {1, &oid_null_function}, /* 0xCE */ - {1, &oid_null_function}, /* 0xCF */ - -}; - -struct oid_obj_priv oid_rtl_seg_01_03[] = { - {1, &oid_rt_ap_get_associated_station_list_hdl}, /* 0x00 */ - {1, &oid_null_function}, /* 0x01 */ - {1, &oid_rt_ap_switch_into_ap_mode_hdl}, /* 0x02 */ - {1, &oid_null_function}, /* 0x03 */ - {1, &oid_rt_ap_supported_hdl}, /* 0x04 */ - {1, &oid_rt_ap_set_passphrase_hdl}, /* 0x05 */ - -}; - -struct oid_obj_priv oid_rtl_seg_01_11[] = { - {1, &oid_null_function}, /* 0xC0 OID_RT_PRO_RX_FILTER */ - {1, &oid_null_function}, /* 0xC1 OID_CE_USB_WRITE_REGISTRY */ - {1, &oid_null_function}, /* 0xC2 OID_CE_USB_READ_REGISTRY */ - {1, &oid_null_function}, /* 0xC3 OID_RT_PRO_SET_INITIAL_GAIN */ - {1, &oid_null_function}, /* 0xC4 OID_RT_PRO_SET_BB_RF_STANDBY_MODE */ - {1, &oid_null_function}, /* 0xC5 OID_RT_PRO_SET_BB_RF_SHUTDOWN_MODE */ - {1, &oid_null_function}, /* 0xC6 OID_RT_PRO_SET_TX_CHARGE_PUMP */ - {1, &oid_null_function}, /* 0xC7 OID_RT_PRO_SET_RX_CHARGE_PUMP */ - {1, &oid_rt_pro_rf_write_registry_hdl}, /* 0xC8 */ - {1, &oid_rt_pro_rf_read_registry_hdl}, /* 0xC9 */ - {1, &oid_null_function} /* 0xCA OID_RT_PRO_QUERY_RF_TYPE */ - -}; - -struct oid_obj_priv oid_rtl_seg_03_00[] = { - {1, &oid_null_function}, /* 0x00 */ - {1, &oid_rt_get_connect_state_hdl}, /* 0x01 */ - {1, &oid_null_function}, /* 0x02 */ - {1, &oid_null_function}, /* 0x03 */ - {1, &oid_rt_set_default_key_id_hdl}, /* 0x04 */ - - -}; - - -/* ************** oid_rtl_seg_01_01 section start ************** */ - -NDIS_STATUS oid_rt_pro_set_fw_dig_state_hdl(struct oid_par_priv *poid_par_priv) -{ - NDIS_STATUS status = NDIS_STATUS_SUCCESS; -#if 0 - PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); - _irqL oldirql; - - - if (poid_par_priv->type_of_oid != SET_OID) { - status = NDIS_STATUS_NOT_ACCEPTED; - return status; - } - - _irqlevel_changed_(&oldirql, LOWER); - if (poid_par_priv->information_buf_len >= sizeof(struct setdig_parm)) { - /* DEBUG_ERR(("===> oid_rt_pro_set_fw_dig_state_hdl. type:0x%02x.\n",*((unsigned char*)poid_par_priv->information_buf ))); */ - if (!rtw_setfwdig_cmd(Adapter, *((unsigned char *)poid_par_priv->information_buf))) - status = NDIS_STATUS_NOT_ACCEPTED; - - } else - status = NDIS_STATUS_NOT_ACCEPTED; - _irqlevel_changed_(&oldirql, RAISE); -#endif - return status; -} -/* ----------------------------------------------------------------------------- */ -NDIS_STATUS oid_rt_pro_set_fw_ra_state_hdl(struct oid_par_priv *poid_par_priv) -{ - - NDIS_STATUS status = NDIS_STATUS_SUCCESS; -#if 0 - PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); - _irqL oldirql; - - if (poid_par_priv->type_of_oid != SET_OID) { - status = NDIS_STATUS_NOT_ACCEPTED; - return status; - } - - - _irqlevel_changed_(&oldirql, LOWER); - - if (poid_par_priv->information_buf_len >= sizeof(struct setra_parm)) { - /* DEBUG_ERR(("===> oid_rt_pro_set_fw_ra_state_hdl. type:0x%02x.\n",*((unsigned char*)poid_par_priv->information_buf ))); */ - if (!rtw_setfwra_cmd(Adapter, *((unsigned char *)poid_par_priv->information_buf))) - status = NDIS_STATUS_NOT_ACCEPTED; - - } else - status = NDIS_STATUS_NOT_ACCEPTED; - _irqlevel_changed_(&oldirql, RAISE); -#endif - return status; -} -/* ----------------------------------------------------------------------------- */ -NDIS_STATUS oid_rt_get_signal_quality_hdl(struct oid_par_priv *poid_par_priv) -{ - NDIS_STATUS status = NDIS_STATUS_SUCCESS; - PADAPTER padapter = (PADAPTER)(poid_par_priv->adapter_context); - - /* DEBUG_ERR(("<**********************oid_rt_get_signal_quality_hdl\n")); */ - if (poid_par_priv->type_of_oid != QUERY_OID) { - status = NDIS_STATUS_NOT_ACCEPTED; - return status; - } - -#if 0 - if (pMgntInfo->mAssoc || pMgntInfo->mIbss) { - ulInfo = pAdapter->RxStats.SignalQuality; - *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; - } else { - ulInfo = 0xffffffff; /* It stands for -1 in 4-byte integer. */ - } - break; -#endif - - return status; -} - -/* ------------------------------------------------------------------------------ */ - -NDIS_STATUS oid_rt_get_small_packet_crc_hdl(struct oid_par_priv *poid_par_priv) -{ - NDIS_STATUS status = NDIS_STATUS_SUCCESS; - PADAPTER padapter = (PADAPTER)(poid_par_priv->adapter_context); - - if (poid_par_priv->type_of_oid != QUERY_OID) { - status = NDIS_STATUS_NOT_ACCEPTED; - return status; - } - - if (poid_par_priv->information_buf_len >= sizeof(ULONG)) { - *(ULONG *)poid_par_priv->information_buf = padapter->recvpriv.rx_smallpacket_crcerr; - *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; - } else - status = NDIS_STATUS_INVALID_LENGTH; - - return status; -} -/* ------------------------------------------------------------------------------ */ -NDIS_STATUS oid_rt_get_middle_packet_crc_hdl(struct oid_par_priv *poid_par_priv) -{ - NDIS_STATUS status = NDIS_STATUS_SUCCESS; - PADAPTER padapter = (PADAPTER)(poid_par_priv->adapter_context); - - if (poid_par_priv->type_of_oid != QUERY_OID) { - status = NDIS_STATUS_NOT_ACCEPTED; - return status; - } - - if (poid_par_priv->information_buf_len >= sizeof(ULONG)) { - *(ULONG *)poid_par_priv->information_buf = padapter->recvpriv.rx_middlepacket_crcerr; - *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; - } else - status = NDIS_STATUS_INVALID_LENGTH; - - - return status; -} -/* ------------------------------------------------------------------------------ */ -NDIS_STATUS oid_rt_get_large_packet_crc_hdl(struct oid_par_priv *poid_par_priv) -{ - NDIS_STATUS status = NDIS_STATUS_SUCCESS; - PADAPTER padapter = (PADAPTER)(poid_par_priv->adapter_context); - - if (poid_par_priv->type_of_oid != QUERY_OID) { - status = NDIS_STATUS_NOT_ACCEPTED; - return status; - } - - if (poid_par_priv->information_buf_len >= sizeof(ULONG)) { - *(ULONG *)poid_par_priv->information_buf = padapter->recvpriv.rx_largepacket_crcerr; - *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; - } else - status = NDIS_STATUS_INVALID_LENGTH; - - - return status; -} - -/* ------------------------------------------------------------------------------ */ -NDIS_STATUS oid_rt_get_tx_retry_hdl(struct oid_par_priv *poid_par_priv) -{ - NDIS_STATUS status = NDIS_STATUS_SUCCESS; - PADAPTER padapter = (PADAPTER)(poid_par_priv->adapter_context); - - if (poid_par_priv->type_of_oid != QUERY_OID) { - status = NDIS_STATUS_NOT_ACCEPTED; - return status; - } - - return status; -} -NDIS_STATUS oid_rt_get_rx_retry_hdl(struct oid_par_priv *poid_par_priv) -{ - NDIS_STATUS status = NDIS_STATUS_SUCCESS; - PADAPTER padapter = (PADAPTER)(poid_par_priv->adapter_context); - - if (poid_par_priv->type_of_oid != QUERY_OID) { - status = NDIS_STATUS_NOT_ACCEPTED; - return status; - } - *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; - return status; -} -/* ------------------------------------------------------------------------------ */ -NDIS_STATUS oid_rt_get_rx_total_packet_hdl(struct oid_par_priv *poid_par_priv) -{ - NDIS_STATUS status = NDIS_STATUS_SUCCESS; - PADAPTER padapter = (PADAPTER)(poid_par_priv->adapter_context); - - if (poid_par_priv->type_of_oid != QUERY_OID) { - status = NDIS_STATUS_NOT_ACCEPTED; - return status; - } - if (poid_par_priv->information_buf_len >= sizeof(ULONG)) { - *(u64 *)poid_par_priv->information_buf = padapter->recvpriv.rx_pkts + padapter->recvpriv.rx_drop; - *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; - } else - status = NDIS_STATUS_INVALID_LENGTH; - - - return status; -} -/* ------------------------------------------------------------------------------ */ -NDIS_STATUS oid_rt_get_tx_beacon_ok_hdl(struct oid_par_priv *poid_par_priv) -{ - NDIS_STATUS status = NDIS_STATUS_SUCCESS; - PADAPTER padapter = (PADAPTER)(poid_par_priv->adapter_context); - - if (poid_par_priv->type_of_oid != QUERY_OID) { - status = NDIS_STATUS_NOT_ACCEPTED; - return status; - } - - return status; -} -NDIS_STATUS oid_rt_get_tx_beacon_err_hdl(struct oid_par_priv *poid_par_priv) -{ - NDIS_STATUS status = NDIS_STATUS_SUCCESS; - PADAPTER padapter = (PADAPTER)(poid_par_priv->adapter_context); - - if (poid_par_priv->type_of_oid != QUERY_OID) { - status = NDIS_STATUS_NOT_ACCEPTED; - return status; - } - - return status; -} -/* ------------------------------------------------------------------------------ */ -NDIS_STATUS oid_rt_get_rx_icv_err_hdl(struct oid_par_priv *poid_par_priv) -{ - NDIS_STATUS status = NDIS_STATUS_SUCCESS; - PADAPTER padapter = (PADAPTER)(poid_par_priv->adapter_context); - - if (poid_par_priv->type_of_oid != QUERY_OID) { - status = NDIS_STATUS_NOT_ACCEPTED; - return status; - } - if (poid_par_priv->information_buf_len >= sizeof(u32)) { - /* _rtw_memcpy(*(uint *)poid_par_priv->information_buf,padapter->recvpriv.rx_icv_err,sizeof(u32)); */ - *(uint *)poid_par_priv->information_buf = padapter->recvpriv.rx_icv_err; - *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; - } else - status = NDIS_STATUS_INVALID_LENGTH ; - - - return status; -} -/* ------------------------------------------------------------------------------ */ -NDIS_STATUS oid_rt_set_encryption_algorithm_hdl(struct oid_par_priv *poid_par_priv) -{ - NDIS_STATUS status = NDIS_STATUS_SUCCESS; - PADAPTER padapter = (PADAPTER)(poid_par_priv->adapter_context); - - if (poid_par_priv->type_of_oid != SET_OID) { - status = NDIS_STATUS_NOT_ACCEPTED; - return status; - } - - return status; -} -/* ------------------------------------------------------------------------------ */ -NDIS_STATUS oid_rt_get_preamble_mode_hdl(struct oid_par_priv *poid_par_priv) -{ - NDIS_STATUS status = NDIS_STATUS_SUCCESS; - PADAPTER padapter = (PADAPTER)(poid_par_priv->adapter_context); - ULONG preamblemode = 0 ; - - if (poid_par_priv->type_of_oid != QUERY_OID) { - status = NDIS_STATUS_NOT_ACCEPTED; - return status; - } - if (poid_par_priv->information_buf_len >= sizeof(ULONG)) { - if (padapter->registrypriv.preamble == PREAMBLE_LONG) - preamblemode = 0; - else if (padapter->registrypriv.preamble == PREAMBLE_AUTO) - preamblemode = 1; - else if (padapter->registrypriv.preamble == PREAMBLE_SHORT) - preamblemode = 2; - - - *(ULONG *)poid_par_priv->information_buf = preamblemode ; - *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; - } else - status = NDIS_STATUS_INVALID_LENGTH ; - return status; -} -/* ------------------------------------------------------------------------------ */ -NDIS_STATUS oid_rt_get_ap_ip_hdl(struct oid_par_priv *poid_par_priv) -{ - NDIS_STATUS status = NDIS_STATUS_SUCCESS; - PADAPTER padapter = (PADAPTER)(poid_par_priv->adapter_context); - - if (poid_par_priv->type_of_oid != QUERY_OID) { - status = NDIS_STATUS_NOT_ACCEPTED; - return status; - } - - return status; -} - -NDIS_STATUS oid_rt_get_channelplan_hdl(struct oid_par_priv *poid_par_priv) -{ - NDIS_STATUS status = NDIS_STATUS_SUCCESS; - PADAPTER padapter = (PADAPTER)(poid_par_priv->adapter_context); - - if (poid_par_priv->type_of_oid != QUERY_OID) { - status = NDIS_STATUS_NOT_ACCEPTED; - return status; - } - *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; - *(u16 *)poid_par_priv->information_buf = padapter->mlmepriv.ChannelPlan ; - - return status; -} -NDIS_STATUS oid_rt_set_channelplan_hdl(struct oid_par_priv *poid_par_priv) -{ - NDIS_STATUS status = NDIS_STATUS_SUCCESS; - PADAPTER padapter = (PADAPTER)(poid_par_priv->adapter_context); - - if (poid_par_priv->type_of_oid != SET_OID) { - status = NDIS_STATUS_NOT_ACCEPTED; - return status; - } - - padapter->mlmepriv.ChannelPlan = *(u16 *)poid_par_priv->information_buf ; - - return status; -} -/* ------------------------------------------------------------------------------ */ -NDIS_STATUS oid_rt_set_preamble_mode_hdl(struct oid_par_priv *poid_par_priv) -{ - NDIS_STATUS status = NDIS_STATUS_SUCCESS; - PADAPTER padapter = (PADAPTER)(poid_par_priv->adapter_context); - ULONG preamblemode = 0; - if (poid_par_priv->type_of_oid != SET_OID) { - status = NDIS_STATUS_NOT_ACCEPTED; - return status; - } - - if (poid_par_priv->information_buf_len >= sizeof(ULONG)) { - preamblemode = *(ULONG *)poid_par_priv->information_buf ; - if (preamblemode == 0) - padapter->registrypriv.preamble = PREAMBLE_LONG; - else if (preamblemode == 1) - padapter->registrypriv.preamble = PREAMBLE_AUTO; - else if (preamblemode == 2) - padapter->registrypriv.preamble = PREAMBLE_SHORT; - - *(ULONG *)poid_par_priv->information_buf = preamblemode ; - *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; - } else - status = NDIS_STATUS_INVALID_LENGTH ; - - return status; -} -/* ------------------------------------------------------------------------------ */ -NDIS_STATUS oid_rt_set_bcn_intvl_hdl(struct oid_par_priv *poid_par_priv) -{ - NDIS_STATUS status = NDIS_STATUS_SUCCESS; - PADAPTER padapter = (PADAPTER)(poid_par_priv->adapter_context); - - if (poid_par_priv->type_of_oid != SET_OID) { - status = NDIS_STATUS_NOT_ACCEPTED; - return status; - } - - return status; -} -NDIS_STATUS oid_rt_dedicate_probe_hdl(struct oid_par_priv *poid_par_priv) -{ - NDIS_STATUS status = NDIS_STATUS_SUCCESS; - PADAPTER padapter = (PADAPTER)(poid_par_priv->adapter_context); - - return status; -} -/* ------------------------------------------------------------------------------ */ -NDIS_STATUS oid_rt_get_total_tx_bytes_hdl(struct oid_par_priv *poid_par_priv) -{ - NDIS_STATUS status = NDIS_STATUS_SUCCESS; - PADAPTER padapter = (PADAPTER)(poid_par_priv->adapter_context); - - if (poid_par_priv->type_of_oid != QUERY_OID) { - status = NDIS_STATUS_NOT_ACCEPTED; - return status; - } - if (poid_par_priv->information_buf_len >= sizeof(ULONG)) { - *(u64 *)poid_par_priv->information_buf = padapter->xmitpriv.tx_bytes; - *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; - } else - status = NDIS_STATUS_INVALID_LENGTH ; - - - return status; -} -/* ------------------------------------------------------------------------------ */ -NDIS_STATUS oid_rt_get_total_rx_bytes_hdl(struct oid_par_priv *poid_par_priv) -{ - NDIS_STATUS status = NDIS_STATUS_SUCCESS; - PADAPTER padapter = (PADAPTER)(poid_par_priv->adapter_context); - - if (poid_par_priv->type_of_oid != QUERY_OID) { - status = NDIS_STATUS_NOT_ACCEPTED; - return status; - } - if (poid_par_priv->information_buf_len >= sizeof(ULONG)) { - /* _rtw_memcpy(*(uint *)poid_par_priv->information_buf,padapter->recvpriv.rx_icv_err,sizeof(u32)); */ - *(u64 *)poid_par_priv->information_buf = padapter->recvpriv.rx_bytes; - *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; - } else - status = NDIS_STATUS_INVALID_LENGTH ; - return status; -} -/* ------------------------------------------------------------------------------ */ -NDIS_STATUS oid_rt_current_tx_power_level_hdl(struct oid_par_priv *poid_par_priv) -{ - NDIS_STATUS status = NDIS_STATUS_SUCCESS; - PADAPTER padapter = (PADAPTER)(poid_par_priv->adapter_context); - - return status; -} -NDIS_STATUS oid_rt_get_enc_key_mismatch_count_hdl(struct oid_par_priv *poid_par_priv) -{ - NDIS_STATUS status = NDIS_STATUS_SUCCESS; - PADAPTER padapter = (PADAPTER)(poid_par_priv->adapter_context); - - if (poid_par_priv->type_of_oid != QUERY_OID) { - status = NDIS_STATUS_NOT_ACCEPTED; - return status; - } - - return status; -} -NDIS_STATUS oid_rt_get_enc_key_match_count_hdl(struct oid_par_priv *poid_par_priv) -{ - NDIS_STATUS status = NDIS_STATUS_SUCCESS; - PADAPTER padapter = (PADAPTER)(poid_par_priv->adapter_context); - - if (poid_par_priv->type_of_oid != QUERY_OID) { - status = NDIS_STATUS_NOT_ACCEPTED; - return status; - } - - return status; -} -NDIS_STATUS oid_rt_get_channel_hdl(struct oid_par_priv *poid_par_priv) -{ - NDIS_STATUS status = NDIS_STATUS_SUCCESS; - PADAPTER padapter = (PADAPTER)(poid_par_priv->adapter_context); - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - NDIS_802_11_CONFIGURATION *pnic_Config; - - ULONG channelnum; - - if (poid_par_priv->type_of_oid != QUERY_OID) { - status = NDIS_STATUS_NOT_ACCEPTED; - return status; - } - - if ((check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE) || - (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == _TRUE)) - pnic_Config = &pmlmepriv->cur_network.network.Configuration; - else - pnic_Config = &padapter->registrypriv.dev_network.Configuration; - - channelnum = pnic_Config->DSConfig; - *(ULONG *)poid_par_priv->information_buf = channelnum; - - *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; - - - - - return status; -} -NDIS_STATUS oid_rt_get_hardware_radio_off_hdl(struct oid_par_priv *poid_par_priv) -{ - NDIS_STATUS status = NDIS_STATUS_SUCCESS; - PADAPTER padapter = (PADAPTER)(poid_par_priv->adapter_context); - - if (poid_par_priv->type_of_oid != QUERY_OID) { - status = NDIS_STATUS_NOT_ACCEPTED; - return status; - } - - return status; -} -NDIS_STATUS oid_rt_get_key_mismatch_hdl(struct oid_par_priv *poid_par_priv) -{ - NDIS_STATUS status = NDIS_STATUS_SUCCESS; - PADAPTER padapter = (PADAPTER)(poid_par_priv->adapter_context); - - if (poid_par_priv->type_of_oid != QUERY_OID) { - status = NDIS_STATUS_NOT_ACCEPTED; - return status; - } - - return status; -} -NDIS_STATUS oid_rt_supported_wireless_mode_hdl(struct oid_par_priv *poid_par_priv) -{ - NDIS_STATUS status = NDIS_STATUS_SUCCESS; - PADAPTER padapter = (PADAPTER)(poid_par_priv->adapter_context); - ULONG ulInfo = 0 ; - /* DEBUG_ERR(("<**********************oid_rt_supported_wireless_mode_hdl\n")); */ - if (poid_par_priv->type_of_oid != QUERY_OID) { - status = NDIS_STATUS_NOT_ACCEPTED; - return status; - } - if (poid_par_priv->information_buf_len >= sizeof(ULONG)) { - ulInfo |= 0x0100; /* WIRELESS_MODE_B */ - ulInfo |= 0x0200; /* WIRELESS_MODE_G */ - ulInfo |= 0x0400; /* WIRELESS_MODE_A */ - - *(ULONG *) poid_par_priv->information_buf = ulInfo; - /* DEBUG_ERR(("<===oid_rt_supported_wireless_mode %x\n",ulInfo)); */ - *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; - } else - status = NDIS_STATUS_INVALID_LENGTH; - - return status; -} -NDIS_STATUS oid_rt_get_channel_list_hdl(struct oid_par_priv *poid_par_priv) -{ - NDIS_STATUS status = NDIS_STATUS_SUCCESS; - PADAPTER padapter = (PADAPTER)(poid_par_priv->adapter_context); - - if (poid_par_priv->type_of_oid != QUERY_OID) { - status = NDIS_STATUS_NOT_ACCEPTED; - return status; - } - - return status; -} -NDIS_STATUS oid_rt_get_scan_in_progress_hdl(struct oid_par_priv *poid_par_priv) -{ - NDIS_STATUS status = NDIS_STATUS_SUCCESS; - PADAPTER padapter = (PADAPTER)(poid_par_priv->adapter_context); - - if (poid_par_priv->type_of_oid != QUERY_OID) { - status = NDIS_STATUS_NOT_ACCEPTED; - return status; - } - - return status; -} - - -NDIS_STATUS oid_rt_forced_data_rate_hdl(struct oid_par_priv *poid_par_priv) -{ - NDIS_STATUS status = NDIS_STATUS_SUCCESS; - PADAPTER padapter = (PADAPTER)(poid_par_priv->adapter_context); - - return status; -} -NDIS_STATUS oid_rt_wireless_mode_for_scan_list_hdl(struct oid_par_priv *poid_par_priv) -{ - NDIS_STATUS status = NDIS_STATUS_SUCCESS; - PADAPTER padapter = (PADAPTER)(poid_par_priv->adapter_context); - - return status; -} -NDIS_STATUS oid_rt_get_bss_wireless_mode_hdl(struct oid_par_priv *poid_par_priv) -{ - NDIS_STATUS status = NDIS_STATUS_SUCCESS; - PADAPTER padapter = (PADAPTER)(poid_par_priv->adapter_context); - - if (poid_par_priv->type_of_oid != QUERY_OID) { - status = NDIS_STATUS_NOT_ACCEPTED; - return status; - } - - return status; -} - -NDIS_STATUS oid_rt_scan_with_magic_packet_hdl(struct oid_par_priv *poid_par_priv) -{ - NDIS_STATUS status = NDIS_STATUS_SUCCESS; - PADAPTER padapter = (PADAPTER)(poid_par_priv->adapter_context); - - return status; -} -/* ************** oid_rtl_seg_01_01 section end ************** */ - -/* ************** oid_rtl_seg_01_03 section start ************** */ -NDIS_STATUS oid_rt_ap_get_associated_station_list_hdl(struct oid_par_priv *poid_par_priv) -{ - NDIS_STATUS status = NDIS_STATUS_SUCCESS; - PADAPTER padapter = (PADAPTER)(poid_par_priv->adapter_context); - - if (poid_par_priv->type_of_oid != QUERY_OID) { - status = NDIS_STATUS_NOT_ACCEPTED; - return status; - } - - return status; -} -NDIS_STATUS oid_rt_ap_switch_into_ap_mode_hdl(struct oid_par_priv *poid_par_priv) -{ - NDIS_STATUS status = NDIS_STATUS_SUCCESS; - PADAPTER padapter = (PADAPTER)(poid_par_priv->adapter_context); - - return status; -} -NDIS_STATUS oid_rt_ap_supported_hdl(struct oid_par_priv *poid_par_priv) -{ - NDIS_STATUS status = NDIS_STATUS_SUCCESS; - PADAPTER padapter = (PADAPTER)(poid_par_priv->adapter_context); - - return status; -} -NDIS_STATUS oid_rt_ap_set_passphrase_hdl(struct oid_par_priv *poid_par_priv) -{ - NDIS_STATUS status = NDIS_STATUS_SUCCESS; - PADAPTER padapter = (PADAPTER)(poid_par_priv->adapter_context); - - if (poid_par_priv->type_of_oid != SET_OID) { - status = NDIS_STATUS_NOT_ACCEPTED; - return status; - } - - return status; -} - -/* ************** oid_rtl_seg_01_03 section end ************** */ - -/* **************** oid_rtl_seg_01_11 section start **************** */ -NDIS_STATUS oid_rt_pro_rf_write_registry_hdl(struct oid_par_priv *poid_par_priv) -{ - NDIS_STATUS status = NDIS_STATUS_SUCCESS; - PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); - _irqL oldirql; - /* DEBUG_ERR(("<**********************oid_rt_pro_rf_write_registry_hdl\n")); */ - if (poid_par_priv->type_of_oid != SET_OID) { /* QUERY_OID */ - status = NDIS_STATUS_NOT_ACCEPTED; - return status; - } - - _irqlevel_changed_(&oldirql, LOWER); - if (poid_par_priv->information_buf_len == (sizeof(unsigned long) * 3)) { - /* RegOffsetValue - The offset of RF register to write. */ - /* RegDataWidth - The data width of RF register to write. */ - /* RegDataValue - The value to write. */ - /* RegOffsetValue = *((unsigned long*)InformationBuffer); */ - /* RegDataWidth = *((unsigned long*)InformationBuffer+1); */ - /* RegDataValue = *((unsigned long*)InformationBuffer+2); */ - if (!rtw_setrfreg_cmd(Adapter, - *(unsigned char *)poid_par_priv->information_buf, - (unsigned long)(*((unsigned long *)poid_par_priv->information_buf + 2)))) - status = NDIS_STATUS_NOT_ACCEPTED; - - } else - status = NDIS_STATUS_INVALID_LENGTH; - _irqlevel_changed_(&oldirql, RAISE); - - return status; -} - -/* ------------------------------------------------------------------------------ */ -NDIS_STATUS oid_rt_pro_rf_read_registry_hdl(struct oid_par_priv *poid_par_priv) -{ - NDIS_STATUS status = NDIS_STATUS_SUCCESS; -#if 0 - PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); - _irqL oldirql; - - /* DEBUG_ERR(("<**********************oid_rt_pro_rf_read_registry_hdl\n")); */ - if (poid_par_priv->type_of_oid != SET_OID) { /* QUERY_OID */ - status = NDIS_STATUS_NOT_ACCEPTED; - return status; - } - - _irqlevel_changed_(&oldirql, LOWER); - if (poid_par_priv->information_buf_len == (sizeof(unsigned long) * 3)) { - if (Adapter->mppriv.act_in_progress == _TRUE) - status = NDIS_STATUS_NOT_ACCEPTED; - else { - /* init workparam */ - Adapter->mppriv.act_in_progress = _TRUE; - Adapter->mppriv.workparam.bcompleted = _FALSE; - Adapter->mppriv.workparam.act_type = MPT_READ_RF; - Adapter->mppriv.workparam.io_offset = *(unsigned long *)poid_par_priv->information_buf; - Adapter->mppriv.workparam.io_value = 0xcccccccc; - - /* RegOffsetValue - The offset of RF register to read. */ - /* RegDataWidth - The data width of RF register to read. */ - /* RegDataValue - The value to read. */ - /* RegOffsetValue = *((unsigned long*)InformationBuffer); */ - /* RegDataWidth = *((unsigned long*)InformationBuffer+1); */ - /* RegDataValue = *((unsigned long*)InformationBuffer+2); */ - if (!rtw_getrfreg_cmd(Adapter, - *(unsigned char *)poid_par_priv->information_buf, - (unsigned char *)&Adapter->mppriv.workparam.io_value)) - status = NDIS_STATUS_NOT_ACCEPTED; - } - - - } else - status = NDIS_STATUS_INVALID_LENGTH; - _irqlevel_changed_(&oldirql, RAISE); -#endif - return status; -} - -/* **************** oid_rtl_seg_01_11 section end**************** */ - - -/* ************** oid_rtl_seg_03_00 section start ************** */ -enum _CONNECT_STATE_ { - CHECKINGSTATUS, - ASSOCIATED, - ADHOCMODE, - NOTASSOCIATED -}; - -NDIS_STATUS oid_rt_get_connect_state_hdl(struct oid_par_priv *poid_par_priv) -{ - NDIS_STATUS status = NDIS_STATUS_SUCCESS; - PADAPTER padapter = (PADAPTER)(poid_par_priv->adapter_context); - - struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); - - ULONG ulInfo; - - if (poid_par_priv->type_of_oid != QUERY_OID) { - status = NDIS_STATUS_NOT_ACCEPTED; - return status; - } - - /* nStatus==0 CheckingStatus */ - /* nStatus==1 Associated */ - /* nStatus==2 AdHocMode */ - /* nStatus==3 NotAssociated */ - - if (check_fwstate(pmlmepriv, _FW_UNDER_LINKING) == _TRUE) - ulInfo = CHECKINGSTATUS; - else if (check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE) - ulInfo = ASSOCIATED; - else if (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) == _TRUE) - ulInfo = ADHOCMODE; - else - ulInfo = NOTASSOCIATED ; - - *(ULONG *)poid_par_priv->information_buf = ulInfo; - *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; - -#if 0 - /* Rearrange the order to let the UI still shows connection when scan is in progress */ - if (pMgntInfo->mAssoc) - ulInfo = 1; - else if (pMgntInfo->mIbss) - ulInfo = 2; - else if (pMgntInfo->bScanInProgress) - ulInfo = 0; - else - ulInfo = 3; - ulInfoLen = sizeof(ULONG); -#endif - - return status; -} - -NDIS_STATUS oid_rt_set_default_key_id_hdl(struct oid_par_priv *poid_par_priv) -{ - NDIS_STATUS status = NDIS_STATUS_SUCCESS; - PADAPTER padapter = (PADAPTER)(poid_par_priv->adapter_context); - - if (poid_par_priv->type_of_oid != SET_OID) { - status = NDIS_STATUS_NOT_ACCEPTED; - return status; - } - - return status; -} -/* ************** oid_rtl_seg_03_00 section end ************** */ diff --git a/core/rtw_mem.c b/core/rtw_mem.c deleted file mode 100644 index 0db65ed..0000000 --- a/core/rtw_mem.c +++ /dev/null @@ -1,114 +0,0 @@ - -#include -#include - -MODULE_LICENSE("GPL"); -MODULE_DESCRIPTION("Realtek Wireless Lan Driver"); -MODULE_AUTHOR("Realtek Semiconductor Corp."); -MODULE_VERSION("DRIVERVERSION"); - -struct sk_buff_head rtk_skb_mem_q; -struct u8 *rtk_buf_mem[NR_RECVBUFF]; - -struct u8 *rtw_get_buf_premem(int index) -{ - RTW_INFO("%s, rtk_buf_mem index : %d\n", __func__, index); - return rtk_buf_mem[index]; -} - -u16 rtw_rtkm_get_buff_size(void) -{ - return MAX_RTKM_RECVBUF_SZ; -} -EXPORT_SYMBOL(rtw_rtkm_get_buff_size); - -u8 rtw_rtkm_get_nr_recv_skb(void) -{ - return MAX_RTKM_NR_PREALLOC_RECV_SKB; -} -EXPORT_SYMBOL(rtw_rtkm_get_nr_recv_skb); - -struct sk_buff *rtw_alloc_skb_premem(u16 in_size) -{ - struct sk_buff *skb = NULL; - - if (in_size > MAX_RTKM_RECVBUF_SZ) { - pr_info("warning %s: driver buffer size(%d) > rtkm buffer size(%d)\n", __func__, in_size, MAX_RTKM_RECVBUF_SZ); - WARN_ON(1); - return skb; - } - - skb = skb_dequeue(&rtk_skb_mem_q); - - RTW_INFO("%s, rtk_skb_mem_q len : %d\n", __func__, skb_queue_len(&rtk_skb_mem_q)); - - return skb; -} -EXPORT_SYMBOL(rtw_alloc_skb_premem); - -int rtw_free_skb_premem(struct sk_buff *pskb) -{ - if (!pskb) - return -1; - - if (skb_queue_len(&rtk_skb_mem_q) >= MAX_RTKM_NR_PREALLOC_RECV_SKB) - return -1; - - skb_queue_tail(&rtk_skb_mem_q, pskb); - - RTW_INFO("%s, rtk_skb_mem_q len : %d\n", __func__, skb_queue_len(&rtk_skb_mem_q)); - - return 0; -} -EXPORT_SYMBOL(rtw_free_skb_premem); - -static int __init rtw_mem_init(void) -{ - int i; - SIZE_PTR tmpaddr = 0; - SIZE_PTR alignment = 0; - struct sk_buff *pskb = NULL; - - RTW_INFO("%s\n", __func__); - pr_info("MAX_RTKM_NR_PREALLOC_RECV_SKB: %d\n", MAX_RTKM_NR_PREALLOC_RECV_SKB); - pr_info("MAX_RTKM_RECVBUF_SZ: %d\n", MAX_RTKM_RECVBUF_SZ); - -#ifdef CONFIG_USE_USB_BUFFER_ALLOC_RX - for (i = 0; i < NR_RECVBUFF; i++) - rtk_buf_mem[i] = usb_buffer_alloc(dev, size, (in_interrupt() ? GFP_ATOMIC : GFP_KERNEL), dma); -#endif /* CONFIG_USE_USB_BUFFER_ALLOC_RX */ - - skb_queue_head_init(&rtk_skb_mem_q); - - for (i = 0; i < MAX_RTKM_NR_PREALLOC_RECV_SKB; i++) { - pskb = __dev_alloc_skb(MAX_RTKM_RECVBUF_SZ + RECVBUFF_ALIGN_SZ, in_interrupt() ? GFP_ATOMIC : GFP_KERNEL); - if (pskb) { - tmpaddr = (SIZE_PTR)pskb->data; - alignment = tmpaddr & (RECVBUFF_ALIGN_SZ - 1); - skb_reserve(pskb, (RECVBUFF_ALIGN_SZ - alignment)); - - skb_queue_tail(&rtk_skb_mem_q, pskb); - } else - RTW_INFO("%s, alloc skb memory fail!\n", __func__); - - pskb = NULL; - } - - RTW_INFO("%s, rtk_skb_mem_q len : %d\n", __func__, skb_queue_len(&rtk_skb_mem_q)); - - return 0; - -} - -static void __exit rtw_mem_exit(void) -{ - if (skb_queue_len(&rtk_skb_mem_q)) - RTW_INFO("%s, rtk_skb_mem_q len : %d\n", __func__, skb_queue_len(&rtk_skb_mem_q)); - - skb_queue_purge(&rtk_skb_mem_q); - - RTW_INFO("%s\n", __func__); -} - -module_init(rtw_mem_init); -module_exit(rtw_mem_exit); diff --git a/core/rtw_mp_ioctl.c b/core/rtw_mp_ioctl.c deleted file mode 100644 index a52107b..0000000 --- a/core/rtw_mp_ioctl.c +++ /dev/null @@ -1,1200 +0,0 @@ -/****************************************************************************** - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of version 2 of the GNU General Public License as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA - * - * - ******************************************************************************/ -#define _RTW_MP_IOCTL_C_ - -#include -#include -#include "../hal/phydm/phydm_precomp.h" - -/* **************** oid_rtl_seg_81_85 section start **************** */ -NDIS_STATUS oid_rt_wireless_mode_hdl(struct oid_par_priv *poid_par_priv) -{ - NDIS_STATUS status = NDIS_STATUS_SUCCESS; - PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); - - if (poid_par_priv->information_buf_len < sizeof(u8)) - return NDIS_STATUS_INVALID_LENGTH; - - if (poid_par_priv->type_of_oid == SET_OID) - Adapter->registrypriv.wireless_mode = *(u8 *)poid_par_priv->information_buf; - else if (poid_par_priv->type_of_oid == QUERY_OID) { - *(u8 *)poid_par_priv->information_buf = Adapter->registrypriv.wireless_mode; - *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; - } else - status = NDIS_STATUS_NOT_ACCEPTED; - - return status; -} -/* **************** oid_rtl_seg_81_87_80 section start **************** */ -NDIS_STATUS oid_rt_pro_write_bb_reg_hdl(struct oid_par_priv *poid_par_priv) -{ - struct bb_reg_param *pbbreg; - u16 offset; - u32 value; - NDIS_STATUS status = NDIS_STATUS_SUCCESS; - PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); - - if (poid_par_priv->type_of_oid != SET_OID) - return NDIS_STATUS_NOT_ACCEPTED; - - if (poid_par_priv->information_buf_len < sizeof(struct bb_reg_param)) - return NDIS_STATUS_INVALID_LENGTH; - - pbbreg = (struct bb_reg_param *)(poid_par_priv->information_buf); - - offset = (u16)(pbbreg->offset) & 0xFFF; /* 0ffset :0x800~0xfff */ - if (offset < BB_REG_BASE_ADDR) - offset |= BB_REG_BASE_ADDR; - - value = pbbreg->value; - - _irqlevel_changed_(&oldirql, LOWER); - write_bbreg(Adapter, offset, 0xFFFFFFFF, value); - _irqlevel_changed_(&oldirql, RAISE); - - return status; -} -/* ------------------------------------------------------------------------------ */ -NDIS_STATUS oid_rt_pro_read_bb_reg_hdl(struct oid_par_priv *poid_par_priv) -{ - struct bb_reg_param *pbbreg; - u16 offset; - u32 value; - NDIS_STATUS status = NDIS_STATUS_SUCCESS; - PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); - - if (poid_par_priv->type_of_oid != QUERY_OID) - return NDIS_STATUS_NOT_ACCEPTED; - - if (poid_par_priv->information_buf_len < sizeof(struct bb_reg_param)) - return NDIS_STATUS_INVALID_LENGTH; - - pbbreg = (struct bb_reg_param *)(poid_par_priv->information_buf); - - offset = (u16)(pbbreg->offset) & 0xFFF; /* 0ffset :0x800~0xfff */ - if (offset < BB_REG_BASE_ADDR) - offset |= BB_REG_BASE_ADDR; - - _irqlevel_changed_(&oldirql, LOWER); - value = read_bbreg(Adapter, offset, 0xFFFFFFFF); - _irqlevel_changed_(&oldirql, RAISE); - - pbbreg->value = value; - *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; - - return status; -} -/* ------------------------------------------------------------------------------ */ -NDIS_STATUS oid_rt_pro_write_rf_reg_hdl(struct oid_par_priv *poid_par_priv) -{ - struct rf_reg_param *pbbreg; - u8 path; - u8 offset; - u32 value; - NDIS_STATUS status = NDIS_STATUS_SUCCESS; - PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); - - if (poid_par_priv->type_of_oid != SET_OID) - return NDIS_STATUS_NOT_ACCEPTED; - - if (poid_par_priv->information_buf_len < sizeof(struct rf_reg_param)) - return NDIS_STATUS_INVALID_LENGTH; - - pbbreg = (struct rf_reg_param *)(poid_par_priv->information_buf); - - if (pbbreg->path >= MAX_RF_PATH_NUMS) - return NDIS_STATUS_NOT_ACCEPTED; - if (pbbreg->offset > 0xFF) - return NDIS_STATUS_NOT_ACCEPTED; - if (pbbreg->value > 0xFFFFF) - return NDIS_STATUS_NOT_ACCEPTED; - - path = (u8)pbbreg->path; - offset = (u8)pbbreg->offset; - value = pbbreg->value; - - _irqlevel_changed_(&oldirql, LOWER); - write_rfreg(Adapter, path, offset, value); - _irqlevel_changed_(&oldirql, RAISE); - - return status; -} -/* ------------------------------------------------------------------------------ */ -NDIS_STATUS oid_rt_pro_read_rf_reg_hdl(struct oid_par_priv *poid_par_priv) -{ - struct rf_reg_param *pbbreg; - u8 path; - u8 offset; - u32 value; - PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); - NDIS_STATUS status = NDIS_STATUS_SUCCESS; - - if (poid_par_priv->type_of_oid != QUERY_OID) - return NDIS_STATUS_NOT_ACCEPTED; - - if (poid_par_priv->information_buf_len < sizeof(struct rf_reg_param)) - return NDIS_STATUS_INVALID_LENGTH; - - pbbreg = (struct rf_reg_param *)(poid_par_priv->information_buf); - - if (pbbreg->path >= MAX_RF_PATH_NUMS) - return NDIS_STATUS_NOT_ACCEPTED; - if (pbbreg->offset > 0xFF) - return NDIS_STATUS_NOT_ACCEPTED; - - path = (u8)pbbreg->path; - offset = (u8)pbbreg->offset; - - _irqlevel_changed_(&oldirql, LOWER); - value = read_rfreg(Adapter, path, offset); - _irqlevel_changed_(&oldirql, RAISE); - - pbbreg->value = value; - - *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; - - return status; -} -/* **************** oid_rtl_seg_81_87_00 section end**************** - * ------------------------------------------------------------------------------ */ - -/* **************** oid_rtl_seg_81_80_00 section start **************** - * ------------------------------------------------------------------------------ */ -NDIS_STATUS oid_rt_pro_set_data_rate_hdl(struct oid_par_priv *poid_par_priv) -{ - u32 ratevalue;/* 4 */ - NDIS_STATUS status = NDIS_STATUS_SUCCESS; - PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); - - if (poid_par_priv->type_of_oid != SET_OID) - return NDIS_STATUS_NOT_ACCEPTED; - - if (poid_par_priv->information_buf_len != sizeof(u32)) - return NDIS_STATUS_INVALID_LENGTH; - - ratevalue = *((u32 *)poid_par_priv->information_buf); /* 4 */ - if (ratevalue >= MPT_RATE_LAST) - return NDIS_STATUS_INVALID_DATA; - - Adapter->mppriv.rateidx = ratevalue; - - _irqlevel_changed_(&oldirql, LOWER); - SetDataRate(Adapter); - _irqlevel_changed_(&oldirql, RAISE); - - return status; -} -/* ------------------------------------------------------------------------------ */ -NDIS_STATUS oid_rt_pro_start_test_hdl(struct oid_par_priv *poid_par_priv) -{ - u32 mode; - NDIS_STATUS status = NDIS_STATUS_SUCCESS; - PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); - - if (Adapter->registrypriv.mp_mode == 0) - return NDIS_STATUS_NOT_ACCEPTED; - - if (poid_par_priv->type_of_oid != SET_OID) - return NDIS_STATUS_NOT_ACCEPTED; - - _irqlevel_changed_(&oldirql, LOWER); - - /* IQCalibrateBcut(Adapter); */ - - mode = *((u32 *)poid_par_priv->information_buf); - Adapter->mppriv.mode = mode;/* 1 for loopback */ - - if (mp_start_test(Adapter) == _FAIL) { - status = NDIS_STATUS_NOT_ACCEPTED; - goto exit; - } - -exit: - _irqlevel_changed_(&oldirql, RAISE); - - return status; -} -/* ------------------------------------------------------------------------------ */ -NDIS_STATUS oid_rt_pro_stop_test_hdl(struct oid_par_priv *poid_par_priv) -{ - NDIS_STATUS status = NDIS_STATUS_SUCCESS; - PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); - - if (poid_par_priv->type_of_oid != SET_OID) - return NDIS_STATUS_NOT_ACCEPTED; - - _irqlevel_changed_(&oldirql, LOWER); - mp_stop_test(Adapter); - _irqlevel_changed_(&oldirql, RAISE); - - return status; -} -/* ------------------------------------------------------------------------------ */ -NDIS_STATUS oid_rt_pro_set_channel_direct_call_hdl(struct oid_par_priv *poid_par_priv) -{ - u32 Channel; - NDIS_STATUS status = NDIS_STATUS_SUCCESS; - PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); - - if (poid_par_priv->information_buf_len != sizeof(u32)) - return NDIS_STATUS_INVALID_LENGTH; - - if (poid_par_priv->type_of_oid == QUERY_OID) { - *((u32 *)poid_par_priv->information_buf) = Adapter->mppriv.channel; - return NDIS_STATUS_SUCCESS; - } - - if (poid_par_priv->type_of_oid != SET_OID) - return NDIS_STATUS_NOT_ACCEPTED; - - Channel = *((u32 *)poid_par_priv->information_buf); - if (Channel > 14) - return NDIS_STATUS_NOT_ACCEPTED; - Adapter->mppriv.channel = Channel; - - _irqlevel_changed_(&oldirql, LOWER); - SetChannel(Adapter); - _irqlevel_changed_(&oldirql, RAISE); - - return status; -} -/* ------------------------------------------------------------------------------ */ -NDIS_STATUS oid_rt_set_bandwidth_hdl(struct oid_par_priv *poid_par_priv) -{ - u16 bandwidth; - u16 channel_offset; - NDIS_STATUS status = NDIS_STATUS_SUCCESS; - PADAPTER padapter = (PADAPTER)(poid_par_priv->adapter_context); - - if (poid_par_priv->type_of_oid != SET_OID) - return NDIS_STATUS_NOT_ACCEPTED; - - if (poid_par_priv->information_buf_len < sizeof(u32)) - return NDIS_STATUS_INVALID_LENGTH; - - bandwidth = *((u32 *)poid_par_priv->information_buf); /* 4 */ - channel_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE; - - if (bandwidth != CHANNEL_WIDTH_40) - bandwidth = CHANNEL_WIDTH_20; - padapter->mppriv.bandwidth = (u8)bandwidth; - padapter->mppriv.prime_channel_offset = (u8)channel_offset; - - _irqlevel_changed_(&oldirql, LOWER); - SetBandwidth(padapter); - _irqlevel_changed_(&oldirql, RAISE); - - return status; -} -/* ------------------------------------------------------------------------------ */ -NDIS_STATUS oid_rt_pro_set_antenna_bb_hdl(struct oid_par_priv *poid_par_priv) -{ - u32 antenna; - NDIS_STATUS status = NDIS_STATUS_SUCCESS; - PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); - - if (poid_par_priv->information_buf_len != sizeof(u32)) - return NDIS_STATUS_INVALID_LENGTH; - - if (poid_par_priv->type_of_oid == SET_OID) { - antenna = *(u32 *)poid_par_priv->information_buf; - - Adapter->mppriv.antenna_tx = (u16)((antenna & 0xFFFF0000) >> 16); - Adapter->mppriv.antenna_rx = (u16)(antenna & 0x0000FFFF); - - _irqlevel_changed_(&oldirql, LOWER); - SetAntenna(Adapter); - _irqlevel_changed_(&oldirql, RAISE); - } else { - antenna = (Adapter->mppriv.antenna_tx << 16) | Adapter->mppriv.antenna_rx; - *(u32 *)poid_par_priv->information_buf = antenna; - } - - return status; -} - -NDIS_STATUS oid_rt_pro_set_tx_power_control_hdl(struct oid_par_priv *poid_par_priv) -{ - u32 tx_pwr_idx; - NDIS_STATUS status = NDIS_STATUS_SUCCESS; - PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); - - if (poid_par_priv->type_of_oid != SET_OID) - return NDIS_STATUS_NOT_ACCEPTED; - - if (poid_par_priv->information_buf_len != sizeof(u32)) - return NDIS_STATUS_INVALID_LENGTH; - - tx_pwr_idx = *((u32 *)poid_par_priv->information_buf); - if (tx_pwr_idx > MAX_TX_PWR_INDEX_N_MODE) - return NDIS_STATUS_NOT_ACCEPTED; - - Adapter->mppriv.txpoweridx = (u8)tx_pwr_idx; - - _irqlevel_changed_(&oldirql, LOWER); - SetTxPower(Adapter); - _irqlevel_changed_(&oldirql, RAISE); - - return status; -} - -/* ------------------------------------------------------------------------------ - * **************** oid_rtl_seg_81_80_20 section start **************** - * ------------------------------------------------------------------------------ */ -NDIS_STATUS oid_rt_pro_query_tx_packet_sent_hdl(struct oid_par_priv *poid_par_priv) -{ - NDIS_STATUS status = NDIS_STATUS_SUCCESS; - PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); - - if (poid_par_priv->type_of_oid != QUERY_OID) { - status = NDIS_STATUS_NOT_ACCEPTED; - return status; - } - - if (poid_par_priv->information_buf_len == sizeof(ULONG)) { - *(ULONG *)poid_par_priv->information_buf = Adapter->mppriv.tx_pktcount; - *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; - } else - status = NDIS_STATUS_INVALID_LENGTH; - - return status; -} -/* ------------------------------------------------------------------------------ */ -NDIS_STATUS oid_rt_pro_query_rx_packet_received_hdl(struct oid_par_priv *poid_par_priv) -{ - NDIS_STATUS status = NDIS_STATUS_SUCCESS; - PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); - - if (poid_par_priv->type_of_oid != QUERY_OID) { - status = NDIS_STATUS_NOT_ACCEPTED; - return status; - } - if (poid_par_priv->information_buf_len == sizeof(ULONG)) { - *(ULONG *)poid_par_priv->information_buf = Adapter->mppriv.rx_pktcount; - *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; - } else - status = NDIS_STATUS_INVALID_LENGTH; - - return status; -} -/* ------------------------------------------------------------------------------ */ -NDIS_STATUS oid_rt_pro_query_rx_packet_crc32_error_hdl(struct oid_par_priv *poid_par_priv) -{ - NDIS_STATUS status = NDIS_STATUS_SUCCESS; - PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); - - if (poid_par_priv->type_of_oid != QUERY_OID) { - status = NDIS_STATUS_NOT_ACCEPTED; - return status; - } - if (poid_par_priv->information_buf_len == sizeof(ULONG)) { - *(ULONG *)poid_par_priv->information_buf = Adapter->mppriv.rx_crcerrpktcount; - *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; - } else - status = NDIS_STATUS_INVALID_LENGTH; - - return status; -} -/* ------------------------------------------------------------------------------ */ - -NDIS_STATUS oid_rt_pro_reset_tx_packet_sent_hdl(struct oid_par_priv *poid_par_priv) -{ - NDIS_STATUS status = NDIS_STATUS_SUCCESS; - PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); - - if (poid_par_priv->type_of_oid != SET_OID) { - status = NDIS_STATUS_NOT_ACCEPTED; - return status; - } - - Adapter->mppriv.tx_pktcount = 0; - - return status; -} -/* ------------------------------------------------------------------------------ */ -NDIS_STATUS oid_rt_pro_reset_rx_packet_received_hdl(struct oid_par_priv *poid_par_priv) -{ - NDIS_STATUS status = NDIS_STATUS_SUCCESS; - PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); - - if (poid_par_priv->type_of_oid != SET_OID) { - status = NDIS_STATUS_NOT_ACCEPTED; - return status; - } - - if (poid_par_priv->information_buf_len == sizeof(ULONG)) { - Adapter->mppriv.rx_pktcount = 0; - Adapter->mppriv.rx_crcerrpktcount = 0; - } else - status = NDIS_STATUS_INVALID_LENGTH; - - return status; -} -/* ------------------------------------------------------------------------------ */ -NDIS_STATUS oid_rt_reset_phy_rx_packet_count_hdl(struct oid_par_priv *poid_par_priv) -{ - NDIS_STATUS status = NDIS_STATUS_SUCCESS; - PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); - - if (poid_par_priv->type_of_oid != SET_OID) { - status = NDIS_STATUS_NOT_ACCEPTED; - return status; - } - - _irqlevel_changed_(&oldirql, LOWER); - ResetPhyRxPktCount(Adapter); - _irqlevel_changed_(&oldirql, RAISE); - - return status; -} -/* ------------------------------------------------------------------------------ */ -NDIS_STATUS oid_rt_get_phy_rx_packet_received_hdl(struct oid_par_priv *poid_par_priv) -{ - NDIS_STATUS status = NDIS_STATUS_SUCCESS; - PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); - - if (poid_par_priv->type_of_oid != QUERY_OID) - return NDIS_STATUS_NOT_ACCEPTED; - - if (poid_par_priv->information_buf_len != sizeof(ULONG)) - return NDIS_STATUS_INVALID_LENGTH; - - _irqlevel_changed_(&oldirql, LOWER); - *(ULONG *)poid_par_priv->information_buf = GetPhyRxPktReceived(Adapter); - _irqlevel_changed_(&oldirql, RAISE); - - *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; - - return status; -} -/* ------------------------------------------------------------------------------ */ -NDIS_STATUS oid_rt_get_phy_rx_packet_crc32_error_hdl(struct oid_par_priv *poid_par_priv) -{ - NDIS_STATUS status = NDIS_STATUS_SUCCESS; - PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); - - if (poid_par_priv->type_of_oid != QUERY_OID) - return NDIS_STATUS_NOT_ACCEPTED; - - if (poid_par_priv->information_buf_len != sizeof(ULONG)) - return NDIS_STATUS_INVALID_LENGTH; - - _irqlevel_changed_(&oldirql, LOWER); - *(ULONG *)poid_par_priv->information_buf = GetPhyRxPktCRC32Error(Adapter); - _irqlevel_changed_(&oldirql, RAISE); - - *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; - - return status; -} -/* **************** oid_rtl_seg_81_80_20 section end **************** */ -NDIS_STATUS oid_rt_pro_set_continuous_tx_hdl(struct oid_par_priv *poid_par_priv) -{ - u32 bStartTest; - NDIS_STATUS status = NDIS_STATUS_SUCCESS; - PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); - - if (poid_par_priv->type_of_oid != SET_OID) - return NDIS_STATUS_NOT_ACCEPTED; - - bStartTest = *((u32 *)poid_par_priv->information_buf); - - _irqlevel_changed_(&oldirql, LOWER); - SetContinuousTx(Adapter, (u8)bStartTest); - if (bStartTest) { - struct mp_priv *pmp_priv = &Adapter->mppriv; - if (pmp_priv->tx.stop == 0) { - pmp_priv->tx.stop = 1; - RTW_INFO("%s: pkt tx is running...\n", __func__); - rtw_msleep_os(5); - } - pmp_priv->tx.stop = 0; - pmp_priv->tx.count = 1; - SetPacketTx(Adapter); - } - _irqlevel_changed_(&oldirql, RAISE); - - return status; -} - -NDIS_STATUS oid_rt_pro_set_single_carrier_tx_hdl(struct oid_par_priv *poid_par_priv) -{ - u32 bStartTest; - NDIS_STATUS status = NDIS_STATUS_SUCCESS; - PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); - - if (poid_par_priv->type_of_oid != SET_OID) - return NDIS_STATUS_NOT_ACCEPTED; - - bStartTest = *((u32 *)poid_par_priv->information_buf); - - _irqlevel_changed_(&oldirql, LOWER); - SetSingleCarrierTx(Adapter, (u8)bStartTest); - if (bStartTest) { - struct mp_priv *pmp_priv = &Adapter->mppriv; - if (pmp_priv->tx.stop == 0) { - pmp_priv->tx.stop = 1; - RTW_INFO("%s: pkt tx is running...\n", __func__); - rtw_msleep_os(5); - } - pmp_priv->tx.stop = 0; - pmp_priv->tx.count = 1; - SetPacketTx(Adapter); - } - _irqlevel_changed_(&oldirql, RAISE); - - return status; -} - -NDIS_STATUS oid_rt_pro_set_carrier_suppression_tx_hdl(struct oid_par_priv *poid_par_priv) -{ - u32 bStartTest; - NDIS_STATUS status = NDIS_STATUS_SUCCESS; - PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); - - if (poid_par_priv->type_of_oid != SET_OID) - return NDIS_STATUS_NOT_ACCEPTED; - - bStartTest = *((u32 *)poid_par_priv->information_buf); - - _irqlevel_changed_(&oldirql, LOWER); - SetCarrierSuppressionTx(Adapter, (u8)bStartTest); - if (bStartTest) { - struct mp_priv *pmp_priv = &Adapter->mppriv; - if (pmp_priv->tx.stop == 0) { - pmp_priv->tx.stop = 1; - RTW_INFO("%s: pkt tx is running...\n", __func__); - rtw_msleep_os(5); - } - pmp_priv->tx.stop = 0; - pmp_priv->tx.count = 1; - SetPacketTx(Adapter); - } - _irqlevel_changed_(&oldirql, RAISE); - - return status; -} - -NDIS_STATUS oid_rt_pro_set_single_tone_tx_hdl(struct oid_par_priv *poid_par_priv) -{ - u32 bStartTest; - NDIS_STATUS status = NDIS_STATUS_SUCCESS; - PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); - - if (poid_par_priv->type_of_oid != SET_OID) - return NDIS_STATUS_NOT_ACCEPTED; - - bStartTest = *((u32 *)poid_par_priv->information_buf); - - _irqlevel_changed_(&oldirql, LOWER); - SetSingleToneTx(Adapter, (u8)bStartTest); - _irqlevel_changed_(&oldirql, RAISE); - - return status; -} - -NDIS_STATUS oid_rt_pro_set_modulation_hdl(struct oid_par_priv *poid_par_priv) -{ - return 0; -} - -NDIS_STATUS oid_rt_pro_trigger_gpio_hdl(struct oid_par_priv *poid_par_priv) -{ - PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); - - NDIS_STATUS status = NDIS_STATUS_SUCCESS; - - if (poid_par_priv->type_of_oid != SET_OID) - return NDIS_STATUS_NOT_ACCEPTED; - - _irqlevel_changed_(&oldirql, LOWER); - rtw_hal_set_hwreg(Adapter, HW_VAR_TRIGGER_GPIO_0, 0); - _irqlevel_changed_(&oldirql, RAISE); - - return status; -} -/* **************** oid_rtl_seg_81_80_00 section end **************** - * ------------------------------------------------------------------------------ */ -NDIS_STATUS oid_rt_pro8711_join_bss_hdl(struct oid_par_priv *poid_par_priv) -{ - return 0; -} -/* ------------------------------------------------------------------------------ */ -NDIS_STATUS oid_rt_pro_read_register_hdl(struct oid_par_priv *poid_par_priv) -{ - pRW_Reg RegRWStruct; - u32 offset, width; - NDIS_STATUS status = NDIS_STATUS_SUCCESS; - PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); - - if (poid_par_priv->type_of_oid != QUERY_OID) - return NDIS_STATUS_NOT_ACCEPTED; - - RegRWStruct = (pRW_Reg)poid_par_priv->information_buf; - offset = RegRWStruct->offset; - width = RegRWStruct->width; - - if (offset > 0xFFF) - return NDIS_STATUS_NOT_ACCEPTED; - - _irqlevel_changed_(&oldirql, LOWER); - - switch (width) { - case 1: - RegRWStruct->value = rtw_read8(Adapter, offset); - break; - case 2: - RegRWStruct->value = rtw_read16(Adapter, offset); - break; - default: - width = 4; - RegRWStruct->value = rtw_read32(Adapter, offset); - break; - } - - _irqlevel_changed_(&oldirql, RAISE); - - *poid_par_priv->bytes_rw = width; - - return status; -} -/* ------------------------------------------------------------------------------ */ -NDIS_STATUS oid_rt_pro_write_register_hdl(struct oid_par_priv *poid_par_priv) -{ - pRW_Reg RegRWStruct; - u32 offset, width, value; - NDIS_STATUS status = NDIS_STATUS_SUCCESS; - PADAPTER padapter = (PADAPTER)(poid_par_priv->adapter_context); - - if (poid_par_priv->type_of_oid != SET_OID) - return NDIS_STATUS_NOT_ACCEPTED; - - RegRWStruct = (pRW_Reg)poid_par_priv->information_buf; - offset = RegRWStruct->offset; - width = RegRWStruct->width; - value = RegRWStruct->value; - - if (offset > 0xFFF) - return NDIS_STATUS_NOT_ACCEPTED; - - _irqlevel_changed_(&oldirql, LOWER); - - switch (RegRWStruct->width) { - case 1: - if (value > 0xFF) { - status = NDIS_STATUS_NOT_ACCEPTED; - break; - } - rtw_write8(padapter, offset, (u8)value); - break; - case 2: - if (value > 0xFFFF) { - status = NDIS_STATUS_NOT_ACCEPTED; - break; - } - rtw_write16(padapter, offset, (u16)value); - break; - case 4: - rtw_write32(padapter, offset, value); - break; - default: - status = NDIS_STATUS_NOT_ACCEPTED; - break; - } - - _irqlevel_changed_(&oldirql, RAISE); - - return status; -} -/* ------------------------------------------------------------------------------ */ -NDIS_STATUS oid_rt_pro_burst_read_register_hdl(struct oid_par_priv *poid_par_priv) -{ - return 0; -} -/* ------------------------------------------------------------------------------ */ -NDIS_STATUS oid_rt_pro_burst_write_register_hdl(struct oid_par_priv *poid_par_priv) -{ - return 0; -} -/* ------------------------------------------------------------------------------ */ -NDIS_STATUS oid_rt_pro_write_txcmd_hdl(struct oid_par_priv *poid_par_priv) -{ - return 0; -} - -/* ------------------------------------------------------------------------------ */ -NDIS_STATUS oid_rt_pro_read16_eeprom_hdl(struct oid_par_priv *poid_par_priv) -{ - return 0; -} - -/* ------------------------------------------------------------------------------ */ -NDIS_STATUS oid_rt_pro_write16_eeprom_hdl(struct oid_par_priv *poid_par_priv) -{ - return 0; -} -/* ------------------------------------------------------------------------------ */ -NDIS_STATUS oid_rt_pro8711_wi_poll_hdl(struct oid_par_priv *poid_par_priv) -{ - return 0; -} -/* ------------------------------------------------------------------------------ */ -NDIS_STATUS oid_rt_pro8711_pkt_loss_hdl(struct oid_par_priv *poid_par_priv) -{ - return 0; -} -/* ------------------------------------------------------------------------------ */ -NDIS_STATUS oid_rt_rd_attrib_mem_hdl(struct oid_par_priv *poid_par_priv) -{ - return 0; -} -/* ------------------------------------------------------------------------------ */ -NDIS_STATUS oid_rt_wr_attrib_mem_hdl(struct oid_par_priv *poid_par_priv) -{ - return 0; -} -/* ------------------------------------------------------------------------------ */ -NDIS_STATUS oid_rt_pro_set_rf_intfs_hdl(struct oid_par_priv *poid_par_priv) -{ - return 0; -} -/* ------------------------------------------------------------------------------ */ -NDIS_STATUS oid_rt_poll_rx_status_hdl(struct oid_par_priv *poid_par_priv) -{ - return 0; -} -/* ------------------------------------------------------------------------------ */ -NDIS_STATUS oid_rt_pro_cfg_debug_message_hdl(struct oid_par_priv *poid_par_priv) -{ - return 0; -} -/* ------------------------------------------------------------------------------ */ -NDIS_STATUS oid_rt_pro_set_data_rate_ex_hdl(struct oid_par_priv *poid_par_priv) -{ - PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); - - NDIS_STATUS status = NDIS_STATUS_SUCCESS; - - if (poid_par_priv->type_of_oid != SET_OID) - return NDIS_STATUS_NOT_ACCEPTED; - - _irqlevel_changed_(&oldirql, LOWER); - - if (rtw_setdatarate_cmd(Adapter, poid_par_priv->information_buf) != _SUCCESS) - status = NDIS_STATUS_NOT_ACCEPTED; - - _irqlevel_changed_(&oldirql, RAISE); - - return status; -} -/* ----------------------------------------------------------------------------- */ -NDIS_STATUS oid_rt_get_thermal_meter_hdl(struct oid_par_priv *poid_par_priv) -{ - NDIS_STATUS status = NDIS_STATUS_SUCCESS; - u8 thermal = 0; - PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); - - if (poid_par_priv->type_of_oid != QUERY_OID) - return NDIS_STATUS_NOT_ACCEPTED; - - if (poid_par_priv->information_buf_len < sizeof(u32)) - return NDIS_STATUS_INVALID_LENGTH; - - _irqlevel_changed_(&oldirql, LOWER); - GetThermalMeter(Adapter, &thermal); - _irqlevel_changed_(&oldirql, RAISE); - - *(u32 *)poid_par_priv->information_buf = (u32)thermal; - *poid_par_priv->bytes_rw = sizeof(u32); - - return status; -} -/* ----------------------------------------------------------------------------- */ -NDIS_STATUS oid_rt_pro_read_tssi_hdl(struct oid_par_priv *poid_par_priv) -{ - return 0; -} -/* ------------------------------------------------------------------------------ */ -NDIS_STATUS oid_rt_pro_set_power_tracking_hdl(struct oid_par_priv *poid_par_priv) -{ - NDIS_STATUS status = NDIS_STATUS_SUCCESS; - PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); - - /* if (poid_par_priv->type_of_oid != SET_OID) - * return NDIS_STATUS_NOT_ACCEPTED; */ - - if (poid_par_priv->information_buf_len < sizeof(u8)) - return NDIS_STATUS_INVALID_LENGTH; - - _irqlevel_changed_(&oldirql, LOWER); - if (poid_par_priv->type_of_oid == SET_OID) { - u8 enable; - - enable = *(u8 *)poid_par_priv->information_buf; - - SetPowerTracking(Adapter, enable); - } else - GetPowerTracking(Adapter, (u8 *)poid_par_priv->information_buf); - _irqlevel_changed_(&oldirql, RAISE); - - return status; -} -/* ----------------------------------------------------------------------------- */ -NDIS_STATUS oid_rt_pro_set_basic_rate_hdl(struct oid_par_priv *poid_par_priv) -{ - return 0; -} -/* ------------------------------------------------------------------------------ */ -NDIS_STATUS oid_rt_pro_qry_pwrstate_hdl(struct oid_par_priv *poid_par_priv) -{ - return 0; -} -/* ------------------------------------------------------------------------------ */ -NDIS_STATUS oid_rt_pro_set_pwrstate_hdl(struct oid_par_priv *poid_par_priv) -{ - return 0; -} -/* ------------------------------------------------------------------------------ */ -NDIS_STATUS oid_rt_pro_h2c_set_rate_table_hdl(struct oid_par_priv *poid_par_priv) -{ - return 0; -} -/* ------------------------------------------------------------------------------ */ -NDIS_STATUS oid_rt_pro_h2c_get_rate_table_hdl(struct oid_par_priv *poid_par_priv) -{ - return 0; -} - -/* **************** oid_rtl_seg_87_12_00 section start **************** */ -NDIS_STATUS oid_rt_pro_encryption_ctrl_hdl(struct oid_par_priv *poid_par_priv) -{ - return 0; -} -/* ------------------------------------------------------------------------------ */ -NDIS_STATUS oid_rt_pro_add_sta_info_hdl(struct oid_par_priv *poid_par_priv) -{ - return 0; -} -/* ------------------------------------------------------------------------------ */ -NDIS_STATUS oid_rt_pro_dele_sta_info_hdl(struct oid_par_priv *poid_par_priv) -{ - return 0; -} -/* ------------------------------------------------------------------------------ */ - -NDIS_STATUS oid_rt_pro_query_dr_variable_hdl(struct oid_par_priv *poid_par_priv) -{ - return 0; -} -/* ------------------------------------------------------------------------------ */ -NDIS_STATUS oid_rt_pro_rx_packet_type_hdl(struct oid_par_priv *poid_par_priv) -{ - return NDIS_STATUS_SUCCESS; -} -/* ------------------------------------------------------------------------------ */ -NDIS_STATUS oid_rt_pro_read_efuse_hdl(struct oid_par_priv *poid_par_priv) -{ - PEFUSE_ACCESS_STRUCT pefuse; - u8 *data; - u16 addr = 0, cnts = 0, max_available_size = 0; - NDIS_STATUS status = NDIS_STATUS_SUCCESS; - PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); - - if (poid_par_priv->type_of_oid != QUERY_OID) - return NDIS_STATUS_NOT_ACCEPTED; - - if (poid_par_priv->information_buf_len < sizeof(EFUSE_ACCESS_STRUCT)) - return NDIS_STATUS_INVALID_LENGTH; - - pefuse = (PEFUSE_ACCESS_STRUCT)poid_par_priv->information_buf; - addr = pefuse->start_addr; - cnts = pefuse->cnts; - data = pefuse->data; - - EFUSE_GetEfuseDefinition(Adapter, EFUSE_WIFI, TYPE_AVAILABLE_EFUSE_BYTES_TOTAL, (PVOID)&max_available_size, _FALSE); - - if ((addr + cnts) > max_available_size) { - return NDIS_STATUS_NOT_ACCEPTED; - } - - _irqlevel_changed_(&oldirql, LOWER); - if (rtw_efuse_access(Adapter, _FALSE, addr, cnts, data) == _FAIL) { - status = NDIS_STATUS_FAILURE; - } else - *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; - _irqlevel_changed_(&oldirql, RAISE); - - return status; -} -/* ------------------------------------------------------------------------------ */ -NDIS_STATUS oid_rt_pro_write_efuse_hdl(struct oid_par_priv *poid_par_priv) -{ - PEFUSE_ACCESS_STRUCT pefuse; - u8 *data; - u16 addr = 0, cnts = 0, max_available_size = 0; - NDIS_STATUS status = NDIS_STATUS_SUCCESS; - PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); - - if (poid_par_priv->type_of_oid != SET_OID) - return NDIS_STATUS_NOT_ACCEPTED; - - pefuse = (PEFUSE_ACCESS_STRUCT)poid_par_priv->information_buf; - addr = pefuse->start_addr; - cnts = pefuse->cnts; - data = pefuse->data; - - EFUSE_GetEfuseDefinition(Adapter, EFUSE_WIFI, TYPE_AVAILABLE_EFUSE_BYTES_TOTAL, (PVOID)&max_available_size, _FALSE); - - if ((addr + cnts) > max_available_size) { - return NDIS_STATUS_NOT_ACCEPTED; - } - - _irqlevel_changed_(&oldirql, LOWER); - if (rtw_efuse_access(Adapter, _TRUE, addr, cnts, data) == _FAIL) - status = NDIS_STATUS_FAILURE; - _irqlevel_changed_(&oldirql, RAISE); - - return status; -} -/* ------------------------------------------------------------------------------ */ -NDIS_STATUS oid_rt_pro_rw_efuse_pgpkt_hdl(struct oid_par_priv *poid_par_priv) -{ - PPGPKT_STRUCT ppgpkt; - NDIS_STATUS status = NDIS_STATUS_SUCCESS; - PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); - - *poid_par_priv->bytes_rw = 0; - - if (poid_par_priv->information_buf_len < sizeof(PGPKT_STRUCT)) - return NDIS_STATUS_INVALID_LENGTH; - - ppgpkt = (PPGPKT_STRUCT)poid_par_priv->information_buf; - - _irqlevel_changed_(&oldirql, LOWER); - - if (poid_par_priv->type_of_oid == QUERY_OID) { - - Efuse_PowerSwitch(Adapter, _FALSE, _TRUE); - if (Efuse_PgPacketRead(Adapter, ppgpkt->offset, ppgpkt->data, _FALSE) == _TRUE) - *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; - else - status = NDIS_STATUS_FAILURE; - Efuse_PowerSwitch(Adapter, _FALSE, _FALSE); - } else { - - Efuse_PowerSwitch(Adapter, _TRUE, _TRUE); - if (Efuse_PgPacketWrite(Adapter, ppgpkt->offset, ppgpkt->word_en, ppgpkt->data, _FALSE) == _TRUE) - *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; - else - status = NDIS_STATUS_FAILURE; - Efuse_PowerSwitch(Adapter, _TRUE, _FALSE); - } - - _irqlevel_changed_(&oldirql, RAISE); - - return status; -} -/* ------------------------------------------------------------------------------ */ -NDIS_STATUS oid_rt_get_efuse_current_size_hdl(struct oid_par_priv *poid_par_priv) -{ - u16 size; - u8 ret; - NDIS_STATUS status = NDIS_STATUS_SUCCESS; - PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); - - if (poid_par_priv->type_of_oid != QUERY_OID) - return NDIS_STATUS_NOT_ACCEPTED; - - if (poid_par_priv->information_buf_len < sizeof(u32)) - return NDIS_STATUS_INVALID_LENGTH; - - _irqlevel_changed_(&oldirql, LOWER); - ret = efuse_GetCurrentSize(Adapter, &size); - _irqlevel_changed_(&oldirql, RAISE); - if (ret == _SUCCESS) { - *(u32 *)poid_par_priv->information_buf = size; - *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; - } else - status = NDIS_STATUS_FAILURE; - - return status; -} -/* ------------------------------------------------------------------------------ */ -NDIS_STATUS oid_rt_get_efuse_max_size_hdl(struct oid_par_priv *poid_par_priv) -{ - NDIS_STATUS status = NDIS_STATUS_SUCCESS; - PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); - - if (poid_par_priv->type_of_oid != QUERY_OID) - return NDIS_STATUS_NOT_ACCEPTED; - - if (poid_par_priv->information_buf_len < sizeof(u32)) - return NDIS_STATUS_INVALID_LENGTH; - - *(u32 *)poid_par_priv->information_buf = efuse_GetMaxSize(Adapter); - *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; - - return status; -} -/* ------------------------------------------------------------------------------ */ -NDIS_STATUS oid_rt_pro_efuse_hdl(struct oid_par_priv *poid_par_priv) -{ - NDIS_STATUS status; - - if (poid_par_priv->type_of_oid == QUERY_OID) - status = oid_rt_pro_read_efuse_hdl(poid_par_priv); - else - status = oid_rt_pro_write_efuse_hdl(poid_par_priv); - - return status; -} -/* ------------------------------------------------------------------------------ */ -NDIS_STATUS oid_rt_pro_efuse_map_hdl(struct oid_par_priv *poid_par_priv) -{ - u8 *data; - NDIS_STATUS status = NDIS_STATUS_SUCCESS; - PADAPTER Adapter = (PADAPTER)(poid_par_priv->adapter_context); - u16 mapLen = 0; - - EFUSE_GetEfuseDefinition(Adapter, EFUSE_WIFI, TYPE_EFUSE_MAP_LEN, (PVOID)&mapLen, _FALSE); - - *poid_par_priv->bytes_rw = 0; - - if (poid_par_priv->information_buf_len < mapLen) - return NDIS_STATUS_INVALID_LENGTH; - - data = (u8 *)poid_par_priv->information_buf; - - _irqlevel_changed_(&oldirql, LOWER); - - if (poid_par_priv->type_of_oid == QUERY_OID) { - - if (rtw_efuse_map_read(Adapter, 0, mapLen, data) == _SUCCESS) - *poid_par_priv->bytes_rw = mapLen; - else { - status = NDIS_STATUS_FAILURE; - } - } else { - /* SET_OID */ - - if (rtw_efuse_map_write(Adapter, 0, mapLen, data) == _SUCCESS) - *poid_par_priv->bytes_rw = mapLen; - else { - status = NDIS_STATUS_FAILURE; - } - } - - _irqlevel_changed_(&oldirql, RAISE); - - return status; -} - -NDIS_STATUS oid_rt_set_crystal_cap_hdl(struct oid_par_priv *poid_par_priv) -{ - NDIS_STATUS status = NDIS_STATUS_SUCCESS; - return status; -} - -NDIS_STATUS oid_rt_set_rx_packet_type_hdl(struct oid_par_priv *poid_par_priv) -{ - u8 rx_pkt_type; - /* u32 rcr_val32; */ - NDIS_STATUS status = NDIS_STATUS_SUCCESS; - /* PADAPTER padapter = (PADAPTER)(poid_par_priv->adapter_context); */ - - if (poid_par_priv->type_of_oid != SET_OID) - return NDIS_STATUS_NOT_ACCEPTED; - - if (poid_par_priv->information_buf_len < sizeof(u8)) - return NDIS_STATUS_INVALID_LENGTH; - - rx_pkt_type = *((u8 *)poid_par_priv->information_buf); /* 4 */ - - return status; -} - -NDIS_STATUS oid_rt_pro_set_tx_agc_offset_hdl(struct oid_par_priv *poid_par_priv) -{ - return 0; -} - -NDIS_STATUS oid_rt_pro_set_pkt_test_mode_hdl(struct oid_par_priv *poid_par_priv) -{ - return 0; -} - -unsigned int mp_ioctl_xmit_packet_hdl(struct oid_par_priv *poid_par_priv) -{ - PMP_XMIT_PARM pparm; - PADAPTER padapter; - struct mp_priv *pmp_priv; - struct pkt_attrib *pattrib; - - pparm = (PMP_XMIT_PARM)poid_par_priv->information_buf; - padapter = (PADAPTER)poid_par_priv->adapter_context; - pmp_priv = &padapter->mppriv; - - if (poid_par_priv->type_of_oid == QUERY_OID) { - pparm->enable = !pmp_priv->tx.stop; - pparm->count = pmp_priv->tx.sended; - } else { - if (pparm->enable == 0) - pmp_priv->tx.stop = 1; - else if (pmp_priv->tx.stop == 1) { - pmp_priv->tx.stop = 0; - pmp_priv->tx.count = pparm->count; - pmp_priv->tx.payload = pparm->payload_type; - pattrib = &pmp_priv->tx.attrib; - pattrib->pktlen = pparm->length; - _rtw_memcpy(pattrib->dst, pparm->da, ETH_ALEN); - SetPacketTx(padapter); - } else - return NDIS_STATUS_FAILURE; - } - - return NDIS_STATUS_SUCCESS; -} - -/* ------------------------------------------------------------------------------ */ -NDIS_STATUS oid_rt_set_power_down_hdl(struct oid_par_priv *poid_par_priv) -{ - u8 bpwrup; - NDIS_STATUS status = NDIS_STATUS_SUCCESS; -#if defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI) - PADAPTER padapter = (PADAPTER)(poid_par_priv->adapter_context); -#endif - - if (poid_par_priv->type_of_oid != SET_OID) { - status = NDIS_STATUS_NOT_ACCEPTED; - return status; - } - - _irqlevel_changed_(&oldirql, LOWER); - - bpwrup = *(u8 *)poid_par_priv->information_buf; - _irqlevel_changed_(&oldirql, RAISE); - - return status; -} -/* ------------------------------------------------------------------------------ */ -NDIS_STATUS oid_rt_get_power_mode_hdl(struct oid_par_priv *poid_par_priv) -{ - return 0; -} diff --git a/core/rtw_sdio.c b/core/rtw_sdio.c deleted file mode 100644 index b383cd4..0000000 --- a/core/rtw_sdio.c +++ /dev/null @@ -1,98 +0,0 @@ -/****************************************************************************** - * - * Copyright(c) 2015 - 2016 Realtek Corporation. All rights reserved. - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of version 2 of the GNU General Public License as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA - * - ******************************************************************************/ -#define _RTW_SDIO_C_ - -#include /* struct dvobj_priv and etc. */ -#include /* RTW_SDIO_ADDR_CMD52_GEN */ - -/* - * Description: - * Use SDIO cmd52 or cmd53 to read/write data - * - * Parameters: - * d pointer of device object(struct dvobj_priv) - * addr SDIO address, 17 bits - * buf buffer for I/O - * len length - * write 0:read, 1:write - * cmd52 0:cmd52, 1:cmd53 - * - * Return: - * _SUCCESS I/O ok. - * _FAIL I/O fail. - */ -static u8 sdio_io(struct dvobj_priv *d, u32 addr, void *buf, size_t len, u8 write, u8 cmd52) -{ - int err; - - - if (cmd52) - addr = RTW_SDIO_ADDR_CMD52_GEN(addr); - - if (write) - err = d->intf_ops->write(d, addr, buf, len, 0); - else - err = d->intf_ops->read(d, addr, buf, len, 0); - if (err) { - RTW_INFO("%s: [ERROR] %s FAIL! error(%d)\n", - __func__, write ? "write" : "read", err); - return _FAIL; - } - - return _SUCCESS; -} - -u8 rtw_sdio_read_cmd52(struct dvobj_priv *d, u32 addr, void *buf, size_t len) -{ - return sdio_io(d, addr, buf, len, 0, 1); -} - -u8 rtw_sdio_read_cmd53(struct dvobj_priv *d, u32 addr, void *buf, size_t len) -{ - return sdio_io(d, addr, buf, len, 0, 0); -} - -u8 rtw_sdio_write_cmd52(struct dvobj_priv *d, u32 addr, void *buf, size_t len) -{ - return sdio_io(d, addr, buf, len, 1, 1); -} - -u8 rtw_sdio_write_cmd53(struct dvobj_priv *d, u32 addr, void *buf, size_t len) -{ - return sdio_io(d, addr, buf, len, 1, 0); -} - -u8 rtw_sdio_f0_read(struct dvobj_priv *d, u32 addr, void *buf, size_t len) -{ - int err; - u8 ret; - - - ret = _SUCCESS; - addr = RTW_SDIO_ADDR_F0_GEN(addr); - - err = d->intf_ops->read(d, addr, buf, len, 0); - if (err) { - RTW_INFO("%s: [ERROR] Read f0 register FAIL!\n", __func__); - ret = _FAIL; - } - - - return ret; -} diff --git a/core/rtw_wapi.c b/core/rtw_wapi.c deleted file mode 100644 index f5e4126..0000000 --- a/core/rtw_wapi.c +++ /dev/null @@ -1,1240 +0,0 @@ -#ifdef CONFIG_WAPI_SUPPORT - -#include -#include -#include -#include - - -u32 wapi_debug_component = - /* WAPI_INIT | - * WAPI_API | - * WAPI_TX | - * WAPI_RX | */ - WAPI_ERR ; /* always open err flags on */ - -void WapiFreeAllStaInfo(_adapter *padapter) -{ - PRT_WAPI_T pWapiInfo; - PRT_WAPI_STA_INFO pWapiStaInfo; - PRT_WAPI_BKID pWapiBkid; - - WAPI_TRACE(WAPI_INIT, "===========> %s\n", __func__); - pWapiInfo = &padapter->wapiInfo; - - /* Pust to Idle List */ - rtw_wapi_return_all_sta_info(padapter); - - /* Sta Info List */ - while (!list_empty(&(pWapiInfo->wapiSTAIdleList))) { - pWapiStaInfo = (PRT_WAPI_STA_INFO)list_entry(pWapiInfo->wapiSTAIdleList.next, RT_WAPI_STA_INFO, list); - list_del_init(&pWapiStaInfo->list); - } - - /* BKID List */ - while (!list_empty(&(pWapiInfo->wapiBKIDIdleList))) { - pWapiBkid = (PRT_WAPI_BKID)list_entry(pWapiInfo->wapiBKIDIdleList.next, RT_WAPI_BKID, list); - list_del_init(&pWapiBkid->list); - } - WAPI_TRACE(WAPI_INIT, "<=========== %s\n", __func__); - return; -} - -void WapiSetIE(_adapter *padapter) -{ - PRT_WAPI_T pWapiInfo = &(padapter->wapiInfo); - /* PRT_WAPI_BKID pWapiBkid; */ - u16 protocolVer = 1; - u16 akmCnt = 1; - u16 suiteCnt = 1; - u16 capability = 0; - u8 OUI[3]; - - OUI[0] = 0x00; - OUI[1] = 0x14; - OUI[2] = 0x72; - - pWapiInfo->wapiIELength = 0; - /* protocol version */ - memcpy(pWapiInfo->wapiIE + pWapiInfo->wapiIELength, &protocolVer, 2); - pWapiInfo->wapiIELength += 2; - /* akm */ - memcpy(pWapiInfo->wapiIE + pWapiInfo->wapiIELength, &akmCnt, 2); - pWapiInfo->wapiIELength += 2; - - if (pWapiInfo->bWapiPSK) { - memcpy(pWapiInfo->wapiIE + pWapiInfo->wapiIELength, OUI, 3); - pWapiInfo->wapiIELength += 3; - pWapiInfo->wapiIE[pWapiInfo->wapiIELength] = 0x2; - pWapiInfo->wapiIELength += 1; - } else { - memcpy(pWapiInfo->wapiIE + pWapiInfo->wapiIELength, OUI, 3); - pWapiInfo->wapiIELength += 3; - pWapiInfo->wapiIE[pWapiInfo->wapiIELength] = 0x1; - pWapiInfo->wapiIELength += 1; - } - - /* usk */ - memcpy(pWapiInfo->wapiIE + pWapiInfo->wapiIELength, &suiteCnt, 2); - pWapiInfo->wapiIELength += 2; - memcpy(pWapiInfo->wapiIE + pWapiInfo->wapiIELength, OUI, 3); - pWapiInfo->wapiIELength += 3; - pWapiInfo->wapiIE[pWapiInfo->wapiIELength] = 0x1; - pWapiInfo->wapiIELength += 1; - - /* msk */ - memcpy(pWapiInfo->wapiIE + pWapiInfo->wapiIELength, OUI, 3); - pWapiInfo->wapiIELength += 3; - pWapiInfo->wapiIE[pWapiInfo->wapiIELength] = 0x1; - pWapiInfo->wapiIELength += 1; - - /* Capbility */ - memcpy(pWapiInfo->wapiIE + pWapiInfo->wapiIELength, &capability, 2); - pWapiInfo->wapiIELength += 2; -} - - -/* PN1 > PN2, return 1, - * else return 0. - */ -u32 WapiComparePN(u8 *PN1, u8 *PN2) -{ - char i; - - if ((NULL == PN1) || (NULL == PN2)) - return 1; - - /* overflow case */ - if ((PN2[15] - PN1[15]) & 0x80) - return 1; - - for (i = 16; i > 0; i--) { - if (PN1[i - 1] == PN2[i - 1]) - continue; - else if (PN1[i - 1] > PN2[i - 1]) - return 1; - else - return 0; - } - - return 0; -} - -u8 -WapiGetEntryForCamWrite(_adapter *padapter, u8 *pMacAddr, u8 KID, BOOLEAN IsMsk) -{ - PRT_WAPI_T pWapiInfo = NULL; - /* PRT_WAPI_CAM_ENTRY pEntry=NULL; */ - u8 i = 0; - u8 ret = 0xff; - - WAPI_TRACE(WAPI_API, "===========> %s\n", __func__); - - pWapiInfo = &padapter->wapiInfo; - - /* exist? */ - for (i = 0; i < WAPI_CAM_ENTRY_NUM; i++) { - if (pWapiInfo->wapiCamEntry[i].IsUsed - && (_rtw_memcmp(pMacAddr, pWapiInfo->wapiCamEntry[i].PeerMacAddr, ETH_ALEN) == _TRUE) - && pWapiInfo->wapiCamEntry[i].keyidx == KID - && pWapiInfo->wapiCamEntry[i].type == IsMsk) { - ret = pWapiInfo->wapiCamEntry[i].entry_idx; /* cover it */ - break; - } - } - - if (i == WAPI_CAM_ENTRY_NUM) { /* not found */ - for (i = 0; i < WAPI_CAM_ENTRY_NUM; i++) { - if (pWapiInfo->wapiCamEntry[i].IsUsed == 0) { - pWapiInfo->wapiCamEntry[i].IsUsed = 1; - pWapiInfo->wapiCamEntry[i].type = IsMsk; - pWapiInfo->wapiCamEntry[i].keyidx = KID; - _rtw_memcpy(pWapiInfo->wapiCamEntry[i].PeerMacAddr, pMacAddr, ETH_ALEN); - ret = pWapiInfo->wapiCamEntry[i].entry_idx; - break; - } - } - } - - WAPI_TRACE(WAPI_API, "<========== %s\n", __func__); - return ret; - - /* - if(RTIsListEmpty(&pWapiInfo->wapiCamIdleList)) { - return 0; - } - - pEntry = (PRT_WAPI_CAM_ENTRY)RTRemoveHeadList(&pWapiInfo->wapiCamIdleList); - RTInsertTailList(&pWapiInfo->wapiCamUsedList, &pEntry->list); - - - return pEntry->entry_idx;*/ -} - -u8 WapiGetEntryForCamClear(_adapter *padapter, u8 *pPeerMac, u8 keyid, u8 IsMsk) -{ - PRT_WAPI_T pWapiInfo = NULL; - u8 i = 0; - - WAPI_TRACE(WAPI_API, "===========> %s\n", __func__); - - pWapiInfo = &padapter->wapiInfo; - - for (i = 0; i < WAPI_CAM_ENTRY_NUM; i++) { - if (pWapiInfo->wapiCamEntry[i].IsUsed - && (_rtw_memcmp(pPeerMac, pWapiInfo->wapiCamEntry[i].PeerMacAddr, ETH_ALEN) == _TRUE) - && pWapiInfo->wapiCamEntry[i].keyidx == keyid - && pWapiInfo->wapiCamEntry[i].type == IsMsk) { - pWapiInfo->wapiCamEntry[i].IsUsed = 0; - pWapiInfo->wapiCamEntry[i].keyidx = 2; - _rtw_memset(pWapiInfo->wapiCamEntry[i].PeerMacAddr, 0, ETH_ALEN); - - WAPI_TRACE(WAPI_API, "<========== %s\n", __func__); - return pWapiInfo->wapiCamEntry[i].entry_idx; - } - } - - WAPI_TRACE(WAPI_API, "<====WapiGetReturnCamEntry(), No this cam entry.\n"); - return 0xff; - /* - if(RTIsListEmpty(&pWapiInfo->wapiCamUsedList)) { - return FALSE; - } - - pList = &pWapiInfo->wapiCamUsedList; - while(pList->Flink != &pWapiInfo->wapiCamUsedList) - { - pEntry = (PRT_WAPI_CAM_ENTRY)pList->Flink; - if(PlatformCompareMemory(pPeerMac,pEntry->PeerMacAddr, ETHER_ADDRLEN)== 0 - && keyid == pEntry->keyidx) - { - RTRemoveEntryList(pList); - RTInsertHeadList(&pWapiInfo->wapiCamIdleList, pList); - return pEntry->entry_idx; - } - pList = pList->Flink; - } - - return 0; - */ -} - -void -WapiResetAllCamEntry(_adapter *padapter) -{ - PRT_WAPI_T pWapiInfo; - int i; - - WAPI_TRACE(WAPI_API, "===========> %s\n", __func__); - - pWapiInfo = &padapter->wapiInfo; - - for (i = 0; i < WAPI_CAM_ENTRY_NUM; i++) { - _rtw_memset(pWapiInfo->wapiCamEntry[i].PeerMacAddr, 0, ETH_ALEN); - pWapiInfo->wapiCamEntry[i].IsUsed = 0; - pWapiInfo->wapiCamEntry[i].keyidx = 2; /* invalid */ - pWapiInfo->wapiCamEntry[i].entry_idx = 4 + i * 2; - } - - WAPI_TRACE(WAPI_API, "<========== %s\n", __func__); - - return; -} - -u8 WapiWriteOneCamEntry( - _adapter *padapter, - u8 *pMacAddr, - u8 KeyId, - u8 EntryId, - u8 EncAlg, - u8 bGroupKey, - u8 *pKey -) -{ - u8 retVal = 0; - u16 usConfig = 0; - - WAPI_TRACE(WAPI_API, "===========> %s\n", __func__); - - if (EntryId >= 32) { - WAPI_TRACE(WAPI_ERR, "<=== CamAddOneEntry(): ulKeyId exceed!\n"); - return retVal; - } - - usConfig = usConfig | (0x01 << 15) | ((u16)(EncAlg) << 2) | (KeyId); - - if (EncAlg == _SMS4_) { - if (bGroupKey == 1) - usConfig |= (0x01 << 6); - if ((EntryId % 2) == 1) /* ==0 sec key; == 1mic key */ - usConfig |= (0x01 << 5); - } - - write_cam(padapter, EntryId, usConfig, pMacAddr, pKey); - - WAPI_TRACE(WAPI_API, "===========> %s\n", __func__); - return 1; -} - -void rtw_wapi_init(_adapter *padapter) -{ - PRT_WAPI_T pWapiInfo; - int i; - - WAPI_TRACE(WAPI_INIT, "===========> %s\n", __func__); - RT_ASSERT_RET(padapter); - - if (!padapter->WapiSupport) { - WAPI_TRACE(WAPI_INIT, "<========== %s, WAPI not supported!\n", __func__); - return; - } - - pWapiInfo = &padapter->wapiInfo; - pWapiInfo->bWapiEnable = false; - - /* Init BKID List */ - INIT_LIST_HEAD(&pWapiInfo->wapiBKIDIdleList); - INIT_LIST_HEAD(&pWapiInfo->wapiBKIDStoreList); - for (i = 0; i < WAPI_MAX_BKID_NUM; i++) - list_add_tail(&pWapiInfo->wapiBKID[i].list, &pWapiInfo->wapiBKIDIdleList); - - /* Init STA List */ - INIT_LIST_HEAD(&pWapiInfo->wapiSTAIdleList); - INIT_LIST_HEAD(&pWapiInfo->wapiSTAUsedList); - for (i = 0; i < WAPI_MAX_STAINFO_NUM; i++) - list_add_tail(&pWapiInfo->wapiSta[i].list, &pWapiInfo->wapiSTAIdleList); - - for (i = 0; i < WAPI_CAM_ENTRY_NUM; i++) { - pWapiInfo->wapiCamEntry[i].IsUsed = 0; - pWapiInfo->wapiCamEntry[i].keyidx = 2; /* invalid */ - pWapiInfo->wapiCamEntry[i].entry_idx = 4 + i * 2; - } - - WAPI_TRACE(WAPI_INIT, "<========== %s\n", __func__); -} - -void rtw_wapi_free(_adapter *padapter) -{ - WAPI_TRACE(WAPI_INIT, "===========> %s\n", __func__); - RT_ASSERT_RET(padapter); - - if (!padapter->WapiSupport) { - WAPI_TRACE(WAPI_INIT, "<========== %s, WAPI not supported!\n", __func__); - return; - } - - WapiFreeAllStaInfo(padapter); - - WAPI_TRACE(WAPI_INIT, "<========== %s\n", __func__); -} - -void rtw_wapi_disable_tx(_adapter *padapter) -{ - WAPI_TRACE(WAPI_INIT, "===========> %s\n", __func__); - RT_ASSERT_RET(padapter); - - if (!padapter->WapiSupport) { - WAPI_TRACE(WAPI_INIT, "<========== %s, WAPI not supported!\n", __func__); - return; - } - - padapter->wapiInfo.wapiTxMsk.bTxEnable = false; - padapter->wapiInfo.wapiTxMsk.bSet = false; - - WAPI_TRACE(WAPI_INIT, "<========== %s\n", __func__); -} - -u8 rtw_wapi_is_wai_packet(_adapter *padapter, u8 *pkt_data) -{ - PRT_WAPI_T pWapiInfo = &(padapter->wapiInfo); - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - struct security_priv *psecuritypriv = &padapter->securitypriv; - PRT_WAPI_STA_INFO pWapiSta = NULL; - u8 WaiPkt = 0, *pTaddr, bFind = false; - u8 Offset_TypeWAI = 0 ; /* (mac header len + llc length) */ - - WAPI_TRACE(WAPI_TX | WAPI_RX, "===========> %s\n", __func__); - - if ((!padapter->WapiSupport) || (!pWapiInfo->bWapiEnable)) { - WAPI_TRACE(WAPI_MLME, "<========== %s, WAPI not supported or not enabled!\n", __func__); - return 0; - } - - Offset_TypeWAI = 24 + 6 ; - - /* YJ,add,091103. Data frame may also have skb->data[30]=0x88 and skb->data[31]=0xb4. */ - if ((pkt_data[1] & 0x40) != 0) { - /* RTW_INFO("data is privacy\n"); */ - return 0; - } - - pTaddr = get_addr2_ptr(pkt_data); - if (list_empty(&pWapiInfo->wapiSTAUsedList)) - bFind = false; - else { - list_for_each_entry(pWapiSta, &pWapiInfo->wapiSTAUsedList, list) { - if (_rtw_memcmp(pTaddr, pWapiSta->PeerMacAddr, 6) == _TRUE) { - bFind = true; - break; - } - } - } - - WAPI_TRACE(WAPI_TX | WAPI_RX, "%s: bFind=%d pTaddr="MAC_FMT"\n", __func__, bFind, MAC_ARG(pTaddr)); - - if (pkt_data[0] == WIFI_QOS_DATA_TYPE) - Offset_TypeWAI += 2; - - /* 88b4? */ - if ((pkt_data[Offset_TypeWAI] == 0x88) && (pkt_data[Offset_TypeWAI + 1] == 0xb4)) { - WaiPkt = pkt_data[Offset_TypeWAI + 5]; - - psecuritypriv->hw_decrypted = _TRUE; - } else - WAPI_TRACE(WAPI_TX | WAPI_RX, "%s(): non wai packet\n", __func__); - - WAPI_TRACE(WAPI_TX | WAPI_RX, "%s(): Recvd WAI frame. IsWAIPkt(%d)\n", __func__, WaiPkt); - - return WaiPkt; -} - - -void rtw_wapi_update_info(_adapter *padapter, union recv_frame *precv_frame) -{ - PRT_WAPI_T pWapiInfo = &(padapter->wapiInfo); - struct recv_frame_hdr *precv_hdr; - u8 *ptr; - u8 *pTA; - u8 *pRecvPN; - - - WAPI_TRACE(WAPI_RX, "===========> %s\n", __func__); - - if ((!padapter->WapiSupport) || (!pWapiInfo->bWapiEnable)) { - WAPI_TRACE(WAPI_RX, "<========== %s, WAPI not supported or not enabled!\n", __func__); - return; - } - - precv_hdr = &precv_frame->u.hdr; - ptr = precv_hdr->rx_data; - - if (precv_hdr->attrib.qos == 1) - precv_hdr->UserPriority = GetTid(ptr); - else - precv_hdr->UserPriority = 0; - - pTA = get_addr2_ptr(ptr); - _rtw_memcpy((u8 *)precv_hdr->WapiSrcAddr, pTA, 6); - pRecvPN = ptr + precv_hdr->attrib.hdrlen + 2; - _rtw_memcpy((u8 *)precv_hdr->WapiTempPN, pRecvPN, 16); - - WAPI_TRACE(WAPI_RX, "<========== %s\n", __func__); -} - -/**************************************************************************** -TRUE-----------------Drop -FALSE---------------- handle -add to support WAPI to N-mode -*****************************************************************************/ -u8 rtw_wapi_check_for_drop( - _adapter *padapter, - union recv_frame *precv_frame -) -{ - PRT_WAPI_T pWapiInfo = &(padapter->wapiInfo); - u8 *pLastRecvPN = NULL; - u8 bFind = false; - PRT_WAPI_STA_INFO pWapiSta = NULL; - u8 bDrop = false; - struct recv_frame_hdr *precv_hdr = &precv_frame->u.hdr; - u8 WapiAEPNInitialValueSrc[16] = {0x37, 0x5C, 0x36, 0x5C, 0x36, 0x5C, 0x36, 0x5C, 0x36, 0x5C, 0x36, 0x5C, 0x36, 0x5C, 0x36, 0x5C} ; - u8 WapiAEMultiCastPNInitialValueSrc[16] = {0x36, 0x5C, 0x36, 0x5C, 0x36, 0x5C, 0x36, 0x5C, 0x36, 0x5C, 0x36, 0x5C, 0x36, 0x5C, 0x36, 0x5C} ; - u8 *ptr = precv_frame->u.hdr.rx_data; - int i; - - WAPI_TRACE(WAPI_RX, "===========> %s\n", __func__); - - if ((!padapter->WapiSupport) || (!pWapiInfo->bWapiEnable)) { - WAPI_TRACE(WAPI_RX, "<========== %s, WAPI not supported or not enabled!\n", __func__); - return false; - } - - if (precv_hdr->bIsWaiPacket != 0) { - if (precv_hdr->bIsWaiPacket == 0x8) { - - RTW_INFO("rtw_wapi_check_for_drop: dump packet\n"); - for (i = 0; i < 50; i++) { - RTW_INFO("%02X ", ptr[i]); - if ((i + 1) % 8 == 0) - RTW_INFO("\n"); - } - RTW_INFO("\n rtw_wapi_check_for_drop: dump packet\n"); - - for (i = 0; i < 16; i++) { - if (ptr[i + 27] != 0) - break; - } - - if (i == 16) { - WAPI_TRACE(WAPI_RX, "rtw_wapi_check_for_drop: drop with zero BKID\n"); - return true; - } else - return false; - } else - return false; - } - - if (list_empty(&pWapiInfo->wapiSTAUsedList)) - bFind = false; - else { - list_for_each_entry(pWapiSta, &pWapiInfo->wapiSTAUsedList, list) { - if (_rtw_memcmp(precv_hdr->WapiSrcAddr, pWapiSta->PeerMacAddr, ETH_ALEN) == _TRUE) { - bFind = true; - break; - } - } - } - WAPI_TRACE(WAPI_RX, "%s: bFind=%d prxb->WapiSrcAddr="MAC_FMT"\n", __func__, bFind, MAC_ARG(precv_hdr->WapiSrcAddr)); - - if (bFind) { - if (IS_MCAST(precv_hdr->attrib.ra)) { - WAPI_TRACE(WAPI_RX, "rtw_wapi_check_for_drop: multicast case\n"); - pLastRecvPN = pWapiSta->lastRxMulticastPN; - } else { - WAPI_TRACE(WAPI_RX, "rtw_wapi_check_for_drop: unicast case\n"); - switch (precv_hdr->UserPriority) { - case 0: - case 3: - pLastRecvPN = pWapiSta->lastRxUnicastPNBEQueue; - break; - case 1: - case 2: - pLastRecvPN = pWapiSta->lastRxUnicastPNBKQueue; - break; - case 4: - case 5: - pLastRecvPN = pWapiSta->lastRxUnicastPNVIQueue; - break; - case 6: - case 7: - pLastRecvPN = pWapiSta->lastRxUnicastPNVOQueue; - break; - default: - WAPI_TRACE(WAPI_ERR, "%s: Unknown TID\n", __func__); - break; - } - } - - if (!WapiComparePN(precv_hdr->WapiTempPN, pLastRecvPN)) { - WAPI_TRACE(WAPI_RX, "%s: Equal PN!!\n", __func__); - if (IS_MCAST(precv_hdr->attrib.ra)) - _rtw_memcpy(pLastRecvPN, WapiAEMultiCastPNInitialValueSrc, 16); - else - _rtw_memcpy(pLastRecvPN, WapiAEPNInitialValueSrc, 16); - bDrop = true; - } else - _rtw_memcpy(pLastRecvPN, precv_hdr->WapiTempPN, 16); - } - - WAPI_TRACE(WAPI_RX, "<========== %s\n", __func__); - return bDrop; -} - -void rtw_build_probe_resp_wapi_ie(_adapter *padapter, unsigned char *pframe, struct pkt_attrib *pattrib) -{ - PRT_WAPI_T pWapiInfo = &(padapter->wapiInfo); - u8 WapiIELength = 0; - - WAPI_TRACE(WAPI_MLME, "===========> %s\n", __func__); - - if ((!padapter->WapiSupport) || (!pWapiInfo->bWapiEnable)) { - WAPI_TRACE(WAPI_MLME, "<========== %s, WAPI not supported!\n", __func__); - return; - } - - WapiSetIE(padapter); - WapiIELength = pWapiInfo->wapiIELength; - pframe[0] = _WAPI_IE_; - pframe[1] = WapiIELength; - _rtw_memcpy(pframe + 2, pWapiInfo->wapiIE, WapiIELength); - pframe += WapiIELength + 2; - pattrib->pktlen += WapiIELength + 2; - - WAPI_TRACE(WAPI_MLME, "<========== %s\n", __func__); -} - -void rtw_build_beacon_wapi_ie(_adapter *padapter, unsigned char *pframe, struct pkt_attrib *pattrib) -{ - PRT_WAPI_T pWapiInfo = &(padapter->wapiInfo); - u8 WapiIELength = 0; - WAPI_TRACE(WAPI_MLME, "===========> %s\n", __func__); - - if ((!padapter->WapiSupport) || (!pWapiInfo->bWapiEnable)) { - WAPI_TRACE(WAPI_MLME, "<========== %s, WAPI not supported!\n", __func__); - return; - } - - WapiSetIE(padapter); - WapiIELength = pWapiInfo->wapiIELength; - pframe[0] = _WAPI_IE_; - pframe[1] = WapiIELength; - _rtw_memcpy(pframe + 2, pWapiInfo->wapiIE, WapiIELength); - pframe += WapiIELength + 2; - pattrib->pktlen += WapiIELength + 2; - - WAPI_TRACE(WAPI_MLME, "<========== %s\n", __func__); -} - -void rtw_build_assoc_req_wapi_ie(_adapter *padapter, unsigned char *pframe, struct pkt_attrib *pattrib) -{ - PRT_WAPI_BKID pWapiBKID; - u16 bkidNum; - PRT_WAPI_T pWapiInfo = &(padapter->wapiInfo); - u8 WapiIELength = 0; - - WAPI_TRACE(WAPI_MLME, "===========> %s\n", __func__); - - if ((!padapter->WapiSupport) || (!pWapiInfo->bWapiEnable)) { - WAPI_TRACE(WAPI_MLME, "<========== %s, WAPI not supported!\n", __func__); - return; - } - - WapiSetIE(padapter); - WapiIELength = pWapiInfo->wapiIELength; - bkidNum = 0; - if (!list_empty(&(pWapiInfo->wapiBKIDStoreList))) { - list_for_each_entry(pWapiBKID, &pWapiInfo->wapiBKIDStoreList, list) { - bkidNum++; - _rtw_memcpy(pWapiInfo->wapiIE + WapiIELength + 2, pWapiBKID->bkid, 16); - WapiIELength += 16; - } - } - _rtw_memcpy(pWapiInfo->wapiIE + WapiIELength, &bkidNum, 2); - WapiIELength += 2; - - pframe[0] = _WAPI_IE_; - pframe[1] = WapiIELength; - _rtw_memcpy(pframe + 2, pWapiInfo->wapiIE, WapiIELength); - pframe += WapiIELength + 2; - pattrib->pktlen += WapiIELength + 2; - WAPI_TRACE(WAPI_MLME, "<========== %s\n", __func__); -} - -void rtw_wapi_on_assoc_ok(_adapter *padapter, PNDIS_802_11_VARIABLE_IEs pIE) -{ - PRT_WAPI_T pWapiInfo = &(padapter->wapiInfo); - PRT_WAPI_STA_INFO pWapiSta; - u8 WapiAEPNInitialValueSrc[16] = {0x37, 0x5C, 0x36, 0x5C, 0x36, 0x5C, 0x36, 0x5C, 0x36, 0x5C, 0x36, 0x5C, 0x36, 0x5C, 0x36, 0x5C} ; - /* u8 WapiASUEPNInitialValueSrc[16] = {0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C,0x36,0x5C} ; */ - u8 WapiAEMultiCastPNInitialValueSrc[16] = {0x36, 0x5C, 0x36, 0x5C, 0x36, 0x5C, 0x36, 0x5C, 0x36, 0x5C, 0x36, 0x5C, 0x36, 0x5C, 0x36, 0x5C} ; - - WAPI_TRACE(WAPI_MLME, "===========> %s\n", __func__); - - if ((!padapter->WapiSupport) || (!pWapiInfo->bWapiEnable)) { - WAPI_TRACE(WAPI_MLME, "<========== %s, WAPI not supported or not enabled!\n", __func__); - return; - } - - pWapiSta = (PRT_WAPI_STA_INFO)list_entry(pWapiInfo->wapiSTAIdleList.next, RT_WAPI_STA_INFO, list); - list_del_init(&pWapiSta->list); - list_add_tail(&pWapiSta->list, &pWapiInfo->wapiSTAUsedList); - _rtw_memcpy(pWapiSta->PeerMacAddr, padapter->mlmeextpriv.mlmext_info.network.MacAddress, 6); - _rtw_memcpy(pWapiSta->lastRxMulticastPN, WapiAEMultiCastPNInitialValueSrc, 16); - _rtw_memcpy(pWapiSta->lastRxUnicastPN, WapiAEPNInitialValueSrc, 16); - - /* For chenk PN error with Qos Data after s3: add by ylb 20111114 */ - _rtw_memcpy(pWapiSta->lastRxUnicastPNBEQueue, WapiAEPNInitialValueSrc, 16); - _rtw_memcpy(pWapiSta->lastRxUnicastPNBKQueue, WapiAEPNInitialValueSrc, 16); - _rtw_memcpy(pWapiSta->lastRxUnicastPNVIQueue, WapiAEPNInitialValueSrc, 16); - _rtw_memcpy(pWapiSta->lastRxUnicastPNVOQueue, WapiAEPNInitialValueSrc, 16); - - WAPI_TRACE(WAPI_MLME, "<========== %s\n", __func__); -} - - -void rtw_wapi_return_one_sta_info(_adapter *padapter, u8 *MacAddr) -{ - PRT_WAPI_T pWapiInfo; - PRT_WAPI_STA_INFO pWapiStaInfo = NULL; - PRT_WAPI_BKID pWapiBkid = NULL; - struct mlme_priv *pmlmepriv = &padapter->mlmepriv; - - pWapiInfo = &padapter->wapiInfo; - - WAPI_TRACE(WAPI_API, "==========> %s\n", __func__); - - if ((!padapter->WapiSupport) || (!pWapiInfo->bWapiEnable)) { - WAPI_TRACE(WAPI_MLME, "<========== %s, WAPI not supported or not enabled!\n", __func__); - return; - } - - if (check_fwstate(pmlmepriv, WIFI_STATION_STATE)) { - while (!list_empty(&(pWapiInfo->wapiBKIDStoreList))) { - pWapiBkid = (PRT_WAPI_BKID)list_entry(pWapiInfo->wapiBKIDStoreList.next, RT_WAPI_BKID, list); - list_del_init(&pWapiBkid->list); - _rtw_memset(pWapiBkid->bkid, 0, 16); - list_add_tail(&pWapiBkid->list, &pWapiInfo->wapiBKIDIdleList); - } - } - - - WAPI_TRACE(WAPI_API, " %s: after clear bkid\n", __func__); - - - /* Remove STA info */ - if (list_empty(&(pWapiInfo->wapiSTAUsedList))) { - WAPI_TRACE(WAPI_API, " %s: wapiSTAUsedList is null\n", __func__); - return; - } else { - - WAPI_TRACE(WAPI_API, " %s: wapiSTAUsedList is not null\n", __func__); -#if 0 - pWapiStaInfo = (PRT_WAPI_STA_INFO)list_entry((pWapiInfo->wapiSTAUsedList.next), RT_WAPI_STA_INFO, list); - - list_for_each_entry(pWapiStaInfo, &(pWapiInfo->wapiSTAUsedList), list) { - - RTW_INFO("MAC Addr %02x-%02x-%02x-%02x-%02x-%02x\n", MacAddr[0], MacAddr[1], MacAddr[2], MacAddr[3], MacAddr[4], MacAddr[5]); - - - RTW_INFO("peer Addr %02x-%02x-%02x-%02x-%02x-%02x\n", pWapiStaInfo->PeerMacAddr[0], pWapiStaInfo->PeerMacAddr[1], pWapiStaInfo->PeerMacAddr[2], pWapiStaInfo->PeerMacAddr[3], - pWapiStaInfo->PeerMacAddr[4], pWapiStaInfo->PeerMacAddr[5]); - - if (pWapiStaInfo == NULL) { - WAPI_TRACE(WAPI_API, " %s: pWapiStaInfo == NULL Case\n", __func__); - return; - } - - if (pWapiStaInfo->PeerMacAddr == NULL) { - WAPI_TRACE(WAPI_API, " %s: pWapiStaInfo->PeerMacAddr == NULL Case\n", __func__); - return; - } - - if (MacAddr == NULL) { - WAPI_TRACE(WAPI_API, " %s: MacAddr == NULL Case\n", __func__); - return; - } - - if (_rtw_memcmp(pWapiStaInfo->PeerMacAddr, MacAddr, ETH_ALEN) == _TRUE) { - pWapiStaInfo->bAuthenticateInProgress = false; - pWapiStaInfo->bSetkeyOk = false; - _rtw_memset(pWapiStaInfo->PeerMacAddr, 0, ETH_ALEN); - list_del_init(&pWapiStaInfo->list); - list_add_tail(&pWapiStaInfo->list, &pWapiInfo->wapiSTAIdleList); - break; - } - - } -#endif - - while (!list_empty(&(pWapiInfo->wapiSTAUsedList))) { - pWapiStaInfo = (PRT_WAPI_STA_INFO)list_entry(pWapiInfo->wapiSTAUsedList.next, RT_WAPI_STA_INFO, list); - - RTW_INFO("peer Addr %02x-%02x-%02x-%02x-%02x-%02x\n", pWapiStaInfo->PeerMacAddr[0], pWapiStaInfo->PeerMacAddr[1], pWapiStaInfo->PeerMacAddr[2], pWapiStaInfo->PeerMacAddr[3], - pWapiStaInfo->PeerMacAddr[4], pWapiStaInfo->PeerMacAddr[5]); - - list_del_init(&pWapiStaInfo->list); - memset(pWapiStaInfo->PeerMacAddr, 0, ETH_ALEN); - pWapiStaInfo->bSetkeyOk = 0; - list_add_tail(&pWapiStaInfo->list, &pWapiInfo->wapiSTAIdleList); - } - - } - - WAPI_TRACE(WAPI_API, "<========== %s\n", __func__); - return; -} - -void rtw_wapi_return_all_sta_info(_adapter *padapter) -{ - PRT_WAPI_T pWapiInfo; - PRT_WAPI_STA_INFO pWapiStaInfo; - PRT_WAPI_BKID pWapiBkid; - WAPI_TRACE(WAPI_API, "===========> %s\n", __func__); - - pWapiInfo = &padapter->wapiInfo; - - if ((!padapter->WapiSupport) || (!pWapiInfo->bWapiEnable)) { - WAPI_TRACE(WAPI_MLME, "<========== %s, WAPI not supported or not enabled!\n", __func__); - return; - } - - /* Sta Info List */ - while (!list_empty(&(pWapiInfo->wapiSTAUsedList))) { - pWapiStaInfo = (PRT_WAPI_STA_INFO)list_entry(pWapiInfo->wapiSTAUsedList.next, RT_WAPI_STA_INFO, list); - list_del_init(&pWapiStaInfo->list); - memset(pWapiStaInfo->PeerMacAddr, 0, ETH_ALEN); - pWapiStaInfo->bSetkeyOk = 0; - list_add_tail(&pWapiStaInfo->list, &pWapiInfo->wapiSTAIdleList); - } - - /* BKID List */ - while (!list_empty(&(pWapiInfo->wapiBKIDStoreList))) { - pWapiBkid = (PRT_WAPI_BKID)list_entry(pWapiInfo->wapiBKIDStoreList.next, RT_WAPI_BKID, list); - list_del_init(&pWapiBkid->list); - memset(pWapiBkid->bkid, 0, 16); - list_add_tail(&pWapiBkid->list, &pWapiInfo->wapiBKIDIdleList); - } - WAPI_TRACE(WAPI_API, "<========== %s\n", __func__); -} - -void rtw_wapi_clear_cam_entry(_adapter *padapter, u8 *pMacAddr) -{ - u8 UcIndex = 0; - - WAPI_TRACE(WAPI_API, "===========> %s\n", __func__); - - if ((!padapter->WapiSupport) || (!padapter->wapiInfo.bWapiEnable)) { - WAPI_TRACE(WAPI_MLME, "<========== %s, WAPI not supported or not enabled!\n", __func__); - return; - } - - UcIndex = WapiGetEntryForCamClear(padapter, pMacAddr, 0, 0); - if (UcIndex != 0xff) { - /* CAM_mark_invalid(Adapter, UcIndex); */ - CAM_empty_entry(padapter, UcIndex); - } - - UcIndex = WapiGetEntryForCamClear(padapter, pMacAddr, 1, 0); - if (UcIndex != 0xff) { - /* CAM_mark_invalid(Adapter, UcIndex); */ - CAM_empty_entry(padapter, UcIndex); - } - - UcIndex = WapiGetEntryForCamClear(padapter, pMacAddr, 0, 1); - if (UcIndex != 0xff) { - /* CAM_mark_invalid(Adapter, UcIndex); */ - CAM_empty_entry(padapter, UcIndex); - } - - UcIndex = WapiGetEntryForCamClear(padapter, pMacAddr, 1, 1); - if (UcIndex != 0xff) { - /* CAM_mark_invalid(padapter, UcIndex); */ - CAM_empty_entry(padapter, UcIndex); - } - - WAPI_TRACE(WAPI_API, "<========== %s\n", __func__); -} - -void rtw_wapi_clear_all_cam_entry(_adapter *padapter) -{ - WAPI_TRACE(WAPI_API, "===========> %s\n", __func__); - - if ((!padapter->WapiSupport) || (!padapter->wapiInfo.bWapiEnable)) { - WAPI_TRACE(WAPI_MLME, "<========== %s, WAPI not supported or not enabled!\n", __func__); - return; - } - - invalidate_cam_all(padapter); /* is this ok? */ - WapiResetAllCamEntry(padapter); - - WAPI_TRACE(WAPI_API, "===========> %s\n", __func__); -} - -void rtw_wapi_set_key(_adapter *padapter, RT_WAPI_KEY *pWapiKey, RT_WAPI_STA_INFO *pWapiSta, u8 bGroupKey, u8 bUseDefaultKey) -{ - PRT_WAPI_T pWapiInfo = &padapter->wapiInfo; - u8 *pMacAddr = pWapiSta->PeerMacAddr; - u32 EntryId = 0; - BOOLEAN IsPairWise = false ; - u8 EncAlgo; - - WAPI_TRACE(WAPI_API, "===========> %s\n", __func__); - - if ((!padapter->WapiSupport) || (!padapter->wapiInfo.bWapiEnable)) { - WAPI_TRACE(WAPI_API, "<========== %s, WAPI not supported or not enabled!\n", __func__); - return; - } - - EncAlgo = _SMS4_; - - /* For Tx bc/mc pkt,use defualt key entry */ - if (bUseDefaultKey) { - /* when WAPI update key, keyid will be 0 or 1 by turns. */ - if (pWapiKey->keyId == 0) - EntryId = 0; - else - EntryId = 2; - } else { - /* tx/rx unicast pkt, or rx broadcast, find the key entry by peer's MacAddr */ - EntryId = WapiGetEntryForCamWrite(padapter, pMacAddr, pWapiKey->keyId, bGroupKey); - } - - if (EntryId == 0xff) { - WAPI_TRACE(WAPI_API, "===>No entry for WAPI setkey! !!\n"); - return; - } - - /* EntryId is also used to diff Sec key and Mic key */ - /* Sec Key */ - WapiWriteOneCamEntry(padapter, - pMacAddr, - pWapiKey->keyId, /* keyid */ - EntryId, /* entry */ - EncAlgo, /* type */ - bGroupKey, /* pairwise or group key */ - pWapiKey->dataKey); - /* MIC key */ - WapiWriteOneCamEntry(padapter, - pMacAddr, - pWapiKey->keyId, /* keyid */ - EntryId + 1, /* entry */ - EncAlgo, /* type */ - bGroupKey, /* pairwise or group key */ - pWapiKey->micKey); - - WAPI_TRACE(WAPI_API, "Set Wapi Key :KeyId:%d,EntryId:%d,PairwiseKey:%d.\n", pWapiKey->keyId, EntryId, !bGroupKey); - WAPI_TRACE(WAPI_API, "===========> %s\n", __func__); - -} - -#if 0 -/* YJ,test,091013 */ -void wapi_test_set_key(struct _adapter *padapter, u8 *buf) -{ - /*Data: keyType(1) + bTxEnable(1) + bAuthenticator(1) + bUpdate(1) + PeerAddr(6) + DataKey(16) + MicKey(16) + KeyId(1)*/ - PRT_WAPI_T pWapiInfo = &padapter->wapiInfo; - PRT_WAPI_BKID pWapiBkid; - PRT_WAPI_STA_INFO pWapiSta; - u8 data[43]; - bool bTxEnable; - bool bUpdate; - bool bAuthenticator; - u8 PeerAddr[6]; - u8 WapiAEPNInitialValueSrc[16] = {0x37, 0x5C, 0x36, 0x5C, 0x36, 0x5C, 0x36, 0x5C, 0x36, 0x5C, 0x36, 0x5C, 0x36, 0x5C, 0x36, 0x5C} ; - u8 WapiASUEPNInitialValueSrc[16] = {0x36, 0x5C, 0x36, 0x5C, 0x36, 0x5C, 0x36, 0x5C, 0x36, 0x5C, 0x36, 0x5C, 0x36, 0x5C, 0x36, 0x5C} ; - u8 WapiAEMultiCastPNInitialValueSrc[16] = {0x36, 0x5C, 0x36, 0x5C, 0x36, 0x5C, 0x36, 0x5C, 0x36, 0x5C, 0x36, 0x5C, 0x36, 0x5C, 0x36, 0x5C} ; - - WAPI_TRACE(WAPI_INIT, "===========>%s\n", __func__); - - if (!padapter->WapiSupport) - return; - - copy_from_user(data, buf, 43); - bTxEnable = data[1]; - bAuthenticator = data[2]; - bUpdate = data[3]; - memcpy(PeerAddr, data + 4, 6); - - if (data[0] == 0x3) { - if (!list_empty(&(pWapiInfo->wapiBKIDIdleList))) { - pWapiBkid = (PRT_WAPI_BKID)list_entry(pWapiInfo->wapiBKIDIdleList.next, RT_WAPI_BKID, list); - list_del_init(&pWapiBkid->list); - memcpy(pWapiBkid->bkid, data + 10, 16); - WAPI_DATA(WAPI_INIT, "SetKey - BKID", pWapiBkid->bkid, 16); - list_add_tail(&pWapiBkid->list, &pWapiInfo->wapiBKIDStoreList); - } - } else { - list_for_each_entry(pWapiSta, &pWapiInfo->wapiSTAUsedList, list) { - if (!memcmp(pWapiSta->PeerMacAddr, PeerAddr, 6)) { - pWapiSta->bAuthenticatorInUpdata = false; - switch (data[0]) { - case 1: /* usk */ - if (bAuthenticator) { /* authenticator */ - memcpy(pWapiSta->lastTxUnicastPN, WapiAEPNInitialValueSrc, 16); - if (!bUpdate) { /* first */ - WAPI_TRACE(WAPI_INIT, "AE fisrt set usk\n"); - pWapiSta->wapiUsk.bSet = true; - memcpy(pWapiSta->wapiUsk.dataKey, data + 10, 16); - memcpy(pWapiSta->wapiUsk.micKey, data + 26, 16); - pWapiSta->wapiUsk.keyId = *(data + 42); - pWapiSta->wapiUsk.bTxEnable = true; - WAPI_DATA(WAPI_INIT, "SetKey - AE USK Data Key", pWapiSta->wapiUsk.dataKey, 16); - WAPI_DATA(WAPI_INIT, "SetKey - AE USK Mic Key", pWapiSta->wapiUsk.micKey, 16); - } else { /* update */ - WAPI_TRACE(WAPI_INIT, "AE update usk\n"); - pWapiSta->wapiUskUpdate.bSet = true; - pWapiSta->bAuthenticatorInUpdata = true; - memcpy(pWapiSta->wapiUskUpdate.dataKey, data + 10, 16); - memcpy(pWapiSta->wapiUskUpdate.micKey, data + 26, 16); - memcpy(pWapiSta->lastRxUnicastPNBEQueue, WapiASUEPNInitialValueSrc, 16); - memcpy(pWapiSta->lastRxUnicastPNBKQueue, WapiASUEPNInitialValueSrc, 16); - memcpy(pWapiSta->lastRxUnicastPNVIQueue, WapiASUEPNInitialValueSrc, 16); - memcpy(pWapiSta->lastRxUnicastPNVOQueue, WapiASUEPNInitialValueSrc, 16); - memcpy(pWapiSta->lastRxUnicastPN, WapiASUEPNInitialValueSrc, 16); - pWapiSta->wapiUskUpdate.keyId = *(data + 42); - pWapiSta->wapiUskUpdate.bTxEnable = true; - } - } else { - if (!bUpdate) { - WAPI_TRACE(WAPI_INIT, "ASUE fisrt set usk\n"); - if (bTxEnable) { - pWapiSta->wapiUsk.bTxEnable = true; - memcpy(pWapiSta->lastTxUnicastPN, WapiASUEPNInitialValueSrc, 16); - } else { - pWapiSta->wapiUsk.bSet = true; - memcpy(pWapiSta->wapiUsk.dataKey, data + 10, 16); - memcpy(pWapiSta->wapiUsk.micKey, data + 26, 16); - pWapiSta->wapiUsk.keyId = *(data + 42); - pWapiSta->wapiUsk.bTxEnable = false; - } - } else { - WAPI_TRACE(WAPI_INIT, "ASUE update usk\n"); - if (bTxEnable) { - pWapiSta->wapiUskUpdate.bTxEnable = true; - if (pWapiSta->wapiUskUpdate.bSet) { - memcpy(pWapiSta->wapiUsk.dataKey, pWapiSta->wapiUskUpdate.dataKey, 16); - memcpy(pWapiSta->wapiUsk.micKey, pWapiSta->wapiUskUpdate.micKey, 16); - pWapiSta->wapiUsk.keyId = pWapiSta->wapiUskUpdate.keyId; - memcpy(pWapiSta->lastRxUnicastPNBEQueue, WapiASUEPNInitialValueSrc, 16); - memcpy(pWapiSta->lastRxUnicastPNBKQueue, WapiASUEPNInitialValueSrc, 16); - memcpy(pWapiSta->lastRxUnicastPNVIQueue, WapiASUEPNInitialValueSrc, 16); - memcpy(pWapiSta->lastRxUnicastPNVOQueue, WapiASUEPNInitialValueSrc, 16); - memcpy(pWapiSta->lastRxUnicastPN, WapiASUEPNInitialValueSrc, 16); - pWapiSta->wapiUskUpdate.bTxEnable = false; - pWapiSta->wapiUskUpdate.bSet = false; - } - memcpy(pWapiSta->lastTxUnicastPN, WapiASUEPNInitialValueSrc, 16); - } else { - pWapiSta->wapiUskUpdate.bSet = true; - memcpy(pWapiSta->wapiUskUpdate.dataKey, data + 10, 16); - memcpy(pWapiSta->wapiUskUpdate.micKey, data + 26, 16); - pWapiSta->wapiUskUpdate.keyId = *(data + 42); - pWapiSta->wapiUskUpdate.bTxEnable = false; - } - } - } - break; - case 2: /* msk */ - if (bAuthenticator) { /* authenticator */ - pWapiInfo->wapiTxMsk.bSet = true; - memcpy(pWapiInfo->wapiTxMsk.dataKey, data + 10, 16); - memcpy(pWapiInfo->wapiTxMsk.micKey, data + 26, 16); - pWapiInfo->wapiTxMsk.keyId = *(data + 42); - pWapiInfo->wapiTxMsk.bTxEnable = true; - memcpy(pWapiInfo->lastTxMulticastPN, WapiAEMultiCastPNInitialValueSrc, 16); - - if (!bUpdate) { /* first */ - WAPI_TRACE(WAPI_INIT, "AE fisrt set msk\n"); - if (!pWapiSta->bSetkeyOk) - pWapiSta->bSetkeyOk = true; - pWapiInfo->bFirstAuthentiateInProgress = false; - } else /* update */ - WAPI_TRACE(WAPI_INIT, "AE update msk\n"); - - WAPI_DATA(WAPI_INIT, "SetKey - AE MSK Data Key", pWapiInfo->wapiTxMsk.dataKey, 16); - WAPI_DATA(WAPI_INIT, "SetKey - AE MSK Mic Key", pWapiInfo->wapiTxMsk.micKey, 16); - } else { - if (!bUpdate) { - WAPI_TRACE(WAPI_INIT, "ASUE fisrt set msk\n"); - pWapiSta->wapiMsk.bSet = true; - memcpy(pWapiSta->wapiMsk.dataKey, data + 10, 16); - memcpy(pWapiSta->wapiMsk.micKey, data + 26, 16); - pWapiSta->wapiMsk.keyId = *(data + 42); - pWapiSta->wapiMsk.bTxEnable = false; - if (!pWapiSta->bSetkeyOk) - pWapiSta->bSetkeyOk = true; - pWapiInfo->bFirstAuthentiateInProgress = false; - WAPI_DATA(WAPI_INIT, "SetKey - ASUE MSK Data Key", pWapiSta->wapiMsk.dataKey, 16); - WAPI_DATA(WAPI_INIT, "SetKey - ASUE MSK Mic Key", pWapiSta->wapiMsk.micKey, 16); - } else { - WAPI_TRACE(WAPI_INIT, "ASUE update msk\n"); - pWapiSta->wapiMskUpdate.bSet = true; - memcpy(pWapiSta->wapiMskUpdate.dataKey, data + 10, 16); - memcpy(pWapiSta->wapiMskUpdate.micKey, data + 26, 16); - pWapiSta->wapiMskUpdate.keyId = *(data + 42); - pWapiSta->wapiMskUpdate.bTxEnable = false; - } - } - break; - default: - WAPI_TRACE(WAPI_ERR, "Unknown Flag\n"); - break; - } - } - } - } - WAPI_TRACE(WAPI_INIT, "<===========%s\n", __func__); -} - - -void wapi_test_init(struct _adapter *padapter) -{ - u8 keybuf[100]; - u8 mac_addr[6] = {0x00, 0xe0, 0x4c, 0x72, 0x04, 0x70}; - u8 UskDataKey[16] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}; - u8 UskMicKey[16] = {0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f}; - u8 UskId = 0; - u8 MskDataKey[16] = {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}; - u8 MskMicKey[16] = {0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f}; - u8 MskId = 0; - - WAPI_TRACE(WAPI_INIT, "===========>%s\n", __func__); - - /* Enable Wapi */ - WAPI_TRACE(WAPI_INIT, "%s: Enable wapi!!!!\n", __func__); - padapter->wapiInfo.bWapiEnable = true; - padapter->pairwise_key_type = KEY_TYPE_SMS4; - ieee->group_key_type = KEY_TYPE_SMS4; - padapter->wapiInfo.extra_prefix_len = WAPI_EXT_LEN; - padapter->wapiInfo.extra_postfix_len = SMS4_MIC_LEN; - - /* set usk */ - WAPI_TRACE(WAPI_INIT, "%s: Set USK!!!!\n", __func__); - memset(keybuf, 0, 100); - keybuf[0] = 1; /* set usk */ - keybuf[1] = 1; /* enable tx */ - keybuf[2] = 1; /* AE */ - keybuf[3] = 0; /* not update */ - - memcpy(keybuf + 4, mac_addr, 6); - memcpy(keybuf + 10, UskDataKey, 16); - memcpy(keybuf + 26, UskMicKey, 16); - keybuf[42] = UskId; - wapi_test_set_key(padapter, keybuf); - - memset(keybuf, 0, 100); - keybuf[0] = 1; /* set usk */ - keybuf[1] = 1; /* enable tx */ - keybuf[2] = 0; /* AE */ - keybuf[3] = 0; /* not update */ - - memcpy(keybuf + 4, mac_addr, 6); - memcpy(keybuf + 10, UskDataKey, 16); - memcpy(keybuf + 26, UskMicKey, 16); - keybuf[42] = UskId; - wapi_test_set_key(padapter, keybuf); - - /* set msk */ - WAPI_TRACE(WAPI_INIT, "%s: Set MSK!!!!\n", __func__); - memset(keybuf, 0, 100); - keybuf[0] = 2; /* set msk */ - keybuf[1] = 1; /* Enable TX */ - keybuf[2] = 1; /* AE */ - keybuf[3] = 0; /* not update */ - memcpy(keybuf + 4, mac_addr, 6); - memcpy(keybuf + 10, MskDataKey, 16); - memcpy(keybuf + 26, MskMicKey, 16); - keybuf[42] = MskId; - wapi_test_set_key(padapter, keybuf); - - memset(keybuf, 0, 100); - keybuf[0] = 2; /* set msk */ - keybuf[1] = 1; /* Enable TX */ - keybuf[2] = 0; /* AE */ - keybuf[3] = 0; /* not update */ - memcpy(keybuf + 4, mac_addr, 6); - memcpy(keybuf + 10, MskDataKey, 16); - memcpy(keybuf + 26, MskMicKey, 16); - keybuf[42] = MskId; - wapi_test_set_key(padapter, keybuf); - WAPI_TRACE(WAPI_INIT, "<===========%s\n", __func__); -} -#endif - -void rtw_wapi_get_iv(_adapter *padapter, u8 *pRA, u8 *IV) -{ - PWLAN_HEADER_WAPI_EXTENSION pWapiExt = NULL; - PRT_WAPI_T pWapiInfo = &padapter->wapiInfo; - bool bPNOverflow = false; - bool bFindMatchPeer = false; - PRT_WAPI_STA_INFO pWapiSta = NULL; - - pWapiExt = (PWLAN_HEADER_WAPI_EXTENSION)IV; - - WAPI_DATA(WAPI_RX, "wapi_get_iv: pra", pRA, 6); - - if (IS_MCAST(pRA)) { - if (!pWapiInfo->wapiTxMsk.bTxEnable) { - WAPI_TRACE(WAPI_ERR, "%s: bTxEnable = 0!!\n", __func__); - return; - } - - if (pWapiInfo->wapiTxMsk.keyId <= 1) { - pWapiExt->KeyIdx = pWapiInfo->wapiTxMsk.keyId; - pWapiExt->Reserved = 0; - bPNOverflow = WapiIncreasePN(pWapiInfo->lastTxMulticastPN, 1); - memcpy(pWapiExt->PN, pWapiInfo->lastTxMulticastPN, 16); - } - } else { - if (list_empty(&pWapiInfo->wapiSTAUsedList)) { - WAPI_TRACE(WAPI_RX, "rtw_wapi_get_iv: list is empty\n"); - _rtw_memset(IV, 10, 18); - return; - } else { - list_for_each_entry(pWapiSta, &pWapiInfo->wapiSTAUsedList, list) { - WAPI_DATA(WAPI_RX, "rtw_wapi_get_iv: peermacaddr ", pWapiSta->PeerMacAddr, 6); - if (_rtw_memcmp((u8 *)pWapiSta->PeerMacAddr, pRA, 6) == _TRUE) { - bFindMatchPeer = true; - break; - } - } - - WAPI_TRACE(WAPI_RX, "bFindMatchPeer: %d\n", bFindMatchPeer); - WAPI_DATA(WAPI_RX, "Addr", pRA, 6); - - if (bFindMatchPeer) { - if ((!pWapiSta->wapiUskUpdate.bTxEnable) && (!pWapiSta->wapiUsk.bTxEnable)) - return; - - if (pWapiSta->wapiUsk.keyId <= 1) { - if (pWapiSta->wapiUskUpdate.bTxEnable) - pWapiExt->KeyIdx = pWapiSta->wapiUskUpdate.keyId; - else - pWapiExt->KeyIdx = pWapiSta->wapiUsk.keyId; - - pWapiExt->Reserved = 0; - bPNOverflow = WapiIncreasePN(pWapiSta->lastTxUnicastPN, 2); - _rtw_memcpy(pWapiExt->PN, pWapiSta->lastTxUnicastPN, 16); - - } - } - } - - } - -} - -bool rtw_wapi_drop_for_key_absent(_adapter *padapter, u8 *pRA) -{ - PRT_WAPI_T pWapiInfo = &padapter->wapiInfo; - bool bFindMatchPeer = false; - bool bDrop = false; - PRT_WAPI_STA_INFO pWapiSta = NULL; - struct security_priv *psecuritypriv = &padapter->securitypriv; - - WAPI_DATA(WAPI_RX, "rtw_wapi_drop_for_key_absent: ra ", pRA, 6); - - if (psecuritypriv->dot11PrivacyAlgrthm == _SMS4_) { - if ((!padapter->WapiSupport) || (!pWapiInfo->bWapiEnable)) - return true; - - if (IS_MCAST(pRA)) { - if (!pWapiInfo->wapiTxMsk.bTxEnable) { - bDrop = true; - WAPI_TRACE(WAPI_RX, "rtw_wapi_drop_for_key_absent: multicast key is absent\n"); - return bDrop; - } - } else { - if (!list_empty(&pWapiInfo->wapiSTAUsedList)) { - list_for_each_entry(pWapiSta, &pWapiInfo->wapiSTAUsedList, list) { - WAPI_DATA(WAPI_RX, "rtw_wapi_drop_for_key_absent: pWapiSta->PeerMacAddr ", pWapiSta->PeerMacAddr, 6); - if (_rtw_memcmp(pRA, pWapiSta->PeerMacAddr, 6) == _TRUE) { - bFindMatchPeer = true; - break; - } - } - if (bFindMatchPeer) { - if (!pWapiSta->wapiUsk.bTxEnable) { - bDrop = true; - WAPI_TRACE(WAPI_RX, "rtw_wapi_drop_for_key_absent: unicast key is absent\n"); - return bDrop; - } - } else { - bDrop = true; - WAPI_TRACE(WAPI_RX, "rtw_wapi_drop_for_key_absent: no peer find\n"); - return bDrop; - } - - } else { - bDrop = true; - WAPI_TRACE(WAPI_RX, "rtw_wapi_drop_for_key_absent: no sta exist\n"); - return bDrop; - } - } - } else - return bDrop; - - return bDrop; -} - -#endif diff --git a/core/rtw_wapi_sms4.c b/core/rtw_wapi_sms4.c deleted file mode 100644 index c7a816c..0000000 --- a/core/rtw_wapi_sms4.c +++ /dev/null @@ -1,908 +0,0 @@ -#ifdef CONFIG_WAPI_SUPPORT - -#include -#include -#include -#include - - -#ifdef CONFIG_WAPI_SW_SMS4 - -#define WAPI_LITTLE_ENDIAN -/* #define BIG_ENDIAN */ -#define ENCRYPT 0 -#define DECRYPT 1 - - -/********************************************************** - **********************************************************/ -const u8 Sbox[256] = { - 0xd6, 0x90, 0xe9, 0xfe, 0xcc, 0xe1, 0x3d, 0xb7, 0x16, 0xb6, 0x14, 0xc2, 0x28, 0xfb, 0x2c, 0x05, - 0x2b, 0x67, 0x9a, 0x76, 0x2a, 0xbe, 0x04, 0xc3, 0xaa, 0x44, 0x13, 0x26, 0x49, 0x86, 0x06, 0x99, - 0x9c, 0x42, 0x50, 0xf4, 0x91, 0xef, 0x98, 0x7a, 0x33, 0x54, 0x0b, 0x43, 0xed, 0xcf, 0xac, 0x62, - 0xe4, 0xb3, 0x1c, 0xa9, 0xc9, 0x08, 0xe8, 0x95, 0x80, 0xdf, 0x94, 0xfa, 0x75, 0x8f, 0x3f, 0xa6, - 0x47, 0x07, 0xa7, 0xfc, 0xf3, 0x73, 0x17, 0xba, 0x83, 0x59, 0x3c, 0x19, 0xe6, 0x85, 0x4f, 0xa8, - 0x68, 0x6b, 0x81, 0xb2, 0x71, 0x64, 0xda, 0x8b, 0xf8, 0xeb, 0x0f, 0x4b, 0x70, 0x56, 0x9d, 0x35, - 0x1e, 0x24, 0x0e, 0x5e, 0x63, 0x58, 0xd1, 0xa2, 0x25, 0x22, 0x7c, 0x3b, 0x01, 0x21, 0x78, 0x87, - 0xd4, 0x00, 0x46, 0x57, 0x9f, 0xd3, 0x27, 0x52, 0x4c, 0x36, 0x02, 0xe7, 0xa0, 0xc4, 0xc8, 0x9e, - 0xea, 0xbf, 0x8a, 0xd2, 0x40, 0xc7, 0x38, 0xb5, 0xa3, 0xf7, 0xf2, 0xce, 0xf9, 0x61, 0x15, 0xa1, - 0xe0, 0xae, 0x5d, 0xa4, 0x9b, 0x34, 0x1a, 0x55, 0xad, 0x93, 0x32, 0x30, 0xf5, 0x8c, 0xb1, 0xe3, - 0x1d, 0xf6, 0xe2, 0x2e, 0x82, 0x66, 0xca, 0x60, 0xc0, 0x29, 0x23, 0xab, 0x0d, 0x53, 0x4e, 0x6f, - 0xd5, 0xdb, 0x37, 0x45, 0xde, 0xfd, 0x8e, 0x2f, 0x03, 0xff, 0x6a, 0x72, 0x6d, 0x6c, 0x5b, 0x51, - 0x8d, 0x1b, 0xaf, 0x92, 0xbb, 0xdd, 0xbc, 0x7f, 0x11, 0xd9, 0x5c, 0x41, 0x1f, 0x10, 0x5a, 0xd8, - 0x0a, 0xc1, 0x31, 0x88, 0xa5, 0xcd, 0x7b, 0xbd, 0x2d, 0x74, 0xd0, 0x12, 0xb8, 0xe5, 0xb4, 0xb0, - 0x89, 0x69, 0x97, 0x4a, 0x0c, 0x96, 0x77, 0x7e, 0x65, 0xb9, 0xf1, 0x09, 0xc5, 0x6e, 0xc6, 0x84, - 0x18, 0xf0, 0x7d, 0xec, 0x3a, 0xdc, 0x4d, 0x20, 0x79, 0xee, 0x5f, 0x3e, 0xd7, 0xcb, 0x39, 0x48 -}; - -const u32 CK[32] = { - 0x00070e15, 0x1c232a31, 0x383f464d, 0x545b6269, - 0x70777e85, 0x8c939aa1, 0xa8afb6bd, 0xc4cbd2d9, - 0xe0e7eef5, 0xfc030a11, 0x181f262d, 0x343b4249, - 0x50575e65, 0x6c737a81, 0x888f969d, 0xa4abb2b9, - 0xc0c7ced5, 0xdce3eaf1, 0xf8ff060d, 0x141b2229, - 0x30373e45, 0x4c535a61, 0x686f767d, 0x848b9299, - 0xa0a7aeb5, 0xbcc3cad1, 0xd8dfe6ed, 0xf4fb0209, - 0x10171e25, 0x2c333a41, 0x484f565d, 0x646b7279 -}; - -#define Rotl(_x, _y) (((_x) << (_y)) | ((_x) >> (32 - (_y)))) - -#define ByteSub(_A) (Sbox[(_A) >> 24 & 0xFF] << 24 | \ - Sbox[(_A) >> 16 & 0xFF] << 16 | \ - Sbox[(_A) >> 8 & 0xFF] << 8 | \ - Sbox[(_A) & 0xFF]) - -#define L1(_B) ((_B) ^ Rotl(_B, 2) ^ Rotl(_B, 10) ^ Rotl(_B, 18) ^ Rotl(_B, 24)) -#define L2(_B) ((_B) ^ Rotl(_B, 13) ^ Rotl(_B, 23)) - -static void -xor_block(void *dst, void *src1, void *src2) -/* 128-bit xor: *dst = *src1 xor *src2. Pointers must be 32-bit aligned */ -{ - ((u32 *)dst)[0] = ((u32 *)src1)[0] ^ ((u32 *)src2)[0]; - ((u32 *)dst)[1] = ((u32 *)src1)[1] ^ ((u32 *)src2)[1]; - ((u32 *)dst)[2] = ((u32 *)src1)[2] ^ ((u32 *)src2)[2]; - ((u32 *)dst)[3] = ((u32 *)src1)[3] ^ ((u32 *)src2)[3]; -} - - -void SMS4Crypt(u8 *Input, u8 *Output, u32 *rk) -{ - u32 r, mid, x0, x1, x2, x3, *p; - p = (u32 *)Input; - x0 = p[0]; - x1 = p[1]; - x2 = p[2]; - x3 = p[3]; -#ifdef WAPI_LITTLE_ENDIAN - x0 = Rotl(x0, 16); - x0 = ((x0 & 0x00FF00FF) << 8) | ((x0 & 0xFF00FF00) >> 8); - x1 = Rotl(x1, 16); - x1 = ((x1 & 0x00FF00FF) << 8) | ((x1 & 0xFF00FF00) >> 8); - x2 = Rotl(x2, 16); - x2 = ((x2 & 0x00FF00FF) << 8) | ((x2 & 0xFF00FF00) >> 8); - x3 = Rotl(x3, 16); - x3 = ((x3 & 0x00FF00FF) << 8) | ((x3 & 0xFF00FF00) >> 8); -#endif - for (r = 0; r < 32; r += 4) { - mid = x1 ^ x2 ^ x3 ^ rk[r + 0]; - mid = ByteSub(mid); - x0 ^= L1(mid); - mid = x2 ^ x3 ^ x0 ^ rk[r + 1]; - mid = ByteSub(mid); - x1 ^= L1(mid); - mid = x3 ^ x0 ^ x1 ^ rk[r + 2]; - mid = ByteSub(mid); - x2 ^= L1(mid); - mid = x0 ^ x1 ^ x2 ^ rk[r + 3]; - mid = ByteSub(mid); - x3 ^= L1(mid); - } -#ifdef WAPI_LITTLE_ENDIAN - x0 = Rotl(x0, 16); - x0 = ((x0 & 0x00FF00FF) << 8) | ((x0 & 0xFF00FF00) >> 8); - x1 = Rotl(x1, 16); - x1 = ((x1 & 0x00FF00FF) << 8) | ((x1 & 0xFF00FF00) >> 8); - x2 = Rotl(x2, 16); - x2 = ((x2 & 0x00FF00FF) << 8) | ((x2 & 0xFF00FF00) >> 8); - x3 = Rotl(x3, 16); - x3 = ((x3 & 0x00FF00FF) << 8) | ((x3 & 0xFF00FF00) >> 8); -#endif - p = (u32 *)Output; - p[0] = x3; - p[1] = x2; - p[2] = x1; - p[3] = x0; -} - - - -void SMS4KeyExt(u8 *Key, u32 *rk, u32 CryptFlag) -{ - u32 r, mid, x0, x1, x2, x3, *p; - - p = (u32 *)Key; - x0 = p[0]; - x1 = p[1]; - x2 = p[2]; - x3 = p[3]; -#ifdef WAPI_LITTLE_ENDIAN - x0 = Rotl(x0, 16); - x0 = ((x0 & 0xFF00FF) << 8) | ((x0 & 0xFF00FF00) >> 8); - x1 = Rotl(x1, 16); - x1 = ((x1 & 0xFF00FF) << 8) | ((x1 & 0xFF00FF00) >> 8); - x2 = Rotl(x2, 16); - x2 = ((x2 & 0xFF00FF) << 8) | ((x2 & 0xFF00FF00) >> 8); - x3 = Rotl(x3, 16); - x3 = ((x3 & 0xFF00FF) << 8) | ((x3 & 0xFF00FF00) >> 8); -#endif - - x0 ^= 0xa3b1bac6; - x1 ^= 0x56aa3350; - x2 ^= 0x677d9197; - x3 ^= 0xb27022dc; - for (r = 0; r < 32; r += 4) { - mid = x1 ^ x2 ^ x3 ^ CK[r + 0]; - mid = ByteSub(mid); - rk[r + 0] = x0 ^= L2(mid); - mid = x2 ^ x3 ^ x0 ^ CK[r + 1]; - mid = ByteSub(mid); - rk[r + 1] = x1 ^= L2(mid); - mid = x3 ^ x0 ^ x1 ^ CK[r + 2]; - mid = ByteSub(mid); - rk[r + 2] = x2 ^= L2(mid); - mid = x0 ^ x1 ^ x2 ^ CK[r + 3]; - mid = ByteSub(mid); - rk[r + 3] = x3 ^= L2(mid); - } - if (CryptFlag == DECRYPT) { - for (r = 0; r < 16; r++) - mid = rk[r], rk[r] = rk[31 - r], rk[31 - r] = mid; - } -} - - -void WapiSMS4Cryption(u8 *Key, u8 *IV, u8 *Input, u16 InputLength, - u8 *Output, u16 *OutputLength, u32 CryptFlag) -{ - u32 blockNum, i, j, rk[32]; - u16 remainder; - u8 blockIn[16], blockOut[16], tempIV[16], k; - - *OutputLength = 0; - remainder = InputLength & 0x0F; - blockNum = InputLength >> 4; - if (remainder != 0) - blockNum++; - else - remainder = 16; - - for (k = 0; k < 16; k++) - tempIV[k] = IV[15 - k]; - - memcpy(blockIn, tempIV, 16); - - SMS4KeyExt((u8 *)Key, rk, CryptFlag); - - for (i = 0; i < blockNum - 1; i++) { - SMS4Crypt((u8 *)blockIn, blockOut, rk); - xor_block(&Output[i * 16], &Input[i * 16], blockOut); - memcpy(blockIn, blockOut, 16); - } - - *OutputLength = i * 16; - - SMS4Crypt((u8 *)blockIn, blockOut, rk); - - for (j = 0; j < remainder; j++) - Output[i * 16 + j] = Input[i * 16 + j] ^ blockOut[j]; - *OutputLength += remainder; - -} - -void WapiSMS4Encryption(u8 *Key, u8 *IV, u8 *Input, u16 InputLength, - u8 *Output, u16 *OutputLength) -{ - - WapiSMS4Cryption(Key, IV, Input, InputLength, Output, OutputLength, ENCRYPT); -} - -void WapiSMS4Decryption(u8 *Key, u8 *IV, u8 *Input, u16 InputLength, - u8 *Output, u16 *OutputLength) -{ - /* OFB mode: is also ENCRYPT flag */ - WapiSMS4Cryption(Key, IV, Input, InputLength, Output, OutputLength, ENCRYPT); -} - -void WapiSMS4CalculateMic(u8 *Key, u8 *IV, u8 *Input1, u8 Input1Length, - u8 *Input2, u16 Input2Length, u8 *Output, u8 *OutputLength) -{ - u32 blockNum, i, remainder, rk[32]; - u8 BlockIn[16], BlockOut[16], TempBlock[16], tempIV[16], k; - - *OutputLength = 0; - remainder = Input1Length & 0x0F; - blockNum = Input1Length >> 4; - - for (k = 0; k < 16; k++) - tempIV[k] = IV[15 - k]; - - memcpy(BlockIn, tempIV, 16); - - SMS4KeyExt((u8 *)Key, rk, ENCRYPT); - - SMS4Crypt((u8 *)BlockIn, BlockOut, rk); - - for (i = 0; i < blockNum; i++) { - xor_block(BlockIn, (Input1 + i * 16), BlockOut); - SMS4Crypt((u8 *)BlockIn, BlockOut, rk); - } - - if (remainder != 0) { - memset(TempBlock, 0, 16); - memcpy(TempBlock, (Input1 + blockNum * 16), remainder); - - xor_block(BlockIn, TempBlock, BlockOut); - SMS4Crypt((u8 *)BlockIn, BlockOut, rk); - } - - remainder = Input2Length & 0x0F; - blockNum = Input2Length >> 4; - - for (i = 0; i < blockNum; i++) { - xor_block(BlockIn, (Input2 + i * 16), BlockOut); - SMS4Crypt((u8 *)BlockIn, BlockOut, rk); - } - - if (remainder != 0) { - memset(TempBlock, 0, 16); - memcpy(TempBlock, (Input2 + blockNum * 16), remainder); - - xor_block(BlockIn, TempBlock, BlockOut); - SMS4Crypt((u8 *)BlockIn, BlockOut, rk); - } - - memcpy(Output, BlockOut, 16); - *OutputLength = 16; -} - -void SecCalculateMicSMS4( - u8 KeyIdx, - u8 *MicKey, - u8 *pHeader, - u8 *pData, - u16 DataLen, - u8 *MicBuffer -) -{ -#if 0 - struct ieee80211_hdr_3addr_qos *header; - u8 TempBuf[34], TempLen = 32, MicLen, QosOffset, *IV; - u16 *pTemp, fc; - - WAPI_TRACE(WAPI_TX | WAPI_RX, "=========>%s\n", __func__); - - header = (struct ieee80211_hdr_3addr_qos *)pHeader; - memset(TempBuf, 0, 34); - memcpy(TempBuf, pHeader, 2); /* FrameCtrl */ - pTemp = (u16 *)TempBuf; - *pTemp &= 0xc78f; /* bit4,5,6,11,12,13 */ - - memcpy((TempBuf + 2), (pHeader + 4), 12); /* Addr1, Addr2 */ - memcpy((TempBuf + 14), (pHeader + 22), 2); /* SeqCtrl */ - pTemp = (u16 *)(TempBuf + 14); - *pTemp &= 0x000f; - - memcpy((TempBuf + 16), (pHeader + 16), 6); /* Addr3 */ - - fc = le16_to_cpu(header->frame_ctl); - - - - if (GetFrDs((u16 *)&fc) && GetToDs((u16 *)&fc)) { - memcpy((TempBuf + 22), (pHeader + 24), 6); - QosOffset = 30; - } else { - memset((TempBuf + 22), 0, 6); - QosOffset = 24; - } - - if ((fc & 0x0088) == 0x0088) { - memcpy((TempBuf + 28), (pHeader + QosOffset), 2); - TempLen += 2; - /* IV = pHeader + QosOffset + 2 + SNAP_SIZE + sizeof(u16) + 2; */ - IV = pHeader + QosOffset + 2 + 2; - } else { - IV = pHeader + QosOffset + 2; - /* IV = pHeader + QosOffset + SNAP_SIZE + sizeof(u16) + 2; */ - } - - TempBuf[TempLen - 1] = (u8)(DataLen & 0xff); - TempBuf[TempLen - 2] = (u8)((DataLen & 0xff00) >> 8); - TempBuf[TempLen - 4] = KeyIdx; - - WAPI_DATA(WAPI_TX, "CalculateMic - KEY", MicKey, 16); - WAPI_DATA(WAPI_TX, "CalculateMic - IV", IV, 16); - WAPI_DATA(WAPI_TX, "CalculateMic - TempBuf", TempBuf, TempLen); - WAPI_DATA(WAPI_TX, "CalculateMic - pData", pData, DataLen); - - WapiSMS4CalculateMic(MicKey, IV, TempBuf, TempLen, - pData, DataLen, MicBuffer, &MicLen); - - if (MicLen != 16) - WAPI_TRACE(WAPI_ERR, "%s: MIC Length Error!!\n", __func__); - - WAPI_TRACE(WAPI_TX | WAPI_RX, "<=========%s\n", __func__); -#endif -} - -/* AddCount: 1 or 2. - * If overflow, return 1, - * else return 0. - */ -u8 WapiIncreasePN(u8 *PN, u8 AddCount) -{ - u8 i; - - if (NULL == PN) - return 1; - /* YJ,test,091102 */ - /* - if(AddCount == 2){ - RTW_INFO("############################%s(): PN[0]=0x%x\n", __func__, PN[0]); - if(PN[0] == 0x48){ - PN[0] += AddCount; - return 1; - }else{ - PN[0] += AddCount; - return 0; - } - } - */ - /* YJ,test,091102,end */ - - for (i = 0; i < 16; i++) { - if (PN[i] + AddCount <= 0xff) { - PN[i] += AddCount; - return 0; - } else { - PN[i] += AddCount; - AddCount = 1; - } - } - return 1; -} - - -void WapiGetLastRxUnicastPNForQoSData( - u8 UserPriority, - PRT_WAPI_STA_INFO pWapiStaInfo, - u8 *PNOut -) -{ - WAPI_TRACE(WAPI_RX, "===========> %s\n", __func__); - switch (UserPriority) { - case 0: - case 3: - memcpy(PNOut, pWapiStaInfo->lastRxUnicastPNBEQueue, 16); - break; - case 1: - case 2: - memcpy(PNOut, pWapiStaInfo->lastRxUnicastPNBKQueue, 16); - break; - case 4: - case 5: - memcpy(PNOut, pWapiStaInfo->lastRxUnicastPNVIQueue, 16); - break; - case 6: - case 7: - memcpy(PNOut, pWapiStaInfo->lastRxUnicastPNVOQueue, 16); - break; - default: - WAPI_TRACE(WAPI_ERR, "%s: Unknown TID\n", __func__); - break; - } - WAPI_TRACE(WAPI_RX, "<=========== %s\n", __func__); -} - - -void WapiSetLastRxUnicastPNForQoSData( - u8 UserPriority, - u8 *PNIn, - PRT_WAPI_STA_INFO pWapiStaInfo -) -{ - WAPI_TRACE(WAPI_RX, "===========> %s\n", __func__); - switch (UserPriority) { - case 0: - case 3: - memcpy(pWapiStaInfo->lastRxUnicastPNBEQueue, PNIn, 16); - break; - case 1: - case 2: - memcpy(pWapiStaInfo->lastRxUnicastPNBKQueue, PNIn, 16); - break; - case 4: - case 5: - memcpy(pWapiStaInfo->lastRxUnicastPNVIQueue, PNIn, 16); - break; - case 6: - case 7: - memcpy(pWapiStaInfo->lastRxUnicastPNVOQueue, PNIn, 16); - break; - default: - WAPI_TRACE(WAPI_ERR, "%s: Unknown TID\n", __func__); - break; - } - WAPI_TRACE(WAPI_RX, "<=========== %s\n", __func__); -} - - -/**************************************************************************** - FALSE not RX-Reorder - TRUE do RX Reorder -add to support WAPI to N-mode -*****************************************************************************/ -u8 WapiCheckPnInSwDecrypt( - _adapter *padapter, - struct sk_buff *pskb -) -{ - u8 ret = false; - -#if 0 - struct ieee80211_hdr_3addr_qos *header; - u16 fc; - u8 *pDaddr, *pTaddr, *pRaddr; - - header = (struct ieee80211_hdr_3addr_qos *)pskb->data; - pTaddr = header->addr2; - pRaddr = header->addr1; - fc = le16_to_cpu(header->frame_ctl); - - if (GetToDs(&fc)) - pDaddr = header->addr3; - else - pDaddr = header->addr1; - - if ((_rtw_memcmp(pRaddr, padapter->pnetdev->dev_addr, ETH_ALEN) == 0) - && !(pDaddr) - && (GetFrameType(&fc) == WIFI_QOS_DATA_TYPE)) - /* && ieee->pHTInfo->bCurrentHTSupport && */ - /* ieee->pHTInfo->bCurRxReorderEnable) */ - ret = false; - else - ret = true; -#endif - WAPI_TRACE(WAPI_RX, "%s: return %d\n", __func__, ret); - return ret; -} - -int SecSMS4HeaderFillIV(_adapter *padapter, u8 *pxmitframe) -{ - struct pkt_attrib *pattrib = &((struct xmit_frame *)pxmitframe)->attrib; - u8 *frame = ((struct xmit_frame *)pxmitframe)->buf_addr + TXDESC_OFFSET; - u8 *pSecHeader = NULL, *pos = NULL, *pRA = NULL; - u8 bPNOverflow = false, bFindMatchPeer = false, hdr_len = 0; - PWLAN_HEADER_WAPI_EXTENSION pWapiExt = NULL; - PRT_WAPI_T pWapiInfo = &padapter->wapiInfo; - PRT_WAPI_STA_INFO pWapiSta = NULL; - int ret = 0; - - WAPI_TRACE(WAPI_TX, "=========>%s\n", __func__); - - return ret; -#if 0 - hdr_len = sMacHdrLng; - if (GetFrameType(pskb->data) == WIFI_QOS_DATA_TYPE) - hdr_len += 2; - /* hdr_len += SNAP_SIZE + sizeof(u16); */ - - pos = skb_push(pskb, padapter->wapiInfo.extra_prefix_len); - memmove(pos, pos + padapter->wapiInfo.extra_prefix_len, hdr_len); - - pSecHeader = pskb->data + hdr_len; - pWapiExt = (PWLAN_HEADER_WAPI_EXTENSION)pSecHeader; - pRA = pskb->data + 4; - - WAPI_DATA(WAPI_TX, "FillIV - Before Fill IV", pskb->data, pskb->len); - - /* Address 1 is always receiver's address */ - if (IS_MCAST(pRA)) { - if (!pWapiInfo->wapiTxMsk.bTxEnable) { - WAPI_TRACE(WAPI_ERR, "%s: bTxEnable = 0!!\n", __func__); - return -2; - } - if (pWapiInfo->wapiTxMsk.keyId <= 1) { - pWapiExt->KeyIdx = pWapiInfo->wapiTxMsk.keyId; - pWapiExt->Reserved = 0; - bPNOverflow = WapiIncreasePN(pWapiInfo->lastTxMulticastPN, 1); - memcpy(pWapiExt->PN, pWapiInfo->lastTxMulticastPN, 16); - if (bPNOverflow) { - /* Update MSK Notification. */ - WAPI_TRACE(WAPI_ERR, "===============>%s():multicast PN overflow\n", __func__); - rtw_wapi_app_event_handler(padapter, NULL, 0, pRA, false, false, true, 0, false); - } - } else { - WAPI_TRACE(WAPI_ERR, "%s: Invalid Wapi Multicast KeyIdx!!\n", __func__); - ret = -3; - } - } else { - list_for_each_entry(pWapiSta, &pWapiInfo->wapiSTAUsedList, list) { - if (!memcmp(pWapiSta->PeerMacAddr, pRA, 6)) { - bFindMatchPeer = true; - break; - } - } - if (bFindMatchPeer) { - if ((!pWapiSta->wapiUskUpdate.bTxEnable) && (!pWapiSta->wapiUsk.bTxEnable)) { - WAPI_TRACE(WAPI_ERR, "%s: bTxEnable = 0!!\n", __func__); - return -4; - } - if (pWapiSta->wapiUsk.keyId <= 1) { - if (pWapiSta->wapiUskUpdate.bTxEnable) - pWapiExt->KeyIdx = pWapiSta->wapiUskUpdate.keyId; - else - pWapiExt->KeyIdx = pWapiSta->wapiUsk.keyId; - - pWapiExt->Reserved = 0; - bPNOverflow = WapiIncreasePN(pWapiSta->lastTxUnicastPN, 2); - memcpy(pWapiExt->PN, pWapiSta->lastTxUnicastPN, 16); - if (bPNOverflow) { - /* Update USK Notification. */ - WAPI_TRACE(WAPI_ERR, "===============>%s():unicast PN overflow\n", __func__); - rtw_wapi_app_event_handler(padapter, NULL, 0, pWapiSta->PeerMacAddr, false, true, false, 0, false); - } - } else { - WAPI_TRACE(WAPI_ERR, "%s: Invalid Wapi Unicast KeyIdx!!\n", __func__); - ret = -5; - } - } else { - WAPI_TRACE(WAPI_ERR, "%s: Can not find Peer Sta "MAC_FMT"!!\n", __func__, MAC_ARG(pRA)); - ret = -6; - } - } - - WAPI_DATA(WAPI_TX, "FillIV - After Fill IV", pskb->data, pskb->len); - WAPI_TRACE(WAPI_TX, "<=========%s\n", __func__); - return ret; -#endif -} - -/* WAPI SW Enc: must have done Coalesce! */ -void SecSWSMS4Encryption( - _adapter *padapter, - u8 *pxmitframe -) -{ - PRT_WAPI_T pWapiInfo = &padapter->wapiInfo; - PRT_WAPI_STA_INFO pWapiSta = NULL; - u8 *pframe = ((struct xmit_frame *)pxmitframe)->buf_addr + TXDESC_SIZE; - struct pkt_attrib *pattrib = &((struct xmit_frame *)pxmitframe)->attrib; - - u8 *SecPtr = NULL, *pRA, *pMicKey = NULL, *pDataKey = NULL, *pIV = NULL; - u8 IVOffset, DataOffset, bFindMatchPeer = false, KeyIdx = 0, MicBuffer[16]; - u16 OutputLength; - - WAPI_TRACE(WAPI_TX, "=========>%s\n", __func__); - - WAPI_TRACE(WAPI_TX, "hdrlen: %d\n", pattrib->hdrlen); - - return; - - DataOffset = pattrib->hdrlen + pattrib->iv_len; - - pRA = pframe + 4; - - - if (IS_MCAST(pRA)) { - KeyIdx = pWapiInfo->wapiTxMsk.keyId; - pIV = pWapiInfo->lastTxMulticastPN; - pMicKey = pWapiInfo->wapiTxMsk.micKey; - pDataKey = pWapiInfo->wapiTxMsk.dataKey; - } else { - if (!list_empty(&(pWapiInfo->wapiSTAUsedList))) { - list_for_each_entry(pWapiSta, &pWapiInfo->wapiSTAUsedList, list) { - if (0 == memcmp(pWapiSta->PeerMacAddr, pRA, 6)) { - bFindMatchPeer = true; - break; - } - } - - if (bFindMatchPeer) { - if (pWapiSta->wapiUskUpdate.bTxEnable) { - KeyIdx = pWapiSta->wapiUskUpdate.keyId; - WAPI_TRACE(WAPI_TX, "%s(): Use update USK!! KeyIdx=%d\n", __func__, KeyIdx); - pIV = pWapiSta->lastTxUnicastPN; - pMicKey = pWapiSta->wapiUskUpdate.micKey; - pDataKey = pWapiSta->wapiUskUpdate.dataKey; - } else { - KeyIdx = pWapiSta->wapiUsk.keyId; - WAPI_TRACE(WAPI_TX, "%s(): Use USK!! KeyIdx=%d\n", __func__, KeyIdx); - pIV = pWapiSta->lastTxUnicastPN; - pMicKey = pWapiSta->wapiUsk.micKey; - pDataKey = pWapiSta->wapiUsk.dataKey; - } - } else { - WAPI_TRACE(WAPI_ERR, "%s: Can not find Peer Sta!!\n", __func__); - return; - } - } else { - WAPI_TRACE(WAPI_ERR, "%s: wapiSTAUsedList is empty!!\n", __func__); - return; - } - } - - SecPtr = pframe; - SecCalculateMicSMS4(KeyIdx, pMicKey, SecPtr, (SecPtr + DataOffset), pattrib->pktlen, MicBuffer); - - WAPI_DATA(WAPI_TX, "Encryption - MIC", MicBuffer, padapter->wapiInfo.extra_postfix_len); - - memcpy(pframe + pattrib->hdrlen + pattrib->iv_len + pattrib->pktlen - pattrib->icv_len, - (u8 *)MicBuffer, - padapter->wapiInfo.extra_postfix_len - ); - - - WapiSMS4Encryption(pDataKey, pIV, (SecPtr + DataOffset), pattrib->pktlen + pattrib->icv_len, (SecPtr + DataOffset), &OutputLength); - - WAPI_DATA(WAPI_TX, "Encryption - After SMS4 encryption", pframe, pattrib->hdrlen + pattrib->iv_len + pattrib->pktlen); - - WAPI_TRACE(WAPI_TX, "<=========%s\n", __func__); -} - -u8 SecSWSMS4Decryption( - _adapter *padapter, - u8 *precv_frame, - struct recv_priv *precv_priv -) -{ - PRT_WAPI_T pWapiInfo = &padapter->wapiInfo; - struct recv_frame_hdr *precv_hdr; - PRT_WAPI_STA_INFO pWapiSta = NULL; - u8 IVOffset, DataOffset, bFindMatchPeer = false, bUseUpdatedKey = false; - u8 KeyIdx, MicBuffer[16], lastRxPNforQoS[16]; - u8 *pRA, *pTA, *pMicKey, *pDataKey, *pLastRxPN, *pRecvPN, *pSecData, *pRecvMic, *pos; - u8 TID = 0; - u16 OutputLength, DataLen; - u8 bQosData; - struct sk_buff *pskb; - - WAPI_TRACE(WAPI_RX, "=========>%s\n", __func__); - - return 0; - - precv_hdr = &((union recv_frame *)precv_frame)->u.hdr; - pskb = (struct sk_buff *)(precv_hdr->rx_data); - precv_hdr->bWapiCheckPNInDecrypt = WapiCheckPnInSwDecrypt(padapter, pskb); - WAPI_TRACE(WAPI_RX, "=========>%s: check PN %d\n", __func__, precv_hdr->bWapiCheckPNInDecrypt); - WAPI_DATA(WAPI_RX, "Decryption - Before decryption", pskb->data, pskb->len); - - IVOffset = sMacHdrLng; - bQosData = GetFrameType(pskb->data) == WIFI_QOS_DATA_TYPE; - if (bQosData) - IVOffset += 2; - - /* if(GetHTC()) */ - /* IVOffset += 4; */ - - /* IVOffset += SNAP_SIZE + sizeof(u16); */ - - DataOffset = IVOffset + padapter->wapiInfo.extra_prefix_len; - - pRA = pskb->data + 4; - pTA = pskb->data + 10; - KeyIdx = *(pskb->data + IVOffset); - pRecvPN = pskb->data + IVOffset + 2; - pSecData = pskb->data + DataOffset; - DataLen = pskb->len - DataOffset; - pRecvMic = pskb->data + pskb->len - padapter->wapiInfo.extra_postfix_len; - TID = GetTid(pskb->data); - - if (!list_empty(&(pWapiInfo->wapiSTAUsedList))) { - list_for_each_entry(pWapiSta, &pWapiInfo->wapiSTAUsedList, list) { - if (0 == memcmp(pWapiSta->PeerMacAddr, pTA, 6)) { - bFindMatchPeer = true; - break; - } - } - } - - if (!bFindMatchPeer) { - WAPI_TRACE(WAPI_ERR, "%s: Can not find Peer Sta "MAC_FMT" for Key Info!!!\n", __func__, MAC_ARG(pTA)); - return false; - } - - if (IS_MCAST(pRA)) { - WAPI_TRACE(WAPI_RX, "%s: Multicast decryption !!!\n", __func__); - if (pWapiSta->wapiMsk.keyId == KeyIdx && pWapiSta->wapiMsk.bSet) { - pLastRxPN = pWapiSta->lastRxMulticastPN; - if (!WapiComparePN(pRecvPN, pLastRxPN)) { - WAPI_TRACE(WAPI_ERR, "%s: MSK PN is not larger than last, Dropped!!!\n", __func__); - WAPI_DATA(WAPI_ERR, "pRecvPN:", pRecvPN, 16); - WAPI_DATA(WAPI_ERR, "pLastRxPN:", pLastRxPN, 16); - return false; - } - - memcpy(pLastRxPN, pRecvPN, 16); - pMicKey = pWapiSta->wapiMsk.micKey; - pDataKey = pWapiSta->wapiMsk.dataKey; - } else if (pWapiSta->wapiMskUpdate.keyId == KeyIdx && pWapiSta->wapiMskUpdate.bSet) { - WAPI_TRACE(WAPI_RX, "%s: Use Updated MSK for Decryption !!!\n", __func__); - bUseUpdatedKey = true; - memcpy(pWapiSta->lastRxMulticastPN, pRecvPN, 16); - pMicKey = pWapiSta->wapiMskUpdate.micKey; - pDataKey = pWapiSta->wapiMskUpdate.dataKey; - } else { - WAPI_TRACE(WAPI_ERR, "%s: Can not find MSK with matched KeyIdx(%d), Dropped !!!\n", __func__, KeyIdx); - return false; - } - } else { - WAPI_TRACE(WAPI_RX, "%s: Unicast decryption !!!\n", __func__); - if (pWapiSta->wapiUsk.keyId == KeyIdx && pWapiSta->wapiUsk.bSet) { - WAPI_TRACE(WAPI_RX, "%s: Use USK for Decryption!!!\n", __func__); - if (precv_hdr->bWapiCheckPNInDecrypt) { - if (GetFrameType(pskb->data) == WIFI_QOS_DATA_TYPE) { - WapiGetLastRxUnicastPNForQoSData(TID, pWapiSta, lastRxPNforQoS); - pLastRxPN = lastRxPNforQoS; - } else - pLastRxPN = pWapiSta->lastRxUnicastPN; - if (!WapiComparePN(pRecvPN, pLastRxPN)) - return false; - if (bQosData) - WapiSetLastRxUnicastPNForQoSData(TID, pRecvPN, pWapiSta); - else - memcpy(pWapiSta->lastRxUnicastPN, pRecvPN, 16); - } else - memcpy(precv_hdr->WapiTempPN, pRecvPN, 16); - - if (check_fwstate(&padapter->mlmepriv, WIFI_STATION_STATE)) { - if ((pRecvPN[0] & 0x1) == 0) { - WAPI_TRACE(WAPI_ERR, "%s: Rx USK PN is not odd when Infra STA mode, Dropped !!!\n", __func__); - return false; - } - } - - pMicKey = pWapiSta->wapiUsk.micKey; - pDataKey = pWapiSta->wapiUsk.dataKey; - } else if (pWapiSta->wapiUskUpdate.keyId == KeyIdx && pWapiSta->wapiUskUpdate.bSet) { - WAPI_TRACE(WAPI_RX, "%s: Use Updated USK for Decryption!!!\n", __func__); - if (pWapiSta->bAuthenticatorInUpdata) - bUseUpdatedKey = true; - else - bUseUpdatedKey = false; - - if (bQosData) - WapiSetLastRxUnicastPNForQoSData(TID, pRecvPN, pWapiSta); - else - memcpy(pWapiSta->lastRxUnicastPN, pRecvPN, 16); - pMicKey = pWapiSta->wapiUskUpdate.micKey; - pDataKey = pWapiSta->wapiUskUpdate.dataKey; - } else { - WAPI_TRACE(WAPI_ERR, "%s: No valid USK!!!KeyIdx=%d pWapiSta->wapiUsk.keyId=%d pWapiSta->wapiUskUpdate.keyId=%d\n", __func__, KeyIdx, pWapiSta->wapiUsk.keyId, - pWapiSta->wapiUskUpdate.keyId); - /* dump_buf(pskb->data,pskb->len); */ - return false; - } - } - - WAPI_DATA(WAPI_RX, "Decryption - DataKey", pDataKey, 16); - WAPI_DATA(WAPI_RX, "Decryption - IV", pRecvPN, 16); - WapiSMS4Decryption(pDataKey, pRecvPN, pSecData, DataLen, pSecData, &OutputLength); - - if (OutputLength != DataLen) - WAPI_TRACE(WAPI_ERR, "%s: Output Length Error!!!!\n", __func__); - - WAPI_DATA(WAPI_RX, "Decryption - After decryption", pskb->data, pskb->len); - - DataLen -= padapter->wapiInfo.extra_postfix_len; - - SecCalculateMicSMS4(KeyIdx, pMicKey, pskb->data, pSecData, DataLen, MicBuffer); - - WAPI_DATA(WAPI_RX, "Decryption - MIC received", pRecvMic, SMS4_MIC_LEN); - WAPI_DATA(WAPI_RX, "Decryption - MIC calculated", MicBuffer, SMS4_MIC_LEN); - - if (0 == memcmp(MicBuffer, pRecvMic, padapter->wapiInfo.extra_postfix_len)) { - WAPI_TRACE(WAPI_RX, "%s: Check MIC OK!!\n", __func__); - if (bUseUpdatedKey) { - /* delete the old key */ - if (IS_MCAST(pRA)) { - WAPI_TRACE(WAPI_API, "%s(): AE use new update MSK!!\n", __func__); - pWapiSta->wapiMsk.keyId = pWapiSta->wapiMskUpdate.keyId; - memcpy(pWapiSta->wapiMsk.dataKey, pWapiSta->wapiMskUpdate.dataKey, 16); - memcpy(pWapiSta->wapiMsk.micKey, pWapiSta->wapiMskUpdate.micKey, 16); - pWapiSta->wapiMskUpdate.bTxEnable = pWapiSta->wapiMskUpdate.bSet = false; - } else { - WAPI_TRACE(WAPI_API, "%s(): AE use new update USK!!\n", __func__); - pWapiSta->wapiUsk.keyId = pWapiSta->wapiUskUpdate.keyId; - memcpy(pWapiSta->wapiUsk.dataKey, pWapiSta->wapiUskUpdate.dataKey, 16); - memcpy(pWapiSta->wapiUsk.micKey, pWapiSta->wapiUskUpdate.micKey, 16); - pWapiSta->wapiUskUpdate.bTxEnable = pWapiSta->wapiUskUpdate.bSet = false; - } - } - } else { - WAPI_TRACE(WAPI_ERR, "%s: Check MIC Error, Dropped !!!!\n", __func__); - return false; - } - - pos = pskb->data; - memmove(pos + padapter->wapiInfo.extra_prefix_len, pos, IVOffset); - skb_pull(pskb, padapter->wapiInfo.extra_prefix_len); - - WAPI_TRACE(WAPI_RX, "<=========%s\n", __func__); - - return true; -} - -u32 rtw_sms4_encrypt(_adapter *padapter, u8 *pxmitframe) -{ - - u8 *pframe; - u32 res = _SUCCESS; - - WAPI_TRACE(WAPI_TX, "=========>%s\n", __func__); - - if ((!padapter->WapiSupport) || (!padapter->wapiInfo.bWapiEnable)) { - WAPI_TRACE(WAPI_TX, "<========== %s, WAPI not supported or enabled!\n", __func__); - return _FAIL; - } - - if (((struct xmit_frame *)pxmitframe)->buf_addr == NULL) - return _FAIL; - - pframe = ((struct xmit_frame *)pxmitframe)->buf_addr + TXDESC_OFFSET; - - SecSWSMS4Encryption(padapter, pxmitframe); - - WAPI_TRACE(WAPI_TX, "<=========%s\n", __func__); - return res; -} - -u32 rtw_sms4_decrypt(_adapter *padapter, u8 *precvframe) -{ - u8 *pframe; - u32 res = _SUCCESS; - - WAPI_TRACE(WAPI_RX, "=========>%s\n", __func__); - - if ((!padapter->WapiSupport) || (!padapter->wapiInfo.bWapiEnable)) { - WAPI_TRACE(WAPI_RX, "<========== %s, WAPI not supported or enabled!\n", __func__); - return _FAIL; - } - - - /* drop packet when hw decrypt fail - * return tempraily */ - return _FAIL; - - /* pframe=(unsigned char *)((union recv_frame*)precvframe)->u.hdr.rx_data; */ - - if (false == SecSWSMS4Decryption(padapter, precvframe, &padapter->recvpriv)) { - WAPI_TRACE(WAPI_ERR, "%s():SMS4 decrypt frame error\n", __func__); - return _FAIL; - } - - WAPI_TRACE(WAPI_RX, "<=========%s\n", __func__); - return res; -} - -#else - -u32 rtw_sms4_encrypt(_adapter *padapter, u8 *pxmitframe) -{ - WAPI_TRACE(WAPI_TX, "=========>Dummy %s\n", __func__); - WAPI_TRACE(WAPI_TX, "<=========Dummy %s\n", __func__); - return _SUCCESS; -} - -u32 rtw_sms4_decrypt(_adapter *padapter, u8 *precvframe) -{ - WAPI_TRACE(WAPI_RX, "=========>Dummy %s\n", __func__); - WAPI_TRACE(WAPI_RX, "<=========Dummy %s\n", __func__); - return _SUCCESS; -} - -#endif - -#endif diff --git a/hal/btc/halbtc8192e1ant.c b/hal/btc/halbtc8192e1ant.c deleted file mode 100644 index 38c89d1..0000000 --- a/hal/btc/halbtc8192e1ant.c +++ /dev/null @@ -1,3417 +0,0 @@ -/* ************************************************************ - * Description: - * - * This file is for RTL8192E Co-exist mechanism - * - * History - * 2012/11/15 Cosa first check in. - * - * ************************************************************ */ - -/* ************************************************************ - * include files - * ************************************************************ */ -#include "mp_precomp.h" - -#if (BT_SUPPORT == 1 && COEX_SUPPORT == 1) - -#if (RTL8192E_SUPPORT == 1) -/* ************************************************************ - * Global variables, these are static variables - * ************************************************************ */ -static u8 *trace_buf = &gl_btc_trace_buf[0]; -static struct coex_dm_8192e_1ant glcoex_dm_8192e_1ant; -static struct coex_dm_8192e_1ant *coex_dm = &glcoex_dm_8192e_1ant; -static struct coex_sta_8192e_1ant glcoex_sta_8192e_1ant; -static struct coex_sta_8192e_1ant *coex_sta = &glcoex_sta_8192e_1ant; - -const char *const glbt_info_src_8192e_1ant[] = { - "BT Info[wifi fw]", - "BT Info[bt rsp]", - "BT Info[bt auto report]", -}; - -u32 glcoex_ver_date_8192e_1ant = 20140527; -u32 glcoex_ver_8192e_1ant = 0x4f; - -/* ************************************************************ - * local function proto type if needed - * ************************************************************ - * ************************************************************ - * local function start with halbtc8192e1ant_ - * ************************************************************ */ -u8 halbtc8192e1ant_bt_rssi_state(u8 level_num, u8 rssi_thresh, u8 rssi_thresh1) -{ - s32 bt_rssi = 0; - u8 bt_rssi_state = coex_sta->pre_bt_rssi_state; - - bt_rssi = coex_sta->bt_rssi; - - if (level_num == 2) { - if ((coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_LOW) || - (coex_sta->pre_bt_rssi_state == - BTC_RSSI_STATE_STAY_LOW)) { - if (bt_rssi >= (rssi_thresh + - BTC_RSSI_COEX_THRESH_TOL_8192E_1ANT)) - bt_rssi_state = BTC_RSSI_STATE_HIGH; - else - bt_rssi_state = BTC_RSSI_STATE_STAY_LOW; - } else { - if (bt_rssi < rssi_thresh) - bt_rssi_state = BTC_RSSI_STATE_LOW; - else - bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH; - } - } else if (level_num == 3) { - if (rssi_thresh > rssi_thresh1) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Rssi thresh error!!\n"); - BTC_TRACE(trace_buf); - return coex_sta->pre_bt_rssi_state; - } - - if ((coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_LOW) || - (coex_sta->pre_bt_rssi_state == - BTC_RSSI_STATE_STAY_LOW)) { - if (bt_rssi >= (rssi_thresh + - BTC_RSSI_COEX_THRESH_TOL_8192E_1ANT)) - bt_rssi_state = BTC_RSSI_STATE_MEDIUM; - else - bt_rssi_state = BTC_RSSI_STATE_STAY_LOW; - } else if ((coex_sta->pre_bt_rssi_state == - BTC_RSSI_STATE_MEDIUM) || - (coex_sta->pre_bt_rssi_state == - BTC_RSSI_STATE_STAY_MEDIUM)) { - if (bt_rssi >= (rssi_thresh1 + - BTC_RSSI_COEX_THRESH_TOL_8192E_1ANT)) - bt_rssi_state = BTC_RSSI_STATE_HIGH; - else if (bt_rssi < rssi_thresh) - bt_rssi_state = BTC_RSSI_STATE_LOW; - else - bt_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM; - } else { - if (bt_rssi < rssi_thresh1) - bt_rssi_state = BTC_RSSI_STATE_MEDIUM; - else - bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH; - } - } - - coex_sta->pre_bt_rssi_state = bt_rssi_state; - - return bt_rssi_state; -} - -u8 halbtc8192e1ant_wifi_rssi_state(IN struct btc_coexist *btcoexist, - IN u8 index, IN u8 level_num, IN u8 rssi_thresh, IN u8 rssi_thresh1) -{ - s32 wifi_rssi = 0; - u8 wifi_rssi_state = coex_sta->pre_wifi_rssi_state[index]; - - btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi); - - if (level_num == 2) { - if ((coex_sta->pre_wifi_rssi_state[index] == BTC_RSSI_STATE_LOW) - || - (coex_sta->pre_wifi_rssi_state[index] == - BTC_RSSI_STATE_STAY_LOW)) { - if (wifi_rssi >= (rssi_thresh + - BTC_RSSI_COEX_THRESH_TOL_8192E_1ANT)) - wifi_rssi_state = BTC_RSSI_STATE_HIGH; - else - wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW; - } else { - if (wifi_rssi < rssi_thresh) - wifi_rssi_state = BTC_RSSI_STATE_LOW; - else - wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH; - } - } else if (level_num == 3) { - if (rssi_thresh > rssi_thresh1) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], wifi RSSI thresh error!!\n"); - BTC_TRACE(trace_buf); - return coex_sta->pre_wifi_rssi_state[index]; - } - - if ((coex_sta->pre_wifi_rssi_state[index] == BTC_RSSI_STATE_LOW) - || - (coex_sta->pre_wifi_rssi_state[index] == - BTC_RSSI_STATE_STAY_LOW)) { - if (wifi_rssi >= (rssi_thresh + - BTC_RSSI_COEX_THRESH_TOL_8192E_1ANT)) - wifi_rssi_state = BTC_RSSI_STATE_MEDIUM; - else - wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW; - } else if ((coex_sta->pre_wifi_rssi_state[index] == - BTC_RSSI_STATE_MEDIUM) || - (coex_sta->pre_wifi_rssi_state[index] == - BTC_RSSI_STATE_STAY_MEDIUM)) { - if (wifi_rssi >= (rssi_thresh1 + - BTC_RSSI_COEX_THRESH_TOL_8192E_1ANT)) - wifi_rssi_state = BTC_RSSI_STATE_HIGH; - else if (wifi_rssi < rssi_thresh) - wifi_rssi_state = BTC_RSSI_STATE_LOW; - else - wifi_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM; - } else { - if (wifi_rssi < rssi_thresh1) - wifi_rssi_state = BTC_RSSI_STATE_MEDIUM; - else - wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH; - } - } - - coex_sta->pre_wifi_rssi_state[index] = wifi_rssi_state; - - return wifi_rssi_state; -} - -void halbtc8192e1ant_update_ra_mask(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u32 dis_rate_mask) -{ - coex_dm->cur_ra_mask = dis_rate_mask; - - if (force_exec || (coex_dm->pre_ra_mask != coex_dm->cur_ra_mask)) - btcoexist->btc_set(btcoexist, BTC_SET_ACT_UPDATE_RAMASK, - &coex_dm->cur_ra_mask); - coex_dm->pre_ra_mask = coex_dm->cur_ra_mask; -} - -void halbtc8192e1ant_auto_rate_fallback_retry(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 type) -{ - boolean wifi_under_b_mode = false; - - coex_dm->cur_arfr_type = type; - - if (force_exec || (coex_dm->pre_arfr_type != coex_dm->cur_arfr_type)) { - switch (coex_dm->cur_arfr_type) { - case 0: /* normal mode */ - btcoexist->btc_write_4byte(btcoexist, 0x430, - coex_dm->backup_arfr_cnt1); - btcoexist->btc_write_4byte(btcoexist, 0x434, - coex_dm->backup_arfr_cnt2); - break; - case 1: - btcoexist->btc_get(btcoexist, - BTC_GET_BL_WIFI_UNDER_B_MODE, - &wifi_under_b_mode); - if (wifi_under_b_mode) { - btcoexist->btc_write_4byte(btcoexist, - 0x430, 0x0); - btcoexist->btc_write_4byte(btcoexist, - 0x434, 0x01010101); - } else { - btcoexist->btc_write_4byte(btcoexist, - 0x430, 0x0); - btcoexist->btc_write_4byte(btcoexist, - 0x434, 0x04030201); - } - break; - default: - break; - } - } - - coex_dm->pre_arfr_type = coex_dm->cur_arfr_type; -} - -void halbtc8192e1ant_retry_limit(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 type) -{ - coex_dm->cur_retry_limit_type = type; - - if (force_exec || - (coex_dm->pre_retry_limit_type != - coex_dm->cur_retry_limit_type)) { - switch (coex_dm->cur_retry_limit_type) { - case 0: /* normal mode */ - btcoexist->btc_write_2byte(btcoexist, 0x42a, - coex_dm->backup_retry_limit); - break; - case 1: /* retry limit=8 */ - btcoexist->btc_write_2byte(btcoexist, 0x42a, - 0x0808); - break; - default: - break; - } - } - - coex_dm->pre_retry_limit_type = coex_dm->cur_retry_limit_type; -} - -void halbtc8192e1ant_ampdu_max_time(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 type) -{ - coex_dm->cur_ampdu_time_type = type; - - if (force_exec || - (coex_dm->pre_ampdu_time_type != coex_dm->cur_ampdu_time_type)) { - switch (coex_dm->cur_ampdu_time_type) { - case 0: /* normal mode */ - btcoexist->btc_write_1byte(btcoexist, 0x456, - coex_dm->backup_ampdu_max_time); - break; - case 1: /* AMPDU timw = 0x38 * 32us */ - btcoexist->btc_write_1byte(btcoexist, 0x456, - 0x38); - break; - default: - break; - } - } - - coex_dm->pre_ampdu_time_type = coex_dm->cur_ampdu_time_type; -} - -void halbtc8192e1ant_limited_tx(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 ra_mask_type, IN u8 arfr_type, - IN u8 retry_limit_type, IN u8 ampdu_time_type) -{ - switch (ra_mask_type) { - case 0: /* normal mode */ - halbtc8192e1ant_update_ra_mask(btcoexist, force_exec, - 0x0); - break; - case 1: /* disable cck 1/2 */ - halbtc8192e1ant_update_ra_mask(btcoexist, force_exec, - 0x00000003); - break; - case 2: /* disable cck 1/2/5.5, ofdm 6/9/12/18/24, mcs 0/1/2/3/4 */ - halbtc8192e1ant_update_ra_mask(btcoexist, force_exec, - 0x0001f1f7); - break; - default: - break; - } - - halbtc8192e1ant_auto_rate_fallback_retry(btcoexist, force_exec, - arfr_type); - halbtc8192e1ant_retry_limit(btcoexist, force_exec, retry_limit_type); - halbtc8192e1ant_ampdu_max_time(btcoexist, force_exec, ampdu_time_type); -} - -void halbtc8192e1ant_limited_rx(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean rej_ap_agg_pkt, - IN boolean bt_ctrl_agg_buf_size, IN u8 agg_buf_size) -{ - boolean reject_rx_agg = rej_ap_agg_pkt; - boolean bt_ctrl_rx_agg_size = bt_ctrl_agg_buf_size; - u8 rx_agg_size = agg_buf_size; - - /* ============================================ */ - /* Rx Aggregation related setting */ - /* ============================================ */ - btcoexist->btc_set(btcoexist, BTC_SET_BL_TO_REJ_AP_AGG_PKT, - &reject_rx_agg); - /* decide BT control aggregation buf size or not */ - btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_CTRL_AGG_SIZE, - &bt_ctrl_rx_agg_size); - /* aggregation buf size, only work when BT control Rx aggregation size. */ - btcoexist->btc_set(btcoexist, BTC_SET_U1_AGG_BUF_SIZE, &rx_agg_size); - /* real update aggregation setting */ - btcoexist->btc_set(btcoexist, BTC_SET_ACT_AGGREGATE_CTRL, NULL); - - -} - -void halbtc8192e1ant_query_bt_info(IN struct btc_coexist *btcoexist) -{ - u8 h2c_parameter[1] = {0}; - - coex_sta->c2h_bt_info_req_sent = true; - - h2c_parameter[0] |= BIT(0); /* trigger */ - - btcoexist->btc_fill_h2c(btcoexist, 0x61, 1, h2c_parameter); -} - -void halbtc8192e1ant_monitor_bt_ctr(IN struct btc_coexist *btcoexist) -{ - u32 reg_hp_txrx, reg_lp_txrx, u32tmp; - u32 reg_hp_tx = 0, reg_hp_rx = 0, reg_lp_tx = 0, reg_lp_rx = 0; - static u8 num_of_bt_counter_chk = 0; - - /* to avoid 0x76e[3] = 1 (WLAN_Act control by PTA) during IPS */ - /* if (! (btcoexist->btc_read_1byte(btcoexist, 0x76e) & 0x8) ) */ - - if (coex_sta->under_ips) { - coex_sta->high_priority_tx = 65535; - coex_sta->high_priority_rx = 65535; - coex_sta->low_priority_tx = 65535; - coex_sta->low_priority_rx = 65535; - return; - } - - reg_hp_txrx = 0x770; - reg_lp_txrx = 0x774; - - u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_hp_txrx); - reg_hp_tx = u32tmp & MASKLWORD; - reg_hp_rx = (u32tmp & MASKHWORD) >> 16; - - u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_lp_txrx); - reg_lp_tx = u32tmp & MASKLWORD; - reg_lp_rx = (u32tmp & MASKHWORD) >> 16; - - coex_sta->high_priority_tx = reg_hp_tx; - coex_sta->high_priority_rx = reg_hp_rx; - coex_sta->low_priority_tx = reg_lp_tx; - coex_sta->low_priority_rx = reg_lp_rx; - - if ((coex_sta->low_priority_tx >= 1050) && - (!coex_sta->c2h_bt_inquiry_page)) - coex_sta->pop_event_cnt++; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Hi-Pri Rx/Tx: %d/%d, Lo-Pri Rx/Tx: %d/%d\n", - reg_hp_rx, reg_hp_tx, reg_lp_rx, reg_lp_tx); - BTC_TRACE(trace_buf); - - /* reset counter */ - btcoexist->btc_write_1byte(btcoexist, 0x76e, 0xc); - - if ((reg_hp_tx == 0) && (reg_hp_rx == 0) && (reg_lp_tx == 0) && - (reg_lp_rx == 0)) { - num_of_bt_counter_chk++; - if (num_of_bt_counter_chk >= 3) { - halbtc8192e1ant_query_bt_info(btcoexist); - num_of_bt_counter_chk = 0; - } - } -} - - -void halbtc8192e1ant_monitor_wifi_ctr(IN struct btc_coexist *btcoexist) -{ - s32 wifi_rssi = 0; - boolean wifi_busy = false, wifi_under_b_mode = false; - static u8 cck_lock_counter = 0; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_B_MODE, - &wifi_under_b_mode); - - if (coex_sta->under_ips) { - coex_sta->crc_ok_cck = 0; - coex_sta->crc_ok_11g = 0; - coex_sta->crc_ok_11n = 0; - coex_sta->crc_ok_11n_agg = 0; - - coex_sta->crc_err_cck = 0; - coex_sta->crc_err_11g = 0; - coex_sta->crc_err_11n = 0; - coex_sta->crc_err_11n_agg = 0; - } else { - coex_sta->crc_ok_cck = btcoexist->btc_read_4byte(btcoexist, - 0xf88); - coex_sta->crc_ok_11g = btcoexist->btc_read_2byte(btcoexist, - 0xf94); - coex_sta->crc_ok_11n = btcoexist->btc_read_2byte(btcoexist, - 0xf90); - coex_sta->crc_ok_11n_agg = btcoexist->btc_read_2byte(btcoexist, - 0xfb8); - - coex_sta->crc_err_cck = btcoexist->btc_read_4byte(btcoexist, - 0xf84); - coex_sta->crc_err_11g = btcoexist->btc_read_2byte(btcoexist, - 0xf96); - coex_sta->crc_err_11n = btcoexist->btc_read_2byte(btcoexist, - 0xf92); - coex_sta->crc_err_11n_agg = btcoexist->btc_read_2byte(btcoexist, - 0xfba); - } - - - /* reset counter */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0xf16, 0x1, 0x1); - btcoexist->btc_write_1byte_bitmask(btcoexist, 0xf16, 0x1, 0x0); - - if ((wifi_busy) && (wifi_rssi >= 30) && (!wifi_under_b_mode)) { - if ((coex_dm->bt_status == BT_8192E_1ANT_BT_STATUS_ACL_BUSY) || - (coex_dm->bt_status == - BT_8192E_1ANT_BT_STATUS_ACL_SCO_BUSY) || - (coex_dm->bt_status == - BT_8192E_1ANT_BT_STATUS_SCO_BUSY)) { - if (coex_sta->crc_ok_cck > (coex_sta->crc_ok_11g + - coex_sta->crc_ok_11n + - coex_sta->crc_ok_11n_agg)) { - if (cck_lock_counter < 5) - cck_lock_counter++; - } else { - if (cck_lock_counter > 0) - cck_lock_counter--; - } - - } else { - if (cck_lock_counter > 0) - cck_lock_counter--; - } - } else { - if (cck_lock_counter > 0) - cck_lock_counter--; - } - - if (!coex_sta->pre_ccklock) { - - if (cck_lock_counter >= 5) - coex_sta->cck_lock = true; - else - coex_sta->cck_lock = false; - } else { - if (cck_lock_counter == 0) - coex_sta->cck_lock = false; - else - coex_sta->cck_lock = true; - } - - coex_sta->pre_ccklock = coex_sta->cck_lock; - - -} - -boolean halbtc8192e1ant_is_wifi_status_changed(IN struct btc_coexist *btcoexist) -{ - static boolean pre_wifi_busy = false, pre_under_4way = false, - pre_bt_hs_on = false; - boolean wifi_busy = false, under_4way = false, bt_hs_on = false; - boolean wifi_connected = false; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS, - &under_4way); - - if (wifi_connected) { - if (wifi_busy != pre_wifi_busy) { - pre_wifi_busy = wifi_busy; - return true; - } - if (under_4way != pre_under_4way) { - pre_under_4way = under_4way; - return true; - } - if (bt_hs_on != pre_bt_hs_on) { - pre_bt_hs_on = bt_hs_on; - return true; - } - } - - return false; -} - -void halbtc8192e1ant_update_bt_link_info(IN struct btc_coexist *btcoexist) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - boolean bt_hs_on = false; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); - - bt_link_info->bt_link_exist = coex_sta->bt_link_exist; - bt_link_info->sco_exist = coex_sta->sco_exist; - bt_link_info->a2dp_exist = coex_sta->a2dp_exist; - bt_link_info->pan_exist = coex_sta->pan_exist; - bt_link_info->hid_exist = coex_sta->hid_exist; - - /* work around for HS mode. */ - if (bt_hs_on) { - bt_link_info->pan_exist = true; - bt_link_info->bt_link_exist = true; - } - - /* check if Sco only */ - if (bt_link_info->sco_exist && - !bt_link_info->a2dp_exist && - !bt_link_info->pan_exist && - !bt_link_info->hid_exist) - bt_link_info->sco_only = true; - else - bt_link_info->sco_only = false; - - /* check if A2dp only */ - if (!bt_link_info->sco_exist && - bt_link_info->a2dp_exist && - !bt_link_info->pan_exist && - !bt_link_info->hid_exist) - bt_link_info->a2dp_only = true; - else - bt_link_info->a2dp_only = false; - - /* check if Pan only */ - if (!bt_link_info->sco_exist && - !bt_link_info->a2dp_exist && - bt_link_info->pan_exist && - !bt_link_info->hid_exist) - bt_link_info->pan_only = true; - else - bt_link_info->pan_only = false; - - /* check if Hid only */ - if (!bt_link_info->sco_exist && - !bt_link_info->a2dp_exist && - !bt_link_info->pan_exist && - bt_link_info->hid_exist) - bt_link_info->hid_only = true; - else - bt_link_info->hid_only = false; -} - -u8 halbtc8192e1ant_action_algorithm(IN struct btc_coexist *btcoexist) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - boolean bt_hs_on = false; - u8 algorithm = BT_8192E_1ANT_COEX_ALGO_UNDEFINED; - u8 num_of_diff_profile = 0; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); - - if (!bt_link_info->bt_link_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], No BT link exists!!!\n"); - BTC_TRACE(trace_buf); - return algorithm; - } - - if (bt_link_info->sco_exist) - num_of_diff_profile++; - if (bt_link_info->hid_exist) - num_of_diff_profile++; - if (bt_link_info->pan_exist) - num_of_diff_profile++; - if (bt_link_info->a2dp_exist) - num_of_diff_profile++; - - if (num_of_diff_profile == 1) { - if (bt_link_info->sco_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = SCO only\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8192E_1ANT_COEX_ALGO_SCO; - } else { - if (bt_link_info->hid_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = HID only\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8192E_1ANT_COEX_ALGO_HID; - } else if (bt_link_info->a2dp_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = A2DP only\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8192E_1ANT_COEX_ALGO_A2DP; - } else if (bt_link_info->pan_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = PAN(HS) only\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8192E_1ANT_COEX_ALGO_PANHS; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = PAN(EDR) only\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8192E_1ANT_COEX_ALGO_PANEDR; - } - } - } - } else if (num_of_diff_profile == 2) { - if (bt_link_info->sco_exist) { - if (bt_link_info->hid_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = SCO + HID\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8192E_1ANT_COEX_ALGO_HID; - } else if (bt_link_info->a2dp_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = SCO + A2DP ==> SCO\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8192E_1ANT_COEX_ALGO_SCO; - } else if (bt_link_info->pan_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = SCO + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8192E_1ANT_COEX_ALGO_SCO; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = SCO + PAN(EDR)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8192E_1ANT_COEX_ALGO_PANEDR_HID; - } - } - } else { - if (bt_link_info->hid_exist && - bt_link_info->a2dp_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = HID + A2DP\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8192E_1ANT_COEX_ALGO_HID_A2DP; - } else if (bt_link_info->hid_exist && - bt_link_info->pan_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = HID + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8192E_1ANT_COEX_ALGO_HID_A2DP; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = HID + PAN(EDR)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8192E_1ANT_COEX_ALGO_PANEDR_HID; - } - } else if (bt_link_info->pan_exist && - bt_link_info->a2dp_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = A2DP + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8192E_1ANT_COEX_ALGO_A2DP_PANHS; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = A2DP + PAN(EDR)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8192E_1ANT_COEX_ALGO_PANEDR_A2DP; - } - } - } - } else if (num_of_diff_profile == 3) { - if (bt_link_info->sco_exist) { - if (bt_link_info->hid_exist && - bt_link_info->a2dp_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = SCO + HID + A2DP ==> HID\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8192E_1ANT_COEX_ALGO_HID; - } else if (bt_link_info->hid_exist && - bt_link_info->pan_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = SCO + HID + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8192E_1ANT_COEX_ALGO_HID_A2DP; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = SCO + HID + PAN(EDR)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8192E_1ANT_COEX_ALGO_PANEDR_HID; - } - } else if (bt_link_info->pan_exist && - bt_link_info->a2dp_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = SCO + A2DP + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8192E_1ANT_COEX_ALGO_SCO; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = SCO + A2DP + PAN(EDR) ==> HID\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8192E_1ANT_COEX_ALGO_PANEDR_HID; - } - } - } else { - if (bt_link_info->hid_exist && - bt_link_info->pan_exist && - bt_link_info->a2dp_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = HID + A2DP + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8192E_1ANT_COEX_ALGO_HID_A2DP; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = HID + A2DP + PAN(EDR)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8192E_1ANT_COEX_ALGO_HID_A2DP_PANEDR; - } - } - } - } else if (num_of_diff_profile >= 3) { - if (bt_link_info->sco_exist) { - if (bt_link_info->hid_exist && - bt_link_info->pan_exist && - bt_link_info->a2dp_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Error!!! BT Profile = SCO + HID + A2DP + PAN(HS)\n"); - BTC_TRACE(trace_buf); - - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = SCO + HID + A2DP + PAN(EDR)==>PAN(EDR)+HID\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8192E_1ANT_COEX_ALGO_PANEDR_HID; - } - } - } - } - - return algorithm; -} - -void halbtc8192e1ant_set_bt_auto_report(IN struct btc_coexist *btcoexist, - IN boolean enable_auto_report) -{ - u8 h2c_parameter[1] = {0}; - - h2c_parameter[0] = 0; - - if (enable_auto_report) - h2c_parameter[0] |= BIT(0); - - btcoexist->btc_fill_h2c(btcoexist, 0x68, 1, h2c_parameter); -} - -void halbtc8192e1ant_bt_auto_report(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean enable_auto_report) -{ - coex_dm->cur_bt_auto_report = enable_auto_report; - - if (!force_exec) { - if (coex_dm->pre_bt_auto_report == coex_dm->cur_bt_auto_report) - return; - } - halbtc8192e1ant_set_bt_auto_report(btcoexist, - coex_dm->cur_bt_auto_report); - - coex_dm->pre_bt_auto_report = coex_dm->cur_bt_auto_report; -} - -void halbtc8192e1ant_set_sw_penalty_tx_rate_adaptive(IN struct btc_coexist - *btcoexist, IN boolean low_penalty_ra) -{ - u8 h2c_parameter[6] = {0}; - - h2c_parameter[0] = 0x6; /* op_code, 0x6= Retry_Penalty */ - - if (low_penalty_ra) { - h2c_parameter[1] |= BIT(0); - h2c_parameter[2] = - 0x00; /* normal rate except MCS7/6/5, OFDM54/48/36 */ - h2c_parameter[3] = 0xf7; /* MCS7 or OFDM54 */ - h2c_parameter[4] = 0xf8; /* MCS6 or OFDM48 */ - h2c_parameter[5] = 0xf9; /* MCS5 or OFDM36 */ - } - - btcoexist->btc_fill_h2c(btcoexist, 0x69, 6, h2c_parameter); -} - -void halbtc8192e1ant_low_penalty_ra(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean low_penalty_ra) -{ - coex_dm->cur_low_penalty_ra = low_penalty_ra; - - if (!force_exec) { - if (coex_dm->pre_low_penalty_ra == coex_dm->cur_low_penalty_ra) - return; - } - halbtc8192e1ant_set_sw_penalty_tx_rate_adaptive(btcoexist, - coex_dm->cur_low_penalty_ra); - - coex_dm->pre_low_penalty_ra = coex_dm->cur_low_penalty_ra; -} - -void halbtc8192e1ant_set_coex_table(IN struct btc_coexist *btcoexist, - IN u32 val0x6c0, IN u32 val0x6c4, IN u32 val0x6c8, IN u8 val0x6cc) -{ - btcoexist->btc_write_4byte(btcoexist, 0x6c0, val0x6c0); - - btcoexist->btc_write_4byte(btcoexist, 0x6c4, val0x6c4); - - btcoexist->btc_write_4byte(btcoexist, 0x6c8, val0x6c8); - - btcoexist->btc_write_1byte(btcoexist, 0x6cc, val0x6cc); -} - -void halbtc8192e1ant_coex_table(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u32 val0x6c0, IN u32 val0x6c4, - IN u32 val0x6c8, IN u8 val0x6cc) -{ - coex_dm->cur_val0x6c0 = val0x6c0; - coex_dm->cur_val0x6c4 = val0x6c4; - coex_dm->cur_val0x6c8 = val0x6c8; - coex_dm->cur_val0x6cc = val0x6cc; - - if (!force_exec) { - if ((coex_dm->pre_val0x6c0 == coex_dm->cur_val0x6c0) && - (coex_dm->pre_val0x6c4 == coex_dm->cur_val0x6c4) && - (coex_dm->pre_val0x6c8 == coex_dm->cur_val0x6c8) && - (coex_dm->pre_val0x6cc == coex_dm->cur_val0x6cc)) - return; - } - halbtc8192e1ant_set_coex_table(btcoexist, val0x6c0, val0x6c4, val0x6c8, - val0x6cc); - - coex_dm->pre_val0x6c0 = coex_dm->cur_val0x6c0; - coex_dm->pre_val0x6c4 = coex_dm->cur_val0x6c4; - coex_dm->pre_val0x6c8 = coex_dm->cur_val0x6c8; - coex_dm->pre_val0x6cc = coex_dm->cur_val0x6cc; -} - -void halbtc8192e1ant_coex_table_with_type(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 type) -{ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** CoexTable(%d) **********\n", type); - BTC_TRACE(trace_buf); - - coex_sta->coex_table_type = type; - - switch (type) { - case 0: - halbtc8192e1ant_coex_table(btcoexist, force_exec, - 0x55555555, 0x55555555, 0xffffff, 0x3); - break; - case 1: - halbtc8192e1ant_coex_table(btcoexist, force_exec, - 0x55555555, 0x5a5a5a5a, 0xffffff, 0x3); - break; - case 2: - halbtc8192e1ant_coex_table(btcoexist, force_exec, - 0x5a5a5a5a, 0x5a5a5a5a, 0xffffff, 0x3); - break; - case 3: - halbtc8192e1ant_coex_table(btcoexist, force_exec, - 0x55555555, 0x5a5a5a5a, 0xffffff, 0x3); - break; - case 4: - halbtc8192e1ant_coex_table(btcoexist, force_exec, - 0x55555555, 0xaaaa5a5a, 0xffffff, 0x3); - break; - case 5: - halbtc8192e1ant_coex_table(btcoexist, force_exec, - 0x5a5a5a5a, 0xaa5a5a5a, 0xffffff, 0x3); - break; - case 6: - halbtc8192e1ant_coex_table(btcoexist, force_exec, - 0x55555555, 0xaaaaaaaa, 0xffffff, 0x3); - break; - case 7: - halbtc8192e1ant_coex_table(btcoexist, force_exec, - 0xaaaaaaaa, 0xaaaaaaaa, 0xffffff, 0x3); - break; - default: - break; - } -} - -void halbtc8192e1ant_set_fw_ignore_wlan_act(IN struct btc_coexist *btcoexist, - IN boolean enable) -{ - u8 h2c_parameter[1] = {0}; - - if (enable) - h2c_parameter[0] |= BIT(0); /* function enable */ - - btcoexist->btc_fill_h2c(btcoexist, 0x63, 1, h2c_parameter); -} - -void halbtc8192e1ant_ignore_wlan_act(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean enable) -{ - coex_dm->cur_ignore_wlan_act = enable; - - if (!force_exec) { - if (coex_dm->pre_ignore_wlan_act == - coex_dm->cur_ignore_wlan_act) - return; - } - halbtc8192e1ant_set_fw_ignore_wlan_act(btcoexist, enable); - - coex_dm->pre_ignore_wlan_act = coex_dm->cur_ignore_wlan_act; -} - -void halbtc8192e1ant_set_lps_rpwm(IN struct btc_coexist *btcoexist, - IN u8 lps_val, IN u8 rpwm_val) -{ - u8 lps = lps_val; - u8 rpwm = rpwm_val; - - btcoexist->btc_set(btcoexist, BTC_SET_U1_LPS_VAL, &lps); - btcoexist->btc_set(btcoexist, BTC_SET_U1_RPWM_VAL, &rpwm); -} - -void halbtc8192e1ant_lps_rpwm(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 lps_val, IN u8 rpwm_val) -{ - coex_dm->cur_lps = lps_val; - coex_dm->cur_rpwm = rpwm_val; - - if (!force_exec) { - if ((coex_dm->pre_lps == coex_dm->cur_lps) && - (coex_dm->pre_rpwm == coex_dm->cur_rpwm)) - return; - } - halbtc8192e1ant_set_lps_rpwm(btcoexist, lps_val, rpwm_val); - - coex_dm->pre_lps = coex_dm->cur_lps; - coex_dm->pre_rpwm = coex_dm->cur_rpwm; -} - -void halbtc8192e1ant_sw_mechanism(IN struct btc_coexist *btcoexist, - IN boolean low_penalty_ra) -{ - halbtc8192e1ant_low_penalty_ra(btcoexist, NORMAL_EXEC, low_penalty_ra); -} - -void halbtc8192e1ant_set_ant_path(IN struct btc_coexist *btcoexist, - IN u8 ant_pos_type, IN boolean init_hwcfg, IN boolean wifi_off) -{ - u32 u32tmp = 0; - - if (init_hwcfg) { - btcoexist->btc_write_1byte(btcoexist, 0x944, 0x24); - btcoexist->btc_write_4byte(btcoexist, 0x930, 0x700700); - if (btcoexist->chip_interface == BTC_INTF_USB) - btcoexist->btc_write_4byte(btcoexist, 0x64, 0x30430004); - else - btcoexist->btc_write_4byte(btcoexist, 0x64, 0x30030004); - - /* 0x4c[27][24]='00', Set Antenna to BB */ - u32tmp = btcoexist->btc_read_4byte(btcoexist, 0x4c); - u32tmp &= ~BIT(24); - u32tmp &= ~BIT(27); - btcoexist->btc_write_4byte(btcoexist, 0x4c, u32tmp); - } else if (wifi_off) { - if (btcoexist->chip_interface == BTC_INTF_USB) - btcoexist->btc_write_4byte(btcoexist, 0x64, 0x30430004); - else - btcoexist->btc_write_4byte(btcoexist, 0x64, 0x30030004); - - /* 0x4c[27][24]='11', Set Antenna to BT, 0x64[8:7]=0, 0x64[2]=1 */ - u32tmp = btcoexist->btc_read_4byte(btcoexist, 0x4c); - u32tmp |= BIT(24); - u32tmp |= BIT(27); - btcoexist->btc_write_4byte(btcoexist, 0x4c, u32tmp); - } - - /* ext switch setting */ - switch (ant_pos_type) { - case BTC_ANT_PATH_WIFI: - btcoexist->btc_write_1byte(btcoexist, 0x92c, 0x4); - break; - case BTC_ANT_PATH_BT: - btcoexist->btc_write_1byte(btcoexist, 0x92c, 0x20); - break; - default: - case BTC_ANT_PATH_PTA: - btcoexist->btc_write_1byte(btcoexist, 0x92c, 0x4); - break; - } -} - -void halbtc8192e1ant_set_fw_pstdma(IN struct btc_coexist *btcoexist, - IN u8 byte1, IN u8 byte2, IN u8 byte3, IN u8 byte4, IN u8 byte5) -{ - u8 h2c_parameter[5] = {0}; - u8 real_byte1 = byte1, real_byte5 = byte5; - boolean ap_enable = false; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, - &ap_enable); - - if (ap_enable) { - if (byte1 & BIT(4) && !(byte1 & BIT(5))) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], FW for 1Ant AP mode\n"); - BTC_TRACE(trace_buf); - real_byte1 &= ~BIT(4); - real_byte1 |= BIT(5); - - real_byte5 |= BIT(5); - real_byte5 &= ~BIT(6); - } - } - - h2c_parameter[0] = real_byte1; - h2c_parameter[1] = byte2; - h2c_parameter[2] = byte3; - h2c_parameter[3] = byte4; - h2c_parameter[4] = real_byte5; - - coex_dm->ps_tdma_para[0] = real_byte1; - coex_dm->ps_tdma_para[1] = byte2; - coex_dm->ps_tdma_para[2] = byte3; - coex_dm->ps_tdma_para[3] = byte4; - coex_dm->ps_tdma_para[4] = real_byte5; - - btcoexist->btc_fill_h2c(btcoexist, 0x60, 5, h2c_parameter); -} - - -void halbtc8192e1ant_ps_tdma(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean turn_on, IN u8 type) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - boolean wifi_busy = false; - u8 rssi_adjust_val = 0; - u8 ps_tdma_byte4_val = 0x50, ps_tdma_byte0_val = 0x51, - ps_tdma_byte3_val = 0x10; - s8 wifi_duration_adjust = 0x0; - - coex_dm->cur_ps_tdma_on = turn_on; - coex_dm->cur_ps_tdma = type; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - - if (coex_dm->cur_ps_tdma_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** TDMA(on, %d) **********\n", - coex_dm->cur_ps_tdma); - BTC_TRACE(trace_buf); - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** TDMA(off, %d) **********\n", - coex_dm->cur_ps_tdma); - BTC_TRACE(trace_buf); - } - - if (!force_exec) { - if ((coex_dm->pre_ps_tdma_on == coex_dm->cur_ps_tdma_on) && - (coex_dm->pre_ps_tdma == coex_dm->cur_ps_tdma)) - return; - } - - if (coex_sta->scan_ap_num <= 5) - wifi_duration_adjust = 5; - else if (coex_sta->scan_ap_num >= 40) - wifi_duration_adjust = -15; - else if (coex_sta->scan_ap_num >= 20) - wifi_duration_adjust = -10; - - if (!coex_sta->force_lps_on) { /* only for A2DP-only case 1/2/9/11 while wifi noisy threshold > 30 */ - ps_tdma_byte0_val = 0x61; /* no null-pkt */ - ps_tdma_byte3_val = 0x11; /* no tx-pause at BT-slot */ - ps_tdma_byte4_val = 0x10; /* 0x778 = d/1 toggle */ - } - - if ((type == 3) || (type == 13) || (type == 14)) - ps_tdma_byte4_val = ps_tdma_byte4_val & - 0xbf; /* no dynamic slot for multi-profile */ - - if (bt_link_info->slave_role == true) - ps_tdma_byte4_val = ps_tdma_byte4_val | - 0x1; /* 0x778 = 0x1 at wifi slot (no blocking BT Low-Pri pkts) */ - - if (turn_on) { - switch (type) { - default: - halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x51, - 0x1a, 0x1a, 0x0, ps_tdma_byte4_val); - break; - case 1: - halbtc8192e1ant_set_fw_pstdma(btcoexist, - ps_tdma_byte0_val, 0x3a + - wifi_duration_adjust, 0x03, - ps_tdma_byte3_val, ps_tdma_byte4_val); - break; - case 2: - halbtc8192e1ant_set_fw_pstdma(btcoexist, - ps_tdma_byte0_val, 0x2d + - wifi_duration_adjust, 0x03, - ps_tdma_byte3_val, ps_tdma_byte4_val); - break; - case 3: - halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x51, - 0x1d, 0x1d, 0x0, ps_tdma_byte4_val); - break; - case 4: - halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x93, - 0x15, 0x3, 0x14, 0x0); - break; - case 5: - halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x61, - 0x15, 0x3, 0x11, 0x11); - break; - case 6: - halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x61, - 0x20, 0x3, 0x11, 0x11); - break; - case 7: - halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x13, - 0xc, 0x5, 0x0, 0x0); - break; - case 8: - halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x93, - 0x25, 0x3, 0x10, 0x0); - break; - case 9: - halbtc8192e1ant_set_fw_pstdma(btcoexist, - ps_tdma_byte0_val, 0x21, 0x3, - ps_tdma_byte3_val, ps_tdma_byte4_val); - break; - case 10: - halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x13, - 0xa, 0xa, 0x0, 0x40); - break; - case 11: - halbtc8192e1ant_set_fw_pstdma(btcoexist, - ps_tdma_byte0_val, 0x21, 0x03, - ps_tdma_byte3_val, ps_tdma_byte4_val); - break; - case 12: - halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x51, - 0x0a, 0x0a, 0x0, 0x50); - break; - case 13: - halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x51, - 0x12, 0x12, 0x0, ps_tdma_byte4_val); - break; - case 14: - halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x51, - 0x21, 0x3, 0x10, ps_tdma_byte4_val); - break; - case 15: - halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x13, - 0xa, 0x3, 0x8, 0x0); - break; - case 16: - halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x93, - 0x15, 0x3, 0x10, 0x0); - break; - case 18: - halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x93, - 0x25, 0x3, 0x10, 0x0); - break; - case 20: - halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x61, - 0x3f, 0x03, 0x11, 0x10); - break; - case 21: - halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x61, - 0x25, 0x03, 0x11, 0x11); - break; - case 22: - halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x61, - 0x25, 0x03, 0x11, 0x10); - break; - case 23: - halbtc8192e1ant_set_fw_pstdma(btcoexist, 0xe3, - 0x25, 0x3, 0x31, 0x18); - break; - case 24: - halbtc8192e1ant_set_fw_pstdma(btcoexist, 0xe3, - 0x15, 0x3, 0x31, 0x18); - break; - case 25: - halbtc8192e1ant_set_fw_pstdma(btcoexist, 0xe3, - 0xa, 0x3, 0x31, 0x18); - break; - case 26: - halbtc8192e1ant_set_fw_pstdma(btcoexist, 0xe3, - 0xa, 0x3, 0x31, 0x18); - break; - case 27: - halbtc8192e1ant_set_fw_pstdma(btcoexist, 0xe3, - 0x25, 0x3, 0x31, 0x98); - break; - case 28: - halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x69, - 0x25, 0x3, 0x31, 0x0); - break; - case 29: - halbtc8192e1ant_set_fw_pstdma(btcoexist, 0xab, - 0x1a, 0x1a, 0x1, 0x10); - break; - case 30: - halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x51, - 0x30, 0x3, 0x10, 0x10); - break; - case 31: - halbtc8192e1ant_set_fw_pstdma(btcoexist, 0xd3, - 0x1a, 0x1a, 0, 0x58); - break; - case 32: - halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x61, - 0x35, 0x3, 0x11, 0x11); - break; - case 33: - halbtc8192e1ant_set_fw_pstdma(btcoexist, 0xa3, - 0x25, 0x3, 0x30, 0x90); - break; - case 34: - halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x53, - 0x1a, 0x1a, 0x0, 0x10); - break; - case 35: - halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x63, - 0x1a, 0x1a, 0x0, 0x10); - break; - case 36: - halbtc8192e1ant_set_fw_pstdma(btcoexist, 0xd3, - 0x12, 0x3, 0x14, 0x50); - break; - case 40: /* SoftAP only with no sta associated,BT disable ,TDMA mode for power saving */ - /* here softap mode screen off will cost 70-80mA for phone */ - halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x23, - 0x18, 0x00, 0x10, 0x24); - break; - } - } else { - - /* disable PS tdma */ - switch (type) { - case 8: /* PTA Control */ - halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x8, - 0x0, 0x0, 0x0, 0x0); - halbtc8192e1ant_set_ant_path(btcoexist, - BTC_ANT_PATH_PTA, false, false); - break; - case 0: - default: /* Software control, Antenna at BT side */ - halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x0, - 0x0, 0x0, 0x0, 0x0); - halbtc8192e1ant_set_ant_path(btcoexist, - BTC_ANT_PATH_BT, false, false); - break; - case 9: /* Software control, Antenna at WiFi side */ - halbtc8192e1ant_set_fw_pstdma(btcoexist, 0x0, - 0x0, 0x0, 0x0, 0x0); - halbtc8192e1ant_set_ant_path(btcoexist, - BTC_ANT_PATH_WIFI, false, false); - break; - } - } - rssi_adjust_val = 0; - btcoexist->btc_set(btcoexist, - BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE, &rssi_adjust_val); - - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "############# [BTCoex], 0x948=0x%x, 0x765=0x%x, 0x67=0x%x\n", - btcoexist->btc_read_4byte(btcoexist, 0x948), - btcoexist->btc_read_1byte(btcoexist, 0x765), - btcoexist->btc_read_1byte(btcoexist, 0x67)); - BTC_TRACE(trace_buf); - /* update pre state */ - coex_dm->pre_ps_tdma_on = coex_dm->cur_ps_tdma_on; - coex_dm->pre_ps_tdma = coex_dm->cur_ps_tdma; -} - -void halbtc8192e1ant_coex_all_off(IN struct btc_coexist *btcoexist) -{ - /* sw all off */ - halbtc8192e1ant_sw_mechanism(btcoexist, false); - - /* hw all off */ - halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); -} - -boolean halbtc8192e1ant_is_common_action(IN struct btc_coexist *btcoexist) -{ - boolean common = false, wifi_connected = false, wifi_busy = false; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - - if (!wifi_connected && - BT_8192E_1ANT_BT_STATUS_NON_CONNECTED_IDLE == - coex_dm->bt_status) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi non connected-idle + BT non connected-idle!!\n"); - BTC_TRACE(trace_buf); - /* halbtc8192e1ant_sw_mechanism(btcoexist, false); */ - - common = true; - } else if (wifi_connected && - (BT_8192E_1ANT_BT_STATUS_NON_CONNECTED_IDLE == - coex_dm->bt_status)) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi connected + BT non connected-idle!!\n"); - BTC_TRACE(trace_buf); - /* halbtc8192e1ant_sw_mechanism(btcoexist, false); */ - - common = true; - } else if (!wifi_connected && - (BT_8192E_1ANT_BT_STATUS_CONNECTED_IDLE == coex_dm->bt_status)) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi non connected-idle + BT connected-idle!!\n"); - BTC_TRACE(trace_buf); - /* halbtc8192e1ant_sw_mechanism(btcoexist, false); */ - - common = true; - } else if (wifi_connected && - (BT_8192E_1ANT_BT_STATUS_CONNECTED_IDLE == coex_dm->bt_status)) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi connected + BT connected-idle!!\n"); - BTC_TRACE(trace_buf); - /* halbtc8192e1ant_sw_mechanism(btcoexist, false); */ - - common = true; - } else if (!wifi_connected && - (BT_8192E_1ANT_BT_STATUS_CONNECTED_IDLE != coex_dm->bt_status)) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi non connected-idle + BT Busy!!\n"); - BTC_TRACE(trace_buf); - /* halbtc8192e1ant_sw_mechanism(btcoexist, false); */ - - common = true; - } else { - if (wifi_busy) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi Connected-Busy + BT Busy!!\n"); - BTC_TRACE(trace_buf); - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi Connected-Idle + BT Busy!!\n"); - BTC_TRACE(trace_buf); - } - - common = false; - } - - return common; -} - - -void halbtc8192e1ant_tdma_duration_adjust_for_acl(IN struct btc_coexist - *btcoexist, IN u8 wifi_status) -{ - static s32 up, dn, m, n, wait_count; - s32 result; /* 0: no change, +1: increase WiFi duration, -1: decrease WiFi duration */ - u8 retry_count = 0, bt_info_ext; - boolean wifi_busy = false; - /*static boolean pre_wifi_busy = false;*/ - - if (BT_8192E_1ANT_WIFI_STATUS_CONNECTED_BUSY == wifi_status) - wifi_busy = true; - else - wifi_busy = false; - - if ((BT_8192E_1ANT_WIFI_STATUS_NON_CONNECTED_ASSO_AUTH_SCAN == - wifi_status) || - (BT_8192E_1ANT_WIFI_STATUS_CONNECTED_SCAN == wifi_status) || - (BT_8192E_1ANT_WIFI_STATUS_CONNECTED_SPECIFIC_PKT == - wifi_status)) { - if (coex_dm->cur_ps_tdma != 1 && - coex_dm->cur_ps_tdma != 2 && - coex_dm->cur_ps_tdma != 3 && - coex_dm->cur_ps_tdma != 9) { - halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 9); - coex_dm->ps_tdma_du_adj_type = 9; - - up = 0; - dn = 0; - m = 1; - n = 3; - result = 0; - wait_count = 0; - } - return; - } - - if (!coex_dm->auto_tdma_adjust) { - coex_dm->auto_tdma_adjust = true; - - halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 2); - coex_dm->ps_tdma_du_adj_type = 2; - /* ============ */ - up = 0; - dn = 0; - m = 1; - n = 3; - result = 0; - wait_count = 0; - } else { - /* acquire the BT TRx retry count from BT_Info byte2 */ - retry_count = coex_sta->bt_retry_cnt; - bt_info_ext = coex_sta->bt_info_ext; - - if ((coex_sta->low_priority_tx) > 1050 || - (coex_sta->low_priority_rx) > 1250) - retry_count++; - - result = 0; - wait_count++; - - if (retry_count == - 0) { /* no retry in the last 2-second duration */ - up++; - dn--; - - if (dn <= 0) - dn = 0; - - if (up >= n) { /* if retry count during continuous n*2 seconds is 0, enlarge WiFi duration */ - wait_count = 0; - n = 3; - up = 0; - dn = 0; - result = 1; - } - } else if (retry_count <= - 3) { /* <=3 retry in the last 2-second duration */ - up--; - dn++; - - if (up <= 0) - up = 0; - - if (dn == 2) { /* if continuous 2 retry count(every 2 seconds) >0 and < 3, reduce WiFi duration */ - if (wait_count <= 2) - m++; /* to avoid loop between the two levels */ - else - m = 1; - - if (m >= 20) /* maximum of m = 20 ' will recheck if need to adjust wifi duration in maximum time interval 120 seconds */ - m = 20; - - n = 3 * m; - up = 0; - dn = 0; - wait_count = 0; - result = -1; - } - } else { /* retry count > 3, once retry count > 3, to reduce WiFi duration */ - if (wait_count == 1) - m++; /* to avoid loop between the two levels */ - else - m = 1; - - if (m >= 20) /* maximum of m = 20 ' will recheck if need to adjust wifi duration in maximum time interval 120 seconds */ - m = 20; - - n = 3 * m; - up = 0; - dn = 0; - wait_count = 0; - result = -1; - } - - if (result == -1) { - if ((BT_INFO_8192E_1ANT_A2DP_BASIC_RATE(bt_info_ext)) && - ((coex_dm->cur_ps_tdma == 1) || - (coex_dm->cur_ps_tdma == 2))) { - halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 9); - coex_dm->ps_tdma_du_adj_type = 9; - } else if (coex_dm->cur_ps_tdma == 1) { - halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 2); - coex_dm->ps_tdma_du_adj_type = 2; - } else if (coex_dm->cur_ps_tdma == 2) { - halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 9); - coex_dm->ps_tdma_du_adj_type = 9; - } else if (coex_dm->cur_ps_tdma == 9) { - halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 11); - coex_dm->ps_tdma_du_adj_type = 11; - } - } else if (result == 1) { - if ((BT_INFO_8192E_1ANT_A2DP_BASIC_RATE(bt_info_ext)) && - ((coex_dm->cur_ps_tdma == 1) || - (coex_dm->cur_ps_tdma == 2))) { - halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 9); - coex_dm->ps_tdma_du_adj_type = 9; - } else if (coex_dm->cur_ps_tdma == 11) { - halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 9); - coex_dm->ps_tdma_du_adj_type = 9; - } else if (coex_dm->cur_ps_tdma == 9) { - halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 2); - coex_dm->ps_tdma_du_adj_type = 2; - } else if (coex_dm->cur_ps_tdma == 2) { - halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 1); - coex_dm->ps_tdma_du_adj_type = 1; - } - } else { /* no change */ - /* Bryant Modify - if(wifi_busy != pre_wifi_busy) - { - pre_wifi_busy = wifi_busy; - halbtc8192e1ant_ps_tdma(btcoexist, FORCE_EXEC, true, coex_dm->cur_ps_tdma); - } - */ - } - - if (coex_dm->cur_ps_tdma != 1 && - coex_dm->cur_ps_tdma != 2 && - coex_dm->cur_ps_tdma != 9 && - coex_dm->cur_ps_tdma != 11) { - /* recover to previous adjust type */ - halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - coex_dm->ps_tdma_du_adj_type); - } - } -} - -void halbtc8192e1ant_ps_tdma_check_for_power_save_state( - IN struct btc_coexist *btcoexist, IN boolean new_ps_state) -{ - u8 lps_mode = 0x0; - - btcoexist->btc_get(btcoexist, BTC_GET_U1_LPS_MODE, &lps_mode); - - if (lps_mode) { /* already under LPS state */ - if (new_ps_state) { - /* keep state under LPS, do nothing. */ - } else { - /* will leave LPS state, turn off psTdma first */ - halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, - 0); - } - } else { /* NO PS state */ - if (new_ps_state) { - /* will enter LPS state, turn off psTdma first */ - halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, - 0); - } else { - /* keep state under NO PS state, do nothing. */ - } - } -} - -void halbtc8192e1ant_power_save_state(IN struct btc_coexist *btcoexist, - IN u8 ps_type, IN u8 lps_val, IN u8 rpwm_val) -{ - boolean low_pwr_disable = false; - - switch (ps_type) { - case BTC_PS_WIFI_NATIVE: - /* recover to original 32k low power setting */ - low_pwr_disable = false; - btcoexist->btc_set(btcoexist, - BTC_SET_ACT_DISABLE_LOW_POWER, - &low_pwr_disable); - btcoexist->btc_set(btcoexist, BTC_SET_ACT_NORMAL_LPS, - NULL); - coex_sta->force_lps_on = false; - break; - case BTC_PS_LPS_ON: - halbtc8192e1ant_ps_tdma_check_for_power_save_state( - btcoexist, true); - halbtc8192e1ant_lps_rpwm(btcoexist, NORMAL_EXEC, - lps_val, rpwm_val); - /* when coex force to enter LPS, do not enter 32k low power. */ - low_pwr_disable = true; - btcoexist->btc_set(btcoexist, - BTC_SET_ACT_DISABLE_LOW_POWER, - &low_pwr_disable); - /* power save must executed before psTdma. */ - btcoexist->btc_set(btcoexist, BTC_SET_ACT_ENTER_LPS, - NULL); - coex_sta->force_lps_on = true; - break; - case BTC_PS_LPS_OFF: - halbtc8192e1ant_ps_tdma_check_for_power_save_state( - btcoexist, false); - btcoexist->btc_set(btcoexist, BTC_SET_ACT_LEAVE_LPS, - NULL); - coex_sta->force_lps_on = false; - break; - default: - break; - } -} - -void halbtc8192e1ant_action_wifi_only(IN struct btc_coexist *btcoexist) -{ - halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 9); -} - -void halbtc8192e1ant_monitor_bt_enable_disable(IN struct btc_coexist *btcoexist) -{ - static u32 bt_disable_cnt = 0; - boolean bt_active = true, bt_disabled = false; - - /* This function check if bt is disabled */ - - if (coex_sta->high_priority_tx == 0 && - coex_sta->high_priority_rx == 0 && - coex_sta->low_priority_tx == 0 && - coex_sta->low_priority_rx == 0) - bt_active = false; - if (coex_sta->high_priority_tx == 0xffff && - coex_sta->high_priority_rx == 0xffff && - coex_sta->low_priority_tx == 0xffff && - coex_sta->low_priority_rx == 0xffff) - bt_active = false; - if (bt_active) { - bt_disable_cnt = 0; - bt_disabled = false; - btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_DISABLE, - &bt_disabled); - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT is enabled !!\n"); - BTC_TRACE(trace_buf); - } else { - bt_disable_cnt++; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], bt all counters=0, %d times!!\n", - bt_disable_cnt); - BTC_TRACE(trace_buf); - if (bt_disable_cnt >= 2) { - bt_disabled = true; - btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_DISABLE, - &bt_disabled); - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT is disabled !!\n"); - BTC_TRACE(trace_buf); - halbtc8192e1ant_action_wifi_only(btcoexist); - } - } - if (coex_sta->bt_disabled != bt_disabled) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT is from %s to %s!!\n", - (coex_sta->bt_disabled ? "disabled" : "enabled"), - (bt_disabled ? "disabled" : "enabled")); - BTC_TRACE(trace_buf); - coex_sta->bt_disabled = bt_disabled; - if (!bt_disabled) { - } else { - btcoexist->btc_set(btcoexist, BTC_SET_ACT_LEAVE_LPS, - NULL); - btcoexist->btc_set(btcoexist, BTC_SET_ACT_NORMAL_LPS, - NULL); - } - } -} - -/* ********************************************* - * - * Software Coex Mechanism start - * - * ********************************************* */ - -/* SCO only or SCO+PAN(HS) */ - -/* -void halbtc8192e1ant_action_sco(IN struct btc_coexist* btcoexist) -{ - halbtc8192e1ant_sw_mechanism(btcoexist, true); -} - - -void halbtc8192e1ant_action_hid(IN struct btc_coexist* btcoexist) -{ - halbtc8192e1ant_sw_mechanism(btcoexist, true); -} - - -void halbtc8192e1ant_action_a2dp(IN struct btc_coexist* btcoexist) -{ - halbtc8192e1ant_sw_mechanism(btcoexist, false); -} - -void halbtc8192e1ant_action_a2dp_pan_hs(IN struct btc_coexist* btcoexist) -{ - halbtc8192e1ant_sw_mechanism(btcoexist, false); -} - -void halbtc8192e1ant_action_pan_edr(IN struct btc_coexist* btcoexist) -{ - halbtc8192e1ant_sw_mechanism(btcoexist, false); -} - - -void halbtc8192e1ant_action_pan_hs(IN struct btc_coexist* btcoexist) -{ - halbtc8192e1ant_sw_mechanism(btcoexist, false); -} - - -void halbtc8192e1ant_action_pan_edr_a2dp(IN struct btc_coexist* btcoexist) -{ - halbtc8192e1ant_sw_mechanism(btcoexist, false); -} - -void halbtc8192e1ant_action_pan_edr_hid(IN struct btc_coexist* btcoexist) -{ - halbtc8192e1ant_sw_mechanism(btcoexist, true); -} - - -void halbtc8192e1ant_action_hid_a2dp_pan_edr(IN struct btc_coexist* btcoexist) -{ - halbtc8192e1ant_sw_mechanism(btcoexist, true); -} - -void halbtc8192e1ant_action_hid_a2dp(IN struct btc_coexist* btcoexist) -{ - halbtc8192e1ant_sw_mechanism(btcoexist, true); -} - -*/ - -/* ********************************************* - * - * Non-Software Coex Mechanism start - * - * ********************************************* */ -void halbtc8192e1ant_action_wifi_multi_port(IN struct btc_coexist *btcoexist) -{ - halbtc8192e1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0, - 0x0); - - halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8); - halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2); -} - -void halbtc8192e1ant_action_hs(IN struct btc_coexist *btcoexist) -{ - halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 5); - halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2); -} - -void halbtc8192e1ant_action_bt_inquiry(IN struct btc_coexist *btcoexist) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - boolean wifi_connected = false, ap_enable = false, wifi_busy = false, - bt_busy = false; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, - &ap_enable); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bt_busy); - - if ((!wifi_connected) && (!coex_sta->wifi_is_high_pri_task)) { - halbtc8192e1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, - 0x0, 0x0); - halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8); - - halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - } else if ((bt_link_info->sco_exist) || (bt_link_info->hid_exist) || - (bt_link_info->a2dp_exist)) { - /* SCO/HID/A2DP busy */ - halbtc8192e1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, - 0x0, 0x0); - halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32); - - halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); - } else if ((bt_link_info->pan_exist) || (wifi_busy)) { - halbtc8192e1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, - 0x0, 0x0); - halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20); - - halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); - } else { - halbtc8192e1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, - 0x0, 0x0); - halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8); - - halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7); - } -} - -void halbtc8192e1ant_action_bt_sco_hid_only_busy(IN struct btc_coexist - *btcoexist, IN u8 wifi_status) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - boolean wifi_connected = false; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - - /* tdma and coex table */ - - if (bt_link_info->sco_exist) { - halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 5); - halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 5); - } else { /* HID */ - halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 6); - halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 5); - } -} - -void halbtc8192e1ant_action_wifi_connected_bt_acl_busy(IN struct btc_coexist - *btcoexist, IN u8 wifi_status) -{ - u8 bt_rssi_state; - - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - - bt_rssi_state = halbtc8192e1ant_bt_rssi_state(2, 28, 0); - - if ((coex_sta->low_priority_rx >= 1000) && - (coex_sta->low_priority_rx != 65535)) - bt_link_info->slave_role = true; - else - bt_link_info->slave_role = false; - - if (bt_link_info->hid_only) { /* HID */ - halbtc8192e1ant_action_bt_sco_hid_only_busy(btcoexist, - wifi_status); - coex_dm->auto_tdma_adjust = false; - return; - } else if (bt_link_info->a2dp_only) { /* A2DP */ - if (BT_8192E_1ANT_WIFI_STATUS_CONNECTED_IDLE == wifi_status) { - halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 32); - halbtc8192e1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 4); - coex_dm->auto_tdma_adjust = false; - } else { - halbtc8192e1ant_tdma_duration_adjust_for_acl(btcoexist, - wifi_status); -#if 0 - if (coex_sta->cck_lock) - halbtc8192e1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 3); - else -#endif - halbtc8192e1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 4); - coex_dm->auto_tdma_adjust = true; - } - } else if (((bt_link_info->a2dp_exist) && (bt_link_info->pan_exist)) || - (bt_link_info->hid_exist && bt_link_info->a2dp_exist && - bt_link_info->pan_exist)) { /* A2DP+PAN(OPP,FTP), HID+A2DP+PAN(OPP,FTP) */ - halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 13); - halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); - coex_dm->auto_tdma_adjust = false; - } else if (bt_link_info->hid_exist && - bt_link_info->a2dp_exist) { /* HID+A2DP */ - halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 14); - coex_dm->auto_tdma_adjust = false; - - halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 3); - } else if ((bt_link_info->pan_only) || (bt_link_info->hid_exist && - bt_link_info->pan_exist)) { /* PAN(OPP,FTP), HID+PAN(OPP,FTP) */ - halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 3); - halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); - coex_dm->auto_tdma_adjust = false; - } else { - /* BT no-profile busy (0x9) */ - halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32); - halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); - coex_dm->auto_tdma_adjust = false; - } -} - -void halbtc8192e1ant_action_wifi_not_connected(IN struct btc_coexist *btcoexist) -{ - /* power save state */ - halbtc8192e1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0, - 0x0); - - /* tdma and coex table */ - halbtc8192e1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 8); - halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); -} - -void halbtc8192e1ant_action_wifi_not_connected_scan(IN struct btc_coexist - *btcoexist) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - - halbtc8192e1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0, - 0x0); - - /* tdma and coex table */ - if (BT_8192E_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) { - if (bt_link_info->a2dp_exist) { - halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 32); - halbtc8192e1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 4); - } else if (bt_link_info->a2dp_exist && - bt_link_info->pan_exist) { - halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 22); - halbtc8192e1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 4); - } else { - halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 20); - halbtc8192e1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 4); - } - } else if ((BT_8192E_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) || - (BT_8192E_1ANT_BT_STATUS_ACL_SCO_BUSY == - coex_dm->bt_status)) { - halbtc8192e1ant_action_bt_sco_hid_only_busy(btcoexist, - BT_8192E_1ANT_WIFI_STATUS_CONNECTED_SCAN); - } else { - /* Bryant Add */ - halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8); - halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2); - } -} - -void halbtc8192e1ant_action_wifi_not_connected_asso_auth( - IN struct btc_coexist *btcoexist) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - - halbtc8192e1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0, - 0x0); - - /* tdma and coex table */ - if ((bt_link_info->sco_exist) || (bt_link_info->hid_exist) || - (bt_link_info->a2dp_exist)) { - halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32); - halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); - } else if (bt_link_info->pan_exist) { - halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20); - halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); - } else { - halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8); - halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2); - } -} - -void halbtc8192e1ant_action_wifi_connected_scan(IN struct btc_coexist - *btcoexist) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - - halbtc8192e1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0, - 0x0); - - /* tdma and coex table */ - if (BT_8192E_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) { - if (bt_link_info->a2dp_exist) { - halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 32); - halbtc8192e1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 4); - } else if (bt_link_info->a2dp_exist && - bt_link_info->pan_exist) { - halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 22); - halbtc8192e1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 4); - } else { - halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 20); - halbtc8192e1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 4); - } - } else if ((BT_8192E_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) || - (BT_8192E_1ANT_BT_STATUS_ACL_SCO_BUSY == - coex_dm->bt_status)) { - halbtc8192e1ant_action_bt_sco_hid_only_busy(btcoexist, - BT_8192E_1ANT_WIFI_STATUS_CONNECTED_SCAN); - } else { - /* Bryant Add */ - halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8); - halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2); - } -} - -void halbtc8192e1ant_action_wifi_connected_specific_packet( - IN struct btc_coexist *btcoexist) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - - halbtc8192e1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0, - 0x0); - - /* tdma and coex table */ - if ((bt_link_info->sco_exist) || (bt_link_info->hid_exist) || - (bt_link_info->a2dp_exist)) { - halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32); - halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); - } else if (bt_link_info->pan_exist) { - halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20); - halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); - } else { - halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8); - halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2); - } -} - -void halbtc8192e1ant_action_wifi_connected(IN struct btc_coexist *btcoexist) -{ - boolean wifi_busy = false; - boolean scan = false, link = false, roam = false; - boolean under_4way = false, ap_enable = false; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], CoexForWifiConnect()===>\n"); - BTC_TRACE(trace_buf); - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS, - &under_4way); - if (under_4way) { - halbtc8192e1ant_action_wifi_connected_specific_packet(btcoexist); - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], CoexForWifiConnect(), return for wifi is under 4way<===\n"); - BTC_TRACE(trace_buf); - return; - } - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam); - if (scan || link || roam) { - if (scan) - halbtc8192e1ant_action_wifi_connected_scan(btcoexist); - else - halbtc8192e1ant_action_wifi_connected_specific_packet( - btcoexist); - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], CoexForWifiConnect(), return for wifi is under scan<===\n"); - BTC_TRACE(trace_buf); - return; - } - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, - &ap_enable); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - - /* power save state */ - if (!ap_enable && - BT_8192E_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status && - !btcoexist->bt_link_info.hid_only) { - if (btcoexist->bt_link_info.a2dp_only) { /* A2DP */ - if (!wifi_busy) - halbtc8192e1ant_power_save_state(btcoexist, - BTC_PS_WIFI_NATIVE, 0x0, 0x0); - else { /* busy */ - if (coex_sta->scan_ap_num >= - BT_8192E_1ANT_WIFI_NOISY_THRESH) /* no force LPS, no PS-TDMA, use pure TDMA */ - halbtc8192e1ant_power_save_state( - btcoexist, BTC_PS_WIFI_NATIVE, - 0x0, 0x0); - else - halbtc8192e1ant_power_save_state( - btcoexist, BTC_PS_LPS_ON, 0x50, - 0x4); - } - } else if ((coex_sta->pan_exist == false) && - (coex_sta->a2dp_exist == false) && - (coex_sta->hid_exist == false)) - halbtc8192e1ant_power_save_state(btcoexist, - BTC_PS_WIFI_NATIVE, 0x0, 0x0); - else - halbtc8192e1ant_power_save_state(btcoexist, - BTC_PS_LPS_ON, 0x50, 0x4); - } else - halbtc8192e1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, - 0x0, 0x0); - - /* tdma and coex table */ - if (!wifi_busy) { - if (BT_8192E_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) { - halbtc8192e1ant_action_wifi_connected_bt_acl_busy( - btcoexist, - BT_8192E_1ANT_WIFI_STATUS_CONNECTED_IDLE); - } else if ((BT_8192E_1ANT_BT_STATUS_SCO_BUSY == - coex_dm->bt_status) || - (BT_8192E_1ANT_BT_STATUS_ACL_SCO_BUSY == - coex_dm->bt_status)) { - halbtc8192e1ant_action_bt_sco_hid_only_busy(btcoexist, - BT_8192E_1ANT_WIFI_STATUS_CONNECTED_IDLE); - } else { - halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, - 8); - - if ((coex_sta->high_priority_tx) + - (coex_sta->high_priority_rx) <= 60) - halbtc8192e1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 2); - else - halbtc8192e1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 7); - } - } else { - if (BT_8192E_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) { - halbtc8192e1ant_action_wifi_connected_bt_acl_busy( - btcoexist, - BT_8192E_1ANT_WIFI_STATUS_CONNECTED_BUSY); - } else if ((BT_8192E_1ANT_BT_STATUS_SCO_BUSY == - coex_dm->bt_status) || - (BT_8192E_1ANT_BT_STATUS_ACL_SCO_BUSY == - coex_dm->bt_status)) { - halbtc8192e1ant_action_bt_sco_hid_only_busy(btcoexist, - BT_8192E_1ANT_WIFI_STATUS_CONNECTED_BUSY); - } else { - halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, - 8); - - if ((coex_sta->high_priority_tx) + - (coex_sta->high_priority_rx) <= 60) - halbtc8192e1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 2); - else - halbtc8192e1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 7); - } - } -} - -void halbtc8192e1ant_run_sw_coexist_mechanism(IN struct btc_coexist *btcoexist) -{ - u8 algorithm = 0; - - algorithm = halbtc8192e1ant_action_algorithm(btcoexist); - coex_dm->cur_algorithm = algorithm; - - if (halbtc8192e1ant_is_common_action(btcoexist)) { - - } else { - switch (coex_dm->cur_algorithm) { - case BT_8192E_1ANT_COEX_ALGO_SCO: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action algorithm = SCO.\n"); - BTC_TRACE(trace_buf); - /* halbtc8192e1ant_action_sco(btcoexist); */ - break; - case BT_8192E_1ANT_COEX_ALGO_HID: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action algorithm = HID.\n"); - BTC_TRACE(trace_buf); - /* halbtc8192e1ant_action_hid(btcoexist); */ - break; - case BT_8192E_1ANT_COEX_ALGO_A2DP: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action algorithm = A2DP.\n"); - BTC_TRACE(trace_buf); - /* halbtc8192e1ant_action_a2dp(btcoexist); */ - break; - case BT_8192E_1ANT_COEX_ALGO_A2DP_PANHS: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action algorithm = A2DP+PAN(HS).\n"); - BTC_TRACE(trace_buf); - /* halbtc8192e1ant_action_a2dp_pan_hs(btcoexist); */ - break; - case BT_8192E_1ANT_COEX_ALGO_PANEDR: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action algorithm = PAN(EDR).\n"); - BTC_TRACE(trace_buf); - /* halbtc8192e1ant_action_pan_edr(btcoexist); */ - break; - case BT_8192E_1ANT_COEX_ALGO_PANHS: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action algorithm = HS mode.\n"); - BTC_TRACE(trace_buf); - /* halbtc8192e1ant_action_pan_hs(btcoexist); */ - break; - case BT_8192E_1ANT_COEX_ALGO_PANEDR_A2DP: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action algorithm = PAN+A2DP.\n"); - BTC_TRACE(trace_buf); - /* halbtc8192e1ant_action_pan_edr_a2dp(btcoexist); */ - break; - case BT_8192E_1ANT_COEX_ALGO_PANEDR_HID: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action algorithm = PAN(EDR)+HID.\n"); - BTC_TRACE(trace_buf); - /* halbtc8192e1ant_action_pan_edr_hid(btcoexist); */ - break; - case BT_8192E_1ANT_COEX_ALGO_HID_A2DP_PANEDR: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action algorithm = HID+A2DP+PAN.\n"); - BTC_TRACE(trace_buf); - /* halbtc8192e1ant_action_hid_a2dp_pan_edr(btcoexist); */ - break; - case BT_8192E_1ANT_COEX_ALGO_HID_A2DP: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action algorithm = HID+A2DP.\n"); - BTC_TRACE(trace_buf); - /* halbtc8192e1ant_action_hid_a2dp(btcoexist); */ - break; - default: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action algorithm = coexist All Off!!\n"); - BTC_TRACE(trace_buf); - /* halbtc8192e1ant_coex_all_off(btcoexist); */ - break; - } - coex_dm->pre_algorithm = coex_dm->cur_algorithm; - } -} - -void halbtc8192e1ant_run_coexist_mechanism(IN struct btc_coexist *btcoexist) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - boolean wifi_connected = false, bt_hs_on = false; - boolean increase_scan_dev_num = false; - boolean bt_ctrl_agg_buf_size = false; - boolean miracast_plus_bt = false; - u8 agg_buf_size = 5; - u32 wifi_link_status = 0; - u32 num_of_wifi_link = 0; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], RunCoexistMechanism()===>\n"); - BTC_TRACE(trace_buf); - - if (btcoexist->manual_control) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], RunCoexistMechanism(), return for Manual CTRL <===\n"); - BTC_TRACE(trace_buf); - return; - } - - if (btcoexist->stop_coex_dm) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], RunCoexistMechanism(), return for Stop Coex DM <===\n"); - BTC_TRACE(trace_buf); - return; - } - - if (coex_sta->under_ips) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], wifi is under IPS !!!\n"); - BTC_TRACE(trace_buf); - return; - } - - if ((BT_8192E_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) || - (BT_8192E_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) || - (BT_8192E_1ANT_BT_STATUS_ACL_SCO_BUSY == coex_dm->bt_status)) - increase_scan_dev_num = true; - - btcoexist->btc_set(btcoexist, BTC_SET_BL_INC_SCAN_DEV_NUM, - &increase_scan_dev_num); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS, - &wifi_link_status); - num_of_wifi_link = wifi_link_status >> 16; - - if ((num_of_wifi_link >= 2) || - (wifi_link_status & WIFI_P2P_GO_CONNECTED)) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "############# [BTCoex], Multi-Port num_of_wifi_link = %d, wifi_link_status = 0x%x\n", - num_of_wifi_link, wifi_link_status); - BTC_TRACE(trace_buf); - - if (bt_link_info->bt_link_exist) { - halbtc8192e1ant_limited_tx(btcoexist, NORMAL_EXEC, 1, 1, - 0, 1); - miracast_plus_bt = true; - } else { - halbtc8192e1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, - 0, 0); - miracast_plus_bt = false; - } - btcoexist->btc_set(btcoexist, BTC_SET_BL_MIRACAST_PLUS_BT, - &miracast_plus_bt); - halbtc8192e1ant_limited_rx(btcoexist, NORMAL_EXEC, false, - bt_ctrl_agg_buf_size, agg_buf_size); - - if ((bt_link_info->a2dp_exist) && - (coex_sta->c2h_bt_inquiry_page)) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "############# [BTCoex], BT Is Inquirying\n"); - BTC_TRACE(trace_buf); - halbtc8192e1ant_action_bt_inquiry(btcoexist); - } else - halbtc8192e1ant_action_wifi_multi_port(btcoexist); - - return; - } - - miracast_plus_bt = false; - btcoexist->btc_set(btcoexist, BTC_SET_BL_MIRACAST_PLUS_BT, - &miracast_plus_bt); - - if ((bt_link_info->bt_link_exist) && (wifi_connected)) { - halbtc8192e1ant_limited_tx(btcoexist, NORMAL_EXEC, 1, 1, 0, 1); - - if (bt_link_info->sco_exist) - halbtc8192e1ant_limited_rx(btcoexist, NORMAL_EXEC, - false, true, 0x5); - else - halbtc8192e1ant_limited_rx(btcoexist, NORMAL_EXEC, - false, true, 0x8); - - halbtc8192e1ant_sw_mechanism(btcoexist, true); - halbtc8192e1ant_run_sw_coexist_mechanism( - btcoexist); /* just print debug message */ - } else { - halbtc8192e1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0); - - halbtc8192e1ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, - 0x5); - - halbtc8192e1ant_sw_mechanism(btcoexist, false); - halbtc8192e1ant_run_sw_coexist_mechanism( - btcoexist); /* just print debug message */ - } - - btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); - if (coex_sta->c2h_bt_inquiry_page) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "############# [BTCoex], BT Is Inquirying\n"); - BTC_TRACE(trace_buf); - halbtc8192e1ant_action_bt_inquiry(btcoexist); - return; - } else if (bt_hs_on) { - halbtc8192e1ant_action_hs(btcoexist); - return; - } - - - if (!wifi_connected) { - boolean scan = false, link = false, roam = false; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], wifi is non connected-idle !!!\n"); - BTC_TRACE(trace_buf); - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam); - - if (scan || link || roam) { - if (scan) - halbtc8192e1ant_action_wifi_not_connected_scan( - btcoexist); - else - halbtc8192e1ant_action_wifi_not_connected_asso_auth( - btcoexist); - } else - halbtc8192e1ant_action_wifi_not_connected(btcoexist); - } else /* wifi LPS/Busy */ - halbtc8192e1ant_action_wifi_connected(btcoexist); -} - -void halbtc8192e1ant_init_coex_dm(IN struct btc_coexist *btcoexist) -{ - /* force to reset coex mechanism */ - - /* sw all off */ - halbtc8192e1ant_sw_mechanism(btcoexist, false); - - /* halbtc8192e1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 8); */ - halbtc8192e1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 0); - - coex_sta->pop_event_cnt = 0; -} - -void halbtc8192e1ant_init_hw_config(IN struct btc_coexist *btcoexist, - IN boolean wifi_only) -{ - u16 u16tmp = 0; - u8 u8tmp = 0; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], 1Ant Init HW Config!!\n"); - BTC_TRACE(trace_buf); - - /* antenna sw ctrl to bt */ - halbtc8192e1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT, true, false); - - halbtc8192e1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 0); - - /* antenna switch control parameter */ - btcoexist->btc_write_4byte(btcoexist, 0x858, 0x55555555); - - /* coex parameters */ - btcoexist->btc_write_1byte(btcoexist, 0x778, 0x1); - /* 0x790[5:0]=0x5 */ - u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x790); - u8tmp &= 0xc0; - u8tmp |= 0x5; - btcoexist->btc_write_1byte(btcoexist, 0x790, u8tmp); - - /* enable counter statistics */ - btcoexist->btc_write_1byte(btcoexist, 0x76e, 0x4); - - /* enable PTA */ - btcoexist->btc_write_1byte(btcoexist, 0x40, 0x20); - /* enable mailbox interface */ - u16tmp = btcoexist->btc_read_2byte(btcoexist, 0x40); - u16tmp |= BIT(9); - btcoexist->btc_write_2byte(btcoexist, 0x40, u16tmp); - - /* enable PTA I2C mailbox */ - u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x101); - u8tmp |= BIT(4); - btcoexist->btc_write_1byte(btcoexist, 0x101, u8tmp); - - /* enable bt clock when wifi is disabled. */ - u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x93); - u8tmp |= BIT(0); - btcoexist->btc_write_1byte(btcoexist, 0x93, u8tmp); - /* enable bt clock when suspend. */ - u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x7); - u8tmp |= BIT(0); - btcoexist->btc_write_1byte(btcoexist, 0x7, u8tmp); -} - - -/* -void halbtc8192e1ant_wifi_off_hw_cfg(IN struct btc_coexist* btcoexist) -{ - - -} -*/ - -/* ************************************************************ - * work around function start with wa_halbtc8192e1ant_ - * ************************************************************ - * ************************************************************ - * extern function start with ex_halbtc8192e1ant_ - * ************************************************************ */ -void ex_halbtc8192e1ant_power_on_setting(IN struct btc_coexist *btcoexist) -{ -#if 0 - struct btc_board_info *board_info = &btcoexist->board_info; - u8 u8tmp = 0x0; - u16 u16tmp = 0x0; - - btcoexist->stop_coex_dm = true; - - btcoexist->btc_write_1byte(btcoexist, 0x67, 0x20); - - /* enable BB, REG_SYS_FUNC_EN such that we can write 0x948 correctly. */ - u16tmp = btcoexist->btc_read_2byte(btcoexist, 0x2); - btcoexist->btc_write_2byte(btcoexist, 0x2, u16tmp | BIT(0) | BIT(1)); - - /* set GRAN_BT = 1 */ - btcoexist->btc_write_1byte(btcoexist, 0x765, 0x18); - /* set WLAN_ACT = 0 */ - btcoexist->btc_write_1byte(btcoexist, 0x76e, 0x4); - - /* */ - /* S0 or S1 setting and Local register setting(By the setting fw can get ant number, S0/S1, ... info) */ - /* Local setting bit define */ - /* BIT0: "0" for no antenna inverse; "1" for antenna inverse */ - /* BIT1: "0" for internal switch; "1" for external switch */ - /* BIT2: "0" for one antenna; "1" for two antenna */ - /* NOTE: here default all internal switch and 1-antenna ==> BIT1=0 and BIT2=0 */ - if (btcoexist->chip_interface == BTC_INTF_USB) { - /* fixed at S0 for USB interface */ - btcoexist->btc_write_4byte(btcoexist, 0x948, 0x0); - - u8tmp |= 0x1; /* antenna inverse */ - btcoexist->btc_write_local_reg_1byte(btcoexist, 0xfe08, u8tmp); - - board_info->btdm_ant_pos = BTC_ANTENNA_AT_AUX_PORT; - } else { - /* for PCIE and SDIO interface, we check efuse 0xc3[6] */ - if (board_info->single_ant_path == 0) { - /* set to S1 */ - btcoexist->btc_write_4byte(btcoexist, 0x948, 0x280); - board_info->btdm_ant_pos = BTC_ANTENNA_AT_MAIN_PORT; - } else if (board_info->single_ant_path == 1) { - /* set to S0 */ - btcoexist->btc_write_4byte(btcoexist, 0x948, 0x0); - u8tmp |= 0x1; /* antenna inverse */ - board_info->btdm_ant_pos = BTC_ANTENNA_AT_AUX_PORT; - } - - if (btcoexist->chip_interface == BTC_INTF_PCI) - btcoexist->btc_write_local_reg_1byte(btcoexist, 0x384, - u8tmp); - else if (btcoexist->chip_interface == BTC_INTF_SDIO) - btcoexist->btc_write_local_reg_1byte(btcoexist, 0x60, - u8tmp); - } -#endif -} - -void ex_halbtc8192e1ant_pre_load_firmware(IN struct btc_coexist *btcoexist) -{ -} - -void ex_halbtc8192e1ant_init_hw_config(IN struct btc_coexist *btcoexist, - IN boolean wifi_only) -{ - halbtc8192e1ant_init_hw_config(btcoexist, wifi_only); - btcoexist->stop_coex_dm = false; -} - -void ex_halbtc8192e1ant_init_coex_dm(IN struct btc_coexist *btcoexist) -{ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Coex Mechanism Init!!\n"); - BTC_TRACE(trace_buf); - - btcoexist->stop_coex_dm = false; - - halbtc8192e1ant_init_coex_dm(btcoexist); - - halbtc8192e1ant_query_bt_info(btcoexist); -} - -void ex_halbtc8192e1ant_display_coex_info(IN struct btc_coexist *btcoexist) -{ - struct btc_board_info *board_info = &btcoexist->board_info; - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - u8 *cli_buf = btcoexist->cli_buf; - u8 u8tmp[4], i, bt_info_ext, ps_tdma_case = 0; - u32 u32tmp[4]; - u32 fw_ver = 0, bt_patch_ver = 0; - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n ============[BT Coexist info]============"); - CL_PRINTF(cli_buf); - - if (btcoexist->manual_control) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n ============[Under Manual Control]============"); - CL_PRINTF(cli_buf); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n =========================================="); - CL_PRINTF(cli_buf); - } - if (btcoexist->stop_coex_dm) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n ============[Coex is STOPPED]============"); - CL_PRINTF(cli_buf); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n =========================================="); - CL_PRINTF(cli_buf); - } - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d ", - "Ant PG number/ Ant mechanism:", - board_info->pg_ant_num, board_info->btdm_ant_num); - CL_PRINTF(cli_buf); - - btcoexist->btc_get(btcoexist, BTC_GET_U4_BT_PATCH_VER, &bt_patch_ver); - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, &fw_ver); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %d_%d/ 0x%x/ 0x%x(%d)", - "CoexVer/ FwVer/ PatchVer", - glcoex_ver_date_8192e_1ant, glcoex_ver_8192e_1ant, fw_ver, - bt_patch_ver, bt_patch_ver); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x ", - "Wifi channel informed to BT", - coex_dm->wifi_chnl_info[0], coex_dm->wifi_chnl_info[1], - coex_dm->wifi_chnl_info[2]); - CL_PRINTF(cli_buf); - - /* wifi status */ - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s", - "============[Wifi Status]============"); - CL_PRINTF(cli_buf); - btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_WIFI_STATUS); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s", - "============[BT Status]============"); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = [%s/ %d/ %d] ", - "BT [status/ rssi/ retryCnt]", - ((coex_sta->bt_disabled) ? ("disabled") : (( - coex_sta->c2h_bt_inquiry_page) ? ("inquiry/page scan") - : ((BT_8192E_1ANT_BT_STATUS_NON_CONNECTED_IDLE == - coex_dm->bt_status) ? "non-connected idle" : - ((BT_8192E_1ANT_BT_STATUS_CONNECTED_IDLE == coex_dm->bt_status) - ? "connected-idle" : "busy")))), - coex_sta->bt_rssi, coex_sta->bt_retry_cnt); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d / %d / %d", - "SCO/HID/PAN/A2DP", - bt_link_info->sco_exist, bt_link_info->hid_exist, - bt_link_info->pan_exist, bt_link_info->a2dp_exist); - CL_PRINTF(cli_buf); - btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_BT_LINK_INFO); - - bt_info_ext = coex_sta->bt_info_ext; - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s", - "BT Info A2DP rate", - (bt_info_ext & BIT(0)) ? "Basic rate" : "EDR rate"); - CL_PRINTF(cli_buf); - - for (i = 0; i < BT_INFO_SRC_8192E_1ANT_MAX; i++) { - if (coex_sta->bt_info_c2h_cnt[i]) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %02x %02x %02x %02x %02x %02x %02x(%d)", - glbt_info_src_8192e_1ant[i], - coex_sta->bt_info_c2h[i][0], - coex_sta->bt_info_c2h[i][1], - coex_sta->bt_info_c2h[i][2], - coex_sta->bt_info_c2h[i][3], - coex_sta->bt_info_c2h[i][4], - coex_sta->bt_info_c2h[i][5], - coex_sta->bt_info_c2h[i][6], - coex_sta->bt_info_c2h_cnt[i]); - CL_PRINTF(cli_buf); - } - } - - if (!btcoexist->manual_control) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s", - "============[mechanisms]============"); - CL_PRINTF(cli_buf); - - ps_tdma_case = coex_dm->cur_ps_tdma; - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %02x %02x %02x %02x %02x case-%d (auto:%d)", - "PS TDMA", - coex_dm->ps_tdma_para[0], coex_dm->ps_tdma_para[1], - coex_dm->ps_tdma_para[2], coex_dm->ps_tdma_para[3], - coex_dm->ps_tdma_para[4], ps_tdma_case, - coex_dm->auto_tdma_adjust); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x ", - "Latest error condition(should be 0)", - coex_dm->error_condition); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d ", - "IgnWlanAct", - coex_dm->cur_ignore_wlan_act); - CL_PRINTF(cli_buf); - } - - /* Hw setting */ - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s", - "============[Hw setting]============"); - CL_PRINTF(cli_buf); - - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xc04); - u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0xd04); - u32tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0x90c); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", - "0xc04/ 0xd04/ 0x90c", - u32tmp[0], u32tmp[1], u32tmp[2]); - CL_PRINTF(cli_buf); - - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x778); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0x778", - u8tmp[0]); - CL_PRINTF(cli_buf); - - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x92c); - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x930); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", - "0x92c/ 0x930", - (u8tmp[0]), u32tmp[0]); - CL_PRINTF(cli_buf); - - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x40); - u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0x4f); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", - "0x40/ 0x4f", - u8tmp[0], u8tmp[1]); - CL_PRINTF(cli_buf); - - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x550); - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x522); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", - "0x550(bcn ctrl)/0x522", - u32tmp[0], u8tmp[0]); - CL_PRINTF(cli_buf); - - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xc50); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0xc50(dig)", - u32tmp[0]); - CL_PRINTF(cli_buf); - - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x6c0); - u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x6c4); - u32tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0x6c8); - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x6cc); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", - "0x6c0/0x6c4/0x6c8/0x6cc(coexTable)", - u32tmp[0], u32tmp[1], u32tmp[2], u8tmp[0]); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", - "0x770(hp rx[31:16]/tx[15:0])", - coex_sta->high_priority_rx, coex_sta->high_priority_tx); - CL_PRINTF(cli_buf); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", - "0x774(lp rx[31:16]/tx[15:0])", - coex_sta->low_priority_rx, coex_sta->low_priority_tx); - CL_PRINTF(cli_buf); -#if (BT_AUTO_REPORT_ONLY_8192E_1ANT == 1) - halbtc8192e1ant_monitor_bt_ctr(btcoexist); -#endif - - btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_COEX_STATISTICS); -} - -void ex_halbtc8192e1ant_ips_notify(IN struct btc_coexist *btcoexist, IN u8 type) -{ - if (btcoexist->manual_control || btcoexist->stop_coex_dm) - return; - - if (BTC_IPS_ENTER == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], IPS ENTER notify\n"); - BTC_TRACE(trace_buf); - coex_sta->under_ips = true; - - halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); - halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - halbtc8192e1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT, false, - true); - } else if (BTC_IPS_LEAVE == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], IPS LEAVE notify\n"); - BTC_TRACE(trace_buf); - coex_sta->under_ips = false; - - halbtc8192e1ant_init_hw_config(btcoexist, false); - halbtc8192e1ant_init_coex_dm(btcoexist); - halbtc8192e1ant_query_bt_info(btcoexist); - } -} - -void ex_halbtc8192e1ant_lps_notify(IN struct btc_coexist *btcoexist, IN u8 type) -{ - if (btcoexist->manual_control || btcoexist->stop_coex_dm) - return; - - if (BTC_LPS_ENABLE == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], LPS ENABLE notify\n"); - BTC_TRACE(trace_buf); - coex_sta->under_lps = true; - } else if (BTC_LPS_DISABLE == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], LPS DISABLE notify\n"); - BTC_TRACE(trace_buf); - coex_sta->under_lps = false; - } -} - -void ex_halbtc8192e1ant_scan_notify(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - boolean wifi_connected = false, bt_hs_on = false; - u32 wifi_link_status = 0; - u32 num_of_wifi_link = 0; - boolean bt_ctrl_agg_buf_size = false; - u8 agg_buf_size = 5; - - u8 u8tmpa, u8tmpb; - u32 u32tmp; - - if (btcoexist->manual_control || - btcoexist->stop_coex_dm) - return; - - if (BTC_SCAN_START == type) { - coex_sta->wifi_is_high_pri_task = true; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCAN START notify\n"); - BTC_TRACE(trace_buf); - - halbtc8192e1ant_ps_tdma(btcoexist, FORCE_EXEC, false, - 8); /* Force antenna setup for no scan result issue */ - u32tmp = btcoexist->btc_read_4byte(btcoexist, 0x948); - u8tmpa = btcoexist->btc_read_1byte(btcoexist, 0x765); - u8tmpb = btcoexist->btc_read_1byte(btcoexist, 0x67); - - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], 0x948=0x%x, 0x765=0x%x, 0x67=0x%x\n", - u32tmp, u8tmpa, u8tmpb); - BTC_TRACE(trace_buf); - } else { - coex_sta->wifi_is_high_pri_task = false; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCAN FINISH notify\n"); - BTC_TRACE(trace_buf); - - btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM, - &coex_sta->scan_ap_num); - } - - if (coex_sta->bt_disabled) - return; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - - halbtc8192e1ant_query_bt_info(btcoexist); - - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS, - &wifi_link_status); - num_of_wifi_link = wifi_link_status >> 16; - if (num_of_wifi_link >= 2) { - halbtc8192e1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0); - halbtc8192e1ant_limited_rx(btcoexist, NORMAL_EXEC, false, - bt_ctrl_agg_buf_size, agg_buf_size); - halbtc8192e1ant_action_wifi_multi_port(btcoexist); - return; - } - - if (coex_sta->c2h_bt_inquiry_page) { - halbtc8192e1ant_action_bt_inquiry(btcoexist); - return; - } else if (bt_hs_on) { - halbtc8192e1ant_action_hs(btcoexist); - return; - } - - if (BTC_SCAN_START == type) { - if (!wifi_connected) /* non-connected scan */ - halbtc8192e1ant_action_wifi_not_connected_scan( - btcoexist); - else /* wifi is connected */ - halbtc8192e1ant_action_wifi_connected_scan(btcoexist); - } else if (BTC_SCAN_FINISH == type) { - if (!wifi_connected) /* non-connected scan */ - halbtc8192e1ant_action_wifi_not_connected(btcoexist); - else - halbtc8192e1ant_action_wifi_connected(btcoexist); - } -} - -void ex_halbtc8192e1ant_connect_notify(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - boolean wifi_connected = false, bt_hs_on = false; - u32 wifi_link_status = 0; - u32 num_of_wifi_link = 0; - boolean bt_ctrl_agg_buf_size = false; - u8 agg_buf_size = 5; - - if (btcoexist->manual_control || - btcoexist->stop_coex_dm || - coex_sta->bt_disabled) - return; - - if (BTC_ASSOCIATE_START == type) { - coex_sta->wifi_is_high_pri_task = true; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], CONNECT START notify\n"); - BTC_TRACE(trace_buf); - coex_dm->arp_cnt = 0; - } else { - coex_sta->wifi_is_high_pri_task = false; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], CONNECT FINISH notify\n"); - BTC_TRACE(trace_buf); - /* coex_dm->arp_cnt = 0; */ - } - - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS, - &wifi_link_status); - num_of_wifi_link = wifi_link_status >> 16; - if (num_of_wifi_link >= 2) { - halbtc8192e1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0); - halbtc8192e1ant_limited_rx(btcoexist, NORMAL_EXEC, false, - bt_ctrl_agg_buf_size, agg_buf_size); - halbtc8192e1ant_action_wifi_multi_port(btcoexist); - return; - } - - btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); - if (coex_sta->c2h_bt_inquiry_page) { - halbtc8192e1ant_action_bt_inquiry(btcoexist); - return; - } else if (bt_hs_on) { - halbtc8192e1ant_action_hs(btcoexist); - return; - } - - if (BTC_ASSOCIATE_START == type) - halbtc8192e1ant_action_wifi_not_connected_asso_auth(btcoexist); - else if (BTC_ASSOCIATE_FINISH == type) { - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - if (!wifi_connected) /* non-connected scan */ - halbtc8192e1ant_action_wifi_not_connected(btcoexist); - else - halbtc8192e1ant_action_wifi_connected(btcoexist); - } -} - -void ex_halbtc8192e1ant_media_status_notify(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - u8 h2c_parameter[3] = {0}; - u32 wifi_bw; - u8 wifi_central_chnl; - boolean wifi_under_b_mode = false; - - if (btcoexist->manual_control || - btcoexist->stop_coex_dm || - coex_sta->bt_disabled) - return; - - if (BTC_MEDIA_CONNECT == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], MEDIA connect notify\n"); - BTC_TRACE(trace_buf); - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_B_MODE, - &wifi_under_b_mode); - - /* Set CCK Tx/Rx high Pri except 11b mode */ - if (wifi_under_b_mode) { - btcoexist->btc_write_1byte(btcoexist, 0x6cd, - 0x00); /* CCK Tx */ - btcoexist->btc_write_1byte(btcoexist, 0x6cf, - 0x00); /* CCK Rx */ - } else { - btcoexist->btc_write_1byte(btcoexist, 0x6cd, - 0x10); /* CCK Tx */ - btcoexist->btc_write_1byte(btcoexist, 0x6cf, - 0x10); /* CCK Rx */ - } - - coex_dm->backup_arfr_cnt1 = btcoexist->btc_read_4byte(btcoexist, - 0x430); - coex_dm->backup_arfr_cnt2 = btcoexist->btc_read_4byte(btcoexist, - 0x434); - coex_dm->backup_retry_limit = btcoexist->btc_read_2byte( - btcoexist, 0x42a); - coex_dm->backup_ampdu_max_time = btcoexist->btc_read_1byte( - btcoexist, 0x456); - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], MEDIA disconnect notify\n"); - BTC_TRACE(trace_buf); - coex_dm->arp_cnt = 0; - - btcoexist->btc_write_1byte(btcoexist, 0x6cd, 0x0); /* CCK Tx */ - btcoexist->btc_write_1byte(btcoexist, 0x6cf, 0x0); /* CCK Rx */ - } - - /* only 2.4G we need to inform bt the chnl mask */ - btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_CENTRAL_CHNL, - &wifi_central_chnl); - if ((BTC_MEDIA_CONNECT == type) && - (wifi_central_chnl <= 14)) { - /* h2c_parameter[0] = 0x1; */ - h2c_parameter[0] = 0x0; - h2c_parameter[1] = wifi_central_chnl; - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw); - if (BTC_WIFI_BW_HT40 == wifi_bw) - h2c_parameter[2] = 0x30; - else - h2c_parameter[2] = 0x20; - } - - coex_dm->wifi_chnl_info[0] = h2c_parameter[0]; - coex_dm->wifi_chnl_info[1] = h2c_parameter[1]; - coex_dm->wifi_chnl_info[2] = h2c_parameter[2]; - - btcoexist->btc_fill_h2c(btcoexist, 0x66, 3, h2c_parameter); -} - -void ex_halbtc8192e1ant_specific_packet_notify(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - boolean bt_hs_on = false; - u32 wifi_link_status = 0; - u32 num_of_wifi_link = 0; - boolean bt_ctrl_agg_buf_size = false; - u8 agg_buf_size = 5; - - if (btcoexist->manual_control || - btcoexist->stop_coex_dm || - coex_sta->bt_disabled) - return; - - if (BTC_PACKET_DHCP == type || - BTC_PACKET_EAPOL == type || - BTC_PACKET_ARP == type) { - if (BTC_PACKET_ARP == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], specific Packet ARP notify\n"); - BTC_TRACE(trace_buf); - - coex_dm->arp_cnt++; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ARP Packet Count = %d\n", - coex_dm->arp_cnt); - BTC_TRACE(trace_buf); - - if (coex_dm->arp_cnt >= - 10) /* if APR PKT > 10 after connect, do not go to ActionWifiConnectedSpecificPacket(btcoexist) */ - coex_sta->wifi_is_high_pri_task = false; - else - coex_sta->wifi_is_high_pri_task = true; - } else { - coex_sta->wifi_is_high_pri_task = true; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], specific Packet DHCP or EAPOL notify\n"); - BTC_TRACE(trace_buf); - } - } else { - coex_sta->wifi_is_high_pri_task = false; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], specific Packet [Type = %d] notify\n", type); - BTC_TRACE(trace_buf); - } - - coex_sta->specific_pkt_period_cnt = 0; - - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS, - &wifi_link_status); - num_of_wifi_link = wifi_link_status >> 16; - if (num_of_wifi_link >= 2) { - halbtc8192e1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0); - halbtc8192e1ant_limited_rx(btcoexist, NORMAL_EXEC, false, - bt_ctrl_agg_buf_size, agg_buf_size); - halbtc8192e1ant_action_wifi_multi_port(btcoexist); - return; - } - - btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); - if (coex_sta->c2h_bt_inquiry_page) { - halbtc8192e1ant_action_bt_inquiry(btcoexist); - return; - } else if (bt_hs_on) { - halbtc8192e1ant_action_hs(btcoexist); - return; - } - - if (BTC_PACKET_DHCP == type || - BTC_PACKET_EAPOL == type || - ((BTC_PACKET_ARP == type) && (coex_sta->wifi_is_high_pri_task))) - halbtc8192e1ant_action_wifi_connected_specific_packet(btcoexist); -} - -void ex_halbtc8192e1ant_bt_info_notify(IN struct btc_coexist *btcoexist, - IN u8 *tmp_buf, IN u8 length) -{ - u8 bt_info = 0; - u8 i, rsp_source = 0; - boolean wifi_connected = false; - boolean bt_busy = false; - - coex_sta->c2h_bt_info_req_sent = false; - - rsp_source = tmp_buf[0] & 0xf; - if (rsp_source >= BT_INFO_SRC_8192E_1ANT_MAX) - rsp_source = BT_INFO_SRC_8192E_1ANT_WIFI_FW; - coex_sta->bt_info_c2h_cnt[rsp_source]++; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Bt info[%d], length=%d, hex data=[", rsp_source, - length); - BTC_TRACE(trace_buf); - for (i = 0; i < length; i++) { - coex_sta->bt_info_c2h[rsp_source][i] = tmp_buf[i]; - if (i == 1) - bt_info = tmp_buf[i]; - if (i == length - 1) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "0x%02x]\n", - tmp_buf[i]); - BTC_TRACE(trace_buf); - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "0x%02x, ", - tmp_buf[i]); - BTC_TRACE(trace_buf); - } - } - - if (BT_INFO_SRC_8192E_1ANT_WIFI_FW != rsp_source) { - coex_sta->bt_retry_cnt = /* [3:0] */ - coex_sta->bt_info_c2h[rsp_source][2] & 0xf; - - if (coex_sta->bt_retry_cnt >= 1) - coex_sta->pop_event_cnt++; - - if (coex_sta->bt_info_c2h[rsp_source][2] & 0x20) - coex_sta->c2h_bt_page = true; - else - coex_sta->c2h_bt_page = false; - - coex_sta->bt_rssi = - coex_sta->bt_info_c2h[rsp_source][3] * 2 - 90; - /* coex_sta->bt_info_c2h[rsp_source][3]*2+10; */ - - coex_sta->bt_info_ext = - coex_sta->bt_info_c2h[rsp_source][4]; - - coex_sta->bt_tx_rx_mask = (coex_sta->bt_info_c2h[rsp_source][2] - & 0x40); - btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TX_RX_MASK, - &coex_sta->bt_tx_rx_mask); - if (!coex_sta->bt_tx_rx_mask) { - /* BT into is responded by BT FW and BT RF REG 0x3C != 0x15 => Need to switch BT TRx Mask */ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Switch BT TRx Mask since BT RF REG 0x3C != 0x15\n"); - BTC_TRACE(trace_buf); - btcoexist->btc_set_bt_reg(btcoexist, BTC_BT_REG_RF, - 0x3c, 0x15); - } - - /* Here we need to resend some wifi info to BT */ - /* because bt is reset and loss of the info. */ - if (coex_sta->bt_info_ext & BIT(1)) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT ext info bit1 check, send wifi BW&Chnl to BT!!\n"); - BTC_TRACE(trace_buf); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - if (wifi_connected) - ex_halbtc8192e1ant_media_status_notify( - btcoexist, BTC_MEDIA_CONNECT); - else - ex_halbtc8192e1ant_media_status_notify( - btcoexist, BTC_MEDIA_DISCONNECT); - } - - if (coex_sta->bt_info_ext & BIT(3)) { - if (!btcoexist->manual_control && - !btcoexist->stop_coex_dm) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT ext info bit3 check, set BT NOT to ignore Wlan active!!\n"); - BTC_TRACE(trace_buf); - halbtc8192e1ant_ignore_wlan_act(btcoexist, - FORCE_EXEC, false); - } - } else { - /* BT already NOT ignore Wlan active, do nothing here. */ - } -#if (BT_AUTO_REPORT_ONLY_8192E_1ANT == 0) - if ((coex_sta->bt_info_ext & BIT(4))) { - /* BT auto report already enabled, do nothing */ - } else - halbtc8192e1ant_bt_auto_report(btcoexist, FORCE_EXEC, - true); -#endif - } - - /* check BIT2 first ==> check if bt is under inquiry or page scan */ - if (bt_info & BT_INFO_8192E_1ANT_B_INQ_PAGE) - coex_sta->c2h_bt_inquiry_page = true; - else - coex_sta->c2h_bt_inquiry_page = false; - - /* set link exist status */ - if (!(bt_info & BT_INFO_8192E_1ANT_B_CONNECTION)) { - coex_sta->bt_link_exist = false; - coex_sta->pan_exist = false; - coex_sta->a2dp_exist = false; - coex_sta->hid_exist = false; - coex_sta->sco_exist = false; - } else { /* connection exists */ - coex_sta->bt_link_exist = true; - if (bt_info & BT_INFO_8192E_1ANT_B_FTP) - coex_sta->pan_exist = true; - else - coex_sta->pan_exist = false; - if (bt_info & BT_INFO_8192E_1ANT_B_A2DP) - coex_sta->a2dp_exist = true; - else - coex_sta->a2dp_exist = false; - if (bt_info & BT_INFO_8192E_1ANT_B_HID) - coex_sta->hid_exist = true; - else - coex_sta->hid_exist = false; - if (bt_info & BT_INFO_8192E_1ANT_B_SCO_ESCO) - coex_sta->sco_exist = true; - else - coex_sta->sco_exist = false; - } - - halbtc8192e1ant_update_bt_link_info(btcoexist); - - bt_info = bt_info & - 0x1f; /* mask profile bit for connect-ilde identification ( for CSR case: A2DP idle --> 0x41) */ - - if (!(bt_info & BT_INFO_8192E_1ANT_B_CONNECTION)) { - coex_dm->bt_status = BT_8192E_1ANT_BT_STATUS_NON_CONNECTED_IDLE; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), BT Non-Connected idle!!!\n"); - BTC_TRACE(trace_buf); - } else if (bt_info == - BT_INFO_8192E_1ANT_B_CONNECTION) { /* connection exists but no busy */ - coex_dm->bt_status = BT_8192E_1ANT_BT_STATUS_CONNECTED_IDLE; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), BT Connected-idle!!!\n"); - BTC_TRACE(trace_buf); - } else if ((bt_info & BT_INFO_8192E_1ANT_B_SCO_ESCO) || - (bt_info & BT_INFO_8192E_1ANT_B_SCO_BUSY)) { - coex_dm->bt_status = BT_8192E_1ANT_BT_STATUS_SCO_BUSY; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), BT SCO busy!!!\n"); - BTC_TRACE(trace_buf); - } else if (bt_info & BT_INFO_8192E_1ANT_B_ACL_BUSY) { - if (BT_8192E_1ANT_BT_STATUS_ACL_BUSY != coex_dm->bt_status) - coex_dm->auto_tdma_adjust = false; - coex_dm->bt_status = BT_8192E_1ANT_BT_STATUS_ACL_BUSY; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), BT ACL busy!!!\n"); - BTC_TRACE(trace_buf); - } else { - coex_dm->bt_status = BT_8192E_1ANT_BT_STATUS_MAX; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), BT Non-Defined state!!!\n"); - BTC_TRACE(trace_buf); - } - - if ((BT_8192E_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) || - (BT_8192E_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) || - (BT_8192E_1ANT_BT_STATUS_ACL_SCO_BUSY == coex_dm->bt_status)) - bt_busy = true; - else - bt_busy = false; - btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bt_busy); - - halbtc8192e1ant_run_coexist_mechanism(btcoexist); -} - -void ex_halbtc8192e1ant_rf_status_notify(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - u32 u32tmp; - u8 u8tmpa, u8tmpb, u8tmpc; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], RF Status notify\n"); - BTC_TRACE(trace_buf); - - if (BTC_RF_ON == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], RF is turned ON!!\n"); - BTC_TRACE(trace_buf); - btcoexist->stop_coex_dm = false; - } else if (BTC_RF_OFF == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], RF is turned OFF!!\n"); - BTC_TRACE(trace_buf); - - halbtc8192e1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, - 0x0, 0x0); - halbtc8192e1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 0); - halbtc8192e1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT, false, - true); - - halbtc8192e1ant_ignore_wlan_act(btcoexist, FORCE_EXEC, true); - btcoexist->stop_coex_dm = true; - - u32tmp = btcoexist->btc_read_4byte(btcoexist, 0x948); - u8tmpa = btcoexist->btc_read_1byte(btcoexist, 0x765); - u8tmpb = btcoexist->btc_read_1byte(btcoexist, 0x67); - u8tmpc = btcoexist->btc_read_1byte(btcoexist, 0x76e); - - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "############# [BTCoex], 0x948=0x%x, 0x765=0x%x, 0x67=0x%x, 0x76e=0x%x\n", - u32tmp, u8tmpa, u8tmpb, u8tmpc); - BTC_TRACE(trace_buf); - - } -} - -void ex_halbtc8192e1ant_halt_notify(IN struct btc_coexist *btcoexist) -{ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], Halt notify\n"); - BTC_TRACE(trace_buf); - - halbtc8192e1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0, - 0x0); - halbtc8192e1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 0); - halbtc8192e1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT, false, true); - - halbtc8192e1ant_ignore_wlan_act(btcoexist, FORCE_EXEC, true); - - ex_halbtc8192e1ant_media_status_notify(btcoexist, BTC_MEDIA_DISCONNECT); - - btcoexist->stop_coex_dm = true; -} - -void ex_halbtc8192e1ant_pnp_notify(IN struct btc_coexist *btcoexist, - IN u8 pnp_state) -{ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], Pnp notify\n"); - BTC_TRACE(trace_buf); - - if (BTC_WIFI_PNP_SLEEP == pnp_state) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Pnp notify to SLEEP\n"); - BTC_TRACE(trace_buf); - - halbtc8192e1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, - 0x0, 0x0); - halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); - halbtc8192e1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2); - halbtc8192e1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT, false, - true); - - /* Sinda 20150819, workaround for driver skip leave IPS/LPS to speed up sleep time. */ - /* Driver do not leave IPS/LPS when driver is going to sleep, so BTCoexistence think wifi is still under IPS/LPS */ - /* BT should clear UnderIPS/UnderLPS state to avoid mismatch state after wakeup. */ - coex_sta->under_ips = false; - coex_sta->under_lps = false; - btcoexist->stop_coex_dm = true; - } else if (BTC_WIFI_PNP_WAKE_UP == pnp_state) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Pnp notify to WAKE UP\n"); - BTC_TRACE(trace_buf); - btcoexist->stop_coex_dm = false; - halbtc8192e1ant_init_hw_config(btcoexist, false); - halbtc8192e1ant_init_coex_dm(btcoexist); - halbtc8192e1ant_query_bt_info(btcoexist); - } -} - -void ex_halbtc8192e1ant_coex_dm_reset(IN struct btc_coexist *btcoexist) -{ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], *****************Coex DM Reset*****************\n"); - BTC_TRACE(trace_buf); - - halbtc8192e1ant_init_hw_config(btcoexist, false); - /* btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0); */ - /* btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x2, 0xfffff, 0x0); */ - halbtc8192e1ant_init_coex_dm(btcoexist); -} - -void ex_halbtc8192e1ant_periodical(IN struct btc_coexist *btcoexist) -{ -#if (BT_AUTO_REPORT_ONLY_8192E_1ANT == 0) - halbtc8192e1ant_query_bt_info(btcoexist); - halbtc8192e1ant_monitor_bt_enable_disable(btcoexist); -#else - halbtc8192e1ant_monitor_bt_ctr(btcoexist); - halbtc8192e1ant_monitor_wifi_ctr(btcoexist); - - if (halbtc8192e1ant_is_wifi_status_changed(btcoexist) || - coex_dm->auto_tdma_adjust) - - halbtc8192e1ant_run_coexist_mechanism(btcoexist); - - coex_sta->specific_pkt_period_cnt++; -#endif -} - - -void ex_halbtc8192e1ant_dbg_control(IN struct btc_coexist *btcoexist, - IN u8 op_code, IN u8 op_len, IN u8 *pdata) -{ - switch (op_code) { - case BTC_DBG_SET_COEX_NORMAL: - btcoexist->manual_control = false; - halbtc8192e1ant_init_coex_dm(btcoexist); - break; - case BTC_DBG_SET_COEX_WIFI_ONLY: - btcoexist->manual_control = true; - halbtc8192e1ant_power_save_state(btcoexist, - BTC_PS_WIFI_NATIVE, 0x0, 0x0); - halbtc8192e1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, - 9); - break; - case BTC_DBG_SET_COEX_BT_ONLY: - /* todo */ - break; - default: - break; - } -} - -#endif /* #if (RTL8192E_SUPPORT == 1) */ - -#endif /* #if (BT_SUPPORT == 1 && COEX_SUPPORT == 1) */ diff --git a/hal/btc/halbtc8192e1ant.h b/hal/btc/halbtc8192e1ant.h deleted file mode 100644 index e75127c..0000000 --- a/hal/btc/halbtc8192e1ant.h +++ /dev/null @@ -1,226 +0,0 @@ - -#if (BT_SUPPORT == 1 && COEX_SUPPORT == 1) - -#if (RTL8192E_SUPPORT == 1) - -/* ******************************************* - * The following is for 8192E 1ANT BT Co-exist definition - * ******************************************* */ -#define BT_AUTO_REPORT_ONLY_8192E_1ANT 1 - -#define BT_INFO_8192E_1ANT_B_FTP BIT(7) -#define BT_INFO_8192E_1ANT_B_A2DP BIT(6) -#define BT_INFO_8192E_1ANT_B_HID BIT(5) -#define BT_INFO_8192E_1ANT_B_SCO_BUSY BIT(4) -#define BT_INFO_8192E_1ANT_B_ACL_BUSY BIT(3) -#define BT_INFO_8192E_1ANT_B_INQ_PAGE BIT(2) -#define BT_INFO_8192E_1ANT_B_SCO_ESCO BIT(1) -#define BT_INFO_8192E_1ANT_B_CONNECTION BIT(0) - -#define BT_INFO_8192E_1ANT_A2DP_BASIC_RATE(_BT_INFO_EXT_) \ - (((_BT_INFO_EXT_&BIT(0))) ? true : false) - -#define BTC_RSSI_COEX_THRESH_TOL_8192E_1ANT 2 - -#define BT_8192E_1ANT_WIFI_NOISY_THRESH 30 /* max: 255 */ - -enum bt_info_src_8192e_1ant { - BT_INFO_SRC_8192E_1ANT_WIFI_FW = 0x0, - BT_INFO_SRC_8192E_1ANT_BT_RSP = 0x1, - BT_INFO_SRC_8192E_1ANT_BT_ACTIVE_SEND = 0x2, - BT_INFO_SRC_8192E_1ANT_MAX -}; - -enum bt_8192e_1ant_bt_status { - BT_8192E_1ANT_BT_STATUS_NON_CONNECTED_IDLE = 0x0, - BT_8192E_1ANT_BT_STATUS_CONNECTED_IDLE = 0x1, - BT_8192E_1ANT_BT_STATUS_INQ_PAGE = 0x2, - BT_8192E_1ANT_BT_STATUS_ACL_BUSY = 0x3, - BT_8192E_1ANT_BT_STATUS_SCO_BUSY = 0x4, - BT_8192E_1ANT_BT_STATUS_ACL_SCO_BUSY = 0x5, - BT_8192E_1ANT_BT_STATUS_MAX -}; - -enum bt_8192e_1ant_wifi_status { - BT_8192E_1ANT_WIFI_STATUS_NON_CONNECTED_IDLE = 0x0, - BT_8192E_1ANT_WIFI_STATUS_NON_CONNECTED_ASSO_AUTH_SCAN = 0x1, - BT_8192E_1ANT_WIFI_STATUS_CONNECTED_SCAN = 0x2, - BT_8192E_1ANT_WIFI_STATUS_CONNECTED_SPECIFIC_PKT = 0x3, - BT_8192E_1ANT_WIFI_STATUS_CONNECTED_IDLE = 0x4, - BT_8192E_1ANT_WIFI_STATUS_CONNECTED_BUSY = 0x5, - BT_8192E_1ANT_WIFI_STATUS_MAX -}; - -enum bt_8192e_1ant_coex_algo { - BT_8192E_1ANT_COEX_ALGO_UNDEFINED = 0x0, - BT_8192E_1ANT_COEX_ALGO_SCO = 0x1, - BT_8192E_1ANT_COEX_ALGO_HID = 0x2, - BT_8192E_1ANT_COEX_ALGO_A2DP = 0x3, - BT_8192E_1ANT_COEX_ALGO_A2DP_PANHS = 0x4, - BT_8192E_1ANT_COEX_ALGO_PANEDR = 0x5, - BT_8192E_1ANT_COEX_ALGO_PANHS = 0x6, - BT_8192E_1ANT_COEX_ALGO_PANEDR_A2DP = 0x7, - BT_8192E_1ANT_COEX_ALGO_PANEDR_HID = 0x8, - BT_8192E_1ANT_COEX_ALGO_HID_A2DP_PANEDR = 0x9, - BT_8192E_1ANT_COEX_ALGO_HID_A2DP = 0xa, - BT_8192E_1ANT_COEX_ALGO_MAX = 0xb, -}; - -struct coex_dm_8192e_1ant { - /* fw mechanism */ - boolean cur_ignore_wlan_act; - boolean pre_ignore_wlan_act; - u8 pre_ps_tdma; - u8 cur_ps_tdma; - u8 ps_tdma_para[5]; - u8 ps_tdma_du_adj_type; - boolean auto_tdma_adjust; - boolean pre_ps_tdma_on; - boolean cur_ps_tdma_on; - boolean pre_bt_auto_report; - boolean cur_bt_auto_report; - u8 pre_lps; - u8 cur_lps; - u8 pre_rpwm; - u8 cur_rpwm; - - /* sw mechanism */ - boolean pre_low_penalty_ra; - boolean cur_low_penalty_ra; - u32 pre_val0x6c0; - u32 cur_val0x6c0; - u32 pre_val0x6c4; - u32 cur_val0x6c4; - u32 pre_val0x6c8; - u32 cur_val0x6c8; - u8 pre_val0x6cc; - u8 cur_val0x6cc; - boolean limited_dig; - - u32 backup_arfr_cnt1; /* Auto Rate Fallback Retry cnt */ - u32 backup_arfr_cnt2; /* Auto Rate Fallback Retry cnt */ - u16 backup_retry_limit; - u8 backup_ampdu_max_time; - - /* algorithm related */ - u8 pre_algorithm; - u8 cur_algorithm; - u8 bt_status; - u8 wifi_chnl_info[3]; - - u32 pre_ra_mask; - u32 cur_ra_mask; - u8 pre_arfr_type; - u8 cur_arfr_type; - u8 pre_retry_limit_type; - u8 cur_retry_limit_type; - u8 pre_ampdu_time_type; - u8 cur_ampdu_time_type; - u32 arp_cnt; - - u8 error_condition; -}; - -struct coex_sta_8192e_1ant { - boolean bt_disabled; - boolean bt_link_exist; - boolean sco_exist; - boolean a2dp_exist; - boolean hid_exist; - boolean pan_exist; - - boolean under_lps; - boolean under_ips; - u32 specific_pkt_period_cnt; - u32 high_priority_tx; - u32 high_priority_rx; - u32 low_priority_tx; - u32 low_priority_rx; - s8 bt_rssi; - boolean bt_tx_rx_mask; - u8 pre_bt_rssi_state; - u8 pre_wifi_rssi_state[4]; - boolean c2h_bt_info_req_sent; - u8 bt_info_c2h[BT_INFO_SRC_8192E_1ANT_MAX][10]; - u32 bt_info_c2h_cnt[BT_INFO_SRC_8192E_1ANT_MAX]; - boolean c2h_bt_inquiry_page; - boolean c2h_bt_page; /* Add for win8.1 page out issue */ - boolean wifi_is_high_pri_task; /* Add for win8.1 page out issue */ - u8 bt_retry_cnt; - u8 bt_info_ext; - u32 pop_event_cnt; - u8 scan_ap_num; - - u32 crc_ok_cck; - u32 crc_ok_11g; - u32 crc_ok_11n; - u32 crc_ok_11n_agg; - - u32 crc_err_cck; - u32 crc_err_11g; - u32 crc_err_11n; - u32 crc_err_11n_agg; - - boolean cck_lock; - boolean pre_ccklock; - u8 coex_table_type; - - boolean force_lps_on; -}; - -/* ******************************************* - * The following is interface which will notify coex module. - * ******************************************* */ -void ex_halbtc8192e1ant_power_on_setting(IN struct btc_coexist *btcoexist); -void ex_halbtc8192e1ant_pre_load_firmware(IN struct btc_coexist *btcoexist); -void ex_halbtc8192e1ant_init_hw_config(IN struct btc_coexist *btcoexist, - IN boolean wifi_only); -void ex_halbtc8192e1ant_init_coex_dm(IN struct btc_coexist *btcoexist); -void ex_halbtc8192e1ant_ips_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8192e1ant_lps_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8192e1ant_scan_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8192e1ant_connect_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8192e1ant_media_status_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8192e1ant_specific_packet_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8192e1ant_bt_info_notify(IN struct btc_coexist *btcoexist, - IN u8 *tmp_buf, IN u8 length); -void ex_halbtc8192e1ant_rf_status_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8192e1ant_halt_notify(IN struct btc_coexist *btcoexist); -void ex_halbtc8192e1ant_pnp_notify(IN struct btc_coexist *btcoexist, - IN u8 pnp_state); -void ex_halbtc8192e1ant_coex_dm_reset(IN struct btc_coexist *btcoexist); -void ex_halbtc8192e1ant_periodical(IN struct btc_coexist *btcoexist); -void ex_halbtc8192e1ant_display_coex_info(IN struct btc_coexist *btcoexist); -void ex_halbtc8192e1ant_dbg_control(IN struct btc_coexist *btcoexist, - IN u8 op_code, IN u8 op_len, IN u8 *pdata); - -#else /* #if (RTL8192E_SUPPORT == 1) */ -#define ex_halbtc8192e1ant_power_on_setting(btcoexist) -#define ex_halbtc8192e1ant_pre_load_firmware(btcoexist) -#define ex_halbtc8192e1ant_init_hw_config(btcoexist, wifi_only) -#define ex_halbtc8192e1ant_init_coex_dm(btcoexist) -#define ex_halbtc8192e1ant_ips_notify(btcoexist, type) -#define ex_halbtc8192e1ant_lps_notify(btcoexist, type) -#define ex_halbtc8192e1ant_scan_notify(btcoexist, type) -#define ex_halbtc8192e1ant_connect_notify(btcoexist, type) -#define ex_halbtc8192e1ant_media_status_notify(btcoexist, type) -#define ex_halbtc8192e1ant_specific_packet_notify(btcoexist, type) -#define ex_halbtc8192e1ant_bt_info_notify(btcoexist, tmp_buf, length) -#define ex_halbtc8192e1ant_rf_status_notify(btcoexist, type) -#define ex_halbtc8192e1ant_halt_notify(btcoexist) -#define ex_halbtc8192e1ant_pnp_notify(btcoexist, pnp_state) -#define ex_halbtc8192e1ant_coex_dm_reset(btcoexist) -#define ex_halbtc8192e1ant_periodical(btcoexist) -#define ex_halbtc8192e1ant_display_coex_info(btcoexist) -#define ex_halbtc8192e1ant_dbg_control(btcoexist, op_code, op_len, pdata) - -#endif - -#endif diff --git a/hal/btc/halbtc8192e2ant.c b/hal/btc/halbtc8192e2ant.c deleted file mode 100644 index 312877d..0000000 --- a/hal/btc/halbtc8192e2ant.c +++ /dev/null @@ -1,4377 +0,0 @@ -/* ************************************************************ - * Description: - * - * This file is for RTL8192E Co-exist mechanism - * - * History - * 2012/11/15 Cosa first check in. - * - * ************************************************************ */ - -/* ************************************************************ - * include files - * ************************************************************ */ -#include "mp_precomp.h" - - -#if (BT_SUPPORT == 1 && COEX_SUPPORT == 1) - -#if (RTL8192E_SUPPORT == 1) -/* ************************************************************ - * Global variables, these are static variables - * ************************************************************ */ -static u8 *trace_buf = &gl_btc_trace_buf[0]; -static struct coex_dm_8192e_2ant glcoex_dm_8192e_2ant; -static struct coex_dm_8192e_2ant *coex_dm = &glcoex_dm_8192e_2ant; -static struct coex_sta_8192e_2ant glcoex_sta_8192e_2ant; -static struct coex_sta_8192e_2ant *coex_sta = &glcoex_sta_8192e_2ant; - -const char *const glbt_info_src_8192e_2ant[] = { - "BT Info[wifi fw]", - "BT Info[bt rsp]", - "BT Info[bt auto report]", -}; -/* ************************************************************ - * BtCoex Version Format: - * 1. date : glcoex_ver_date_XXXXX_1ant - * 2. WifiCoexVersion : glcoex_ver_XXXX_1ant - * 3. BtCoexVersion : glcoex_ver_btdesired_XXXXX_1ant - * 4. others : glcoex_ver_XXXXXX_XXXXX_1ant - * - * Variable should be indicated IC and Antenna numbers !!! - * Please strictly follow this order and naming style !!! - * - * ************************************************************ */ -u32 glcoex_ver_date_8192e_2ant = 20160818; -u32 glcoex_ver_8192e_2ant = 0x44; -u32 glcoex_ver_btdesired_8192e_2ant = 0x44; -/*1. add coex. log for wifi/BT coex. version*/ -/* ************************************************************ - * local function proto type if needed - * ************************************************************ - * ************************************************************ - * local function start with halbtc8192e2ant_ - * ************************************************************ */ -u8 halbtc8192e2ant_bt_rssi_state(u8 level_num, u8 rssi_thresh, u8 rssi_thresh1) -{ - s32 bt_rssi = 0; - u8 bt_rssi_state = coex_sta->pre_bt_rssi_state; - - bt_rssi = coex_sta->bt_rssi; - - if (level_num == 2) { - if ((coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_LOW) || - (coex_sta->pre_bt_rssi_state == - BTC_RSSI_STATE_STAY_LOW)) { - if (bt_rssi >= (rssi_thresh + - BTC_RSSI_COEX_THRESH_TOL_8192E_2ANT)) - bt_rssi_state = BTC_RSSI_STATE_HIGH; - else - bt_rssi_state = BTC_RSSI_STATE_STAY_LOW; - } else { - if (bt_rssi < rssi_thresh) - bt_rssi_state = BTC_RSSI_STATE_LOW; - else - bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH; - } - } else if (level_num == 3) { - if (rssi_thresh > rssi_thresh1) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Rssi thresh error!!\n"); - BTC_TRACE(trace_buf); - return coex_sta->pre_bt_rssi_state; - } - - if ((coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_LOW) || - (coex_sta->pre_bt_rssi_state == - BTC_RSSI_STATE_STAY_LOW)) { - if (bt_rssi >= (rssi_thresh + - BTC_RSSI_COEX_THRESH_TOL_8192E_2ANT)) - bt_rssi_state = BTC_RSSI_STATE_MEDIUM; - else - bt_rssi_state = BTC_RSSI_STATE_STAY_LOW; - } else if ((coex_sta->pre_bt_rssi_state == - BTC_RSSI_STATE_MEDIUM) || - (coex_sta->pre_bt_rssi_state == - BTC_RSSI_STATE_STAY_MEDIUM)) { - if (bt_rssi >= (rssi_thresh1 + - BTC_RSSI_COEX_THRESH_TOL_8192E_2ANT)) - bt_rssi_state = BTC_RSSI_STATE_HIGH; - else if (bt_rssi < rssi_thresh) - bt_rssi_state = BTC_RSSI_STATE_LOW; - else - bt_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM; - } else { - if (bt_rssi < rssi_thresh1) - bt_rssi_state = BTC_RSSI_STATE_MEDIUM; - else - bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH; - } - } - - coex_sta->pre_bt_rssi_state = bt_rssi_state; - - return bt_rssi_state; -} - -u8 halbtc8192e2ant_wifi_rssi_state(IN struct btc_coexist *btcoexist, - IN u8 index, IN u8 level_num, IN u8 rssi_thresh, IN u8 rssi_thresh1) -{ - s32 wifi_rssi = 0; - u8 wifi_rssi_state = coex_sta->pre_wifi_rssi_state[index]; - - btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi); - - if (level_num == 2) { - if ((coex_sta->pre_wifi_rssi_state[index] == BTC_RSSI_STATE_LOW) - || - (coex_sta->pre_wifi_rssi_state[index] == - BTC_RSSI_STATE_STAY_LOW)) { - if (wifi_rssi >= (rssi_thresh + - BTC_RSSI_COEX_THRESH_TOL_8192E_2ANT)) - wifi_rssi_state = BTC_RSSI_STATE_HIGH; - else - wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW; - } else { - if (wifi_rssi < rssi_thresh) - wifi_rssi_state = BTC_RSSI_STATE_LOW; - else - wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH; - } - } else if (level_num == 3) { - if (rssi_thresh > rssi_thresh1) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], wifi RSSI thresh error!!\n"); - BTC_TRACE(trace_buf); - return coex_sta->pre_wifi_rssi_state[index]; - } - - if ((coex_sta->pre_wifi_rssi_state[index] == BTC_RSSI_STATE_LOW) - || - (coex_sta->pre_wifi_rssi_state[index] == - BTC_RSSI_STATE_STAY_LOW)) { - if (wifi_rssi >= (rssi_thresh + - BTC_RSSI_COEX_THRESH_TOL_8192E_2ANT)) - wifi_rssi_state = BTC_RSSI_STATE_MEDIUM; - else - wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW; - } else if ((coex_sta->pre_wifi_rssi_state[index] == - BTC_RSSI_STATE_MEDIUM) || - (coex_sta->pre_wifi_rssi_state[index] == - BTC_RSSI_STATE_STAY_MEDIUM)) { - if (wifi_rssi >= (rssi_thresh1 + - BTC_RSSI_COEX_THRESH_TOL_8192E_2ANT)) - wifi_rssi_state = BTC_RSSI_STATE_HIGH; - else if (wifi_rssi < rssi_thresh) - wifi_rssi_state = BTC_RSSI_STATE_LOW; - else - wifi_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM; - } else { - if (wifi_rssi < rssi_thresh1) - wifi_rssi_state = BTC_RSSI_STATE_MEDIUM; - else - wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH; - } - } - - coex_sta->pre_wifi_rssi_state[index] = wifi_rssi_state; - - return wifi_rssi_state; -} - -void halbtc8192e2ant_monitor_bt_enable_disable(IN struct btc_coexist *btcoexist) -{ - static u32 bt_disable_cnt = 0; - boolean bt_active = true, bt_disabled = false; - - /* This function check if bt is disabled */ - - if (coex_sta->high_priority_tx == 0 && - coex_sta->high_priority_rx == 0 && - coex_sta->low_priority_tx == 0 && - coex_sta->low_priority_rx == 0) - bt_active = false; - if (coex_sta->high_priority_tx == 0xffff && - coex_sta->high_priority_rx == 0xffff && - coex_sta->low_priority_tx == 0xffff && - coex_sta->low_priority_rx == 0xffff) - bt_active = false; - if (bt_active) { - bt_disable_cnt = 0; - bt_disabled = false; - btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_DISABLE, - &bt_disabled); - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT is enabled !!\n"); - BTC_TRACE(trace_buf); - } else { - bt_disable_cnt++; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], bt all counters=0, %d times!!\n", - bt_disable_cnt); - BTC_TRACE(trace_buf); - if (bt_disable_cnt >= 2) { - bt_disabled = true; - btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_DISABLE, - &bt_disabled); - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT is disabled !!\n"); - BTC_TRACE(trace_buf); - } - } - if (coex_sta->bt_disabled != bt_disabled) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT is from %s to %s!!\n", - (coex_sta->bt_disabled ? "disabled" : "enabled"), - (bt_disabled ? "disabled" : "enabled")); - BTC_TRACE(trace_buf); - coex_sta->bt_disabled = bt_disabled; - /* if (!bt_disabled) { - } else { - } */ - } -} - -u32 halbtc8192e2ant_decide_ra_mask(IN struct btc_coexist *btcoexist, - IN u8 ss_type, IN u32 ra_mask_type) -{ - u32 dis_ra_mask = 0x0; - - switch (ra_mask_type) { - case 0: /* normal mode */ - if (ss_type == 2) - dis_ra_mask = 0x0; /* enable 2ss */ - else - dis_ra_mask = 0xfff00000; /* disable 2ss */ - break; - case 1: /* disable cck 1/2 */ - if (ss_type == 2) - dis_ra_mask = 0x00000003; /* enable 2ss */ - else - dis_ra_mask = 0xfff00003; /* disable 2ss */ - break; - case 2: /* disable cck 1/2/5.5, ofdm 6/9/12/18/24, mcs 0/1/2/3/4 */ - if (ss_type == 2) - dis_ra_mask = 0x0001f1f7; /* enable 2ss */ - else - dis_ra_mask = 0xfff1f1f7; /* disable 2ss */ - break; - default: - break; - } - - return dis_ra_mask; -} - -void halbtc8192e2ant_update_ra_mask(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u32 dis_rate_mask) -{ - coex_dm->cur_ra_mask = dis_rate_mask; - - if (force_exec || (coex_dm->pre_ra_mask != coex_dm->cur_ra_mask)) - btcoexist->btc_set(btcoexist, BTC_SET_ACT_UPDATE_RAMASK, - &coex_dm->cur_ra_mask); - coex_dm->pre_ra_mask = coex_dm->cur_ra_mask; -} - -void halbtc8192e2ant_auto_rate_fallback_retry(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 type) -{ - boolean wifi_under_b_mode = false; - - coex_dm->cur_arfr_type = type; - - if (force_exec || (coex_dm->pre_arfr_type != coex_dm->cur_arfr_type)) { - switch (coex_dm->cur_arfr_type) { - case 0: /* normal mode */ - btcoexist->btc_write_4byte(btcoexist, 0x430, - coex_dm->backup_arfr_cnt1); - btcoexist->btc_write_4byte(btcoexist, 0x434, - coex_dm->backup_arfr_cnt2); - break; - case 1: - btcoexist->btc_get(btcoexist, - BTC_GET_BL_WIFI_UNDER_B_MODE, - &wifi_under_b_mode); - if (wifi_under_b_mode) { - btcoexist->btc_write_4byte(btcoexist, - 0x430, 0x0); - btcoexist->btc_write_4byte(btcoexist, - 0x434, 0x01010101); - } else { - btcoexist->btc_write_4byte(btcoexist, - 0x430, 0x0); - btcoexist->btc_write_4byte(btcoexist, - 0x434, 0x04030201); - } - break; - default: - break; - } - } - - coex_dm->pre_arfr_type = coex_dm->cur_arfr_type; -} - -void halbtc8192e2ant_retry_limit(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 type) -{ - coex_dm->cur_retry_limit_type = type; - - if (force_exec || - (coex_dm->pre_retry_limit_type != - coex_dm->cur_retry_limit_type)) { - switch (coex_dm->cur_retry_limit_type) { - case 0: /* normal mode */ - btcoexist->btc_write_2byte(btcoexist, 0x42a, - coex_dm->backup_retry_limit); - break; - case 1: /* retry limit=8 */ - btcoexist->btc_write_2byte(btcoexist, 0x42a, - 0x0808); - break; - default: - break; - } - } - - coex_dm->pre_retry_limit_type = coex_dm->cur_retry_limit_type; -} - -void halbtc8192e2ant_ampdu_max_time(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 type) -{ - coex_dm->cur_ampdu_time_type = type; - - if (force_exec || - (coex_dm->pre_ampdu_time_type != coex_dm->cur_ampdu_time_type)) { - switch (coex_dm->cur_ampdu_time_type) { - case 0: /* normal mode */ - btcoexist->btc_write_1byte(btcoexist, 0x456, - coex_dm->backup_ampdu_max_time); - break; - case 1: /* AMPDU timw = 0x38 * 32us */ - btcoexist->btc_write_1byte(btcoexist, 0x456, - 0x38); - break; - default: - break; - } - } - - coex_dm->pre_ampdu_time_type = coex_dm->cur_ampdu_time_type; -} - -void halbtc8192e2ant_limited_tx(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 ra_mask_type, IN u8 arfr_type, - IN u8 retry_limit_type, IN u8 ampdu_time_type) -{ - u32 dis_ra_mask = 0x0; - - coex_dm->cur_ra_mask_type = ra_mask_type; - dis_ra_mask = halbtc8192e2ant_decide_ra_mask(btcoexist, - coex_dm->cur_ss_type, ra_mask_type); - halbtc8192e2ant_update_ra_mask(btcoexist, force_exec, dis_ra_mask); - - halbtc8192e2ant_auto_rate_fallback_retry(btcoexist, force_exec, - arfr_type); - halbtc8192e2ant_retry_limit(btcoexist, force_exec, retry_limit_type); - halbtc8192e2ant_ampdu_max_time(btcoexist, force_exec, ampdu_time_type); -} - -void halbtc8192e2ant_limited_rx(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean rej_ap_agg_pkt, - IN boolean bt_ctrl_agg_buf_size, IN u8 agg_buf_size) -{ - boolean reject_rx_agg = rej_ap_agg_pkt; - boolean bt_ctrl_rx_agg_size = bt_ctrl_agg_buf_size; - u8 rx_agg_size = agg_buf_size; - - /* ============================================ */ - /* Rx Aggregation related setting */ - /* ============================================ */ - btcoexist->btc_set(btcoexist, BTC_SET_BL_TO_REJ_AP_AGG_PKT, - &reject_rx_agg); - /* decide BT control aggregation buf size or not */ - btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_CTRL_AGG_SIZE, - &bt_ctrl_rx_agg_size); - /* aggregation buf size, only work when BT control Rx aggregation size. */ - btcoexist->btc_set(btcoexist, BTC_SET_U1_AGG_BUF_SIZE, &rx_agg_size); - /* real update aggregation setting */ - btcoexist->btc_set(btcoexist, BTC_SET_ACT_AGGREGATE_CTRL, NULL); - - -} - -void halbtc8192e2ant_monitor_bt_ctr(IN struct btc_coexist *btcoexist) -{ - u32 reg_hp_txrx, reg_lp_txrx, u32tmp; - u32 reg_hp_tx = 0, reg_hp_rx = 0, reg_lp_tx = 0, reg_lp_rx = 0; - - reg_hp_txrx = 0x770; - reg_lp_txrx = 0x774; - - u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_hp_txrx); - reg_hp_tx = u32tmp & MASKLWORD; - reg_hp_rx = (u32tmp & MASKHWORD) >> 16; - - u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_lp_txrx); - reg_lp_tx = u32tmp & MASKLWORD; - reg_lp_rx = (u32tmp & MASKHWORD) >> 16; - - coex_sta->high_priority_tx = reg_hp_tx; - coex_sta->high_priority_rx = reg_hp_rx; - coex_sta->low_priority_tx = reg_lp_tx; - coex_sta->low_priority_rx = reg_lp_rx; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], High Priority Tx/Rx (reg 0x%x)=0x%x(%d)/0x%x(%d)\n", - reg_hp_txrx, reg_hp_tx, reg_hp_tx, reg_hp_rx, reg_hp_rx); - BTC_TRACE(trace_buf); - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Low Priority Tx/Rx (reg 0x%x)=0x%x(%d)/0x%x(%d)\n", - reg_lp_txrx, reg_lp_tx, reg_lp_tx, reg_lp_rx, reg_lp_rx); - BTC_TRACE(trace_buf); - - /* reset counter */ - btcoexist->btc_write_1byte(btcoexist, 0x76e, 0xc); -} - - -void halbtc8192e2ant_monitor_wifi_ctr(IN struct btc_coexist *btcoexist) -{ -#if 1 - - coex_sta->crc_ok_cck = - btcoexist->btc_phydm_query_PHY_counter( - btcoexist, - PHYDM_INFO_CRC32_OK_CCK); - coex_sta->crc_ok_11g = - btcoexist->btc_phydm_query_PHY_counter( - btcoexist, - PHYDM_INFO_CRC32_OK_LEGACY); - coex_sta->crc_ok_11n = - btcoexist->btc_phydm_query_PHY_counter( - btcoexist, - PHYDM_INFO_CRC32_OK_HT); - coex_sta->crc_ok_11n_vht = - btcoexist->btc_phydm_query_PHY_counter( - btcoexist, - PHYDM_INFO_CRC32_OK_VHT); - - coex_sta->crc_err_cck = - btcoexist->btc_phydm_query_PHY_counter( - btcoexist, - PHYDM_INFO_CRC32_ERROR_CCK); - coex_sta->crc_err_11g = - btcoexist->btc_phydm_query_PHY_counter( - btcoexist, - PHYDM_INFO_CRC32_ERROR_LEGACY); - coex_sta->crc_err_11n = - btcoexist->btc_phydm_query_PHY_counter( - btcoexist, - PHYDM_INFO_CRC32_ERROR_HT); - coex_sta->crc_err_11n_vht = - btcoexist->btc_phydm_query_PHY_counter( - btcoexist, - PHYDM_INFO_CRC32_ERROR_VHT); -#endif -} - - - -void halbtc8192e2ant_query_bt_info(IN struct btc_coexist *btcoexist) -{ - u8 h2c_parameter[1] = {0}; - - coex_sta->c2h_bt_info_req_sent = true; - - h2c_parameter[0] |= BIT(0); /* trigger */ - - btcoexist->btc_fill_h2c(btcoexist, 0x61, 1, h2c_parameter); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex],Query BT info!!!! H2C 0x61 = 0x1\n"); - BTC_TRACE(trace_buf); -} - -boolean halbtc8192e2ant_is_wifi_status_changed(IN struct btc_coexist *btcoexist) -{ - static boolean pre_wifi_busy = false, pre_under_4way = false, - pre_bt_hs_on = false; - boolean wifi_busy = false, under_4way = false, bt_hs_on = false; - boolean wifi_connected = false; - u8 wifi_rssi_state = BTC_RSSI_STATE_HIGH; - - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS, - &under_4way); - - if (wifi_connected) { - if (wifi_busy != pre_wifi_busy) { - pre_wifi_busy = wifi_busy; - return true; - } - if (under_4way != pre_under_4way) { - pre_under_4way = under_4way; - return true; - } - if (bt_hs_on != pre_bt_hs_on) { - pre_bt_hs_on = bt_hs_on; - return true; - } - - wifi_rssi_state = halbtc8192e2ant_wifi_rssi_state(btcoexist, 0, - 2, 34, 0); - - if ((BTC_RSSI_STATE_HIGH == wifi_rssi_state) || - (BTC_RSSI_STATE_LOW == wifi_rssi_state)) - return true; - } - - return false; -} - -void halbtc8192e2ant_update_bt_link_info(IN struct btc_coexist *btcoexist) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - boolean bt_hs_on = false; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); - - bt_link_info->bt_link_exist = coex_sta->bt_link_exist; - bt_link_info->sco_exist = coex_sta->sco_exist; - bt_link_info->a2dp_exist = coex_sta->a2dp_exist; - bt_link_info->pan_exist = coex_sta->pan_exist; - bt_link_info->hid_exist = coex_sta->hid_exist; - - /* work around for HS mode. */ - if (bt_hs_on) { - bt_link_info->pan_exist = true; - bt_link_info->bt_link_exist = true; - } - - /* check if Sco only */ - if (bt_link_info->sco_exist && - !bt_link_info->a2dp_exist && - !bt_link_info->pan_exist && - !bt_link_info->hid_exist) - bt_link_info->sco_only = true; - else - bt_link_info->sco_only = false; - - /* check if A2dp only */ - if (!bt_link_info->sco_exist && - bt_link_info->a2dp_exist && - !bt_link_info->pan_exist && - !bt_link_info->hid_exist) - bt_link_info->a2dp_only = true; - else - bt_link_info->a2dp_only = false; - - /* check if Pan only */ - if (!bt_link_info->sco_exist && - !bt_link_info->a2dp_exist && - bt_link_info->pan_exist && - !bt_link_info->hid_exist) - bt_link_info->pan_only = true; - else - bt_link_info->pan_only = false; - - /* check if Hid only */ - if (!bt_link_info->sco_exist && - !bt_link_info->a2dp_exist && - !bt_link_info->pan_exist && - bt_link_info->hid_exist) - bt_link_info->hid_only = true; - else - bt_link_info->hid_only = false; -} - -u8 halbtc8192e2ant_action_algorithm(IN struct btc_coexist *btcoexist) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - struct btc_stack_info *stack_info = &btcoexist->stack_info; - boolean bt_hs_on = false; - u8 algorithm = BT_8192E_2ANT_COEX_ALGO_UNDEFINED; - u8 num_of_diff_profile = 0; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); - - if (!bt_link_info->bt_link_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], No BT link exists!!!\n"); - BTC_TRACE(trace_buf); - return algorithm; - } - - if (bt_link_info->sco_exist) - num_of_diff_profile++; - if (bt_link_info->hid_exist) - num_of_diff_profile++; - if (bt_link_info->pan_exist) - num_of_diff_profile++; - if (bt_link_info->a2dp_exist) - num_of_diff_profile++; - - if (num_of_diff_profile == 1) { - if (bt_link_info->sco_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCO only\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8192E_2ANT_COEX_ALGO_SCO; - } else { - if (bt_link_info->hid_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], HID only\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8192E_2ANT_COEX_ALGO_HID; - } else if (bt_link_info->a2dp_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], A2DP only\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8192E_2ANT_COEX_ALGO_A2DP; - } else if (bt_link_info->pan_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], PAN(HS) only\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8192E_2ANT_COEX_ALGO_PANHS; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], PAN(EDR) only\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8192E_2ANT_COEX_ALGO_PANEDR; - } - } - } - } else if (num_of_diff_profile == 2) { - if (bt_link_info->sco_exist) { - if (bt_link_info->hid_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCO + HID\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8192E_2ANT_COEX_ALGO_SCO; - } else if (bt_link_info->a2dp_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCO + A2DP ==> SCO\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8192E_2ANT_COEX_ALGO_PANEDR_HID; - } else if (bt_link_info->pan_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCO + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8192E_2ANT_COEX_ALGO_SCO; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCO + PAN(EDR)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8192E_2ANT_COEX_ALGO_SCO_PAN; - } - } - } else { - if (bt_link_info->hid_exist && - bt_link_info->a2dp_exist) { - if (stack_info->num_of_hid >= 2) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], HID*2 + A2DP\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8192E_2ANT_COEX_ALGO_HID_A2DP_PANEDR; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], HID + A2DP\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8192E_2ANT_COEX_ALGO_HID_A2DP; - } - } else if (bt_link_info->hid_exist && - bt_link_info->pan_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], HID + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8192E_2ANT_COEX_ALGO_HID; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], HID + PAN(EDR)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8192E_2ANT_COEX_ALGO_PANEDR_HID; - } - } else if (bt_link_info->pan_exist && - bt_link_info->a2dp_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], A2DP + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8192E_2ANT_COEX_ALGO_A2DP_PANHS; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], A2DP + PAN(EDR)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8192E_2ANT_COEX_ALGO_PANEDR_A2DP; - } - } - } - } else if (num_of_diff_profile == 3) { - if (bt_link_info->sco_exist) { - if (bt_link_info->hid_exist && - bt_link_info->a2dp_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCO + HID + A2DP ==> HID\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8192E_2ANT_COEX_ALGO_PANEDR_HID; - } else if (bt_link_info->hid_exist && - bt_link_info->pan_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCO + HID + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8192E_2ANT_COEX_ALGO_SCO; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCO + HID + PAN(EDR)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8192E_2ANT_COEX_ALGO_SCO_PAN; - } - } else if (bt_link_info->pan_exist && - bt_link_info->a2dp_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCO + A2DP + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8192E_2ANT_COEX_ALGO_SCO; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCO + A2DP + PAN(EDR) ==> HID\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8192E_2ANT_COEX_ALGO_PANEDR_HID; - } - } - } else { - if (bt_link_info->hid_exist && - bt_link_info->pan_exist && - bt_link_info->a2dp_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], HID + A2DP + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8192E_2ANT_COEX_ALGO_HID_A2DP; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], HID + A2DP + PAN(EDR)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8192E_2ANT_COEX_ALGO_HID_A2DP_PANEDR; - } - } - } - } else if (num_of_diff_profile >= 3) { - if (bt_link_info->sco_exist) { - if (bt_link_info->hid_exist && - bt_link_info->pan_exist && - bt_link_info->a2dp_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Error!!! SCO + HID + A2DP + PAN(HS)\n"); - BTC_TRACE(trace_buf); - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCO + HID + A2DP + PAN(EDR)==>PAN(EDR)+HID\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8192E_2ANT_COEX_ALGO_PANEDR_HID; - } - } - } - } - - return algorithm; -} - -void halbtc8192e2ant_set_fw_dac_swing_level(IN struct btc_coexist *btcoexist, - IN u8 dac_swing_lvl) -{ - u8 h2c_parameter[1] = {0}; - - /* There are several type of dacswing */ - /* 0x18/ 0x10/ 0xc/ 0x8/ 0x4/ 0x6 */ - h2c_parameter[0] = dac_swing_lvl; - - btcoexist->btc_fill_h2c(btcoexist, 0x64, 1, h2c_parameter); -} - -void halbtc8192e2ant_set_fw_dec_bt_pwr(IN struct btc_coexist *btcoexist, - IN u8 dec_bt_pwr_lvl) -{ - u8 h2c_parameter[1] = {0}; - - h2c_parameter[0] = dec_bt_pwr_lvl; - - btcoexist->btc_fill_h2c(btcoexist, 0x62, 1, h2c_parameter); -} - -void halbtc8192e2ant_dec_bt_pwr(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 dec_bt_pwr_lvl) -{ - coex_dm->cur_bt_dec_pwr_lvl = dec_bt_pwr_lvl; - - if (!force_exec) { -#if 0 /* work around, avoid h2c command fail. */ - if (coex_dm->pre_bt_dec_pwr_lvl == coex_dm->cur_bt_dec_pwr_lvl) - return; -#endif - } - halbtc8192e2ant_set_fw_dec_bt_pwr(btcoexist, - coex_dm->cur_bt_dec_pwr_lvl); - - coex_dm->pre_bt_dec_pwr_lvl = coex_dm->cur_bt_dec_pwr_lvl; -} - -void halbtc8192e2ant_set_bt_auto_report(IN struct btc_coexist *btcoexist, - IN boolean enable_auto_report) -{ - u8 h2c_parameter[1] = {0}; - - h2c_parameter[0] = 0; - - if (enable_auto_report) - h2c_parameter[0] |= BIT(0); - - btcoexist->btc_fill_h2c(btcoexist, 0x68, 1, h2c_parameter); -} - -void halbtc8192e2ant_bt_auto_report(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean enable_auto_report) -{ - coex_dm->cur_bt_auto_report = enable_auto_report; - - if (!force_exec) { - if (coex_dm->pre_bt_auto_report == coex_dm->cur_bt_auto_report) - return; - } - halbtc8192e2ant_set_bt_auto_report(btcoexist, - coex_dm->cur_bt_auto_report); - - coex_dm->pre_bt_auto_report = coex_dm->cur_bt_auto_report; -} - -void halbtc8192e2ant_fw_dac_swing_lvl(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 fw_dac_swing_lvl) -{ - coex_dm->cur_fw_dac_swing_lvl = fw_dac_swing_lvl; - - if (!force_exec) { - if (coex_dm->pre_fw_dac_swing_lvl == - coex_dm->cur_fw_dac_swing_lvl) - return; - } - - halbtc8192e2ant_set_fw_dac_swing_level(btcoexist, - coex_dm->cur_fw_dac_swing_lvl); - - coex_dm->pre_fw_dac_swing_lvl = coex_dm->cur_fw_dac_swing_lvl; -} - -void halbtc8192e2ant_set_sw_rf_rx_lpf_corner(IN struct btc_coexist *btcoexist, - IN boolean rx_rf_shrink_on) -{ - if (rx_rf_shrink_on) { - /* Shrink RF Rx LPF corner */ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Shrink RF Rx LPF corner!!\n"); - BTC_TRACE(trace_buf); - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1e, 0xfffff, - 0xffffc); - } else { - /* Resume RF Rx LPF corner */ - /* After initialized, we can use coex_dm->bt_rf_0x1e_backup */ - if (btcoexist->initilized) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Resume RF Rx LPF corner!!\n"); - BTC_TRACE(trace_buf); - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1e, - 0xfffff, coex_dm->bt_rf_0x1e_backup); - } - } -} - -void halbtc8192e2ant_rf_shrink(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean rx_rf_shrink_on) -{ - coex_dm->cur_rf_rx_lpf_shrink = rx_rf_shrink_on; - - if (!force_exec) { - if (coex_dm->pre_rf_rx_lpf_shrink == - coex_dm->cur_rf_rx_lpf_shrink) - return; - } - halbtc8192e2ant_set_sw_rf_rx_lpf_corner(btcoexist, - coex_dm->cur_rf_rx_lpf_shrink); - - coex_dm->pre_rf_rx_lpf_shrink = coex_dm->cur_rf_rx_lpf_shrink; -} - -void halbtc8192e2ant_set_sw_penalty_tx_rate_adaptive(IN struct btc_coexist - *btcoexist, IN boolean low_penalty_ra) -{ - u8 h2c_parameter[6] = {0}; - - h2c_parameter[0] = 0x6; /* op_code, 0x6= Retry_Penalty */ - - if (low_penalty_ra) { - h2c_parameter[1] |= BIT(0); - h2c_parameter[2] = - 0x00; /* normal rate except MCS7/6/5, OFDM54/48/36 */ - h2c_parameter[3] = 0xf7; /* MCS7 or OFDM54 */ - h2c_parameter[4] = 0xf8; /* MCS6 or OFDM48 */ - h2c_parameter[5] = 0xf9; /* MCS5 or OFDM36 */ - } - - btcoexist->btc_fill_h2c(btcoexist, 0x69, 6, h2c_parameter); -} - -void halbtc8192e2ant_low_penalty_ra(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean low_penalty_ra) -{ - coex_dm->cur_low_penalty_ra = low_penalty_ra; - - if (!force_exec) { - if (coex_dm->pre_low_penalty_ra == coex_dm->cur_low_penalty_ra) - return; - } - halbtc8192e2ant_set_sw_penalty_tx_rate_adaptive(btcoexist, - coex_dm->cur_low_penalty_ra); - - coex_dm->pre_low_penalty_ra = coex_dm->cur_low_penalty_ra; -} - -void halbtc8192e2ant_set_dac_swing_reg(IN struct btc_coexist *btcoexist, - IN u32 level) -{ - u8 val = (u8)level; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Write SwDacSwing = 0x%x\n", level); - BTC_TRACE(trace_buf); - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x883, 0x3e, val); -} - -void halbtc8192e2ant_set_sw_full_time_dac_swing(IN struct btc_coexist - *btcoexist, IN boolean sw_dac_swing_on, IN u32 sw_dac_swing_lvl) -{ - if (sw_dac_swing_on) - halbtc8192e2ant_set_dac_swing_reg(btcoexist, sw_dac_swing_lvl); - else - halbtc8192e2ant_set_dac_swing_reg(btcoexist, 0x18); -} - - -void halbtc8192e2ant_dac_swing(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean dac_swing_on, IN u32 dac_swing_lvl) -{ - coex_dm->cur_dac_swing_on = dac_swing_on; - coex_dm->cur_dac_swing_lvl = dac_swing_lvl; - - if (!force_exec) { - if ((coex_dm->pre_dac_swing_on == coex_dm->cur_dac_swing_on) && - (coex_dm->pre_dac_swing_lvl == - coex_dm->cur_dac_swing_lvl)) - return; - } - delay_ms(30); - halbtc8192e2ant_set_sw_full_time_dac_swing(btcoexist, dac_swing_on, - dac_swing_lvl); - - coex_dm->pre_dac_swing_on = coex_dm->cur_dac_swing_on; - coex_dm->pre_dac_swing_lvl = coex_dm->cur_dac_swing_lvl; -} - -void halbtc8192e2ant_set_adc_back_off(IN struct btc_coexist *btcoexist, - IN boolean adc_back_off) -{ - if (adc_back_off) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BB BackOff Level On!\n"); - BTC_TRACE(trace_buf); - btcoexist->btc_write_1byte_bitmask(btcoexist, 0xc05, 0x30, 0x3); - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BB BackOff Level Off!\n"); - BTC_TRACE(trace_buf); - btcoexist->btc_write_1byte_bitmask(btcoexist, 0xc05, 0x30, 0x1); - } -} - -void halbtc8192e2ant_adc_back_off(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean adc_back_off) -{ - coex_dm->cur_adc_back_off = adc_back_off; - - if (!force_exec) { - if (coex_dm->pre_adc_back_off == coex_dm->cur_adc_back_off) - return; - } - halbtc8192e2ant_set_adc_back_off(btcoexist, coex_dm->cur_adc_back_off); - - coex_dm->pre_adc_back_off = coex_dm->cur_adc_back_off; -} - -void halbtc8192e2ant_set_agc_table(IN struct btc_coexist *btcoexist, - IN boolean agc_table_en) -{ - /* =================BB AGC Gain Table */ - if (agc_table_en) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BB Agc Table On!\n"); - BTC_TRACE(trace_buf); - btcoexist->btc_write_4byte(btcoexist, 0xc78, 0x0a1A0001); - btcoexist->btc_write_4byte(btcoexist, 0xc78, 0x091B0001); - btcoexist->btc_write_4byte(btcoexist, 0xc78, 0x081C0001); - btcoexist->btc_write_4byte(btcoexist, 0xc78, 0x071D0001); - btcoexist->btc_write_4byte(btcoexist, 0xc78, 0x061E0001); - btcoexist->btc_write_4byte(btcoexist, 0xc78, 0x051F0001); - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BB Agc Table Off!\n"); - BTC_TRACE(trace_buf); - btcoexist->btc_write_4byte(btcoexist, 0xc78, 0xaa1A0001); - btcoexist->btc_write_4byte(btcoexist, 0xc78, 0xa91B0001); - btcoexist->btc_write_4byte(btcoexist, 0xc78, 0xa81C0001); - btcoexist->btc_write_4byte(btcoexist, 0xc78, 0xa71D0001); - btcoexist->btc_write_4byte(btcoexist, 0xc78, 0xa61E0001); - btcoexist->btc_write_4byte(btcoexist, 0xc78, 0xa51F0001); - } -} - -void halbtc8192e2ant_agc_table(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean agc_table_en) -{ - coex_dm->cur_agc_table_en = agc_table_en; - - if (!force_exec) { - if (coex_dm->pre_agc_table_en == coex_dm->cur_agc_table_en) - return; - } - halbtc8192e2ant_set_agc_table(btcoexist, agc_table_en); - - coex_dm->pre_agc_table_en = coex_dm->cur_agc_table_en; -} - -void halbtc8192e2ant_set_coex_table(IN struct btc_coexist *btcoexist, - IN u32 val0x6c0, IN u32 val0x6c4, IN u32 val0x6c8, IN u8 val0x6cc) -{ - btcoexist->btc_write_4byte(btcoexist, 0x6c0, val0x6c0); - - btcoexist->btc_write_4byte(btcoexist, 0x6c4, val0x6c4); - - btcoexist->btc_write_4byte(btcoexist, 0x6c8, val0x6c8); - - btcoexist->btc_write_1byte(btcoexist, 0x6cc, val0x6cc); -} - -void halbtc8192e2ant_coex_table(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u32 val0x6c0, IN u32 val0x6c4, - IN u32 val0x6c8, IN u8 val0x6cc) -{ - coex_dm->cur_val0x6c0 = val0x6c0; - coex_dm->cur_val0x6c4 = val0x6c4; - coex_dm->cur_val0x6c8 = val0x6c8; - coex_dm->cur_val0x6cc = val0x6cc; - - if (!force_exec) { - if ((coex_dm->pre_val0x6c0 == coex_dm->cur_val0x6c0) && - (coex_dm->pre_val0x6c4 == coex_dm->cur_val0x6c4) && - (coex_dm->pre_val0x6c8 == coex_dm->cur_val0x6c8) && - (coex_dm->pre_val0x6cc == coex_dm->cur_val0x6cc)) - return; - } - halbtc8192e2ant_set_coex_table(btcoexist, val0x6c0, val0x6c4, val0x6c8, - val0x6cc); - - coex_dm->pre_val0x6c0 = coex_dm->cur_val0x6c0; - coex_dm->pre_val0x6c4 = coex_dm->cur_val0x6c4; - coex_dm->pre_val0x6c8 = coex_dm->cur_val0x6c8; - coex_dm->pre_val0x6cc = coex_dm->cur_val0x6cc; -} - -void halbtc8192e2ant_coex_table_with_type(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 type) -{ - switch (type) { - case 0: - halbtc8192e2ant_coex_table(btcoexist, force_exec, 0x55555555, - 0x5a5a5a5a, 0xffffff, 0x3); - break; - case 1: - halbtc8192e2ant_coex_table(btcoexist, force_exec, 0x5a5a5a5a, - 0x5a5a5a5a, 0xffffff, 0x3); - break; - case 2: - halbtc8192e2ant_coex_table(btcoexist, force_exec, 0x55dd55dd, - 0x5ada5ada, 0xffffff, 0x3); - break; - case 3: - halbtc8192e2ant_coex_table(btcoexist, force_exec, 0x5fdf5fdf, - 0x5fdb5fdb, 0xffffff, 0x3); - break; - case 4: - halbtc8192e2ant_coex_table(btcoexist, force_exec, 0xdfffdfff, - 0x5ffb5ffb, 0xffffff, 0x3); - break; - case 5: - halbtc8192e2ant_coex_table(btcoexist, force_exec, 0x5ddd5ddd, - 0x5fdb5fdb, 0xffffff, 0x3); - break; - case 6: - halbtc8192e2ant_coex_table(btcoexist, force_exec, 0x5fff5fff, - 0x5a5a5a5a, 0xffffff, 0x3); - break; - case 7: - if (coex_sta->scan_ap_num <= NOISY_AP_NUM_THRESH_8192E) - halbtc8192e2ant_coex_table(btcoexist, force_exec, - 0xffffffff, 0xfafafafa, 0xffffff, 0x3); - else - halbtc8192e2ant_coex_table(btcoexist, force_exec, - 0xffffffff, 0x5a5a5a5a, 0xffffff, 0x3); - break; - case 8: - halbtc8192e2ant_coex_table(btcoexist, force_exec, 0x5f5f5f5f, - 0x5a5a5a5a, 0xffffff, 0x3); - break; - default: - break; - } -} - -void halbtc8192e2ant_set_fw_ignore_wlan_act(IN struct btc_coexist *btcoexist, - IN boolean enable) -{ - u8 h2c_parameter[1] = {0}; - - if (enable) - h2c_parameter[0] |= BIT(0); /* function enable */ - - btcoexist->btc_fill_h2c(btcoexist, 0x63, 1, h2c_parameter); -} - -void halbtc8192e2ant_ignore_wlan_act(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean enable) -{ - coex_dm->cur_ignore_wlan_act = enable; - - if (!force_exec) { - if (coex_dm->pre_ignore_wlan_act == - coex_dm->cur_ignore_wlan_act) - return; - } - halbtc8192e2ant_set_fw_ignore_wlan_act(btcoexist, enable); - - coex_dm->pre_ignore_wlan_act = coex_dm->cur_ignore_wlan_act; -} - -void halbtc8192e2ant_set_lps_rpwm(IN struct btc_coexist *btcoexist, - IN u8 lps_val, IN u8 rpwm_val) -{ - u8 lps = lps_val; - u8 rpwm = rpwm_val; - - btcoexist->btc_set(btcoexist, BTC_SET_U1_LPS_VAL, &lps); - btcoexist->btc_set(btcoexist, BTC_SET_U1_RPWM_VAL, &rpwm); -} - -void halbtc8192e2ant_lps_rpwm(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 lps_val, IN u8 rpwm_val) -{ - coex_dm->cur_lps = lps_val; - coex_dm->cur_rpwm = rpwm_val; - - if (!force_exec) { - if ((coex_dm->pre_lps == coex_dm->cur_lps) && - (coex_dm->pre_rpwm == coex_dm->cur_rpwm)) - return; - } - halbtc8192e2ant_set_lps_rpwm(btcoexist, lps_val, rpwm_val); - - coex_dm->pre_lps = coex_dm->cur_lps; - coex_dm->pre_rpwm = coex_dm->cur_rpwm; -} - -void halbtc8192e2ant_set_fw_pstdma(IN struct btc_coexist *btcoexist, - IN u8 byte1, IN u8 byte2, IN u8 byte3, IN u8 byte4, IN u8 byte5) -{ - u8 h2c_parameter[5] = {0}; - u8 real_byte1 = byte1, real_byte5 = byte5; - boolean ap_enable = false; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, - &ap_enable); - - if (ap_enable) { - if (byte1 & BIT(4) && !(byte1 & BIT(5))) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], FW for 1Ant AP mode\n"); - real_byte1 &= ~BIT(4); - real_byte1 |= BIT(5); - - real_byte5 |= BIT(5); - real_byte5 &= ~BIT(6); - } - } - - h2c_parameter[0] = byte1; - h2c_parameter[1] = byte2; - h2c_parameter[2] = byte3; - h2c_parameter[3] = byte4; - h2c_parameter[4] = byte5; - - coex_dm->ps_tdma_para[0] = byte1; - coex_dm->ps_tdma_para[1] = byte2; - coex_dm->ps_tdma_para[2] = byte3; - coex_dm->ps_tdma_para[3] = byte4; - coex_dm->ps_tdma_para[4] = byte5; - - btcoexist->btc_fill_h2c(btcoexist, 0x60, 5, h2c_parameter); -} - -void halbtc8192e2ant_sw_mechanism1(IN struct btc_coexist *btcoexist, - IN boolean shrink_rx_lpf, IN boolean low_penalty_ra, - IN boolean limited_dig, IN boolean bt_lna_constrain) -{ - /* - u32 wifi_bw; - - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw); - - if(BTC_WIFI_BW_HT40 != wifi_bw) - { - if (shrink_rx_lpf) - shrink_rx_lpf = false; - } - */ - - halbtc8192e2ant_rf_shrink(btcoexist, NORMAL_EXEC, shrink_rx_lpf); - /* halbtc8192e2ant_low_penalty_ra(btcoexist, NORMAL_EXEC, low_penalty_ra); */ -} - -void halbtc8192e2ant_sw_mechanism2(IN struct btc_coexist *btcoexist, - IN boolean agc_table_shift, IN boolean adc_back_off, - IN boolean sw_dac_swing, IN u32 dac_swing_lvl) -{ - halbtc8192e2ant_agc_table(btcoexist, NORMAL_EXEC, agc_table_shift); - /* halbtc8192e2ant_adc_back_off(btcoexist, NORMAL_EXEC, adc_back_off); */ - halbtc8192e2ant_dac_swing(btcoexist, NORMAL_EXEC, sw_dac_swing, - dac_swing_lvl); -} - -void halbtc8192e2ant_set_ant_path(IN struct btc_coexist *btcoexist, - IN u8 ant_pos_type, IN boolean init_hwcfg, IN boolean wifi_off) -{ - u32 u32tmp = 0; - - if (init_hwcfg) { - btcoexist->btc_write_1byte(btcoexist, 0x944, 0x24); - btcoexist->btc_write_4byte(btcoexist, 0x930, 0x700700); - if (btcoexist->chip_interface == BTC_INTF_USB) - btcoexist->btc_write_4byte(btcoexist, 0x64, 0x30430004); - else - btcoexist->btc_write_4byte(btcoexist, 0x64, 0x30030004); - - /* 0x4c[27][24]='00', Set Antenna to BB */ - u32tmp = btcoexist->btc_read_4byte(btcoexist, 0x4c); - u32tmp &= ~BIT(24); - u32tmp &= ~BIT(27); - btcoexist->btc_write_4byte(btcoexist, 0x4c, u32tmp); - } else if (wifi_off) { - if (btcoexist->chip_interface == BTC_INTF_USB) - btcoexist->btc_write_4byte(btcoexist, 0x64, 0x30430004); - else - btcoexist->btc_write_4byte(btcoexist, 0x64, 0x30030004); - - /* 0x4c[27][24]='11', Set Antenna to BT, 0x64[8:7]=0, 0x64[2]=1 */ - u32tmp = btcoexist->btc_read_4byte(btcoexist, 0x4c); - u32tmp |= BIT(24); - u32tmp |= BIT(27); - btcoexist->btc_write_4byte(btcoexist, 0x4c, u32tmp); - } - - /* ext switch setting */ - switch (ant_pos_type) { - case BTC_ANT_PATH_WIFI: - btcoexist->btc_write_1byte(btcoexist, 0x92c, 0x4); - break; - case BTC_ANT_PATH_BT: - btcoexist->btc_write_1byte(btcoexist, 0x92c, 0x20); - break; - default: - case BTC_ANT_PATH_PTA: - btcoexist->btc_write_1byte(btcoexist, 0x92c, 0x4); - break; - } -} - -void halbtc8192e2ant_ps_tdma(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean turn_on, IN u8 type) -{ - s8 wifi_duration_adjust = 0x0; - - coex_dm->cur_ps_tdma_on = turn_on; - coex_dm->cur_ps_tdma = type; - - if (!force_exec) { - if ((coex_dm->pre_ps_tdma_on == coex_dm->cur_ps_tdma_on) && - (coex_dm->pre_ps_tdma == coex_dm->cur_ps_tdma)) - return; - } - - if (coex_sta->scan_ap_num >= 40) - wifi_duration_adjust = -15; - else if (coex_sta->scan_ap_num >= 20) - wifi_duration_adjust = -10; - - - if (turn_on) { - switch (type) { - case 1: - default: /*d1,wb*/ - halbtc8192e2ant_set_fw_pstdma(btcoexist, 0xe3, 0x3c, - 0x03, 0x11, 0x10); - break; - case 2: - halbtc8192e2ant_set_fw_pstdma(btcoexist, 0xe3, 0x32, - 0x03, 0x11, 0x10); - break; - case 3: - halbtc8192e2ant_set_fw_pstdma(btcoexist, 0xe3, 0x28, - 0x03, 0x11, 0x10); - break; - case 4: - halbtc8192e2ant_set_fw_pstdma(btcoexist, 0xe3, 0x1e, - 0x03, 0x11, 0x10); - break; - case 5: /*d1,pb,TXpause*/ - halbtc8192e2ant_set_fw_pstdma(btcoexist, 0x63, 0x3c, - 0x03, 0x90, 0x10); - break; - case 6: - halbtc8192e2ant_set_fw_pstdma(btcoexist, 0x63, 0x32, - 0x03, 0x90, 0x10); - break; - case 7: - halbtc8192e2ant_set_fw_pstdma(btcoexist, 0x63, 0x28, - 0x03, 0x90, 0x10); - break; - case 8: - halbtc8192e2ant_set_fw_pstdma(btcoexist, 0x63, 0x1e, - 0x03, 0x90, 0x10); - break; - case 9: /*d1,bb*/ - halbtc8192e2ant_set_fw_pstdma(btcoexist, 0xe3, 0x3c, - 0x03, 0x31, 0x10); - break; - case 10: - halbtc8192e2ant_set_fw_pstdma(btcoexist, 0xe3, 0x32, - 0x03, 0x31, 0x10); - break; - case 11: - halbtc8192e2ant_set_fw_pstdma(btcoexist, 0xe3, 0x28, - 0x03, 0x31, 0x10); - break; - case 12: - halbtc8192e2ant_set_fw_pstdma(btcoexist, 0xe3, 0x1e, - 0x03, 0x31, 0x10); - break; - case 13: /*d1,bb,TXpause*/ - halbtc8192e2ant_set_fw_pstdma(btcoexist, 0xe3, 0x3c, - 0x03, 0x30, 0x10); - break; - case 14: - halbtc8192e2ant_set_fw_pstdma(btcoexist, 0xe3, 0x32, - 0x03, 0x30, 0x10); - break; - case 15: - halbtc8192e2ant_set_fw_pstdma(btcoexist, 0xe3, 0x28, - 0x03, 0x30, 0x10); - break; - case 16: - halbtc8192e2ant_set_fw_pstdma(btcoexist, 0xe3, 0x1e, - 0x03, 0x30, 0x10); - break; - case 17: - halbtc8192e2ant_set_fw_pstdma(btcoexist, 0x61, 0x20, - 0x03, 0x10, 0x10); - break; - case 18: - halbtc8192e2ant_set_fw_pstdma(btcoexist, 0xe3, 0x5, 0x5, - 0xe1, 0x90); - break; - case 19: - halbtc8192e2ant_set_fw_pstdma(btcoexist, 0xe3, 0x25, - 0x25, 0xe1, 0x90); - break; - case 20: - halbtc8192e2ant_set_fw_pstdma(btcoexist, 0xe3, 0x25, - 0x25, 0x60, 0x90); - break; - case 21: - halbtc8192e2ant_set_fw_pstdma(btcoexist, 0x61, 0x35, - 0x03, 0x11, 0x11); - break; - case 22: /* d1,wb */ - halbtc8192e2ant_set_fw_pstdma(btcoexist, 0xe3, 0x14, - 0x03, 0x11, 0x14); - break; - case 23: /* d1,pb,TXpause */ - halbtc8192e2ant_set_fw_pstdma(btcoexist, 0x63, 0x14, - 0x03, 0x90, 0x14); - break; - case 24: /* d1,bb */ - halbtc8192e2ant_set_fw_pstdma(btcoexist, 0xe3, 0x14, - 0x03, 0x31, 0x14); - break; - case 25: /* d1,bb,TXpause */ - halbtc8192e2ant_set_fw_pstdma(btcoexist, 0xe3, 0x14, - 0x03, 0x30, 0x14); - break; - case 71: - halbtc8192e2ant_set_fw_pstdma(btcoexist, 0xe3, 0x1a, - 0x1a, 0xe1, 0x90); - break; - /* following cases is for wifi rssi low // bad antenna isolation, started from 81 */ - case 80: - halbtc8192e2ant_set_fw_pstdma(btcoexist, 0x51, 0x3c, - 0x3, 0x10, 0x50); - break; - case 81: - halbtc8192e2ant_set_fw_pstdma(btcoexist, 0x51, - 0x3a + wifi_duration_adjust, 0x3, 0x10, 0x50); - break; - case 82: - halbtc8192e2ant_set_fw_pstdma(btcoexist, 0x51, - 0x30 + wifi_duration_adjust, 0x03, 0x10, 0x50); - break; - case 83: - halbtc8192e2ant_set_fw_pstdma(btcoexist, 0x51, 0x21, - 0x03, 0x10, 0x50); - break; - case 84: - halbtc8192e2ant_set_fw_pstdma(btcoexist, 0x51, 0x15, - 0x3, 0x10, 0x50); - break; - case 85: - halbtc8192e2ant_set_fw_pstdma(btcoexist, 0x51, 0x3a, - 0x03, 0x10, 0x50); - break; - case 86: - halbtc8192e2ant_set_fw_pstdma(btcoexist, 0x51, 0x21, - 0x03, 0x10, 0x50); - break; - case 87: - halbtc8192e2ant_set_fw_pstdma(btcoexist, 0x51, 0x14, - 0x03, 0x10, 0x54); - break; - - } - } else { - /* disable PS tdma */ - switch (type) { - default: - case 0: /* ANT2PTA, 0x778=1 */ - halbtc8192e2ant_set_fw_pstdma(btcoexist, 0x8, - 0x0, 0x0, 0x0, 0x0); - halbtc8192e2ant_set_ant_path(btcoexist, - BTC_ANT_PATH_PTA, false, false); - break; - case 1: /* ANT2BT, 0x778=3 */ - halbtc8192e2ant_set_fw_pstdma(btcoexist, 0x0, - 0x0, 0x0, 0x8, 0x0); - delay_ms(5); - halbtc8192e2ant_set_ant_path(btcoexist, - BTC_ANT_PATH_BT, false, false); - break; - - } - } - - /* update pre state */ - coex_dm->pre_ps_tdma_on = coex_dm->cur_ps_tdma_on; - coex_dm->pre_ps_tdma = coex_dm->cur_ps_tdma; -} - -void halbtc8192e2ant_set_switch_ss_type(IN struct btc_coexist *btcoexist, - IN u8 ss_type) -{ - u8 mimo_ps = BTC_MIMO_PS_DYNAMIC; - u32 dis_ra_mask = 0x0; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], REAL set SS Type = %d\n", ss_type); - BTC_TRACE(trace_buf); - - dis_ra_mask = halbtc8192e2ant_decide_ra_mask(btcoexist, ss_type, - coex_dm->cur_ra_mask_type); - halbtc8192e2ant_update_ra_mask(btcoexist, FORCE_EXEC, dis_ra_mask); - - if (ss_type == 1) { - halbtc8192e2ant_ps_tdma(btcoexist, FORCE_EXEC, false, 1); - /* switch ofdm path */ - btcoexist->btc_write_1byte(btcoexist, 0xc04, 0x11); - btcoexist->btc_write_1byte(btcoexist, 0xd04, 0x1); - btcoexist->btc_write_4byte(btcoexist, 0x90c, 0x81111111); - /* switch cck patch */ - /* btcoexist->btc_write_1byte_bitmask(btcoexist, 0xe77, 0x4, 0x1); */ - /* btcoexist->btc_write_1byte(btcoexist, 0xa07, 0x81); */ - mimo_ps = BTC_MIMO_PS_STATIC; - } else if (ss_type == 2) { - halbtc8192e2ant_ps_tdma(btcoexist, FORCE_EXEC, false, 0); - btcoexist->btc_write_1byte(btcoexist, 0xc04, 0x33); - btcoexist->btc_write_1byte(btcoexist, 0xd04, 0x3); - btcoexist->btc_write_4byte(btcoexist, 0x90c, 0x81121313); - /* remove, if 0xe77[2]=0x0 then CCK will fail, advised by Jenyu */ - /* btcoexist->btc_write_1byte_bitmask(btcoexist, 0xe77, 0x4, 0x0); */ - /* btcoexist->btc_write_1byte(btcoexist, 0xa07, 0x41); */ - mimo_ps = BTC_MIMO_PS_DYNAMIC; - } - - btcoexist->btc_set(btcoexist, BTC_SET_ACT_SEND_MIMO_PS, - &mimo_ps); /* set rx 1ss or 2ss */ -} - -void halbtc8192e2ant_switch_ss_type(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 new_ss_type) -{ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], %s Switch SS Type = %d\n", - (force_exec ? "force to" : ""), new_ss_type); - BTC_TRACE(trace_buf); - coex_dm->cur_ss_type = new_ss_type; - - if (!force_exec) { - if (coex_dm->pre_ss_type == coex_dm->cur_ss_type) - return; - } - halbtc8192e2ant_set_switch_ss_type(btcoexist, coex_dm->cur_ss_type); - - coex_dm->pre_ss_type = coex_dm->cur_ss_type; -} - -void halbtc8192e2ant_ps_tdma_check_for_power_save_state( - IN struct btc_coexist *btcoexist, IN boolean new_ps_state) -{ - u8 lps_mode = 0x0; - - btcoexist->btc_get(btcoexist, BTC_GET_U1_LPS_MODE, &lps_mode); - - if (lps_mode) { /* already under LPS state */ - if (new_ps_state) { - /* keep state under LPS, do nothing. */ - } else { - /* will leave LPS state, turn off psTdma first */ - halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, - 0); - } - } else { /* NO PS state */ - if (new_ps_state) { - /* will enter LPS state, turn off psTdma first */ - halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, - 0); - } else { - /* keep state under NO PS state, do nothing. */ - } - } -} - -void halbtc8192e2ant_power_save_state(IN struct btc_coexist *btcoexist, - IN u8 ps_type, IN u8 lps_val, IN u8 rpwm_val) -{ - boolean low_pwr_disable = false; - boolean ap_enable = false; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, - &ap_enable); - - if (ap_enable) { - ps_type = BTC_PS_WIFI_NATIVE; - lps_val = 0x0; - rpwm_val = 0x0; - } - switch (ps_type) { - case BTC_PS_WIFI_NATIVE: - btcoexist->btc_set(btcoexist, - BTC_SET_ACT_DISABLE_LOW_POWER, - &low_pwr_disable); - btcoexist->btc_set(btcoexist, BTC_SET_ACT_NORMAL_LPS, - NULL); - break; - case BTC_PS_LPS_ON: - halbtc8192e2ant_ps_tdma_check_for_power_save_state( - btcoexist, true); - halbtc8192e2ant_lps_rpwm(btcoexist, NORMAL_EXEC, - lps_val, rpwm_val); - btcoexist->btc_set(btcoexist, - BTC_SET_ACT_DISABLE_LOW_POWER, - &low_pwr_disable); - /* power save must executed before psTdma. */ - btcoexist->btc_set(btcoexist, BTC_SET_ACT_ENTER_LPS, - NULL); - break; - default: - break; - } -} - - -void halbtc8192e2ant_coex_all_off(IN struct btc_coexist *btcoexist) -{ - /* fw all off */ - halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1); - halbtc8192e2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6); - halbtc8192e2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - /* sw all off */ - halbtc8192e2ant_sw_mechanism1(btcoexist, false, false, false, false); - halbtc8192e2ant_sw_mechanism2(btcoexist, false, false, false, 0x18); - - /* hw all off */ - halbtc8192e2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); -} - -void halbtc8192e2ant_init_coex_dm(IN struct btc_coexist *btcoexist) -{ - /* force to reset coex mechanism */ - halbtc8192e2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0, - 0x0); - halbtc8192e2ant_ps_tdma(btcoexist, FORCE_EXEC, false, 0); - halbtc8192e2ant_fw_dac_swing_lvl(btcoexist, FORCE_EXEC, 6); - halbtc8192e2ant_dec_bt_pwr(btcoexist, FORCE_EXEC, 0); - - halbtc8192e2ant_coex_table_with_type(btcoexist, FORCE_EXEC, 0); - halbtc8192e2ant_switch_ss_type(btcoexist, FORCE_EXEC, 2); - - halbtc8192e2ant_sw_mechanism1(btcoexist, false, false, false, false); - halbtc8192e2ant_sw_mechanism2(btcoexist, false, false, false, 0x18); -} - -void halbtc8192e2ant_action_bt_inquiry(IN struct btc_coexist *btcoexist) -{ - - - /* halbtc8192e2ant_switch_ss_type(btcoexist, NORMAL_EXEC, 1);*/ - halbtc8192e2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0, - 0x0); - - halbtc8192e2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - halbtc8192e2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0, - 0x0); - halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 21); - halbtc8192e2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6); - halbtc8192e2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - halbtc8192e2ant_sw_mechanism1(btcoexist, false, false, false, false); - halbtc8192e2ant_sw_mechanism2(btcoexist, false, false, false, 0x18); -} - -boolean halbtc8192e2ant_is_common_action(IN struct btc_coexist *btcoexist) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - boolean common = false, wifi_connected = false, wifi_busy = false; - boolean bt_hs_on = false, low_pwr_disable = false; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - - if (bt_link_info->sco_exist || bt_link_info->hid_exist) - halbtc8192e2ant_limited_tx(btcoexist, NORMAL_EXEC, 1, 0, 0, 0); - else - halbtc8192e2ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0); - - if (!wifi_connected) { - - halbtc8192e2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, - 0x0, 0x0); - - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi non-connected idle!!\n"); - BTC_TRACE(trace_buf); - - if ((BT_8192E_2ANT_BT_STATUS_NON_CONNECTED_IDLE == - coex_dm->bt_status) || - (BT_8192E_2ANT_BT_STATUS_CONNECTED_IDLE == - coex_dm->bt_status)) { - /* halbtc8192e2ant_switch_ss_type(btcoexist, NORMAL_EXEC, 2);*/ - halbtc8192e2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 1); - halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, - 0); - } else { - /* halbtc8192e2ant_switch_ss_type(btcoexist, NORMAL_EXEC, 1);*/ - halbtc8192e2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 0); - halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, - 1); - } - - halbtc8192e2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6); - halbtc8192e2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - halbtc8192e2ant_sw_mechanism1(btcoexist, false, false, false, - false); - halbtc8192e2ant_sw_mechanism2(btcoexist, false, false, false, - 0x18); - - common = true; - } else { - if (BT_8192E_2ANT_BT_STATUS_NON_CONNECTED_IDLE == - coex_dm->bt_status) { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi connected + BT non connected-idle!!\n"); - BTC_TRACE(trace_buf); - - halbtc8192e2ant_power_save_state(btcoexist, - BTC_PS_WIFI_NATIVE, 0x0, 0x0); - /* halbtc8192e2ant_switch_ss_type(btcoexist, NORMAL_EXEC, 2);*/ - - halbtc8192e2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 1); - halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, - 0); - halbtc8192e2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, - 6); - halbtc8192e2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - halbtc8192e2ant_sw_mechanism1(btcoexist, false, false, - false, false); - halbtc8192e2ant_sw_mechanism2(btcoexist, false, false, - false, 0x18); - - common = true; - } else if (BT_8192E_2ANT_BT_STATUS_CONNECTED_IDLE == - coex_dm->bt_status) { - - if (bt_hs_on) - return false; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi connected + BT connected-idle!!\n"); - BTC_TRACE(trace_buf); - - halbtc8192e2ant_power_save_state(btcoexist, - BTC_PS_WIFI_NATIVE, 0x0, 0x0); - /* halbtc8192e2ant_switch_ss_type(btcoexist, NORMAL_EXEC, 2);*/ - halbtc8192e2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 0); - halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, - 0); - halbtc8192e2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, - 6); - halbtc8192e2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - halbtc8192e2ant_sw_mechanism1(btcoexist, true, false, - false, false); - halbtc8192e2ant_sw_mechanism2(btcoexist, false, false, - false, 0x18); - - common = true; - } else { - - if (wifi_busy) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi Connected-Busy + BT Busy!!\n"); - BTC_TRACE(trace_buf); - common = false; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi Connected-Idle + BT Busy!!\n"); - BTC_TRACE(trace_buf); - - halbtc8192e2ant_power_save_state(btcoexist, - BTC_PS_WIFI_NATIVE, 0x0, 0x0); - /* halbtc8192e2ant_switch_ss_type(btcoexist, NORMAL_EXEC, 1);*/ - halbtc8192e2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 0); - halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 21); - halbtc8192e2ant_fw_dac_swing_lvl(btcoexist, - NORMAL_EXEC, 6); - halbtc8192e2ant_dec_bt_pwr(btcoexist, - NORMAL_EXEC, 0); - halbtc8192e2ant_sw_mechanism1(btcoexist, false, - false, false, false); - halbtc8192e2ant_sw_mechanism2(btcoexist, false, - false, false, 0x18); - common = true; - } - } - } - - return common; -} -void halbtc8192e2ant_tdma_duration_adjust(IN struct btc_coexist *btcoexist, - IN boolean sco_hid, IN boolean tx_pause, IN u8 max_interval) -{ - static s32 up, dn, m, n, wait_count; - s32 result; /* 0: no change, +1: increase WiFi duration, -1: decrease WiFi duration */ - u8 retry_count = 0; - - - if (!coex_dm->auto_tdma_adjust) { - coex_dm->auto_tdma_adjust = true; - { - if (sco_hid) { - if (tx_pause) { - if (max_interval == 1) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 13); - coex_dm->ps_tdma_du_adj_type = - 13; - } else if (max_interval == 2) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 14); - coex_dm->ps_tdma_du_adj_type = - 14; - } else if (max_interval == 3) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 15); - coex_dm->ps_tdma_du_adj_type = - 15; - } else { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 15); - coex_dm->ps_tdma_du_adj_type = - 15; - } - } else { - if (max_interval == 1) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 9); - coex_dm->ps_tdma_du_adj_type = - 9; - } else if (max_interval == 2) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 10); - coex_dm->ps_tdma_du_adj_type = - 10; - } else if (max_interval == 3) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 11); - coex_dm->ps_tdma_du_adj_type = - 11; - } else { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 11); - coex_dm->ps_tdma_du_adj_type = - 11; - } - } - } else { - if (tx_pause) { - if (max_interval == 1) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 5); - coex_dm->ps_tdma_du_adj_type = - 5; - } else if (max_interval == 2) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 6); - coex_dm->ps_tdma_du_adj_type = - 6; - } else if (max_interval == 3) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 7); - coex_dm->ps_tdma_du_adj_type = - 7; - } else { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 7); - coex_dm->ps_tdma_du_adj_type = - 7; - } - } else { - if (max_interval == 1) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 1); - coex_dm->ps_tdma_du_adj_type = - 1; - } else if (max_interval == 2) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 2); - coex_dm->ps_tdma_du_adj_type = - 2; - } else if (max_interval == 3) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 3); - coex_dm->ps_tdma_du_adj_type = - 3; - } else { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 3); - coex_dm->ps_tdma_du_adj_type = - 3; - } - } - } - } - /* ============ */ - up = 0; - dn = 0; - m = 1; - n = 3; - result = 0; - wait_count = 0; - } else { - /* acquire the BT TRx retry count from BT_Info byte2 */ - retry_count = coex_sta->bt_retry_cnt; - result = 0; - wait_count++; - - if (retry_count == - 0) { /* no retry in the last 2-second duration */ - up++; - dn--; - - if (dn <= 0) - dn = 0; - - if (up >= n) { /* if retry count during continuous n*2 seconds is 0, enlarge WiFi duration */ - wait_count = 0; - n = 3; - up = 0; - dn = 0; - result = 1; - } - } else if (retry_count <= - 3) { /* <=3 retry in the last 2-second duration */ - up--; - dn++; - - if (up <= 0) - up = 0; - - if (dn == 2) { /* if continuous 2 retry count(every 2 seconds) >0 and < 3, reduce WiFi duration */ - if (wait_count <= 2) - m++; /* to avoid loop between the two levels */ - else - m = 1; - - if (m >= 20) /* maximum of m = 20 ' will recheck if need to adjust wifi duration in maximum time interval 120 seconds */ - m = 20; - - n = 3 * m; - up = 0; - dn = 0; - wait_count = 0; - result = -1; - } - } else { /* retry count > 3, once retry count > 3, to reduce WiFi duration */ - if (wait_count == 1) - m++; /* to avoid loop between the two levels */ - else - m = 1; - - if (m >= 20) /* maximum of m = 20 ' will recheck if need to adjust wifi duration in maximum time interval 120 seconds */ - m = 20; - - n = 3 * m; - up = 0; - dn = 0; - wait_count = 0; - result = -1; - } - - if (max_interval == 1) { - if (tx_pause) { - if (coex_dm->cur_ps_tdma == 1) { - halbtc8192e2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 5); - coex_dm->ps_tdma_du_adj_type = 5; - } else if (coex_dm->cur_ps_tdma == 2) { - halbtc8192e2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 6); - coex_dm->ps_tdma_du_adj_type = 6; - } else if (coex_dm->cur_ps_tdma == 3) { - halbtc8192e2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 7); - coex_dm->ps_tdma_du_adj_type = 7; - } else if (coex_dm->cur_ps_tdma == 4) { - halbtc8192e2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 8); - coex_dm->ps_tdma_du_adj_type = 8; - } - if (coex_dm->cur_ps_tdma == 9) { - halbtc8192e2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 13); - coex_dm->ps_tdma_du_adj_type = 13; - } else if (coex_dm->cur_ps_tdma == 10) { - halbtc8192e2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 14); - coex_dm->ps_tdma_du_adj_type = 14; - } else if (coex_dm->cur_ps_tdma == 11) { - halbtc8192e2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 15); - coex_dm->ps_tdma_du_adj_type = 15; - } else if (coex_dm->cur_ps_tdma == 12) { - halbtc8192e2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 16); - coex_dm->ps_tdma_du_adj_type = 16; - } - - if (result == -1) { - if (coex_dm->cur_ps_tdma == 5) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 6); - coex_dm->ps_tdma_du_adj_type = - 6; - } else if (coex_dm->cur_ps_tdma == 6) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 7); - coex_dm->ps_tdma_du_adj_type = - 7; - } else if (coex_dm->cur_ps_tdma == 7) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 8); - coex_dm->ps_tdma_du_adj_type = - 8; - } else if (coex_dm->cur_ps_tdma == 13) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 14); - coex_dm->ps_tdma_du_adj_type = - 14; - } else if (coex_dm->cur_ps_tdma == 14) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 15); - coex_dm->ps_tdma_du_adj_type = - 15; - } else if (coex_dm->cur_ps_tdma == 15) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 16); - coex_dm->ps_tdma_du_adj_type = - 16; - } - } else if (result == 1) { - if (coex_dm->cur_ps_tdma == 8) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 7); - coex_dm->ps_tdma_du_adj_type = - 7; - } else if (coex_dm->cur_ps_tdma == 7) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 6); - coex_dm->ps_tdma_du_adj_type = - 6; - } else if (coex_dm->cur_ps_tdma == 6) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 5); - coex_dm->ps_tdma_du_adj_type = - 5; - } else if (coex_dm->cur_ps_tdma == 16) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 15); - coex_dm->ps_tdma_du_adj_type = - 15; - } else if (coex_dm->cur_ps_tdma == 15) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 14); - coex_dm->ps_tdma_du_adj_type = - 14; - } else if (coex_dm->cur_ps_tdma == 14) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 13); - coex_dm->ps_tdma_du_adj_type = - 13; - } - } - } else { - if (coex_dm->cur_ps_tdma == 5) { - halbtc8192e2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 1); - coex_dm->ps_tdma_du_adj_type = 1; - } else if (coex_dm->cur_ps_tdma == 6) { - halbtc8192e2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 2); - coex_dm->ps_tdma_du_adj_type = 2; - } else if (coex_dm->cur_ps_tdma == 7) { - halbtc8192e2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 3); - coex_dm->ps_tdma_du_adj_type = 3; - } else if (coex_dm->cur_ps_tdma == 8) { - halbtc8192e2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 4); - coex_dm->ps_tdma_du_adj_type = 4; - } - if (coex_dm->cur_ps_tdma == 13) { - halbtc8192e2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 9); - coex_dm->ps_tdma_du_adj_type = 9; - } else if (coex_dm->cur_ps_tdma == 14) { - halbtc8192e2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 10); - coex_dm->ps_tdma_du_adj_type = 10; - } else if (coex_dm->cur_ps_tdma == 15) { - halbtc8192e2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 11); - coex_dm->ps_tdma_du_adj_type = 11; - } else if (coex_dm->cur_ps_tdma == 16) { - halbtc8192e2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 12); - coex_dm->ps_tdma_du_adj_type = 12; - } - - if (result == -1) { - if (coex_dm->cur_ps_tdma == 1) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 2); - coex_dm->ps_tdma_du_adj_type = - 2; - } else if (coex_dm->cur_ps_tdma == 2) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 3); - coex_dm->ps_tdma_du_adj_type = - 3; - } else if (coex_dm->cur_ps_tdma == 3) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 4); - coex_dm->ps_tdma_du_adj_type = - 4; - } else if (coex_dm->cur_ps_tdma == 9) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 10); - coex_dm->ps_tdma_du_adj_type = - 10; - } else if (coex_dm->cur_ps_tdma == 10) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 11); - coex_dm->ps_tdma_du_adj_type = - 11; - } else if (coex_dm->cur_ps_tdma == 11) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 12); - coex_dm->ps_tdma_du_adj_type = - 12; - } - } else if (result == 1) { - if (coex_dm->cur_ps_tdma == 4) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 3); - coex_dm->ps_tdma_du_adj_type = - 3; - } else if (coex_dm->cur_ps_tdma == 3) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 2); - coex_dm->ps_tdma_du_adj_type = - 2; - } else if (coex_dm->cur_ps_tdma == 2) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 1); - coex_dm->ps_tdma_du_adj_type = - 1; - } else if (coex_dm->cur_ps_tdma == 1) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 71); - coex_dm->ps_tdma_du_adj_type = - 71; - } else if (coex_dm->cur_ps_tdma == 12) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 11); - coex_dm->ps_tdma_du_adj_type = - 11; - } else if (coex_dm->cur_ps_tdma == 11) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 10); - coex_dm->ps_tdma_du_adj_type = - 10; - } else if (coex_dm->cur_ps_tdma == 10) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 9); - coex_dm->ps_tdma_du_adj_type = - 9; - } - } - } - } else if (max_interval == 2) { - if (tx_pause) { - if (coex_dm->cur_ps_tdma == 1) { - halbtc8192e2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 6); - coex_dm->ps_tdma_du_adj_type = 6; - } else if (coex_dm->cur_ps_tdma == 2) { - halbtc8192e2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 6); - coex_dm->ps_tdma_du_adj_type = 6; - } else if (coex_dm->cur_ps_tdma == 3) { - halbtc8192e2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 7); - coex_dm->ps_tdma_du_adj_type = 7; - } else if (coex_dm->cur_ps_tdma == 4) { - halbtc8192e2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 8); - coex_dm->ps_tdma_du_adj_type = 8; - } - if (coex_dm->cur_ps_tdma == 9) { - halbtc8192e2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 14); - coex_dm->ps_tdma_du_adj_type = 14; - } else if (coex_dm->cur_ps_tdma == 10) { - halbtc8192e2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 14); - coex_dm->ps_tdma_du_adj_type = 14; - } else if (coex_dm->cur_ps_tdma == 11) { - halbtc8192e2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 15); - coex_dm->ps_tdma_du_adj_type = 15; - } else if (coex_dm->cur_ps_tdma == 12) { - halbtc8192e2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 16); - coex_dm->ps_tdma_du_adj_type = 16; - } - if (result == -1) { - if (coex_dm->cur_ps_tdma == 5) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 6); - coex_dm->ps_tdma_du_adj_type = - 6; - } else if (coex_dm->cur_ps_tdma == 6) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 7); - coex_dm->ps_tdma_du_adj_type = - 7; - } else if (coex_dm->cur_ps_tdma == 7) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 8); - coex_dm->ps_tdma_du_adj_type = - 8; - } else if (coex_dm->cur_ps_tdma == 13) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 14); - coex_dm->ps_tdma_du_adj_type = - 14; - } else if (coex_dm->cur_ps_tdma == 14) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 15); - coex_dm->ps_tdma_du_adj_type = - 15; - } else if (coex_dm->cur_ps_tdma == 15) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 16); - coex_dm->ps_tdma_du_adj_type = - 16; - } - } else if (result == 1) { - if (coex_dm->cur_ps_tdma == 8) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 7); - coex_dm->ps_tdma_du_adj_type = - 7; - } else if (coex_dm->cur_ps_tdma == 7) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 6); - coex_dm->ps_tdma_du_adj_type = - 6; - } else if (coex_dm->cur_ps_tdma == 6) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 6); - coex_dm->ps_tdma_du_adj_type = - 6; - } else if (coex_dm->cur_ps_tdma == 16) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 15); - coex_dm->ps_tdma_du_adj_type = - 15; - } else if (coex_dm->cur_ps_tdma == 15) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 14); - coex_dm->ps_tdma_du_adj_type = - 14; - } else if (coex_dm->cur_ps_tdma == 14) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 14); - coex_dm->ps_tdma_du_adj_type = - 14; - } - } - } else { - if (coex_dm->cur_ps_tdma == 5) { - halbtc8192e2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 2); - coex_dm->ps_tdma_du_adj_type = 2; - } else if (coex_dm->cur_ps_tdma == 6) { - halbtc8192e2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 2); - coex_dm->ps_tdma_du_adj_type = 2; - } else if (coex_dm->cur_ps_tdma == 7) { - halbtc8192e2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 3); - coex_dm->ps_tdma_du_adj_type = 3; - } else if (coex_dm->cur_ps_tdma == 8) { - halbtc8192e2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 4); - coex_dm->ps_tdma_du_adj_type = 4; - } - if (coex_dm->cur_ps_tdma == 13) { - halbtc8192e2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 10); - coex_dm->ps_tdma_du_adj_type = 10; - } else if (coex_dm->cur_ps_tdma == 14) { - halbtc8192e2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 10); - coex_dm->ps_tdma_du_adj_type = 10; - } else if (coex_dm->cur_ps_tdma == 15) { - halbtc8192e2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 11); - coex_dm->ps_tdma_du_adj_type = 11; - } else if (coex_dm->cur_ps_tdma == 16) { - halbtc8192e2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 12); - coex_dm->ps_tdma_du_adj_type = 12; - } - if (result == -1) { - if (coex_dm->cur_ps_tdma == 1) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 2); - coex_dm->ps_tdma_du_adj_type = - 2; - } else if (coex_dm->cur_ps_tdma == 2) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 3); - coex_dm->ps_tdma_du_adj_type = - 3; - } else if (coex_dm->cur_ps_tdma == 3) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 4); - coex_dm->ps_tdma_du_adj_type = - 4; - } else if (coex_dm->cur_ps_tdma == 9) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 10); - coex_dm->ps_tdma_du_adj_type = - 10; - } else if (coex_dm->cur_ps_tdma == 10) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 11); - coex_dm->ps_tdma_du_adj_type = - 11; - } else if (coex_dm->cur_ps_tdma == 11) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 12); - coex_dm->ps_tdma_du_adj_type = - 12; - } - } else if (result == 1) { - if (coex_dm->cur_ps_tdma == 4) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 3); - coex_dm->ps_tdma_du_adj_type = - 3; - } else if (coex_dm->cur_ps_tdma == 3) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 2); - coex_dm->ps_tdma_du_adj_type = - 2; - } else if (coex_dm->cur_ps_tdma == 2) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 2); - coex_dm->ps_tdma_du_adj_type = - 2; - } else if (coex_dm->cur_ps_tdma == 12) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 11); - coex_dm->ps_tdma_du_adj_type = - 11; - } else if (coex_dm->cur_ps_tdma == 11) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 10); - coex_dm->ps_tdma_du_adj_type = - 10; - } else if (coex_dm->cur_ps_tdma == 10) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 10); - coex_dm->ps_tdma_du_adj_type = - 10; - } - } - } - } else if (max_interval == 3) { - if (tx_pause) { - if (coex_dm->cur_ps_tdma == 1) { - halbtc8192e2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 7); - coex_dm->ps_tdma_du_adj_type = 7; - } else if (coex_dm->cur_ps_tdma == 2) { - halbtc8192e2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 7); - coex_dm->ps_tdma_du_adj_type = 7; - } else if (coex_dm->cur_ps_tdma == 3) { - halbtc8192e2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 7); - coex_dm->ps_tdma_du_adj_type = 7; - } else if (coex_dm->cur_ps_tdma == 4) { - halbtc8192e2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 8); - coex_dm->ps_tdma_du_adj_type = 8; - } - if (coex_dm->cur_ps_tdma == 9) { - halbtc8192e2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 15); - coex_dm->ps_tdma_du_adj_type = 15; - } else if (coex_dm->cur_ps_tdma == 10) { - halbtc8192e2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 15); - coex_dm->ps_tdma_du_adj_type = 15; - } else if (coex_dm->cur_ps_tdma == 11) { - halbtc8192e2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 15); - coex_dm->ps_tdma_du_adj_type = 15; - } else if (coex_dm->cur_ps_tdma == 12) { - halbtc8192e2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 16); - coex_dm->ps_tdma_du_adj_type = 16; - } - if (result == -1) { - if (coex_dm->cur_ps_tdma == 5) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 7); - coex_dm->ps_tdma_du_adj_type = - 7; - } else if (coex_dm->cur_ps_tdma == 6) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 7); - coex_dm->ps_tdma_du_adj_type = - 7; - } else if (coex_dm->cur_ps_tdma == 7) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 8); - coex_dm->ps_tdma_du_adj_type = - 8; - } else if (coex_dm->cur_ps_tdma == 13) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 15); - coex_dm->ps_tdma_du_adj_type = - 15; - } else if (coex_dm->cur_ps_tdma == 14) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 15); - coex_dm->ps_tdma_du_adj_type = - 15; - } else if (coex_dm->cur_ps_tdma == 15) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 16); - coex_dm->ps_tdma_du_adj_type = - 16; - } - } else if (result == 1) { - if (coex_dm->cur_ps_tdma == 8) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 7); - coex_dm->ps_tdma_du_adj_type = - 7; - } else if (coex_dm->cur_ps_tdma == 7) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 7); - coex_dm->ps_tdma_du_adj_type = - 7; - } else if (coex_dm->cur_ps_tdma == 6) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 7); - coex_dm->ps_tdma_du_adj_type = - 7; - } else if (coex_dm->cur_ps_tdma == 16) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 15); - coex_dm->ps_tdma_du_adj_type = - 15; - } else if (coex_dm->cur_ps_tdma == 15) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 15); - coex_dm->ps_tdma_du_adj_type = - 15; - } else if (coex_dm->cur_ps_tdma == 14) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 15); - coex_dm->ps_tdma_du_adj_type = - 15; - } - } - } else { - if (coex_dm->cur_ps_tdma == 5) { - halbtc8192e2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 3); - coex_dm->ps_tdma_du_adj_type = 3; - } else if (coex_dm->cur_ps_tdma == 6) { - halbtc8192e2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 3); - coex_dm->ps_tdma_du_adj_type = 3; - } else if (coex_dm->cur_ps_tdma == 7) { - halbtc8192e2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 3); - coex_dm->ps_tdma_du_adj_type = 3; - } else if (coex_dm->cur_ps_tdma == 8) { - halbtc8192e2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 4); - coex_dm->ps_tdma_du_adj_type = 4; - } - if (coex_dm->cur_ps_tdma == 13) { - halbtc8192e2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 11); - coex_dm->ps_tdma_du_adj_type = 11; - } else if (coex_dm->cur_ps_tdma == 14) { - halbtc8192e2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 11); - coex_dm->ps_tdma_du_adj_type = 11; - } else if (coex_dm->cur_ps_tdma == 15) { - halbtc8192e2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 11); - coex_dm->ps_tdma_du_adj_type = 11; - } else if (coex_dm->cur_ps_tdma == 16) { - halbtc8192e2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 12); - coex_dm->ps_tdma_du_adj_type = 12; - } - if (result == -1) { - if (coex_dm->cur_ps_tdma == 1) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 3); - coex_dm->ps_tdma_du_adj_type = - 3; - } else if (coex_dm->cur_ps_tdma == 2) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 3); - coex_dm->ps_tdma_du_adj_type = - 3; - } else if (coex_dm->cur_ps_tdma == 3) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 4); - coex_dm->ps_tdma_du_adj_type = - 4; - } else if (coex_dm->cur_ps_tdma == 9) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 11); - coex_dm->ps_tdma_du_adj_type = - 11; - } else if (coex_dm->cur_ps_tdma == 10) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 11); - coex_dm->ps_tdma_du_adj_type = - 11; - } else if (coex_dm->cur_ps_tdma == 11) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 12); - coex_dm->ps_tdma_du_adj_type = - 12; - } - } else if (result == 1) { - if (coex_dm->cur_ps_tdma == 4) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 3); - coex_dm->ps_tdma_du_adj_type = - 3; - } else if (coex_dm->cur_ps_tdma == 3) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 3); - coex_dm->ps_tdma_du_adj_type = - 3; - } else if (coex_dm->cur_ps_tdma == 2) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 3); - coex_dm->ps_tdma_du_adj_type = - 3; - } else if (coex_dm->cur_ps_tdma == 12) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 11); - coex_dm->ps_tdma_du_adj_type = - 11; - } else if (coex_dm->cur_ps_tdma == 11) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 11); - coex_dm->ps_tdma_du_adj_type = - 11; - } else if (coex_dm->cur_ps_tdma == 10) { - halbtc8192e2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 11); - coex_dm->ps_tdma_du_adj_type = - 11; - } - } - } - } - } - - /* if current PsTdma not match with the recorded one (when scan, dhcp...), */ - /* then we have to adjust it back to the previous record one. */ - if (coex_dm->cur_ps_tdma != coex_dm->ps_tdma_du_adj_type) { - boolean scan = false, link = false, roam = false; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], PsTdma type dismatch!!!, cur_ps_tdma=%d, recordPsTdma=%d\n", - coex_dm->cur_ps_tdma, coex_dm->ps_tdma_du_adj_type); - BTC_TRACE(trace_buf); - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam); - - if (!scan && !link && !roam) - halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - coex_dm->ps_tdma_du_adj_type); - else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], roaming/link/scan is under progress, will adjust next time!!!\n"); - BTC_TRACE(trace_buf); - } - } -} - -/* ****************** - * pstdma for wifi rssi low - * ****************** */ -void halbtc8192e2ant_tdma_duration_adjust_for_wifi_rssi_low( - IN struct btc_coexist *btcoexist/* , */ /* IN u8 wifi_status */) -{ - static s32 up, dn, m, n, wait_count; - s32 result; /* 0: no change, +1: increase WiFi duration, -1: decrease WiFi duration */ - u8 retry_count = 0, bt_info_ext; - - coex_dm->auto_tdma_adjust = false; - - retry_count = coex_sta->bt_retry_cnt; - bt_info_ext = coex_sta->bt_info_ext; - - if (!coex_dm->auto_tdma_adjust_low_rssi) { - coex_dm->auto_tdma_adjust_low_rssi = true; - halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 81); - coex_dm->ps_tdma_du_adj_type = 81; - /* ============ */ - up = 0; - dn = 0; - m = 1; - n = 3; - result = 0; - wait_count = 0; - } else { - /* acquire the BT TRx retry count from BT_Info byte2 - * retry_count = coex_sta->bt_retry_cnt; - * bt_info_ext = coex_sta->bt_info_ext; */ - result = 0; - wait_count++; - - if ((coex_sta->low_priority_tx) > 1050 || - (coex_sta->low_priority_rx) > 1250) - retry_count++; - - if (retry_count == - 0) { /* no retry in the last 2-second duration */ - up++; - dn--; - - if (dn <= 0) - dn = 0; - - if (up >= n) { /* if retry count during continuous n*2 seconds is 0, enlarge WiFi duration */ - wait_count = 0; - n = 3; - up = 0; - dn = 0; - result = 1; - } - } else if (retry_count <= - 3) { /* <=3 retry in the last 2-second duration */ - up--; - dn++; - - if (up <= 0) - up = 0; - - if (dn == 2) { /* if continuous 2 retry count(every 2 seconds) >0 and < 3, reduce WiFi duration */ - if (wait_count <= 2) - m++; /* to avoid loop between the two levels */ - else - m = 1; - - if (m >= 20) /* maximum of m = 20 ' will recheck if need to adjust wifi duration in maximum time interval 120 seconds */ - m = 20; - - n = 3 * m; - up = 0; - dn = 0; - wait_count = 0; - result = -1; - } - } else { /* retry count > 3, once retry count > 3, to reduce WiFi duration */ - if (wait_count == 1) - m++; /* to avoid loop between the two levels */ - else - m = 1; - - if (m >= 20) /* maximum of m = 20 ' will recheck if need to adjust wifi duration in maximum time interval 120 seconds */ - m = 20; - - n = 3 * m; - up = 0; - dn = 0; - wait_count = 0; - result = -1; - } - - if (result == -1) { - if (coex_dm->cur_ps_tdma == 80) { - halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 81); - coex_dm->ps_tdma_du_adj_type = 81; - } else if (coex_dm->cur_ps_tdma == 81) { - halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 82); - coex_dm->ps_tdma_du_adj_type = 82; - } else if (coex_dm->cur_ps_tdma == 82) { - halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 83); - coex_dm->ps_tdma_du_adj_type = 83; - } else if (coex_dm->cur_ps_tdma == 83) { - halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 84); - coex_dm->ps_tdma_du_adj_type = 84; - } - } else if (result == 1) { - if (coex_dm->cur_ps_tdma == 84) { - halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 83); - coex_dm->ps_tdma_du_adj_type = 83; - } else if (coex_dm->cur_ps_tdma == 83) { - halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 82); - coex_dm->ps_tdma_du_adj_type = 82; - } else if (coex_dm->cur_ps_tdma == 82) { - halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 81); - coex_dm->ps_tdma_du_adj_type = 81; - } else if ((coex_dm->cur_ps_tdma == 81) && - (coex_sta->scan_ap_num <= 5)) { - halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 81); - coex_dm->ps_tdma_du_adj_type = 81; - } - } - - if (coex_dm->cur_ps_tdma != 80 && - coex_dm->cur_ps_tdma != 81 && - coex_dm->cur_ps_tdma != 82 && - coex_dm->cur_ps_tdma != 83 && - coex_dm->cur_ps_tdma != 84) { - /* recover to previous adjust type */ - halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - coex_dm->ps_tdma_du_adj_type); - } - } -} - - -void halbtc8192e2ant_get_bt_rssi_threshold(IN struct btc_coexist *btcoexist, - IN u8 *pThres0, IN u8 *pThres1) -{ - u8 ant_type; - - struct btc_board_info *board_info = &btcoexist->board_info; - - ant_type = board_info->ant_type; - - switch (ant_type) { - case BTC_ANT_TYPE_0: - *pThres0 = 100; - *pThres1 = 100; - break; - case BTC_ANT_TYPE_1: - *pThres0 = 34; - *pThres1 = 42; - break; - case BTC_ANT_TYPE_2: - *pThres0 = 34; - *pThres1 = 42; - break; - case BTC_ANT_TYPE_3: - *pThres0 = 34; - *pThres1 = 42; - break; - case BTC_ANT_TYPE_4: - *pThres0 = 34; - *pThres1 = 42; - break; - default: - break; - } -} - - - - -/* SCO only or SCO+PAN(HS) */ -void halbtc8192e2ant_action_sco(IN struct btc_coexist *btcoexist) -{ - u8 wifi_rssi_state, bt_rssi_state = BTC_RSSI_STATE_STAY_LOW; - u32 wifi_bw; - u8 bt_thresh0 = 0, bt_thresh1 = 0; - - halbtc8192e2ant_get_bt_rssi_threshold(btcoexist, &bt_thresh0, - &bt_thresh1); - bt_rssi_state = halbtc8192e2ant_bt_rssi_state(3, bt_thresh0, - bt_thresh1); - - wifi_rssi_state = halbtc8192e2ant_wifi_rssi_state(btcoexist, 0, 2, 34, - 0); - - if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state))) - halbtc8192e2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, - 0x0, 0x0); - else - halbtc8192e2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, - 0x0, 0x0); - - - if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state))) - halbtc8192e2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - else - halbtc8192e2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - - - if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state))) - halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); - else - halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); - - - halbtc8192e2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - halbtc8192e2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8); - halbtc8192e2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6); - - halbtc8192e2ant_sw_mechanism1(btcoexist, false, false, false, false); - halbtc8192e2ant_sw_mechanism2(btcoexist, false, false, false, 0x18); -} - -void halbtc8192e2ant_action_sco_pan(IN struct btc_coexist *btcoexist) -{ - u8 wifi_rssi_state, bt_rssi_state = BTC_RSSI_STATE_STAY_LOW; - u32 wifi_bw; - u8 bt_thresh0 = 0, bt_thresh1 = 0; - - - halbtc8192e2ant_get_bt_rssi_threshold(btcoexist, &bt_thresh0, - &bt_thresh1); - bt_rssi_state = halbtc8192e2ant_bt_rssi_state(3, bt_thresh0, - bt_thresh1); - - wifi_rssi_state = halbtc8192e2ant_wifi_rssi_state(btcoexist, 0, 2, 34, - 0); - - if ((BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state)))) - halbtc8192e2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, - 0x0, 0x0); - else - halbtc8192e2ant_power_save_state(btcoexist, BTC_PS_LPS_ON, 0x50, - 0x4); - - - if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state))) - halbtc8192e2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); - else - halbtc8192e2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - - - - if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state))) - halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 10); - else - halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 86); - - halbtc8192e2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8); - halbtc8192e2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6); - - halbtc8192e2ant_sw_mechanism1(btcoexist, false, false, false, false); - if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state)) && - (coex_sta->scan_ap_num < NOISY_AP_NUM_THRESH_8192E)) - halbtc8192e2ant_sw_mechanism2(btcoexist, false, false, false, - 0x18); - else if (BTC_RSSI_HIGH(wifi_rssi_state) && - (!BTC_RSSI_LOW(bt_rssi_state)) && - (coex_sta->scan_ap_num > NOISY_AP_NUM_THRESH_8192E)) - halbtc8192e2ant_sw_mechanism2(btcoexist, false, false, false, - 0x18); - else - halbtc8192e2ant_sw_mechanism2(btcoexist, false, false, false, - 0x18); -} - - -void halbtc8192e2ant_action_hid(IN struct btc_coexist *btcoexist) -{ - u8 wifi_rssi_state, bt_rssi_state = BTC_RSSI_STATE_HIGH; - u32 wifi_bw; - u8 anttype = 0; - - btcoexist->btc_get(btcoexist, BTC_GET_U1_ANT_TYPE, &anttype); - - wifi_rssi_state = halbtc8192e2ant_wifi_rssi_state(btcoexist, 0, 2, 34, - 0); - bt_rssi_state = halbtc8192e2ant_bt_rssi_state(3, 34, 42); - - if (anttype == 0) { - /*ANTTYPE = 0 92E 2ant with SPDT*/ - halbtc8192e2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, - 0x0, 0x0); - halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); - halbtc8192e2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - } else if (anttype == 1) { - /*92E 2ant with coupler and bad ant. isolation, 92E 3ant with bad ant. isolation*/ - halbtc8192e2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, - 0x0, 0x0); - halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); - halbtc8192e2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - } else if (anttype == 2) { - /*ANTTYPE = 2, 92E 2ant with coupler and normal/good ant. isolation, 92E 3ant with normal ant. isolation*/ - if (BTC_RSSI_HIGH(wifi_rssi_state) && - (!BTC_RSSI_LOW(bt_rssi_state))) { - halbtc8192e2ant_power_save_state(btcoexist, - BTC_PS_WIFI_NATIVE, 0x0, 0x0); - halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 9); - halbtc8192e2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 3); - } else { - halbtc8192e2ant_power_save_state(btcoexist, - BTC_PS_WIFI_NATIVE, 0x0, 0x0); - halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 9); - halbtc8192e2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 3); - } - } else if (anttype == 3) { - /*ANTTYPE = 3, 92E 3ant with good ant. isolation*/ - if (BTC_RSSI_HIGH(wifi_rssi_state) && - (!BTC_RSSI_LOW(bt_rssi_state))) { - halbtc8192e2ant_power_save_state(btcoexist, - BTC_PS_WIFI_NATIVE, 0x0, 0x0); - halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, - 1); - halbtc8192e2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 0); - } else { - halbtc8192e2ant_power_save_state(btcoexist, - BTC_PS_WIFI_NATIVE, 0x0, 0x0); - halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, - 1); - halbtc8192e2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 0); - } - } - - halbtc8192e2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0, - 0x0); - halbtc8192e2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); - halbtc8192e2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - halbtc8192e2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8); - halbtc8192e2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6); - - halbtc8192e2ant_sw_mechanism1(btcoexist, false, false, false, false); - halbtc8192e2ant_sw_mechanism2(btcoexist, false, false, false, 0x18); -} - -/* A2DP only / PAN(EDR) only/ A2DP+PAN(HS) */ -void halbtc8192e2ant_action_a2dp(IN struct btc_coexist *btcoexist) -{ - u8 wifi_rssi_state, bt_rssi_state = BTC_RSSI_STATE_HIGH; - u32 wifi_bw; - boolean long_dist = false; - u8 anttype = 0; - - btcoexist->btc_get(btcoexist, BTC_GET_U1_ANT_TYPE, &anttype); - - wifi_rssi_state = halbtc8192e2ant_wifi_rssi_state(btcoexist, 0, 2, 34, - 0); - bt_rssi_state = halbtc8192e2ant_bt_rssi_state(3, 34, 42); - - if (anttype == 0) { - /*ANTTYPE = 0 92E 2ant with SPDT*/ - halbtc8192e2ant_power_save_state(btcoexist, BTC_PS_LPS_ON, 0x50, - 0x4); - halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 87); - halbtc8192e2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7); - } else if (anttype == 1) { - /*92E 2ant with coupler and bad ant. isolation, 92E 3ant with bad ant. isolation*/ - if (BTC_RSSI_HIGH(wifi_rssi_state) && - (!BTC_RSSI_LOW(bt_rssi_state))) { - halbtc8192e2ant_power_save_state(btcoexist, - BTC_PS_WIFI_NATIVE, 0x0, 0x0); - halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 25); - halbtc8192e2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 7); - } else { - halbtc8192e2ant_power_save_state(btcoexist, - BTC_PS_LPS_ON, 0x50, 0x4); - halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 87); - halbtc8192e2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 7); - } - } else if (anttype == 2) { - /*ANTTYPE = 2, 92E 2ant with coupler and normal/good ant. isolation, 92E 3ant with normal ant. isolation*/ - if (BTC_RSSI_HIGH(wifi_rssi_state) && - (!BTC_RSSI_LOW(bt_rssi_state))) { - halbtc8192e2ant_power_save_state(btcoexist, - BTC_PS_WIFI_NATIVE, 0x0, 0x0); - halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 22); - halbtc8192e2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 5); - } else { - halbtc8192e2ant_power_save_state(btcoexist, - BTC_PS_LPS_ON, 0x50, 0x4); - halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 87); - halbtc8192e2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 7); - } - } else if (anttype == 3) { - /*ANTTYPE = 3, 92E 3ant with good ant. isolation*/ - halbtc8192e2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, - 0x0, 0x0); - halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1); - halbtc8192e2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - } - - halbtc8192e2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8); - halbtc8192e2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6); - halbtc8192e2ant_sw_mechanism1(btcoexist, false, false, false, false); - if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state)) && - (coex_sta->scan_ap_num < NOISY_AP_NUM_THRESH_8192E)) - halbtc8192e2ant_sw_mechanism2(btcoexist, false, false, false, - 0x18); - else if (BTC_RSSI_HIGH(wifi_rssi_state) && - (!BTC_RSSI_LOW(bt_rssi_state)) && - (coex_sta->scan_ap_num > NOISY_AP_NUM_THRESH_8192E)) - halbtc8192e2ant_sw_mechanism2(btcoexist, false, false, true, - 0x06); - else - halbtc8192e2ant_sw_mechanism2(btcoexist, false, false, false, - 0x18); -} - -void halbtc8192e2ant_action_a2dp_pan_hs(IN struct btc_coexist *btcoexist) -{ - u8 wifi_rssi_state, bt_rssi_state = BTC_RSSI_STATE_HIGH; - u32 wifi_bw; - - wifi_rssi_state = halbtc8192e2ant_wifi_rssi_state(btcoexist, 0, 2, 15, - 0); - bt_rssi_state = halbtc8192e2ant_bt_rssi_state(3, 34, 42); - - halbtc8192e2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8); - - halbtc8192e2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6); - halbtc8192e2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2); - - if ((bt_rssi_state == BTC_RSSI_STATE_LOW) || - (bt_rssi_state == BTC_RSSI_STATE_STAY_LOW)) { - halbtc8192e2ant_tdma_duration_adjust(btcoexist, false, true, 2); - halbtc8192e2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - } else if ((bt_rssi_state == BTC_RSSI_STATE_MEDIUM) || - (bt_rssi_state == BTC_RSSI_STATE_STAY_MEDIUM)) { - halbtc8192e2ant_tdma_duration_adjust(btcoexist, false, false, - 2); - halbtc8192e2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2); - } else if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) || - (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) { - halbtc8192e2ant_tdma_duration_adjust(btcoexist, false, false, - 2); - halbtc8192e2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 4); - } - - /* sw mechanism */ - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw); - if (BTC_WIFI_BW_HT40 == wifi_bw) { - if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) || - (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) { - halbtc8192e2ant_sw_mechanism1(btcoexist, true, false, - false, false); - halbtc8192e2ant_sw_mechanism2(btcoexist, true, false, - true, 0x6); - } else { - halbtc8192e2ant_sw_mechanism1(btcoexist, true, false, - false, false); - halbtc8192e2ant_sw_mechanism2(btcoexist, false, false, - true, 0x6); - } - } else { - if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) || - (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) { - halbtc8192e2ant_sw_mechanism1(btcoexist, false, false, - false, false); - halbtc8192e2ant_sw_mechanism2(btcoexist, true, false, - true, 0x6); - } else { - halbtc8192e2ant_sw_mechanism1(btcoexist, false, false, - false, false); - halbtc8192e2ant_sw_mechanism2(btcoexist, false, false, - true, 0x6); - } - } -} - -void halbtc8192e2ant_action_pan_edr(IN struct btc_coexist *btcoexist) -{ - u8 wifi_rssi_state, bt_rssi_state = BTC_RSSI_STATE_HIGH; - u32 wifi_bw; - u8 bt_thresh0 = 0, bt_thresh1 = 0; - - halbtc8192e2ant_get_bt_rssi_threshold(btcoexist, &bt_thresh0, - &bt_thresh1); - bt_rssi_state = halbtc8192e2ant_bt_rssi_state(3, bt_thresh0, - bt_thresh1); - /* wifi_rssi_state = halbtc8192e2ant_wifi_rssi_state(btcoexist, 0, 2, 34, 0); */ - wifi_rssi_state = BTC_RSSI_STATE_LOW; - - if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state))) - halbtc8192e2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, - 0x0, 0x0); - else - halbtc8192e2ant_power_save_state(btcoexist, BTC_PS_LPS_ON, 0x50, - 0x4); - - if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state))) - halbtc8192e2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2); - else - halbtc8192e2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - - if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state))) - halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 1); - else - halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 85); - - halbtc8192e2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8); - halbtc8192e2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6); - - halbtc8192e2ant_sw_mechanism1(btcoexist, false, false, false, false); - if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state)) && - (coex_sta->scan_ap_num < NOISY_AP_NUM_THRESH_8192E)) - halbtc8192e2ant_sw_mechanism2(btcoexist, false, false, false, - 0x18); - else if (BTC_RSSI_HIGH(wifi_rssi_state) && - (!BTC_RSSI_LOW(bt_rssi_state)) && - (coex_sta->scan_ap_num > NOISY_AP_NUM_THRESH_8192E)) - halbtc8192e2ant_sw_mechanism2(btcoexist, false, false, false, - 0x18); - else - halbtc8192e2ant_sw_mechanism2(btcoexist, false, false, false, - 0x18); -} - -/* PAN(HS) only */ -void halbtc8192e2ant_action_pan_hs(IN struct btc_coexist *btcoexist) -{ - u8 wifi_rssi_state, bt_rssi_state = BTC_RSSI_STATE_HIGH; - u32 wifi_bw; - - wifi_rssi_state = halbtc8192e2ant_wifi_rssi_state(btcoexist, 0, 2, 15, - 0); - bt_rssi_state = halbtc8192e2ant_bt_rssi_state(3, 34, 42); - - /* halbtc8192e2ant_switch_ss_type(btcoexist, NORMAL_EXEC, 1);*/ - halbtc8192e2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8); - - halbtc8192e2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6); - - halbtc8192e2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2); - - if ((bt_rssi_state == BTC_RSSI_STATE_LOW) || - (bt_rssi_state == BTC_RSSI_STATE_STAY_LOW)) - halbtc8192e2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - else if ((bt_rssi_state == BTC_RSSI_STATE_MEDIUM) || - (bt_rssi_state == BTC_RSSI_STATE_STAY_MEDIUM)) - halbtc8192e2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2); - else if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) || - (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) - halbtc8192e2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 4); - halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1); - - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw); - if (BTC_WIFI_BW_HT40 == wifi_bw) { - if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) || - (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) { - halbtc8192e2ant_sw_mechanism1(btcoexist, true, false, - false, false); - halbtc8192e2ant_sw_mechanism2(btcoexist, true, false, - false, 0x18); - } else { - halbtc8192e2ant_sw_mechanism1(btcoexist, true, false, - false, false); - halbtc8192e2ant_sw_mechanism2(btcoexist, false, false, - false, 0x18); - } - } else { - if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) || - (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) { - halbtc8192e2ant_sw_mechanism1(btcoexist, false, false, - false, false); - halbtc8192e2ant_sw_mechanism2(btcoexist, true, false, - false, 0x18); - } else { - halbtc8192e2ant_sw_mechanism1(btcoexist, false, false, - false, false); - halbtc8192e2ant_sw_mechanism2(btcoexist, false, false, - false, 0x18); - } - } -} - -/* PAN(EDR)+A2DP */ -void halbtc8192e2ant_action_pan_edr_a2dp(IN struct btc_coexist *btcoexist) -{ - u8 wifi_rssi_state, bt_rssi_state = BTC_RSSI_STATE_HIGH; - u32 wifi_bw; - u8 bt_thresh0 = 0, bt_thresh1 = 0; - - halbtc8192e2ant_get_bt_rssi_threshold(btcoexist, &bt_thresh0, - &bt_thresh1); - bt_rssi_state = halbtc8192e2ant_bt_rssi_state(3, bt_thresh0, - bt_thresh1); - /* wifi_rssi_state = halbtc8192e2ant_wifi_rssi_state(btcoexist, 0, 2, 34, 0); */ - wifi_rssi_state = BTC_RSSI_STATE_LOW; - - if ((BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state)))) - halbtc8192e2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, - 0x0, 0x0); - else - halbtc8192e2ant_power_save_state(btcoexist, BTC_PS_LPS_ON, 0x50, - 0x4); - - if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state))) - halbtc8192e2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2); - else - halbtc8192e2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - - if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state))) - halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 4); - else - halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 86); - - halbtc8192e2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8); - halbtc8192e2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6); - - halbtc8192e2ant_sw_mechanism1(btcoexist, false, false, false, false); - if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state)) && - (coex_sta->scan_ap_num < NOISY_AP_NUM_THRESH_8192E)) - halbtc8192e2ant_sw_mechanism2(btcoexist, false, false, false, - 0x18); - else if (BTC_RSSI_HIGH(wifi_rssi_state) && - (!BTC_RSSI_LOW(bt_rssi_state)) && - (coex_sta->scan_ap_num > NOISY_AP_NUM_THRESH_8192E)) - halbtc8192e2ant_sw_mechanism2(btcoexist, false, false, false, - 0x18); - else - halbtc8192e2ant_sw_mechanism2(btcoexist, false, false, false, - 0x18); - -} - -void halbtc8192e2ant_action_pan_edr_hid(IN struct btc_coexist *btcoexist) -{ - u8 wifi_rssi_state, bt_rssi_state = BTC_RSSI_STATE_HIGH; - u32 wifi_bw; - u8 bt_thresh0 = 0, bt_thresh1 = 0; - - halbtc8192e2ant_get_bt_rssi_threshold(btcoexist, &bt_thresh0, - &bt_thresh1); - bt_rssi_state = halbtc8192e2ant_bt_rssi_state(3, bt_thresh0, - bt_thresh1); - - wifi_rssi_state = halbtc8192e2ant_wifi_rssi_state(btcoexist, 0, 2, 34, - 0); - - if ((BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state)))) - halbtc8192e2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, - 0x0, 0x0); - else - halbtc8192e2ant_power_save_state(btcoexist, BTC_PS_LPS_ON, 0x50, - 0x4); - - if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state))) - halbtc8192e2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 3); - else - halbtc8192e2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - - if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state))) - halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 10); - else - halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 86); - - halbtc8192e2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8); - halbtc8192e2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6); - - halbtc8192e2ant_sw_mechanism1(btcoexist, false, false, false, false); - if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state)) && - (coex_sta->scan_ap_num < NOISY_AP_NUM_THRESH_8192E)) - halbtc8192e2ant_sw_mechanism2(btcoexist, false, false, false, - 0x18); - else if (BTC_RSSI_HIGH(wifi_rssi_state) && - (!BTC_RSSI_LOW(bt_rssi_state)) && - (coex_sta->scan_ap_num > NOISY_AP_NUM_THRESH_8192E)) - halbtc8192e2ant_sw_mechanism2(btcoexist, false, false, false, - 0x18); - else - halbtc8192e2ant_sw_mechanism2(btcoexist, false, false, false, - 0x18); - - -} - -/* HID+A2DP+PAN(EDR) */ -void halbtc8192e2ant_action_hid_a2dp_pan_edr(IN struct btc_coexist *btcoexist) -{ - u8 wifi_rssi_state, bt_rssi_state = BTC_RSSI_STATE_HIGH; - u32 wifi_bw; - u8 bt_thresh0 = 0, bt_thresh1 = 0; - - halbtc8192e2ant_get_bt_rssi_threshold(btcoexist, &bt_thresh0, - &bt_thresh1); - bt_rssi_state = halbtc8192e2ant_bt_rssi_state(3, bt_thresh0, - bt_thresh1); - wifi_rssi_state = halbtc8192e2ant_wifi_rssi_state(btcoexist, 0, 2, 34, - 0); - - if ((BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state)))) - halbtc8192e2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, - 0x0, 0x0); - else - halbtc8192e2ant_power_save_state(btcoexist, BTC_PS_LPS_ON, 0x50, - 0x4); - - if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state))) - halbtc8192e2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 3); - else - halbtc8192e2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - - if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state))) - halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 4); - else - halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 86); - - halbtc8192e2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8); - halbtc8192e2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6); - - halbtc8192e2ant_sw_mechanism1(btcoexist, false, false, false, false); - if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state)) && - (coex_sta->scan_ap_num < NOISY_AP_NUM_THRESH_8192E)) - halbtc8192e2ant_sw_mechanism2(btcoexist, false, false, false, - 0x18); - else if (BTC_RSSI_HIGH(wifi_rssi_state) && - (!BTC_RSSI_LOW(bt_rssi_state)) && - (coex_sta->scan_ap_num > NOISY_AP_NUM_THRESH_8192E)) - halbtc8192e2ant_sw_mechanism2(btcoexist, false, false, false, - 0x18); - else - halbtc8192e2ant_sw_mechanism2(btcoexist, false, false, false, - 0x18); -} - -void halbtc8192e2ant_action_hid_a2dp(IN struct btc_coexist *btcoexist) -{ - u8 wifi_rssi_state, bt_rssi_state = BTC_RSSI_STATE_HIGH; - u32 wifi_bw; - u8 bt_thresh0 = 0, bt_thresh1 = 0, anttype = 0; - - btcoexist->btc_get(btcoexist, BTC_GET_U1_ANT_TYPE, &anttype); - - wifi_rssi_state = halbtc8192e2ant_wifi_rssi_state(btcoexist, 0, 2, 34, - 0); - bt_rssi_state = halbtc8192e2ant_bt_rssi_state(3, 34, 42); - - if (anttype == 0) { - /*92E 2ant with SPDT*/ - halbtc8192e2ant_power_save_state(btcoexist, BTC_PS_LPS_ON, 0x50, - 0x4); - halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 87); - halbtc8192e2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 8); - - } else if (anttype == 1) { - /*92E 2ant with coupler and bad ant. isolation, 92E 3ant with bad ant. isolation*/ - if (BTC_RSSI_HIGH(wifi_rssi_state) && - (!BTC_RSSI_LOW(bt_rssi_state))) { - halbtc8192e2ant_power_save_state(btcoexist, - BTC_PS_WIFI_NATIVE, 0x0, 0x0); - halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 25); - halbtc8192e2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 8); - } else { - halbtc8192e2ant_power_save_state(btcoexist, - BTC_PS_LPS_ON, 0x50, 0x4); - halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 87); - halbtc8192e2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 8); - } - } else if (anttype == 2) { - /*ANTTYPE = 2, 92E 2ant with coupler and normal/good ant. isolation, 92E 3ant with normal ant. isolation*/ - if (BTC_RSSI_HIGH(wifi_rssi_state) && - (!BTC_RSSI_LOW(bt_rssi_state))) { - halbtc8192e2ant_power_save_state(btcoexist, - BTC_PS_WIFI_NATIVE, 0x0, 0x0); - halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 25); - halbtc8192e2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 8); - } else { - halbtc8192e2ant_power_save_state(btcoexist, - BTC_PS_LPS_ON, 0x50, 0x4); - halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 87); - halbtc8192e2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 8); - } - } else if (anttype == 3) { - /*ANTTYPE = 3, 92E 3ant with good ant. isolation*/ - halbtc8192e2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, - 0x0, 0x0); - halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1); - halbtc8192e2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - } - - halbtc8192e2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8); - halbtc8192e2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6); - - halbtc8192e2ant_sw_mechanism1(btcoexist, false, false, false, false); - if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state)) && - (coex_sta->scan_ap_num < NOISY_AP_NUM_THRESH_8192E)) - halbtc8192e2ant_sw_mechanism2(btcoexist, false, false, false, - 0x18); - else if (BTC_RSSI_HIGH(wifi_rssi_state) && - (!BTC_RSSI_LOW(bt_rssi_state)) && - (coex_sta->scan_ap_num > NOISY_AP_NUM_THRESH_8192E)) - halbtc8192e2ant_sw_mechanism2(btcoexist, false, false, true, - 0x06); - else - halbtc8192e2ant_sw_mechanism2(btcoexist, false, false, false, - 0x18); -} - -void halbtc8192e2ant_run_coexist_mechanism(IN struct btc_coexist *btcoexist) -{ - u8 algorithm = 0; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], RunCoexistMechanism()===>\n"); - BTC_TRACE(trace_buf); - - if (btcoexist->manual_control) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], RunCoexistMechanism(), return for Manual CTRL <===\n"); - BTC_TRACE(trace_buf); - return; - } - - if (coex_sta->under_ips) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], wifi is under IPS !!!\n"); - BTC_TRACE(trace_buf); - return; - } - - algorithm = halbtc8192e2ant_action_algorithm(btcoexist); - if (coex_sta->c2h_bt_inquiry_page && - (BT_8192E_2ANT_COEX_ALGO_PANHS != algorithm)) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT is under inquiry/page scan !!\n"); - BTC_TRACE(trace_buf); - halbtc8192e2ant_action_bt_inquiry(btcoexist); - return; - } - - coex_dm->cur_algorithm = algorithm; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], Algorithm = %d\n", - coex_dm->cur_algorithm); - BTC_TRACE(trace_buf); - - if (halbtc8192e2ant_is_common_action(btcoexist)) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant common.\n"); - BTC_TRACE(trace_buf); - coex_dm->auto_tdma_adjust = false; - coex_dm->auto_tdma_adjust_low_rssi = false; - - } else { - if (coex_dm->cur_algorithm != coex_dm->pre_algorithm) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], pre_algorithm=%d, cur_algorithm=%d\n", - coex_dm->pre_algorithm, coex_dm->cur_algorithm); - BTC_TRACE(trace_buf); - coex_dm->auto_tdma_adjust = false; - coex_dm->auto_tdma_adjust_low_rssi = false; - - } - switch (coex_dm->cur_algorithm) { - case BT_8192E_2ANT_COEX_ALGO_SCO: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, algorithm = SCO.\n"); - BTC_TRACE(trace_buf); - halbtc8192e2ant_action_sco(btcoexist); - break; - case BT_8192E_2ANT_COEX_ALGO_SCO_PAN: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, algorithm = SCO+PAN(EDR).\n"); - BTC_TRACE(trace_buf); - halbtc8192e2ant_action_sco_pan(btcoexist); - break; - case BT_8192E_2ANT_COEX_ALGO_HID: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, algorithm = HID.\n"); - BTC_TRACE(trace_buf); - halbtc8192e2ant_action_hid(btcoexist); - break; - case BT_8192E_2ANT_COEX_ALGO_A2DP: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, algorithm = A2DP.\n"); - BTC_TRACE(trace_buf); - halbtc8192e2ant_action_a2dp(btcoexist); - break; - case BT_8192E_2ANT_COEX_ALGO_A2DP_PANHS: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, algorithm = A2DP+PAN(HS).\n"); - BTC_TRACE(trace_buf); - halbtc8192e2ant_action_a2dp_pan_hs(btcoexist); - break; - case BT_8192E_2ANT_COEX_ALGO_PANEDR: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, algorithm = PAN(EDR).\n"); - BTC_TRACE(trace_buf); - halbtc8192e2ant_action_pan_edr(btcoexist); - break; - case BT_8192E_2ANT_COEX_ALGO_PANHS: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, algorithm = HS mode.\n"); - BTC_TRACE(trace_buf); - halbtc8192e2ant_action_pan_hs(btcoexist); - break; - case BT_8192E_2ANT_COEX_ALGO_PANEDR_A2DP: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, algorithm = PAN+A2DP.\n"); - BTC_TRACE(trace_buf); - halbtc8192e2ant_action_pan_edr_a2dp(btcoexist); - break; - case BT_8192E_2ANT_COEX_ALGO_PANEDR_HID: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, algorithm = PAN(EDR)+HID.\n"); - BTC_TRACE(trace_buf); - halbtc8192e2ant_action_pan_edr_hid(btcoexist); - break; - case BT_8192E_2ANT_COEX_ALGO_HID_A2DP_PANEDR: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, algorithm = HID+A2DP+PAN.\n"); - BTC_TRACE(trace_buf); - halbtc8192e2ant_action_hid_a2dp_pan_edr( - btcoexist); - break; - case BT_8192E_2ANT_COEX_ALGO_HID_A2DP: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, algorithm = HID+A2DP.\n"); - BTC_TRACE(trace_buf); - halbtc8192e2ant_action_hid_a2dp(btcoexist); - break; - default: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, algorithm = unknown!!\n"); - BTC_TRACE(trace_buf); - halbtc8192e2ant_coex_all_off(btcoexist); - break; - } - coex_dm->pre_algorithm = coex_dm->cur_algorithm; - } -} - -void halbtc8192e2ant_init_hw_config(IN struct btc_coexist *btcoexist, - IN boolean back_up) -{ - u16 u16tmp = 0; - u8 u8tmp = 0; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], 2Ant Init HW Config!!\n"); - BTC_TRACE(trace_buf); - - if (back_up) { - /* backup rf 0x1e value */ - coex_dm->bt_rf_0x1e_backup = - btcoexist->btc_get_rf_reg(btcoexist, BTC_RF_A, 0x1e, - 0xfffff); - - coex_dm->backup_arfr_cnt1 = btcoexist->btc_read_4byte(btcoexist, - 0x430); - coex_dm->backup_arfr_cnt2 = btcoexist->btc_read_4byte(btcoexist, - 0x434); - coex_dm->backup_retry_limit = btcoexist->btc_read_2byte( - btcoexist, 0x42a); - coex_dm->backup_ampdu_max_time = btcoexist->btc_read_1byte( - btcoexist, 0x456); - } - - /* antenna sw ctrl to bt */ - halbtc8192e2ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT, true, false); - - halbtc8192e2ant_coex_table_with_type(btcoexist, FORCE_EXEC, 0); - - /* antenna switch control parameter */ - /* btcoexist->btc_write_4byte(btcoexist, 0x858, 0x55555555); */ - - /* coex parameters */ - btcoexist->btc_write_1byte(btcoexist, 0x778, 0x3); - /* 0x790[5:0]=0x5 */ - u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x790); - u8tmp &= 0xc0; - u8tmp |= 0x5; - btcoexist->btc_write_1byte(btcoexist, 0x790, u8tmp); - - /* enable counter statistics */ - btcoexist->btc_write_1byte(btcoexist, 0x76e, 0x4); - - /* enable PTA */ - btcoexist->btc_write_1byte(btcoexist, 0x40, 0x20); - /* enable mailbox interface */ - u16tmp = btcoexist->btc_read_2byte(btcoexist, 0x40); - u16tmp |= BIT(9); - btcoexist->btc_write_2byte(btcoexist, 0x40, u16tmp); - - /* enable PTA I2C mailbox */ - u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x101); - u8tmp |= BIT(4); - btcoexist->btc_write_1byte(btcoexist, 0x101, u8tmp); - - /* enable bt clock when wifi is disabled. */ - u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x93); - u8tmp |= BIT(0); - btcoexist->btc_write_1byte(btcoexist, 0x93, u8tmp); - /* enable bt clock when suspend. */ - u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x7); - u8tmp |= BIT(0); - btcoexist->btc_write_1byte(btcoexist, 0x7, u8tmp); - - /* Give bt_coex_supported_version the default value */ - coex_sta->bt_coex_supported_version = 0; -} - -/* ************************************************************ - * work around function start with wa_halbtc8192e2ant_ - * ************************************************************ - * ************************************************************ - * extern function start with ex_halbtc8192e2ant_ - * ************************************************************ */ -void ex_halbtc8192e2ant_power_on_setting(IN struct btc_coexist *btcoexist) -{ -} - -void ex_halbtc8192e2ant_init_hw_config(IN struct btc_coexist *btcoexist, - IN boolean wifi_only) -{ - halbtc8192e2ant_init_hw_config(btcoexist, true); -} - -void ex_halbtc8192e2ant_init_coex_dm(IN struct btc_coexist *btcoexist) -{ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Coex Mechanism Init!!\n"); - BTC_TRACE(trace_buf); - - halbtc8192e2ant_init_coex_dm(btcoexist); -} - -void ex_halbtc8192e2ant_display_coex_info(IN struct btc_coexist *btcoexist) -{ - struct btc_board_info *board_info = &btcoexist->board_info; - struct btc_stack_info *stack_info = &btcoexist->stack_info; - u8 *cli_buf = btcoexist->cli_buf; - u8 u8tmp[4], i, bt_info_ext, ps_tdma_case = 0; - u16 u16tmp[4]; - u32 u32tmp[4]; - u32 fa_ofdm, fa_cck, cca_ofdm, cca_cck; - u32 fw_ver = 0, bt_patch_ver = 0, bt_coex_ver = 0; - u32 phyver = 0; - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n ============[BT Coexist info]============"); - CL_PRINTF(cli_buf); - - if (btcoexist->manual_control) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n ============[Under Manual Control]============"); - CL_PRINTF(cli_buf); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n =========================================="); - CL_PRINTF(cli_buf); - } - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d ", - "Ant PG number/ Ant mechanism:", - board_info->pg_ant_num, board_info->btdm_ant_num); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d", "Antenna type:", - board_info->ant_type); - CL_PRINTF(cli_buf); - - btcoexist->btc_get(btcoexist, BTC_GET_U4_BT_PATCH_VER, &bt_patch_ver); - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, &fw_ver); - phyver = btcoexist->btc_get_bt_phydm_version(btcoexist); - bt_coex_ver = ((coex_sta->bt_coex_supported_version & 0xff00) >> 8); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %d_%02x/ 0x%02x/ 0x%02x (%s)", - "CoexVer WL/ BT_Desired/ BT_Report", - glcoex_ver_date_8192e_2ant, glcoex_ver_8192e_2ant, - glcoex_ver_btdesired_8192e_2ant, bt_coex_ver, - (bt_coex_ver == 0xff ? "Unknown" : (bt_coex_ver >= - glcoex_ver_btdesired_8192e_2ant ? "Match" : - "Mis-Match"))); - CL_PRINTF(cli_buf); - - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = 0x%x/ 0x%x/ v%d", - "W_FW/ B_FW/ Phy", fw_ver, bt_patch_ver, phyver); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x ", - "Wifi channel informed to BT", - coex_dm->wifi_chnl_info[0], coex_dm->wifi_chnl_info[1], - coex_dm->wifi_chnl_info[2]); - CL_PRINTF(cli_buf); - - /* wifi status */ - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s", - "============[Wifi Status]============"); - CL_PRINTF(cli_buf); - btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_WIFI_STATUS); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s", - "============[BT Status]============"); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = [%s/ %d/ %d] ", - "BT [status/ rssi/ retryCnt]", - ((coex_sta->bt_disabled) ? ("disabled") : (( - coex_sta->c2h_bt_inquiry_page) ? ("inquiry/page scan") - : ((BT_8192E_2ANT_BT_STATUS_NON_CONNECTED_IDLE == - coex_dm->bt_status) ? "non-connected idle" : - ((BT_8192E_2ANT_BT_STATUS_CONNECTED_IDLE == coex_dm->bt_status) - ? "connected-idle" : "busy")))), - coex_sta->bt_rssi, coex_sta->bt_retry_cnt); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d / %d / %d", - "SCO/HID/PAN/A2DP", - stack_info->sco_exist, stack_info->hid_exist, - stack_info->pan_exist, stack_info->a2dp_exist); - CL_PRINTF(cli_buf); - btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_BT_LINK_INFO); - - bt_info_ext = coex_sta->bt_info_ext; - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s", - "BT Info A2DP rate", - (bt_info_ext & BIT(0)) ? "Basic rate" : "EDR rate"); - CL_PRINTF(cli_buf); - - for (i = 0; i < BT_INFO_SRC_8192E_2ANT_MAX; i++) { - if (coex_sta->bt_info_c2h_cnt[i]) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %02x %02x %02x %02x %02x %02x %02x(%d)", - glbt_info_src_8192e_2ant[i], - coex_sta->bt_info_c2h[i][0], - coex_sta->bt_info_c2h[i][1], - coex_sta->bt_info_c2h[i][2], - coex_sta->bt_info_c2h[i][3], - coex_sta->bt_info_c2h[i][4], - coex_sta->bt_info_c2h[i][5], - coex_sta->bt_info_c2h[i][6], - coex_sta->bt_info_c2h_cnt[i]); - CL_PRINTF(cli_buf); - } - } - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x ", "SS Type", - coex_dm->cur_ss_type); - CL_PRINTF(cli_buf); - - /* Sw mechanism */ - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s", - "============[Sw mechanism]============"); - CL_PRINTF(cli_buf); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d ", - "SM1[ShRf/ LpRA/ LimDig]", - coex_dm->cur_rf_rx_lpf_shrink, coex_dm->cur_low_penalty_ra, - coex_dm->limited_dig); - CL_PRINTF(cli_buf); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d(0x%x) ", - "SM2[AgcT/ AdcB/ SwDacSwing(lvl)]", - coex_dm->cur_agc_table_en, coex_dm->cur_adc_back_off, - coex_dm->cur_dac_swing_on, coex_dm->cur_dac_swing_lvl); - CL_PRINTF(cli_buf); - - /* Fw mechanism */ - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s", - "============[Fw mechanism]============"); - CL_PRINTF(cli_buf); - - ps_tdma_case = coex_dm->cur_ps_tdma; - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %02x %02x %02x %02x %02x case-%d (auto:%d)", - "PS TDMA", - coex_dm->ps_tdma_para[0], coex_dm->ps_tdma_para[1], - coex_dm->ps_tdma_para[2], coex_dm->ps_tdma_para[3], - coex_dm->ps_tdma_para[4], ps_tdma_case, - coex_dm->auto_tdma_adjust); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d ", - "DecBtPwr/ IgnWlanAct", - coex_dm->cur_bt_dec_pwr_lvl, coex_dm->cur_ignore_wlan_act); - CL_PRINTF(cli_buf); - - /* Hw setting */ - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s", - "============[Hw setting]============"); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", - "RF-A, 0x1e initVal", - coex_dm->bt_rf_0x1e_backup); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/0x%x/0x%x/0x%x", - "backup ARFR1/ARFR2/RL/AMaxTime", - coex_dm->backup_arfr_cnt1, coex_dm->backup_arfr_cnt2, - coex_dm->backup_retry_limit, - coex_dm->backup_ampdu_max_time); - CL_PRINTF(cli_buf); - - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x430); - u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x434); - u16tmp[0] = btcoexist->btc_read_2byte(btcoexist, 0x42a); - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x456); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/0x%x/0x%x/0x%x", - "0x430/0x434/0x42a/0x456", - u32tmp[0], u32tmp[1], u16tmp[0], u8tmp[0]); - CL_PRINTF(cli_buf); - - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xc04); - u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0xd04); - u32tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0x90c); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", - "0xc04/ 0xd04/ 0x90c", - u32tmp[0], u32tmp[1], u32tmp[2]); - CL_PRINTF(cli_buf); - - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x778); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0x778", - u8tmp[0]); - CL_PRINTF(cli_buf); - - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x92c); - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x930); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", - "0x92c/ 0x930", - (u8tmp[0]), u32tmp[0]); - CL_PRINTF(cli_buf); - - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x40); - u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0x4f); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", - "0x40/ 0x4f", - u8tmp[0], u8tmp[1]); - CL_PRINTF(cli_buf); - - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x550); - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x522); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", - "0x550(bcn ctrl)/0x522", - u32tmp[0], u8tmp[0]); - CL_PRINTF(cli_buf); - - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xc50); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0xc50(dig)", - u32tmp[0]); - CL_PRINTF(cli_buf); - - fa_ofdm = btcoexist->btc_phydm_query_PHY_counter(btcoexist, - PHYDM_INFO_FA_OFDM); - fa_cck = btcoexist->btc_phydm_query_PHY_counter(btcoexist, - PHYDM_INFO_FA_CCK); - cca_ofdm = btcoexist->btc_phydm_query_PHY_counter(btcoexist, - PHYDM_INFO_CCA_OFDM); - cca_cck = btcoexist->btc_phydm_query_PHY_counter(btcoexist, - PHYDM_INFO_CCA_CCK); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", - "CCK-CCA/CCK-FA/OFDM-CCA/OFDM-FA", - cca_cck, fa_cck, cca_ofdm, fa_ofdm); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d", - "CRC_OK CCK/11g/11n/11n-agg", - coex_sta->crc_ok_cck, coex_sta->crc_ok_11g, - coex_sta->crc_ok_11n, coex_sta->crc_ok_11n_vht); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d", - "CRC_Err CCK/11g/11n/11n-agg", - coex_sta->crc_err_cck, coex_sta->crc_err_11g, - coex_sta->crc_err_11n, coex_sta->crc_err_11n_vht); - CL_PRINTF(cli_buf); - - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x6c0); - u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x6c4); - u32tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0x6c8); - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x6cc); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", - "0x6c0/0x6c4/0x6c8/0x6cc(coexTable)", - u32tmp[0], u32tmp[1], u32tmp[2], u8tmp[0]); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", - "0x770(hp rx[31:16]/tx[15:0])", - coex_sta->high_priority_rx, coex_sta->high_priority_tx); - CL_PRINTF(cli_buf); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", - "0x774(lp rx[31:16]/tx[15:0])", - coex_sta->low_priority_rx, coex_sta->low_priority_tx); - CL_PRINTF(cli_buf); -#if (BT_AUTO_REPORT_ONLY_8192E_2ANT == 1) - halbtc8192e2ant_monitor_bt_ctr(btcoexist); -#endif - btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_COEX_STATISTICS); -} - - -void ex_halbtc8192e2ant_ips_notify(IN struct btc_coexist *btcoexist, IN u8 type) -{ - if (BTC_IPS_ENTER == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], IPS ENTER notify\n"); - BTC_TRACE(trace_buf); - coex_sta->under_ips = true; - halbtc8192e2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); - halbtc8192e2ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT, false, - true); - halbtc8192e2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - } else if (BTC_IPS_LEAVE == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], IPS LEAVE notify\n"); - BTC_TRACE(trace_buf); - coex_sta->under_ips = false; - halbtc8192e2ant_init_hw_config(btcoexist, false); - halbtc8192e2ant_init_coex_dm(btcoexist); - halbtc8192e2ant_query_bt_info(btcoexist); - } -} - -void ex_halbtc8192e2ant_lps_notify(IN struct btc_coexist *btcoexist, IN u8 type) -{ - if (BTC_LPS_ENABLE == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], LPS ENABLE notify\n"); - BTC_TRACE(trace_buf); - coex_sta->under_lps = true; - - } else if (BTC_LPS_DISABLE == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], LPS DISABLE notify\n"); - BTC_TRACE(trace_buf); - coex_sta->under_lps = false; - } -} - -void ex_halbtc8192e2ant_scan_notify(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - if (BTC_SCAN_START == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCAN START notify\n"); - BTC_TRACE(trace_buf); - } else if (BTC_SCAN_FINISH == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCAN FINISH notify\n"); - BTC_TRACE(trace_buf); - btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM, - &coex_sta->scan_ap_num); - - } -} - -void ex_halbtc8192e2ant_connect_notify(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - if (BTC_ASSOCIATE_START == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], CONNECT START notify\n"); - BTC_TRACE(trace_buf); - } else if (BTC_ASSOCIATE_FINISH == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], CONNECT FINISH notify\n"); - BTC_TRACE(trace_buf); - } -} - -void ex_halbtc8192e2ant_media_status_notify(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - u8 h2c_parameter[3] = {0}; - u32 wifi_bw; - u8 wifi_central_chnl; - - if (btcoexist->manual_control || - btcoexist->stop_coex_dm || - coex_sta->bt_disabled) - return; - - if (BTC_MEDIA_CONNECT == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], MEDIA connect notify\n"); - BTC_TRACE(trace_buf); - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], MEDIA disconnect notify\n"); - BTC_TRACE(trace_buf); - } - - /* only 2.4G we need to inform bt the chnl mask */ - btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_CENTRAL_CHNL, - &wifi_central_chnl); - if ((BTC_MEDIA_CONNECT == type) && - (wifi_central_chnl <= 14)) { - h2c_parameter[0] = 0x1; - h2c_parameter[1] = wifi_central_chnl; - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw); - if (BTC_WIFI_BW_HT40 == wifi_bw) - h2c_parameter[2] = 0x30; - else - h2c_parameter[2] = 0x20; - } - - coex_dm->wifi_chnl_info[0] = h2c_parameter[0]; - coex_dm->wifi_chnl_info[1] = h2c_parameter[1]; - coex_dm->wifi_chnl_info[2] = h2c_parameter[2]; - - btcoexist->btc_fill_h2c(btcoexist, 0x66, 3, h2c_parameter); -} - -void ex_halbtc8192e2ant_specific_packet_notify(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - if (type == BTC_PACKET_DHCP) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], DHCP Packet notify\n"); - BTC_TRACE(trace_buf); - } -} - -void ex_halbtc8192e2ant_bt_info_notify(IN struct btc_coexist *btcoexist, - IN u8 *tmp_buf, IN u8 length) -{ - u8 bt_info = 0; - u8 i, rsp_source = 0; - boolean bt_busy = false, limited_dig = false; - boolean wifi_connected = false; - - coex_sta->c2h_bt_info_req_sent = false; - - rsp_source = tmp_buf[0] & 0xf; - if (rsp_source >= BT_INFO_SRC_8192E_2ANT_MAX) - rsp_source = BT_INFO_SRC_8192E_2ANT_WIFI_FW; - coex_sta->bt_info_c2h_cnt[rsp_source]++; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Bt info[%d], length=%d, hex data=[", rsp_source, - length); - BTC_TRACE(trace_buf); - for (i = 0; i < length; i++) { - coex_sta->bt_info_c2h[rsp_source][i] = tmp_buf[i]; - if (i == 1) - bt_info = tmp_buf[i]; - if (i == length - 1) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "0x%02x]\n", - tmp_buf[i]); - BTC_TRACE(trace_buf); - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "0x%02x, ", - tmp_buf[i]); - BTC_TRACE(trace_buf); - } - } - - if (BT_INFO_SRC_8192E_2ANT_WIFI_FW != rsp_source) { - coex_sta->bt_retry_cnt = /* [3:0] */ - coex_sta->bt_info_c2h[rsp_source][2] & 0xf; - - coex_sta->bt_rssi = - coex_sta->bt_info_c2h[rsp_source][3] * 2 + 10; - - coex_sta->bt_info_ext = - coex_sta->bt_info_c2h[rsp_source][4]; - - /* Here we need to resend some wifi info to BT */ - /* because bt is reset and loss of the info. */ - if ((coex_sta->bt_info_ext & BIT(1))) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT ext info bit1 check, send wifi BW&Chnl to BT!!\n"); - BTC_TRACE(trace_buf); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - if (wifi_connected) - ex_halbtc8192e2ant_media_status_notify( - btcoexist, BTC_MEDIA_CONNECT); - else - ex_halbtc8192e2ant_media_status_notify( - btcoexist, BTC_MEDIA_DISCONNECT); - } - - if ((coex_sta->bt_info_ext & BIT(3))) { - if (!btcoexist->manual_control && - !btcoexist->stop_coex_dm) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT ext info bit3 check, set BT NOT to ignore Wlan active!!\n"); - BTC_TRACE(trace_buf); - halbtc8192e2ant_ignore_wlan_act(btcoexist, - FORCE_EXEC, false); - } - } else { - /* BT already NOT ignore Wlan active, do nothing here. */ - } - -#if (BT_AUTO_REPORT_ONLY_8192E_2ANT == 0) - if ((coex_sta->bt_info_ext & BIT(4))) { - /* BT auto report already enabled, do nothing */ - } else - halbtc8192e2ant_bt_auto_report(btcoexist, FORCE_EXEC, - true); -#endif - } - - /* check BIT2 first ==> check if bt is under inquiry or page scan */ - if (bt_info & BT_INFO_8192E_2ANT_B_INQ_PAGE) - coex_sta->c2h_bt_inquiry_page = true; - else - coex_sta->c2h_bt_inquiry_page = false; - - /* set link exist status */ - if (!(bt_info & BT_INFO_8192E_2ANT_B_CONNECTION)) { - coex_sta->bt_link_exist = false; - coex_sta->pan_exist = false; - coex_sta->a2dp_exist = false; - coex_sta->hid_exist = false; - coex_sta->sco_exist = false; - } else { /* connection exists */ - coex_sta->bt_link_exist = true; - if (bt_info & BT_INFO_8192E_2ANT_B_FTP) - coex_sta->pan_exist = true; - else - coex_sta->pan_exist = false; - if (bt_info & BT_INFO_8192E_2ANT_B_A2DP) - coex_sta->a2dp_exist = true; - else - coex_sta->a2dp_exist = false; - if (bt_info & BT_INFO_8192E_2ANT_B_HID) - coex_sta->hid_exist = true; - else - coex_sta->hid_exist = false; - if (bt_info & BT_INFO_8192E_2ANT_B_SCO_ESCO) - coex_sta->sco_exist = true; - else - coex_sta->sco_exist = false; - } - - halbtc8192e2ant_update_bt_link_info(btcoexist); - - if (!(bt_info & BT_INFO_8192E_2ANT_B_CONNECTION)) { - coex_dm->bt_status = BT_8192E_2ANT_BT_STATUS_NON_CONNECTED_IDLE; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), BT Non-Connected idle!!!\n"); - BTC_TRACE(trace_buf); - } else if (bt_info == - BT_INFO_8192E_2ANT_B_CONNECTION) { /* connection exists but no busy */ - coex_dm->bt_status = BT_8192E_2ANT_BT_STATUS_CONNECTED_IDLE; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), BT Connected-idle!!!\n"); - BTC_TRACE(trace_buf); - } else if ((bt_info & BT_INFO_8192E_2ANT_B_SCO_ESCO) || - (bt_info & BT_INFO_8192E_2ANT_B_SCO_BUSY)) { - coex_dm->bt_status = BT_8192E_2ANT_BT_STATUS_SCO_BUSY; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), BT SCO busy!!!\n"); - BTC_TRACE(trace_buf); - } else if (bt_info & BT_INFO_8192E_2ANT_B_ACL_BUSY) { - coex_dm->bt_status = BT_8192E_2ANT_BT_STATUS_ACL_BUSY; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), BT ACL busy!!!\n"); - BTC_TRACE(trace_buf); - } else { - coex_dm->bt_status = BT_8192E_2ANT_BT_STATUS_MAX; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), BT Non-Defined state!!!\n"); - BTC_TRACE(trace_buf); - } - - if ((BT_8192E_2ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) || - (BT_8192E_2ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) || - (BT_8192E_2ANT_BT_STATUS_ACL_SCO_BUSY == coex_dm->bt_status)) { - bt_busy = true; - limited_dig = true; - } else { - bt_busy = false; - limited_dig = false; - } - - btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bt_busy); - - coex_dm->limited_dig = limited_dig; - btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_LIMITED_DIG, &limited_dig); - - halbtc8192e2ant_run_coexist_mechanism(btcoexist); -} - -void ex_halbtc8192e2ant_halt_notify(IN struct btc_coexist *btcoexist) -{ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], Halt notify\n"); - BTC_TRACE(trace_buf); - - halbtc8192e2ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT, false, true); - halbtc8192e2ant_ignore_wlan_act(btcoexist, FORCE_EXEC, true); - ex_halbtc8192e2ant_media_status_notify(btcoexist, BTC_MEDIA_DISCONNECT); -} - -void ex_halbtc8192e2ant_periodical(IN struct btc_coexist *btcoexist) -{ - - if ((coex_sta->bt_coex_supported_version == 0) || - (coex_sta->bt_coex_supported_version == 0xffff)) - coex_sta->bt_coex_supported_version = - btcoexist->btc_get_bt_coex_supported_version(btcoexist); - -#if (BT_AUTO_REPORT_ONLY_8192E_2ANT == 0) - halbtc8192e2ant_query_bt_info(btcoexist); - halbtc8192e2ant_monitor_bt_ctr(btcoexist); - halbtc8192e2ant_monitor_wifi_ctr(btcoexist); - halbtc8192e2ant_monitor_bt_enable_disable(btcoexist); -#else - halbtc8192e2ant_monitor_wifi_ctr(btcoexist); - - if (halbtc8192e2ant_is_wifi_status_changed(btcoexist) || - coex_dm->auto_tdma_adjust) - halbtc8192e2ant_run_coexist_mechanism(btcoexist); -#endif -} - -#endif - -#endif /* #if (BT_SUPPORT == 1 && COEX_SUPPORT == 1) */ - - diff --git a/hal/btc/halbtc8192e2ant.h b/hal/btc/halbtc8192e2ant.h deleted file mode 100644 index 00fed71..0000000 --- a/hal/btc/halbtc8192e2ant.h +++ /dev/null @@ -1,211 +0,0 @@ - -#if (BT_SUPPORT == 1 && COEX_SUPPORT == 1) - -#if (RTL8192E_SUPPORT == 1) -/* ******************************************* - * The following is for 8192E 2Ant BT Co-exist definition - * ******************************************* */ -#define BT_AUTO_REPORT_ONLY_8192E_2ANT 0 - -#define BT_INFO_8192E_2ANT_B_FTP BIT(7) -#define BT_INFO_8192E_2ANT_B_A2DP BIT(6) -#define BT_INFO_8192E_2ANT_B_HID BIT(5) -#define BT_INFO_8192E_2ANT_B_SCO_BUSY BIT(4) -#define BT_INFO_8192E_2ANT_B_ACL_BUSY BIT(3) -#define BT_INFO_8192E_2ANT_B_INQ_PAGE BIT(2) -#define BT_INFO_8192E_2ANT_B_SCO_ESCO BIT(1) -#define BT_INFO_8192E_2ANT_B_CONNECTION BIT(0) - -#define BTC_RSSI_COEX_THRESH_TOL_8192E_2ANT 2 -#define NOISY_AP_NUM_THRESH_8192E 10 - -enum bt_info_src_8192e_2ant { - BT_INFO_SRC_8192E_2ANT_WIFI_FW = 0x0, - BT_INFO_SRC_8192E_2ANT_BT_RSP = 0x1, - BT_INFO_SRC_8192E_2ANT_BT_ACTIVE_SEND = 0x2, - BT_INFO_SRC_8192E_2ANT_MAX -}; - -enum bt_8192e_2ant_bt_status { - BT_8192E_2ANT_BT_STATUS_NON_CONNECTED_IDLE = 0x0, - BT_8192E_2ANT_BT_STATUS_CONNECTED_IDLE = 0x1, - BT_8192E_2ANT_BT_STATUS_INQ_PAGE = 0x2, - BT_8192E_2ANT_BT_STATUS_ACL_BUSY = 0x3, - BT_8192E_2ANT_BT_STATUS_SCO_BUSY = 0x4, - BT_8192E_2ANT_BT_STATUS_ACL_SCO_BUSY = 0x5, - BT_8192E_2ANT_BT_STATUS_MAX -}; - -enum bt_8192e_2ant_coex_algo { - BT_8192E_2ANT_COEX_ALGO_UNDEFINED = 0x0, - BT_8192E_2ANT_COEX_ALGO_SCO = 0x1, - BT_8192E_2ANT_COEX_ALGO_SCO_PAN = 0x2, - BT_8192E_2ANT_COEX_ALGO_HID = 0x3, - BT_8192E_2ANT_COEX_ALGO_A2DP = 0x4, - BT_8192E_2ANT_COEX_ALGO_A2DP_PANHS = 0x5, - BT_8192E_2ANT_COEX_ALGO_PANEDR = 0x6, - BT_8192E_2ANT_COEX_ALGO_PANHS = 0x7, - BT_8192E_2ANT_COEX_ALGO_PANEDR_A2DP = 0x8, - BT_8192E_2ANT_COEX_ALGO_PANEDR_HID = 0x9, - BT_8192E_2ANT_COEX_ALGO_HID_A2DP_PANEDR = 0xa, - BT_8192E_2ANT_COEX_ALGO_HID_A2DP = 0xb, - BT_8192E_2ANT_COEX_ALGO_MAX = 0xc -}; - -struct coex_dm_8192e_2ant { - /* fw mechanism */ - u8 pre_bt_dec_pwr_lvl; - u8 cur_bt_dec_pwr_lvl; - u8 pre_fw_dac_swing_lvl; - u8 cur_fw_dac_swing_lvl; - boolean cur_ignore_wlan_act; - boolean pre_ignore_wlan_act; - u8 pre_ps_tdma; - u8 cur_ps_tdma; - u8 ps_tdma_para[5]; - u8 ps_tdma_du_adj_type; - boolean reset_tdma_adjust; - boolean auto_tdma_adjust; - boolean auto_tdma_adjust_low_rssi; - boolean pre_ps_tdma_on; - boolean cur_ps_tdma_on; - boolean pre_bt_auto_report; - boolean cur_bt_auto_report; - - /* sw mechanism */ - boolean pre_rf_rx_lpf_shrink; - boolean cur_rf_rx_lpf_shrink; - u32 bt_rf_0x1e_backup; - boolean pre_low_penalty_ra; - boolean cur_low_penalty_ra; - boolean pre_dac_swing_on; - u32 pre_dac_swing_lvl; - boolean cur_dac_swing_on; - u32 cur_dac_swing_lvl; - boolean pre_adc_back_off; - boolean cur_adc_back_off; - boolean pre_agc_table_en; - boolean cur_agc_table_en; - u32 pre_val0x6c0; - u32 cur_val0x6c0; - u32 pre_val0x6c4; - u32 cur_val0x6c4; - u32 pre_val0x6c8; - u32 cur_val0x6c8; - u8 pre_val0x6cc; - u8 cur_val0x6cc; - boolean limited_dig; - - u32 backup_arfr_cnt1; /* Auto Rate Fallback Retry cnt */ - u32 backup_arfr_cnt2; /* Auto Rate Fallback Retry cnt */ - u16 backup_retry_limit; - u8 backup_ampdu_max_time; - - /* algorithm related */ - u8 pre_algorithm; - u8 cur_algorithm; - u8 bt_status; - u8 wifi_chnl_info[3]; - - u8 pre_ss_type; - u8 cur_ss_type; - - u8 pre_lps; - u8 cur_lps; - u8 pre_rpwm; - u8 cur_rpwm; - - - u32 pre_ra_mask; - u32 cur_ra_mask; - u8 cur_ra_mask_type; - u8 pre_arfr_type; - u8 cur_arfr_type; - u8 pre_retry_limit_type; - u8 cur_retry_limit_type; - u8 pre_ampdu_time_type; - u8 cur_ampdu_time_type; -}; - -struct coex_sta_8192e_2ant { - boolean bt_disabled; - boolean bt_link_exist; - boolean sco_exist; - boolean a2dp_exist; - boolean hid_exist; - boolean pan_exist; - - boolean under_lps; - boolean under_ips; - u32 high_priority_tx; - u32 high_priority_rx; - u32 low_priority_tx; - u32 low_priority_rx; - u8 bt_rssi; - u8 pre_bt_rssi_state; - u8 pre_wifi_rssi_state[4]; - boolean c2h_bt_info_req_sent; - u8 bt_info_c2h[BT_INFO_SRC_8192E_2ANT_MAX][10]; - u32 bt_info_c2h_cnt[BT_INFO_SRC_8192E_2ANT_MAX]; - boolean c2h_bt_inquiry_page; - u8 bt_retry_cnt; - u8 bt_info_ext; - u8 scan_ap_num; - u32 bt_coex_supported_version; - - u32 crc_ok_cck; - u32 crc_ok_11g; - u32 crc_ok_11n; - u32 crc_ok_11n_vht; - - u32 crc_err_cck; - u32 crc_err_11g; - u32 crc_err_11n; - u32 crc_err_11n_vht; -}; - -/* ******************************************* - * The following is interface which will notify coex module. - * ******************************************* */ -void ex_halbtc8192e2ant_power_on_setting(IN struct btc_coexist *btcoexist); -void ex_halbtc8192e2ant_init_hw_config(IN struct btc_coexist *btcoexist, - IN boolean wifi_only); -void ex_halbtc8192e2ant_init_coex_dm(IN struct btc_coexist *btcoexist); -void ex_halbtc8192e2ant_ips_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8192e2ant_lps_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8192e2ant_scan_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8192e2ant_connect_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8192e2ant_media_status_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8192e2ant_specific_packet_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8192e2ant_bt_info_notify(IN struct btc_coexist *btcoexist, - IN u8 *tmp_buf, IN u8 length); -void ex_halbtc8192e2ant_halt_notify(IN struct btc_coexist *btcoexist); -void ex_halbtc8192e2ant_periodical(IN struct btc_coexist *btcoexist); -void ex_halbtc8192e2ant_display_coex_info(IN struct btc_coexist *btcoexist); - -#else /* #if (RTL8192E_SUPPORT == 1) */ -#define ex_halbtc8192e2ant_power_on_setting(btcoexist) -#define ex_halbtc8192e2ant_init_hw_config(btcoexist, wifi_only) -#define ex_halbtc8192e2ant_init_coex_dm(btcoexist) -#define ex_halbtc8192e2ant_ips_notify(btcoexist, type) -#define ex_halbtc8192e2ant_lps_notify(btcoexist, type) -#define ex_halbtc8192e2ant_scan_notify(btcoexist, type) -#define ex_halbtc8192e2ant_connect_notify(btcoexist, type) -#define ex_halbtc8192e2ant_media_status_notify(btcoexist, type) -#define ex_halbtc8192e2ant_specific_packet_notify(btcoexist, type) -#define ex_halbtc8192e2ant_bt_info_notify(btcoexist, tmp_buf, length) -#define ex_halbtc8192e2ant_halt_notify(btcoexist) -#define ex_halbtc8192e2ant_periodical(btcoexist) -#define ex_halbtc8192e2ant_display_coex_info(btcoexist) - -#endif - -#endif - - diff --git a/hal/btc/halbtc8703b1ant.c b/hal/btc/halbtc8703b1ant.c deleted file mode 100644 index 8471ed7..0000000 --- a/hal/btc/halbtc8703b1ant.c +++ /dev/null @@ -1,4293 +0,0 @@ -/* ************************************************************ - * Description: - * - * This file is for RTL8703B Co-exist mechanism - * - * History - * 2012/11/15 Cosa first check in. - * - * ************************************************************ */ - -/* ************************************************************ - * include files - * ************************************************************ */ -#include "mp_precomp.h" - -#if (BT_SUPPORT == 1 && COEX_SUPPORT == 1) - -#if (RTL8703B_SUPPORT == 1) -/* ************************************************************ - * Global variables, these are static variables - * ************************************************************ */ -static u8 *trace_buf = &gl_btc_trace_buf[0]; -static struct coex_dm_8703b_1ant glcoex_dm_8703b_1ant; -static struct coex_dm_8703b_1ant *coex_dm = &glcoex_dm_8703b_1ant; -static struct coex_sta_8703b_1ant glcoex_sta_8703b_1ant; -static struct coex_sta_8703b_1ant *coex_sta = &glcoex_sta_8703b_1ant; -static struct psdscan_sta_8703b_1ant gl_psd_scan_8703b_1ant; -static struct psdscan_sta_8703b_1ant *psd_scan = &gl_psd_scan_8703b_1ant; - - -const char *const glbt_info_src_8703b_1ant[] = { - "BT Info[wifi fw]", - "BT Info[bt rsp]", - "BT Info[bt auto report]", -}; -/* ************************************************************ - * BtCoex Version Format: - * 1. date : glcoex_ver_date_XXXXX_1ant - * 2. WifiCoexVersion : glcoex_ver_XXXX_1ant - * 3. BtCoexVersion : glcoex_ver_btdesired_XXXXX_1ant - * 4. others : glcoex_ver_XXXXXX_XXXXX_1ant - * - * Variable should be indicated IC and Antenna numbers !!! - * Please strictly follow this order and naming style !!! - * - * ************************************************************ */ -u32 glcoex_ver_date_8703b_1ant = 20161027; -u32 glcoex_ver_8703b_1ant = 0x0f; -u32 glcoex_ver_btdesired_8703b_1ant = 0x0d; - - -/* ************************************************************ - * local function proto type if needed - * ************************************************************ - * ************************************************************ - * local function start with halbtc8703b1ant_ - * ************************************************************ */ -u8 halbtc8703b1ant_bt_rssi_state(u8 level_num, u8 rssi_thresh, u8 rssi_thresh1) -{ - s32 bt_rssi = 0; - u8 bt_rssi_state = coex_sta->pre_bt_rssi_state; - - bt_rssi = coex_sta->bt_rssi; - - if (level_num == 2) { - if ((coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_LOW) || - (coex_sta->pre_bt_rssi_state == - BTC_RSSI_STATE_STAY_LOW)) { - if (bt_rssi >= (rssi_thresh + - BTC_RSSI_COEX_THRESH_TOL_8703B_1ANT)) - bt_rssi_state = BTC_RSSI_STATE_HIGH; - else - bt_rssi_state = BTC_RSSI_STATE_STAY_LOW; - } else { - if (bt_rssi < rssi_thresh) - bt_rssi_state = BTC_RSSI_STATE_LOW; - else - bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH; - } - } else if (level_num == 3) { - if (rssi_thresh > rssi_thresh1) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Rssi thresh error!!\n"); - BTC_TRACE(trace_buf); - return coex_sta->pre_bt_rssi_state; - } - - if ((coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_LOW) || - (coex_sta->pre_bt_rssi_state == - BTC_RSSI_STATE_STAY_LOW)) { - if (bt_rssi >= (rssi_thresh + - BTC_RSSI_COEX_THRESH_TOL_8703B_1ANT)) - bt_rssi_state = BTC_RSSI_STATE_MEDIUM; - else - bt_rssi_state = BTC_RSSI_STATE_STAY_LOW; - } else if ((coex_sta->pre_bt_rssi_state == - BTC_RSSI_STATE_MEDIUM) || - (coex_sta->pre_bt_rssi_state == - BTC_RSSI_STATE_STAY_MEDIUM)) { - if (bt_rssi >= (rssi_thresh1 + - BTC_RSSI_COEX_THRESH_TOL_8703B_1ANT)) - bt_rssi_state = BTC_RSSI_STATE_HIGH; - else if (bt_rssi < rssi_thresh) - bt_rssi_state = BTC_RSSI_STATE_LOW; - else - bt_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM; - } else { - if (bt_rssi < rssi_thresh1) - bt_rssi_state = BTC_RSSI_STATE_MEDIUM; - else - bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH; - } - } - - coex_sta->pre_bt_rssi_state = bt_rssi_state; - - return bt_rssi_state; -} - -u8 halbtc8703b1ant_wifi_rssi_state(IN struct btc_coexist *btcoexist, - IN u8 index, IN u8 level_num, IN u8 rssi_thresh, IN u8 rssi_thresh1) -{ - s32 wifi_rssi = 0; - u8 wifi_rssi_state = coex_sta->pre_wifi_rssi_state[index]; - - btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi); - - if (level_num == 2) { - if ((coex_sta->pre_wifi_rssi_state[index] == BTC_RSSI_STATE_LOW) - || - (coex_sta->pre_wifi_rssi_state[index] == - BTC_RSSI_STATE_STAY_LOW)) { - if (wifi_rssi >= (rssi_thresh + - BTC_RSSI_COEX_THRESH_TOL_8703B_1ANT)) - wifi_rssi_state = BTC_RSSI_STATE_HIGH; - else - wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW; - } else { - if (wifi_rssi < rssi_thresh) - wifi_rssi_state = BTC_RSSI_STATE_LOW; - else - wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH; - } - } else if (level_num == 3) { - if (rssi_thresh > rssi_thresh1) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], wifi RSSI thresh error!!\n"); - BTC_TRACE(trace_buf); - return coex_sta->pre_wifi_rssi_state[index]; - } - - if ((coex_sta->pre_wifi_rssi_state[index] == BTC_RSSI_STATE_LOW) - || - (coex_sta->pre_wifi_rssi_state[index] == - BTC_RSSI_STATE_STAY_LOW)) { - if (wifi_rssi >= (rssi_thresh + - BTC_RSSI_COEX_THRESH_TOL_8703B_1ANT)) - wifi_rssi_state = BTC_RSSI_STATE_MEDIUM; - else - wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW; - } else if ((coex_sta->pre_wifi_rssi_state[index] == - BTC_RSSI_STATE_MEDIUM) || - (coex_sta->pre_wifi_rssi_state[index] == - BTC_RSSI_STATE_STAY_MEDIUM)) { - if (wifi_rssi >= (rssi_thresh1 + - BTC_RSSI_COEX_THRESH_TOL_8703B_1ANT)) - wifi_rssi_state = BTC_RSSI_STATE_HIGH; - else if (wifi_rssi < rssi_thresh) - wifi_rssi_state = BTC_RSSI_STATE_LOW; - else - wifi_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM; - } else { - if (wifi_rssi < rssi_thresh1) - wifi_rssi_state = BTC_RSSI_STATE_MEDIUM; - else - wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH; - } - } - - coex_sta->pre_wifi_rssi_state[index] = wifi_rssi_state; - - return wifi_rssi_state; -} - -void halbtc8703b1ant_update_ra_mask(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u32 dis_rate_mask) -{ - coex_dm->cur_ra_mask = dis_rate_mask; - - if (force_exec || (coex_dm->pre_ra_mask != coex_dm->cur_ra_mask)) - btcoexist->btc_set(btcoexist, BTC_SET_ACT_UPDATE_RAMASK, - &coex_dm->cur_ra_mask); - coex_dm->pre_ra_mask = coex_dm->cur_ra_mask; -} - -void halbtc8703b1ant_auto_rate_fallback_retry(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 type) -{ - boolean wifi_under_b_mode = false; - - coex_dm->cur_arfr_type = type; - - if (force_exec || (coex_dm->pre_arfr_type != coex_dm->cur_arfr_type)) { - switch (coex_dm->cur_arfr_type) { - case 0: /* normal mode */ - btcoexist->btc_write_4byte(btcoexist, 0x430, - coex_dm->backup_arfr_cnt1); - btcoexist->btc_write_4byte(btcoexist, 0x434, - coex_dm->backup_arfr_cnt2); - break; - case 1: - btcoexist->btc_get(btcoexist, - BTC_GET_BL_WIFI_UNDER_B_MODE, - &wifi_under_b_mode); - if (wifi_under_b_mode) { - btcoexist->btc_write_4byte(btcoexist, - 0x430, 0x0); - btcoexist->btc_write_4byte(btcoexist, - 0x434, 0x01010101); - } else { - btcoexist->btc_write_4byte(btcoexist, - 0x430, 0x0); - btcoexist->btc_write_4byte(btcoexist, - 0x434, 0x04030201); - } - break; - default: - break; - } - } - - coex_dm->pre_arfr_type = coex_dm->cur_arfr_type; -} - -void halbtc8703b1ant_retry_limit(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 type) -{ - coex_dm->cur_retry_limit_type = type; - - if (force_exec || - (coex_dm->pre_retry_limit_type != - coex_dm->cur_retry_limit_type)) { - switch (coex_dm->cur_retry_limit_type) { - case 0: /* normal mode */ - btcoexist->btc_write_2byte(btcoexist, 0x42a, - coex_dm->backup_retry_limit); - break; - case 1: /* retry limit=8 */ - btcoexist->btc_write_2byte(btcoexist, 0x42a, - 0x0808); - break; - default: - break; - } - } - - coex_dm->pre_retry_limit_type = coex_dm->cur_retry_limit_type; -} - -void halbtc8703b1ant_ampdu_max_time(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 type) -{ - coex_dm->cur_ampdu_time_type = type; - - if (force_exec || - (coex_dm->pre_ampdu_time_type != coex_dm->cur_ampdu_time_type)) { - switch (coex_dm->cur_ampdu_time_type) { - case 0: /* normal mode */ - btcoexist->btc_write_1byte(btcoexist, 0x456, - coex_dm->backup_ampdu_max_time); - break; - case 1: /* AMPDU timw = 0x38 * 32us */ - btcoexist->btc_write_1byte(btcoexist, 0x456, - 0x38); - break; - default: - break; - } - } - - coex_dm->pre_ampdu_time_type = coex_dm->cur_ampdu_time_type; -} - -void halbtc8703b1ant_limited_tx(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 ra_mask_type, IN u8 arfr_type, - IN u8 retry_limit_type, IN u8 ampdu_time_type) -{ - switch (ra_mask_type) { - case 0: /* normal mode */ - halbtc8703b1ant_update_ra_mask(btcoexist, force_exec, - 0x0); - break; - case 1: /* disable cck 1/2 */ - halbtc8703b1ant_update_ra_mask(btcoexist, force_exec, - 0x00000003); - break; - case 2: /* disable cck 1/2/5.5, ofdm 6/9/12/18/24, mcs 0/1/2/3/4 */ - halbtc8703b1ant_update_ra_mask(btcoexist, force_exec, - 0x0001f1f7); - break; - default: - break; - } - - halbtc8703b1ant_auto_rate_fallback_retry(btcoexist, force_exec, - arfr_type); - halbtc8703b1ant_retry_limit(btcoexist, force_exec, retry_limit_type); - halbtc8703b1ant_ampdu_max_time(btcoexist, force_exec, ampdu_time_type); -} - -void halbtc8703b1ant_limited_rx(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean rej_ap_agg_pkt, - IN boolean bt_ctrl_agg_buf_size, IN u8 agg_buf_size) -{ - boolean reject_rx_agg = rej_ap_agg_pkt; - boolean bt_ctrl_rx_agg_size = bt_ctrl_agg_buf_size; - u8 rx_agg_size = agg_buf_size; - - /* ============================================ */ - /* Rx Aggregation related setting */ - /* ============================================ */ - btcoexist->btc_set(btcoexist, BTC_SET_BL_TO_REJ_AP_AGG_PKT, - &reject_rx_agg); - /* decide BT control aggregation buf size or not */ - btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_CTRL_AGG_SIZE, - &bt_ctrl_rx_agg_size); - /* aggregation buf size, only work when BT control Rx aggregation size. */ - btcoexist->btc_set(btcoexist, BTC_SET_U1_AGG_BUF_SIZE, &rx_agg_size); - /* real update aggregation setting */ - btcoexist->btc_set(btcoexist, BTC_SET_ACT_AGGREGATE_CTRL, NULL); - - -} - -void halbtc8703b1ant_query_bt_info(IN struct btc_coexist *btcoexist) -{ - u8 h2c_parameter[1] = {0}; - - - h2c_parameter[0] |= BIT(0); /* trigger */ - - btcoexist->btc_fill_h2c(btcoexist, 0x61, 1, h2c_parameter); -} - -void halbtc8703b1ant_monitor_bt_ctr(IN struct btc_coexist *btcoexist) -{ - u32 reg_hp_txrx, reg_lp_txrx, u32tmp; - u32 reg_hp_tx = 0, reg_hp_rx = 0, reg_lp_tx = 0, reg_lp_rx = 0; - static u8 num_of_bt_counter_chk = 0, cnt_slave = 0, cnt_overhead = 0, - cnt_autoslot_hang = 0; - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - - /* to avoid 0x76e[3] = 1 (WLAN_Act control by PTA) during IPS */ - /* if (! (btcoexist->btc_read_1byte(btcoexist, 0x76e) & 0x8) ) */ - - reg_hp_txrx = 0x770; - reg_lp_txrx = 0x774; - - u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_hp_txrx); - reg_hp_tx = u32tmp & MASKLWORD; - reg_hp_rx = (u32tmp & MASKHWORD) >> 16; - - u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_lp_txrx); - reg_lp_tx = u32tmp & MASKLWORD; - reg_lp_rx = (u32tmp & MASKHWORD) >> 16; - - coex_sta->high_priority_tx = reg_hp_tx; - coex_sta->high_priority_rx = reg_hp_rx; - coex_sta->low_priority_tx = reg_lp_tx; - coex_sta->low_priority_rx = reg_lp_rx; - - if (BT_8703B_1ANT_BT_STATUS_NON_CONNECTED_IDLE == - coex_dm->bt_status) { - - if (coex_sta->high_priority_rx >= 15) { - if (cnt_overhead < 3) - cnt_overhead++; - - if (cnt_overhead == 3) - coex_sta->is_hiPri_rx_overhead = true; - } else { - if (cnt_overhead > 0) - cnt_overhead--; - - if (cnt_overhead == 0) - coex_sta->is_hiPri_rx_overhead = false; - } - } - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Hi-Pri Rx/Tx: %d/%d, Lo-Pri Rx/Tx: %d/%d\n", - reg_hp_rx, reg_hp_tx, reg_lp_rx, reg_lp_tx); - - BTC_TRACE(trace_buf); - - /* reset counter */ - btcoexist->btc_write_1byte(btcoexist, 0x76e, 0xc); - - if ((coex_sta->low_priority_tx > 1150) && - (!coex_sta->c2h_bt_inquiry_page)) - coex_sta->pop_event_cnt++; - - if ((coex_sta->low_priority_rx >= 1150) && - (coex_sta->low_priority_rx >= coex_sta->low_priority_tx) - && (!coex_sta->under_ips) && (!coex_sta->c2h_bt_inquiry_page) && - (coex_sta->bt_link_exist)) { - if (cnt_slave >= 2) { - bt_link_info->slave_role = true; - cnt_slave = 2; - } else - cnt_slave++; - } else { - if (cnt_slave == 0) { - bt_link_info->slave_role = false; - cnt_slave = 0; - } else - cnt_slave--; - - } - - if (coex_sta->is_tdma_btautoslot) { - if ((coex_sta->low_priority_tx >= 1300) && - (coex_sta->low_priority_rx <= 150)) { - if (cnt_autoslot_hang >= 2) { - coex_sta->is_tdma_btautoslot_hang = true; - cnt_autoslot_hang = 2; - } else - cnt_autoslot_hang++; - } else { - if (cnt_autoslot_hang == 0) { - coex_sta->is_tdma_btautoslot_hang = false; - cnt_autoslot_hang = 0; - } else - cnt_autoslot_hang--; - } - } - - if (!coex_sta->bt_disabled) { - if ((coex_sta->high_priority_tx == 0) && - (coex_sta->high_priority_rx == 0) && - (coex_sta->low_priority_tx == 0) && - (coex_sta->low_priority_rx == 0)) { - num_of_bt_counter_chk++; - if (num_of_bt_counter_chk >= 3) { - halbtc8703b1ant_query_bt_info(btcoexist); - num_of_bt_counter_chk = 0; - } - } - } - -} - - -void halbtc8703b1ant_monitor_wifi_ctr(IN struct btc_coexist *btcoexist) -{ -#if 1 - s32 wifi_rssi = 0; - boolean wifi_busy = false, wifi_under_b_mode = false, - wifi_scan = false; - boolean bt_idle = false, wl_idle = false; - static u8 cck_lock_counter = 0, wl_noisy_count0 = 0, - wl_noisy_count1 = 3, wl_noisy_count2 = 0; - u32 total_cnt, reg_val1, reg_val2, cck_cnt; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_B_MODE, - &wifi_under_b_mode); - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &wifi_scan); - - coex_sta->crc_ok_cck = btcoexist->btc_phydm_query_PHY_counter( - btcoexist, PHYDM_INFO_CRC32_OK_CCK); - coex_sta->crc_ok_11g = btcoexist->btc_phydm_query_PHY_counter( - btcoexist, PHYDM_INFO_CRC32_OK_LEGACY); - coex_sta->crc_ok_11n = btcoexist->btc_phydm_query_PHY_counter( - btcoexist, PHYDM_INFO_CRC32_OK_HT); - coex_sta->crc_ok_11n_vht = btcoexist->btc_phydm_query_PHY_counter( - btcoexist, PHYDM_INFO_CRC32_OK_VHT); - - coex_sta->crc_err_cck = btcoexist->btc_phydm_query_PHY_counter( - btcoexist, PHYDM_INFO_CRC32_ERROR_CCK); - coex_sta->crc_err_11g = btcoexist->btc_phydm_query_PHY_counter( - btcoexist, PHYDM_INFO_CRC32_ERROR_LEGACY); - coex_sta->crc_err_11n = btcoexist->btc_phydm_query_PHY_counter( - btcoexist, PHYDM_INFO_CRC32_ERROR_HT); - coex_sta->crc_err_11n_vht = btcoexist->btc_phydm_query_PHY_counter( - btcoexist, PHYDM_INFO_CRC32_ERROR_VHT); - - cck_cnt = coex_sta->crc_ok_cck + coex_sta->crc_err_cck; - - if (cck_cnt > 250) { - if (wl_noisy_count2 < 3) - wl_noisy_count2++; - - if (wl_noisy_count2 == 3) { - wl_noisy_count0 = 0; - wl_noisy_count1 = 0; - } - } else if (cck_cnt < 50) { - if (wl_noisy_count0 < 3) - wl_noisy_count0++; - - if (wl_noisy_count0 == 3) { - wl_noisy_count1 = 0; - wl_noisy_count2 = 0; - } - } else { - if (wl_noisy_count1 < 3) - wl_noisy_count1++; - - if (wl_noisy_count1 == 3) { - wl_noisy_count0 = 0; - wl_noisy_count2 = 0; - } - } - - if (wl_noisy_count2 == 3) - coex_sta->wl_noisy_level = 2; - else if (wl_noisy_count1 == 3) - coex_sta->wl_noisy_level = 1; - else - coex_sta->wl_noisy_level = 0; - - if ((wifi_busy) && (wifi_rssi >= 30) && (!wifi_under_b_mode)) { - total_cnt = coex_sta->crc_ok_cck + coex_sta->crc_ok_11g + - coex_sta->crc_ok_11n + coex_sta->crc_ok_11n_vht; - - if ((coex_dm->bt_status == BT_8703B_1ANT_BT_STATUS_ACL_BUSY) || - (coex_dm->bt_status == BT_8703B_1ANT_BT_STATUS_ACL_SCO_BUSY) || - (coex_dm->bt_status == BT_8703B_1ANT_BT_STATUS_SCO_BUSY)) { - if (coex_sta->crc_ok_cck > (total_cnt - - coex_sta->crc_ok_cck)) { - if (cck_lock_counter < 3) - cck_lock_counter++; - } else { - if (cck_lock_counter > 0) - cck_lock_counter--; - } - - } else { - if (cck_lock_counter > 0) - cck_lock_counter--; - } - } else { - if (cck_lock_counter > 0) - cck_lock_counter--; - } - - if (!coex_sta->pre_ccklock) { - - if (cck_lock_counter >= 3) - coex_sta->cck_lock = true; - else - coex_sta->cck_lock = false; - } else { - if (cck_lock_counter == 0) - coex_sta->cck_lock = false; - else - coex_sta->cck_lock = true; - } - - if (coex_sta->cck_lock) - coex_sta->cck_ever_lock = true; - - coex_sta->pre_ccklock = coex_sta->cck_lock; - -#endif -} - - - -boolean halbtc8703b1ant_is_wifibt_status_changed(IN struct btc_coexist - *btcoexist) -{ - static boolean pre_wifi_busy = false, pre_under_4way = false, - pre_bt_hs_on = false, pre_bt_off = false, pre_bt_slave = false; - static u8 pre_hid_busy_num = 0, pre_wl_noisy_level = 0; - boolean wifi_busy = false, under_4way = false, bt_hs_on = false; - boolean wifi_connected = false; - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS, - &under_4way); - - if (coex_sta->bt_disabled != pre_bt_off) { - pre_bt_off = coex_sta->bt_disabled; - - if (coex_sta->bt_disabled) - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT is disabled !!\n"); - else - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT is enabled !!\n"); - - BTC_TRACE(trace_buf); - - coex_sta->bt_coex_supported_feature = 0; - coex_sta->bt_coex_supported_version = 0; - coex_sta->bt_ble_scan_type = 0; - coex_sta->bt_ble_scan_para[0] = 0; - coex_sta->bt_ble_scan_para[1] = 0; - coex_sta->bt_ble_scan_para[2] = 0; - - return true; - } - - if (wifi_connected) { - if (wifi_busy != pre_wifi_busy) { - pre_wifi_busy = wifi_busy; - return true; - } - if (under_4way != pre_under_4way) { - pre_under_4way = under_4way; - return true; - } - if (bt_hs_on != pre_bt_hs_on) { - pre_bt_hs_on = bt_hs_on; - return true; - } - if (coex_sta->wl_noisy_level != pre_wl_noisy_level) { - pre_wl_noisy_level = coex_sta->wl_noisy_level; - return true; - } - } - - if (!coex_sta->bt_disabled) { - if (coex_sta->hid_busy_num != pre_hid_busy_num) { - pre_hid_busy_num = coex_sta->hid_busy_num; - return true; - } - } - - if (bt_link_info->slave_role != pre_bt_slave) { - pre_bt_slave = bt_link_info->slave_role; - return true; - } - - return false; -} - - -void halbtc8703b1ant_update_bt_link_info(IN struct btc_coexist *btcoexist) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - boolean bt_hs_on = false; - boolean bt_busy = false; - - - coex_sta->num_of_profile = 0; - - /* set link exist status */ - if (!(coex_sta->bt_info & BT_INFO_8703B_1ANT_B_CONNECTION)) { - coex_sta->bt_link_exist = false; - coex_sta->pan_exist = false; - coex_sta->a2dp_exist = false; - coex_sta->hid_exist = false; - coex_sta->sco_exist = false; - } else { /* connection exists */ - coex_sta->bt_link_exist = true; - if (coex_sta->bt_info & BT_INFO_8703B_1ANT_B_FTP) { - coex_sta->pan_exist = true; - coex_sta->num_of_profile++; - } else - coex_sta->pan_exist = false; - - if (coex_sta->bt_info & BT_INFO_8703B_1ANT_B_A2DP) { - coex_sta->a2dp_exist = true; - coex_sta->num_of_profile++; - } else - coex_sta->a2dp_exist = false; - - if (coex_sta->bt_info & BT_INFO_8703B_1ANT_B_HID) { - coex_sta->hid_exist = true; - coex_sta->num_of_profile++; - } else - coex_sta->hid_exist = false; - - if (coex_sta->bt_info & BT_INFO_8703B_1ANT_B_SCO_ESCO) { - coex_sta->sco_exist = true; - coex_sta->num_of_profile++; - } else - coex_sta->sco_exist = false; - - } - - btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); - - bt_link_info->bt_link_exist = coex_sta->bt_link_exist; - bt_link_info->sco_exist = coex_sta->sco_exist; - bt_link_info->a2dp_exist = coex_sta->a2dp_exist; - bt_link_info->pan_exist = coex_sta->pan_exist; - bt_link_info->hid_exist = coex_sta->hid_exist; - bt_link_info->acl_busy = coex_sta->acl_busy; - - /* work around for HS mode. */ - if (bt_hs_on) { - bt_link_info->pan_exist = true; - bt_link_info->bt_link_exist = true; - } - - /* check if Sco only */ - if (bt_link_info->sco_exist && - !bt_link_info->a2dp_exist && - !bt_link_info->pan_exist && - !bt_link_info->hid_exist) - bt_link_info->sco_only = true; - else - bt_link_info->sco_only = false; - - /* check if A2dp only */ - if (!bt_link_info->sco_exist && - bt_link_info->a2dp_exist && - !bt_link_info->pan_exist && - !bt_link_info->hid_exist) - bt_link_info->a2dp_only = true; - else - bt_link_info->a2dp_only = false; - - /* check if Pan only */ - if (!bt_link_info->sco_exist && - !bt_link_info->a2dp_exist && - bt_link_info->pan_exist && - !bt_link_info->hid_exist) - bt_link_info->pan_only = true; - else - bt_link_info->pan_only = false; - - /* check if Hid only */ - if (!bt_link_info->sco_exist && - !bt_link_info->a2dp_exist && - !bt_link_info->pan_exist && - bt_link_info->hid_exist) - bt_link_info->hid_only = true; - else - bt_link_info->hid_only = false; - - if (coex_sta->bt_info & BT_INFO_8703B_1ANT_B_INQ_PAGE) { - coex_dm->bt_status = BT_8703B_1ANT_BT_STATUS_INQ_PAGE; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), BT Inq/page!!!\n"); - } else if (!(coex_sta->bt_info & BT_INFO_8703B_1ANT_B_CONNECTION)) { - coex_dm->bt_status = BT_8703B_1ANT_BT_STATUS_NON_CONNECTED_IDLE; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), BT Non-Connected idle!!!\n"); - } else if (coex_sta->bt_info == BT_INFO_8703B_1ANT_B_CONNECTION) { - /* connection exists but no busy */ - coex_dm->bt_status = BT_8703B_1ANT_BT_STATUS_CONNECTED_IDLE; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), BT Connected-idle!!!\n"); - } else if (((coex_sta->bt_info & BT_INFO_8703B_1ANT_B_SCO_ESCO) || - (coex_sta->bt_info & BT_INFO_8703B_1ANT_B_SCO_BUSY)) && - (coex_sta->bt_info & BT_INFO_8703B_1ANT_B_ACL_BUSY)) { - coex_dm->bt_status = BT_8703B_1ANT_BT_STATUS_ACL_SCO_BUSY; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), BT ACL SCO busy!!!\n"); - } else if ((coex_sta->bt_info & BT_INFO_8703B_1ANT_B_SCO_ESCO) || - (coex_sta->bt_info & BT_INFO_8703B_1ANT_B_SCO_BUSY)) { - coex_dm->bt_status = BT_8703B_1ANT_BT_STATUS_SCO_BUSY; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), BT SCO busy!!!\n"); - } else if (coex_sta->bt_info & BT_INFO_8703B_1ANT_B_ACL_BUSY) { - coex_dm->bt_status = BT_8703B_1ANT_BT_STATUS_ACL_BUSY; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), BT ACL busy!!!\n"); - } else { - coex_dm->bt_status = BT_8703B_1ANT_BT_STATUS_MAX; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), BT Non-Defined state!!!\n"); - } - - BTC_TRACE(trace_buf); - - if ((BT_8703B_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) || - (BT_8703B_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) || - (BT_8703B_1ANT_BT_STATUS_ACL_SCO_BUSY == coex_dm->bt_status)) - bt_busy = true; - else - bt_busy = false; - - btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bt_busy); -} - - -void halbtc8703b1ant_update_wifi_channel_info(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - u8 h2c_parameter[3] = {0}; - u32 wifi_bw; - u8 wifi_central_chnl; - - /* only 2.4G we need to inform bt the chnl mask */ - btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_CENTRAL_CHNL, - &wifi_central_chnl); - if ((BTC_MEDIA_CONNECT == type) && - (wifi_central_chnl <= 14)) { - h2c_parameter[0] = - 0x1; /* enable BT AFH skip WL channel for 8703b because BT Rx LO interference */ - /* h2c_parameter[0] = 0x0; */ - h2c_parameter[1] = wifi_central_chnl; - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw); - if (BTC_WIFI_BW_HT40 == wifi_bw) - h2c_parameter[2] = 0x30; - else - h2c_parameter[2] = 0x20; - } - - coex_dm->wifi_chnl_info[0] = h2c_parameter[0]; - coex_dm->wifi_chnl_info[1] = h2c_parameter[1]; - coex_dm->wifi_chnl_info[2] = h2c_parameter[2]; - - btcoexist->btc_fill_h2c(btcoexist, 0x66, 3, h2c_parameter); - -} - -void halbtc8703b1ant_set_bt_auto_report(IN struct btc_coexist *btcoexist, - IN boolean enable_auto_report) -{ - u8 h2c_parameter[1] = {0}; - - h2c_parameter[0] = 0; - - if (enable_auto_report) - h2c_parameter[0] |= BIT(0); - - btcoexist->btc_fill_h2c(btcoexist, 0x68, 1, h2c_parameter); -} - -void halbtc8703b1ant_bt_auto_report(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean enable_auto_report) -{ - coex_dm->cur_bt_auto_report = enable_auto_report; - - if (!force_exec) { - if (coex_dm->pre_bt_auto_report == coex_dm->cur_bt_auto_report) - return; - } - halbtc8703b1ant_set_bt_auto_report(btcoexist, - coex_dm->cur_bt_auto_report); - - coex_dm->pre_bt_auto_report = coex_dm->cur_bt_auto_report; -} - -void halbtc8703b1ant_set_fw_low_penalty_ra(IN struct btc_coexist - *btcoexist, IN boolean low_penalty_ra) -{ - u8 h2c_parameter[6] = {0}; - - h2c_parameter[0] = 0x6; /* op_code, 0x6= Retry_Penalty */ - - if (low_penalty_ra) { - h2c_parameter[1] |= BIT(0); - h2c_parameter[2] = - 0x00; /* normal rate except MCS7/6/5, OFDM54/48/36 */ - h2c_parameter[3] = 0xf7; /* MCS7 or OFDM54 */ - h2c_parameter[4] = 0xf8; /* MCS6 or OFDM48 */ - h2c_parameter[5] = 0xf9; /* MCS5 or OFDM36 */ - } - - btcoexist->btc_fill_h2c(btcoexist, 0x69, 6, h2c_parameter); -} - -void halbtc8703b1ant_low_penalty_ra(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean low_penalty_ra) -{ - coex_dm->cur_low_penalty_ra = low_penalty_ra; - - if (!force_exec) { - if (coex_dm->pre_low_penalty_ra == coex_dm->cur_low_penalty_ra) - return; - } - - halbtc8703b1ant_set_fw_low_penalty_ra(btcoexist, - coex_dm->cur_low_penalty_ra); - - coex_dm->pre_low_penalty_ra = coex_dm->cur_low_penalty_ra; -} - -void halbtc8703b1ant_write_score_board( - IN struct btc_coexist *btcoexist, - IN u16 bitpos, - IN boolean state -) -{ - - static u16 originalval = 0x8002; - - if (state) - originalval = originalval | bitpos; - else - originalval = originalval & (~bitpos); - - - btcoexist->btc_write_2byte(btcoexist, 0xaa, originalval); -#if 0 - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "\n [BTCoex], ********** Write Scoreboard = %x**********\n", - originalval); - BTC_TRACE(trace_buf); -#endif - -} - -void halbtc8703b1ant_read_score_board( - IN struct btc_coexist *btcoexist, - IN u16 *score_board_val -) -{ - - *score_board_val = (btcoexist->btc_read_2byte(btcoexist, - 0xaa)) & 0x7fff; -} - -void halbtc8703b1ant_post_state_to_bt( - IN struct btc_coexist *btcoexist, - IN u16 type, - IN boolean state -) -{ - halbtc8703b1ant_write_score_board(btcoexist, (u16) type, state); -} - -void halbtc8703b1ant_monitor_bt_enable_disable(IN struct btc_coexist *btcoexist) -{ - static u32 bt_disable_cnt = 0; - boolean bt_active = true, bt_disabled = false; - u16 u16tmp; - - /* This function check if bt is disabled */ -#if 1 - if (coex_sta->high_priority_tx == 0 && - coex_sta->high_priority_rx == 0 && - coex_sta->low_priority_tx == 0 && - coex_sta->low_priority_rx == 0) - bt_active = false; - if (coex_sta->high_priority_tx == 0xffff && - coex_sta->high_priority_rx == 0xffff && - coex_sta->low_priority_tx == 0xffff && - coex_sta->low_priority_rx == 0xffff) - bt_active = false; - - -#else /* 8703b BT can't show correct on/off status in scoreboard[1] 2015/11/26 */ - - halbtc8703b1ant_read_score_board(btcoexist, &u16tmp); - - bt_active = u16tmp & BIT(1); - - -#endif - - if (bt_active) { - bt_disable_cnt = 0; - bt_disabled = false; - btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_DISABLE, - &bt_disabled); - } else { - - bt_disable_cnt++; - if (bt_disable_cnt >= 2) { - bt_disabled = true; - bt_disable_cnt = 2; - } - - btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_DISABLE, - &bt_disabled); - } - - if (bt_disabled) - halbtc8703b1ant_low_penalty_ra(btcoexist, NORMAL_EXEC, false); - else - halbtc8703b1ant_low_penalty_ra(btcoexist, NORMAL_EXEC, true); - - if (coex_sta->bt_disabled != bt_disabled) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT is from %s to %s!!\n", - (coex_sta->bt_disabled ? "disabled" : "enabled"), - (bt_disabled ? "disabled" : "enabled")); - BTC_TRACE(trace_buf); - coex_sta->bt_disabled = bt_disabled; - - } -} - - - -void halbtc8703b1ant_enable_gnt_to_gpio(IN struct btc_coexist *btcoexist, - IN boolean isenable) -{ - -#if (BT_8703B_1ANT_ENABLE_GNTBT_TO_GPIO14 == 1) - if (isenable) { - /* enable GNT_WL/GNT_BT debug signal to GPIO14/15 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x73, 0x8, 0x1); - - /* enable GNT_BT debug to GPIO */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4e, 0x40, 0x0); - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, 0x1, 0x0); - } else { - /* enable GNT_WL/GNT_BT debug signal to GPIO14/15 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x73, 0x8, 0x0); - - /* Disable GNT_BT debug to GPIO, and enable chip_wakeup_host */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4e, 0x40, 0x1); - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, 0x1, 0x1); - } -#endif -} - -u32 halbtc8703b1ant_ltecoex_indirect_read_reg(IN struct btc_coexist *btcoexist, - IN u16 reg_addr) -{ - u32 j = 0; - - - /* wait for ready bit before access 0x7c0 */ - btcoexist->btc_write_4byte(btcoexist, 0x7c0, 0x800F0000 | reg_addr); - - do { - j++; - } while (((btcoexist->btc_read_1byte(btcoexist, - 0x7c3)&BIT(5)) == 0) && - (j < BT_8703B_1ANT_LTECOEX_INDIRECTREG_ACCESS_TIMEOUT)); - - - return btcoexist->btc_read_4byte(btcoexist, - 0x7c8); /* get read data */ - -} - -void halbtc8703b1ant_ltecoex_indirect_write_reg(IN struct btc_coexist - *btcoexist, - IN u16 reg_addr, IN u32 bit_mask, IN u32 reg_value) -{ - u32 val, i = 0, j = 0, bitpos = 0; - - - if (bit_mask == 0x0) - return; - if (bit_mask == 0xffffffff) { - btcoexist->btc_write_4byte(btcoexist, 0x7c4, - reg_value); /* put write data */ - - /* wait for ready bit before access 0x7c0 */ - do { - j++; - } while (((btcoexist->btc_read_1byte(btcoexist, - 0x7c3)&BIT(5)) == 0) && - (j < BT_8703B_1ANT_LTECOEX_INDIRECTREG_ACCESS_TIMEOUT)); - - - btcoexist->btc_write_4byte(btcoexist, 0x7c0, - 0xc00F0000 | reg_addr); - } else { - for (i = 0; i <= 31; i++) { - if (((bit_mask >> i) & 0x1) == 0x1) { - bitpos = i; - break; - } - } - - /* read back register value before write */ - val = halbtc8703b1ant_ltecoex_indirect_read_reg(btcoexist, - reg_addr); - val = (val & (~bit_mask)) | (reg_value << bitpos); - - btcoexist->btc_write_4byte(btcoexist, 0x7c4, - val); /* put write data */ - - /* wait for ready bit before access 0x7c0 */ - do { - j++; - } while (((btcoexist->btc_read_1byte(btcoexist, - 0x7c3)&BIT(5)) == 0) && - (j < BT_8703B_1ANT_LTECOEX_INDIRECTREG_ACCESS_TIMEOUT)); - - - btcoexist->btc_write_4byte(btcoexist, 0x7c0, - 0xc00F0000 | reg_addr); - - } - -} - -void halbtc8703b1ant_ltecoex_enable(IN struct btc_coexist *btcoexist, - IN boolean enable) -{ - u8 val; - - val = (enable) ? 1 : 0; - halbtc8703b1ant_ltecoex_indirect_write_reg(btcoexist, 0x38, 0x80, - val); /* 0x38[7] */ - -} - -void halbtc8703b1ant_ltecoex_pathcontrol_owner(IN struct btc_coexist *btcoexist, - IN boolean wifi_control) -{ - u8 val; - - val = (wifi_control) ? 1 : 0; - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x73, 0x4, - val); /* 0x70[26] */ - -} - -void halbtc8703b1ant_ltecoex_set_gnt_bt(IN struct btc_coexist *btcoexist, - IN u8 control_block, IN boolean sw_control, IN u8 state) -{ - u32 val = 0, val_orig = 0; - - if (!sw_control) - val = 0x0; - else if (state & 0x1) - val = 0x3; - else - val = 0x1; - - val_orig = halbtc8703b1ant_ltecoex_indirect_read_reg(btcoexist, - 0x38); - - switch (control_block) { - case BT_8703B_1ANT_GNT_BLOCK_RFC_BB: - default: - val = ((val << 14) | (val << 10)) | (val_orig & 0xffff33ff); - break; - case BT_8703B_1ANT_GNT_BLOCK_RFC: - val = (val << 14) | (val_orig & 0xffff3fff); - break; - case BT_8703B_1ANT_GNT_BLOCK_BB: - val = (val << 10) | (val_orig & 0xfffff3ff); - break; - } - - halbtc8703b1ant_ltecoex_indirect_write_reg(btcoexist, - 0x38, 0xffffffff, val); -} - - -void halbtc8703b1ant_ltecoex_set_gnt_wl(IN struct btc_coexist *btcoexist, - IN u8 control_block, IN boolean sw_control, IN u8 state) -{ - u32 val = 0, val_orig = 0; - - if (!sw_control) - val = 0x0; - else if (state & 0x1) - val = 0x3; - else - val = 0x1; - - val_orig = halbtc8703b1ant_ltecoex_indirect_read_reg(btcoexist, - 0x38); - - switch (control_block) { - case BT_8703B_1ANT_GNT_BLOCK_RFC_BB: - default: - val = ((val << 12) | (val << 8)) | (val_orig & 0xffffccff); - break; - case BT_8703B_1ANT_GNT_BLOCK_RFC: - val = (val << 12) | (val_orig & 0xffffcfff); - break; - case BT_8703B_1ANT_GNT_BLOCK_BB: - val = (val << 8) | (val_orig & 0xfffffcff); - break; - } - - halbtc8703b1ant_ltecoex_indirect_write_reg(btcoexist, - 0x38, 0xffffffff, val); -} - - -void halbtc8703b1ant_ltecoex_set_coex_table(IN struct btc_coexist *btcoexist, - IN u8 table_type, IN u16 table_content) -{ - u16 reg_addr = 0x0000; - - switch (table_type) { - case BT_8703B_1ANT_CTT_WL_VS_LTE: - reg_addr = 0xa0; - break; - case BT_8703B_1ANT_CTT_BT_VS_LTE: - reg_addr = 0xa4; - break; - } - - if (reg_addr != 0x0000) - halbtc8703b1ant_ltecoex_indirect_write_reg(btcoexist, reg_addr, - 0xffff, table_content); /* 0xa0[15:0] or 0xa4[15:0] */ - - -} - - -void halbtc8703b1ant_ltecoex_set_break_table(IN struct btc_coexist *btcoexist, - IN u8 table_type, IN u8 table_content) -{ - u16 reg_addr = 0x0000; - - switch (table_type) { - case BT_8703B_1ANT_LBTT_WL_BREAK_LTE: - reg_addr = 0xa8; - break; - case BT_8703B_1ANT_LBTT_BT_BREAK_LTE: - reg_addr = 0xac; - break; - case BT_8703B_1ANT_LBTT_LTE_BREAK_WL: - reg_addr = 0xb0; - break; - case BT_8703B_1ANT_LBTT_LTE_BREAK_BT: - reg_addr = 0xb4; - break; - } - - if (reg_addr != 0x0000) - halbtc8703b1ant_ltecoex_indirect_write_reg(btcoexist, reg_addr, - 0xff, table_content); /* 0xa8[15:0] or 0xb4[15:0] */ - - -} - -void halbtc8703b1ant_set_wltoggle_coex_table(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 interval, - IN u8 val0x6c4_b0, IN u8 val0x6c4_b1, IN u8 val0x6c4_b2, - IN u8 val0x6c4_b3) -{ - static u8 pre_h2c_parameter[6] = {0}; - u8 cur_h2c_parameter[6] = {0}; - u8 i, match_cnt = 0; - - cur_h2c_parameter[0] = 0x7; /* op_code, 0x7= wlan toggle slot*/ - - cur_h2c_parameter[1] = interval; - cur_h2c_parameter[2] = val0x6c4_b0; - cur_h2c_parameter[3] = val0x6c4_b1; - cur_h2c_parameter[4] = val0x6c4_b2; - cur_h2c_parameter[5] = val0x6c4_b3; - - if (!force_exec) { - for (i = 1; i <= 5; i++) { - if (cur_h2c_parameter[i] != pre_h2c_parameter[i]) - break; - - match_cnt++; - } - - if (match_cnt == 5) - return; - } - - for (i = 1; i <= 5; i++) - pre_h2c_parameter[i] = cur_h2c_parameter[i]; - - btcoexist->btc_fill_h2c(btcoexist, 0x69, 6, cur_h2c_parameter); -} - - -void halbtc8703b1ant_set_coex_table(IN struct btc_coexist *btcoexist, - IN u32 val0x6c0, IN u32 val0x6c4, IN u32 val0x6c8, IN u8 val0x6cc) -{ - btcoexist->btc_write_4byte(btcoexist, 0x6c0, val0x6c0); - - btcoexist->btc_write_4byte(btcoexist, 0x6c4, val0x6c4); - - btcoexist->btc_write_4byte(btcoexist, 0x6c8, val0x6c8); - - btcoexist->btc_write_1byte(btcoexist, 0x6cc, val0x6cc); -} - -void halbtc8703b1ant_coex_table(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u32 val0x6c0, IN u32 val0x6c4, - IN u32 val0x6c8, IN u8 val0x6cc) -{ - coex_dm->cur_val0x6c0 = val0x6c0; - coex_dm->cur_val0x6c4 = val0x6c4; - coex_dm->cur_val0x6c8 = val0x6c8; - coex_dm->cur_val0x6cc = val0x6cc; - - if (!force_exec) { - if ((coex_dm->pre_val0x6c0 == coex_dm->cur_val0x6c0) && - (coex_dm->pre_val0x6c4 == coex_dm->cur_val0x6c4) && - (coex_dm->pre_val0x6c8 == coex_dm->cur_val0x6c8) && - (coex_dm->pre_val0x6cc == coex_dm->cur_val0x6cc)) - return; - } - halbtc8703b1ant_set_coex_table(btcoexist, val0x6c0, val0x6c4, val0x6c8, - val0x6cc); - - coex_dm->pre_val0x6c0 = coex_dm->cur_val0x6c0; - coex_dm->pre_val0x6c4 = coex_dm->cur_val0x6c4; - coex_dm->pre_val0x6c8 = coex_dm->cur_val0x6c8; - coex_dm->pre_val0x6cc = coex_dm->cur_val0x6cc; -} - -void halbtc8703b1ant_coex_table_with_type(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 type) -{ - u32 break_table; - u8 select_table; - - coex_sta->coex_table_type = type; - - if (coex_sta->concurrent_rx_mode_on == true) { - break_table = 0xf0ffffff; /* set WL hi-pri can break BT */ - select_table = - 0xb; /* set Tx response = Hi-Pri (ex: Transmitting ACK,BA,CTS) */ - } else { - break_table = 0xffffff; - select_table = 0x3; - } - - switch (type) { - case 0: - halbtc8703b1ant_coex_table(btcoexist, force_exec, - 0x55555555, 0x55555555, break_table, - select_table); - break; - case 1: - halbtc8703b1ant_coex_table(btcoexist, force_exec, - 0x55555555, 0x5a5a5a5a, break_table, - select_table); - break; - case 2: - halbtc8703b1ant_coex_table(btcoexist, force_exec, - 0xaa5a5a5a, 0xaa5a5a5a, break_table, - select_table); - break; - case 3: - halbtc8703b1ant_coex_table(btcoexist, force_exec, - 0xaa555555, 0xaa5a5a5a, break_table, - select_table); - break; - case 4: - halbtc8703b1ant_coex_table(btcoexist, force_exec, - 0xa5555555, 0x5a5a5a5a, break_table, - select_table); - break; - case 5: - halbtc8703b1ant_coex_table(btcoexist, force_exec, - 0x5a5a5a5a, 0x5a5a5a5a, break_table, - select_table); - break; - case 6: - halbtc8703b1ant_coex_table(btcoexist, force_exec, - 0xa5555555, 0x5a5a5a5a, break_table, - select_table); - break; - case 7: - halbtc8703b1ant_coex_table(btcoexist, force_exec, - 0xaaaaaaaa, 0xaaaaaaaa, break_table, - select_table); - break; - case 8: - halbtc8703b1ant_coex_table(btcoexist, force_exec, - 0xa5555555, 0xaaaaaaaa, break_table, - select_table); - break; - case 9: - halbtc8703b1ant_coex_table(btcoexist, force_exec, - 0x5a5a5a5a, 0xaaaa5aaa, break_table, - select_table); - break; - default: - break; - } -} - -void halbtc8703b1ant_set_fw_ignore_wlan_act(IN struct btc_coexist *btcoexist, - IN boolean enable) -{ - u8 h2c_parameter[1] = {0}; - - if (enable) - h2c_parameter[0] |= BIT(0);/* function enable */ - - btcoexist->btc_fill_h2c(btcoexist, 0x63, 1, h2c_parameter); -} - -void halbtc8703b1ant_ignore_wlan_act(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean enable) -{ - coex_dm->cur_ignore_wlan_act = enable; - - if (!force_exec) { - if (coex_dm->pre_ignore_wlan_act == - coex_dm->cur_ignore_wlan_act) - return; - } - halbtc8703b1ant_set_fw_ignore_wlan_act(btcoexist, enable); - - coex_dm->pre_ignore_wlan_act = coex_dm->cur_ignore_wlan_act; -} - -void halbtc8703b1ant_set_lps_rpwm(IN struct btc_coexist *btcoexist, - IN u8 lps_val, IN u8 rpwm_val) -{ - u8 lps = lps_val; - u8 rpwm = rpwm_val; - - btcoexist->btc_set(btcoexist, BTC_SET_U1_LPS_VAL, &lps); - btcoexist->btc_set(btcoexist, BTC_SET_U1_RPWM_VAL, &rpwm); -} - -void halbtc8703b1ant_lps_rpwm(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 lps_val, IN u8 rpwm_val) -{ - coex_dm->cur_lps = lps_val; - coex_dm->cur_rpwm = rpwm_val; - - if (!force_exec) { - if ((coex_dm->pre_lps == coex_dm->cur_lps) && - (coex_dm->pre_rpwm == coex_dm->cur_rpwm)) - return; - } - halbtc8703b1ant_set_lps_rpwm(btcoexist, lps_val, rpwm_val); - - coex_dm->pre_lps = coex_dm->cur_lps; - coex_dm->pre_rpwm = coex_dm->cur_rpwm; -} - -void halbtc8703b1ant_ps_tdma_check_for_power_save_state( - IN struct btc_coexist *btcoexist, IN boolean new_ps_state) -{ - u8 lps_mode = 0x0; - u8 h2c_parameter[5] = {0x8, 0, 0, 0, 0}; - - btcoexist->btc_get(btcoexist, BTC_GET_U1_LPS_MODE, &lps_mode); - - if (lps_mode) { /* already under LPS state */ - if (new_ps_state) { - /* keep state under LPS, do nothing. */ - } else { - /* will leave LPS state, turn off psTdma first */ - /*halbtc8703b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, - 8); */ - btcoexist->btc_fill_h2c(btcoexist, 0x60, 5, - h2c_parameter); - } - } else { /* NO PS state */ - if (new_ps_state) { - /* will enter LPS state, turn off psTdma first */ - /*halbtc8703b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, - 8);*/ - btcoexist->btc_fill_h2c(btcoexist, 0x60, 5, - h2c_parameter); - } else { - /* keep state under NO PS state, do nothing. */ - } - } -} - -void halbtc8703b1ant_power_save_state(IN struct btc_coexist *btcoexist, - IN u8 ps_type, IN u8 lps_val, IN u8 rpwm_val) -{ - boolean low_pwr_disable = false; - - switch (ps_type) { - case BTC_PS_WIFI_NATIVE: - /* recover to original 32k low power setting */ - coex_sta->force_lps_on = false; - low_pwr_disable = false; - btcoexist->btc_set(btcoexist, - BTC_SET_ACT_DISABLE_LOW_POWER, - &low_pwr_disable); - btcoexist->btc_set(btcoexist, BTC_SET_ACT_NORMAL_LPS, - NULL); - - break; - case BTC_PS_LPS_ON: - coex_sta->force_lps_on = true; - halbtc8703b1ant_ps_tdma_check_for_power_save_state( - btcoexist, true); - halbtc8703b1ant_lps_rpwm(btcoexist, NORMAL_EXEC, - lps_val, rpwm_val); - /* when coex force to enter LPS, do not enter 32k low power. */ - low_pwr_disable = true; - btcoexist->btc_set(btcoexist, - BTC_SET_ACT_DISABLE_LOW_POWER, - &low_pwr_disable); - /* power save must executed before psTdma. */ - btcoexist->btc_set(btcoexist, BTC_SET_ACT_ENTER_LPS, - NULL); - - break; - case BTC_PS_LPS_OFF: - coex_sta->force_lps_on = false; - halbtc8703b1ant_ps_tdma_check_for_power_save_state( - btcoexist, false); - btcoexist->btc_set(btcoexist, BTC_SET_ACT_LEAVE_LPS, - NULL); - - break; - default: - break; - } -} - - - -void halbtc8703b1ant_set_fw_pstdma(IN struct btc_coexist *btcoexist, - IN u8 byte1, IN u8 byte2, IN u8 byte3, IN u8 byte4, IN u8 byte5) -{ - u8 h2c_parameter[5] = {0}; - u8 real_byte1 = byte1, real_byte5 = byte5; - boolean ap_enable = false; - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - - if (byte5 & BIT(2)) - coex_sta->is_tdma_btautoslot = true; - else - coex_sta->is_tdma_btautoslot = false; - - /* release bt-auto slot for auto-slot hang is detected!! */ - if (coex_sta->is_tdma_btautoslot) - if ((coex_sta->is_tdma_btautoslot_hang) || - (bt_link_info->slave_role)) - byte5 = byte5 & 0xfb; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, - &ap_enable); - - if (ap_enable) { - if (byte1 & BIT(4) && !(byte1 & BIT(5))) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], FW for 1Ant AP mode\n"); - BTC_TRACE(trace_buf); - real_byte1 &= ~BIT(4); - real_byte1 |= BIT(5); - - real_byte5 |= BIT(5); - real_byte5 &= ~BIT(6); - - halbtc8703b1ant_power_save_state(btcoexist, - BTC_PS_WIFI_NATIVE, 0x0, - 0x0); - } - } else if (byte1 & BIT(4) && !(byte1 & BIT(5))) { - - halbtc8703b1ant_power_save_state( - btcoexist, BTC_PS_LPS_ON, 0x50, - 0x4); - } else { - halbtc8703b1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, - 0x0, - 0x0); - } - - - h2c_parameter[0] = real_byte1; - h2c_parameter[1] = byte2; - h2c_parameter[2] = byte3; - h2c_parameter[3] = byte4; - h2c_parameter[4] = real_byte5; - - coex_dm->ps_tdma_para[0] = real_byte1; - coex_dm->ps_tdma_para[1] = byte2; - coex_dm->ps_tdma_para[2] = byte3; - coex_dm->ps_tdma_para[3] = byte4; - coex_dm->ps_tdma_para[4] = real_byte5; - - btcoexist->btc_fill_h2c(btcoexist, 0x60, 5, h2c_parameter); -} - - -void halbtc8703b1ant_ps_tdma(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean turn_on, IN u8 type) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - boolean wifi_busy = false; - u8 rssi_adjust_val = 0; - static u8 psTdmaByte4Modify = 0x0, pre_psTdmaByte4Modify = 0x0; - static boolean pre_wifi_busy = false; - - coex_dm->cur_ps_tdma_on = turn_on; - coex_dm->cur_ps_tdma = type; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - - if (wifi_busy != pre_wifi_busy) { - force_exec = true; - pre_wifi_busy = wifi_busy; - } - - /* 0x778 = 0x1 at wifi slot (no blocking BT Low-Pri pkts) */ - if ((bt_link_info->slave_role) && (bt_link_info->a2dp_exist)) - psTdmaByte4Modify = 0x1; - else - psTdmaByte4Modify = 0x0; - - if (pre_psTdmaByte4Modify != psTdmaByte4Modify) { - - force_exec = true; - pre_psTdmaByte4Modify = psTdmaByte4Modify; - } - - if (!force_exec) { - if ((coex_dm->pre_ps_tdma_on == coex_dm->cur_ps_tdma_on) && - (coex_dm->pre_ps_tdma == coex_dm->cur_ps_tdma)) - return; - } - - if (coex_dm->cur_ps_tdma_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** TDMA(on, %d) **********\n", - coex_dm->cur_ps_tdma); - BTC_TRACE(trace_buf); - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** TDMA(off, %d) **********\n", - coex_dm->cur_ps_tdma); - BTC_TRACE(trace_buf); - } - - if (turn_on) { - - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x550, 0x8, - 0x1); /* enable TBTT nterrupt */ - } - - - if (turn_on) { - switch (type) { - default: - halbtc8703b1ant_set_fw_pstdma(btcoexist, - 0x61, 0x35, 0x03, 0x11, 0x11); - break; - - case 3: - halbtc8703b1ant_set_fw_pstdma(btcoexist, - 0x51, 0x3a, 0x03, 0x10, 0x50); - break; - case 4: - halbtc8703b1ant_set_fw_pstdma(btcoexist, - 0x51, 0x21, 0x03, 0x10, 0x50); - break; - case 5: - halbtc8703b1ant_set_fw_pstdma(btcoexist, - 0x61, 0x15, 0x03, 0x11, 0x11); - break; - case 6: - halbtc8703b1ant_set_fw_pstdma(btcoexist, - 0x61, 0x20, 0x03, 0x11, 0x11); - break; - case 7: - halbtc8703b1ant_set_fw_pstdma(btcoexist, - 0x51, 0x10, 0x03, 0x10, 0x54 | - psTdmaByte4Modify); - break; - case 8: - halbtc8703b1ant_set_fw_pstdma(btcoexist, - 0x51, 0x10, 0x03, 0x10, 0x54 | - psTdmaByte4Modify); - break; - case 9: - halbtc8703b1ant_set_fw_pstdma(btcoexist, - 0x55, 0x10, 0x03, 0x10, 0x54 | - psTdmaByte4Modify); - break; - case 10: - halbtc8703b1ant_set_fw_pstdma(btcoexist, - 0x61, 0x30, 0x03, 0x11, 0x10); - break; - case 11: - halbtc8703b1ant_set_fw_pstdma(btcoexist, - 0x65, 0x25, 0x03, 0x11, 0x11 | - psTdmaByte4Modify); - break; - case 12: - halbtc8703b1ant_set_fw_pstdma(btcoexist, - 0x55, 0x30, 0x03, 0x10, 0x50 | - psTdmaByte4Modify); - break; - case 13: - halbtc8703b1ant_set_fw_pstdma(btcoexist, - 0x51, 0x25, 0x03, 0x10, 0x50 | - psTdmaByte4Modify); - break; - case 14: - halbtc8703b1ant_set_fw_pstdma(btcoexist, - 0x51, 0x15, 0x03, 0x10, 0x50 | - psTdmaByte4Modify); - break; - case 15: - halbtc8703b1ant_set_fw_pstdma(btcoexist, - 0x51, 0x20, 0x03, 0x10, 0x50 | - psTdmaByte4Modify); - break; - case 16: - halbtc8703b1ant_set_fw_pstdma(btcoexist, - 0x61, 0x10, 0x03, 0x11, 0x15 | - psTdmaByte4Modify); - break; - case 17: - halbtc8703b1ant_set_fw_pstdma(btcoexist, - 0x61, 0x10, 0x03, 0x11, 0x14); - break; - case 18: - halbtc8703b1ant_set_fw_pstdma(btcoexist, - 0x51, 0x30, 0x03, 0x10, 0x50 | - psTdmaByte4Modify); - break; - case 19: - halbtc8703b1ant_set_fw_pstdma(btcoexist, - 0x61, 0x15, 0x03, 0x11, 0x10); - break; - case 20: - halbtc8703b1ant_set_fw_pstdma(btcoexist, - 0x61, 0x30, 0x03, 0x11, 0x10); - break; - case 21: - halbtc8703b1ant_set_fw_pstdma(btcoexist, - 0x61, 0x30, 0x03, 0x11, 0x10); - break; - case 22: - halbtc8703b1ant_set_fw_pstdma(btcoexist, - 0x61, 0x25, 0x03, 0x11, 0x10); - break; - case 23: - halbtc8703b1ant_set_fw_pstdma(btcoexist, - 0x61, 0x10, 0x03, 0x11, 0x10); - break; - case 32: - halbtc8703b1ant_set_fw_pstdma(btcoexist, - 0x61, 0x35, 0x03, 0x11, 0x11); - break; - case 33: - halbtc8703b1ant_set_fw_pstdma(btcoexist, - 0x61, 0x35, 0x03, 0x11, 0x10); - break; - case 57: - halbtc8703b1ant_set_fw_pstdma(btcoexist, - 0x51, 0x10, 0x03, 0x10, 0x50 | - psTdmaByte4Modify); - break; - case 58: - halbtc8703b1ant_set_fw_pstdma(btcoexist, - 0x51, 0x10, 0x03, 0x10, 0x50 | - psTdmaByte4Modify); - break; - case 67: - halbtc8703b1ant_set_fw_pstdma(btcoexist, - 0x61, 0x10, 0x03, 0x11, 0x10 | - psTdmaByte4Modify); - break; - } - } else { - - /* disable PS tdma */ - switch (type) { - case 8: /* PTA Control */ - halbtc8703b1ant_set_fw_pstdma(btcoexist, 0x8, - 0x0, 0x0, 0x0, 0x0); - break; - case 0: - default: /* Software control, Antenna at BT side */ - halbtc8703b1ant_set_fw_pstdma(btcoexist, 0x0, - 0x0, 0x0, 0x0, 0x0); - break; - case 1: /* 2-Ant, 0x778=3, antenna control by antenna diversity */ - halbtc8703b1ant_set_fw_pstdma(btcoexist, 0x0, - 0x0, 0x0, 0x48, 0x0); - break; - } - } - - /* update pre state */ - coex_dm->pre_ps_tdma_on = coex_dm->cur_ps_tdma_on; - coex_dm->pre_ps_tdma = coex_dm->cur_ps_tdma; -} - -void halbtc8703b1ant_set_ant_path(IN struct btc_coexist *btcoexist, - IN u8 ant_pos_type, IN boolean force_exec, - IN u8 phase) -{ - u32 cnt_bt_cal_chk = 0; - boolean is_in_mp_mode = false; - u8 u8tmp = 0; - u32 u32tmp1 = 0, u32tmp2 = 0; - - - u32tmp1 = halbtc8703b1ant_ltecoex_indirect_read_reg(btcoexist, - 0x38); - - /* To avoid indirect access fail */ - if (((u32tmp1 & 0xf000) >> 12) != ((u32tmp1 & 0x0f00) >> 8)) { - force_exec = true; - coex_sta->gnt_error_cnt++; - } - -#if 1 - u32tmp2 = halbtc8703b1ant_ltecoex_indirect_read_reg(btcoexist, - 0x54); - u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x73); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** (Before Ant Setup) 0x73 = 0x%x, 0x38= 0x%x, 0x54= 0x%x**********\n", - u8tmp, u32tmp1, u32tmp2); - BTC_TRACE(trace_buf); -#endif - - coex_dm->cur_ant_pos_type = ant_pos_type; - - if (!force_exec) { - if (coex_dm->cur_ant_pos_type == coex_dm->pre_ant_pos_type) { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** Skip Antenna Path Setup because no change!!**********\n"); - BTC_TRACE(trace_buf); - return; - } - } - - coex_dm->pre_ant_pos_type = coex_dm->cur_ant_pos_type; - - switch (phase) { - case BT_8703B_1ANT_PHASE_COEX_INIT: - /* Disable LTE Coex Function in WiFi side (this should be on if LTE coex is required) */ - halbtc8703b1ant_ltecoex_enable(btcoexist, 0x0); - - /* GNT_WL_LTE always = 1 (this should be config if LTE coex is required) */ - halbtc8703b1ant_ltecoex_set_coex_table( - btcoexist, - BT_8703B_1ANT_CTT_WL_VS_LTE, - 0xffff); - - /* GNT_BT_LTE always = 1 (this should be config if LTE coex is required) */ - halbtc8703b1ant_ltecoex_set_coex_table( - btcoexist, - BT_8703B_1ANT_CTT_BT_VS_LTE, - 0xffff); - - /* Wait If BT IQK running, because Path control owner is at BT during BT IQK (setup by WiFi firmware) */ - while (cnt_bt_cal_chk <= 20) { - u8tmp = btcoexist->btc_read_1byte( - btcoexist, - 0x49d); - cnt_bt_cal_chk++; - if (u8tmp & BIT(0)) { - BTC_SPRINTF(trace_buf, - BT_TMP_BUF_SIZE, - "[BTCoex], ########### BT is calibrating (wait cnt=%d) ###########\n", - cnt_bt_cal_chk); - BTC_TRACE(trace_buf); - delay_ms(50); - } else { - BTC_SPRINTF(trace_buf, - BT_TMP_BUF_SIZE, - "[BTCoex], ********** BT is NOT calibrating (wait cnt=%d)**********\n", - cnt_bt_cal_chk); - BTC_TRACE(trace_buf); - break; - } - } - - - /* set Path control owner to WL at initial step */ - halbtc8703b1ant_ltecoex_pathcontrol_owner( - btcoexist, - BT_8703B_1ANT_PCO_WLSIDE); - - /* set GNT_BT to SW high */ - halbtc8703b1ant_ltecoex_set_gnt_bt(btcoexist, - BT_8703B_1ANT_GNT_BLOCK_RFC_BB, - BT_8703B_1ANT_GNT_TYPE_CTRL_BY_SW, - BT_8703B_1ANT_SIG_STA_SET_TO_HIGH); - /* Set GNT_WL to SW low */ - halbtc8703b1ant_ltecoex_set_gnt_wl(btcoexist, - BT_8703B_1ANT_GNT_BLOCK_RFC_BB, - BT_8703B_1ANT_GNT_TYPE_CTRL_BY_SW, - BT_8703B_1ANT_SIG_STA_SET_TO_LOW); - - if (BTC_ANT_PATH_AUTO == ant_pos_type) - ant_pos_type = BTC_ANT_PATH_BT; - - coex_sta->run_time_state = false; - break; - case BT_8703B_1ANT_PHASE_WLANONLY_INIT: - /* Disable LTE Coex Function in WiFi side (this should be on if LTE coex is required) */ - halbtc8703b1ant_ltecoex_enable(btcoexist, 0x0); - - /* GNT_WL_LTE always = 1 (this should be config if LTE coex is required) */ - halbtc8703b1ant_ltecoex_set_coex_table( - btcoexist, - BT_8703B_1ANT_CTT_WL_VS_LTE, - 0xffff); - - /* GNT_BT_LTE always = 1 (this should be config if LTE coex is required) */ - halbtc8703b1ant_ltecoex_set_coex_table( - btcoexist, - BT_8703B_1ANT_CTT_BT_VS_LTE, - 0xffff); - - /* set Path control owner to WL at initial step */ - halbtc8703b1ant_ltecoex_pathcontrol_owner( - btcoexist, - BT_8703B_1ANT_PCO_WLSIDE); - - /* set GNT_BT to SW low */ - halbtc8703b1ant_ltecoex_set_gnt_bt(btcoexist, - BT_8703B_1ANT_GNT_BLOCK_RFC_BB, - BT_8703B_1ANT_GNT_TYPE_CTRL_BY_SW, - BT_8703B_1ANT_SIG_STA_SET_TO_LOW); - /* Set GNT_WL to SW high */ - halbtc8703b1ant_ltecoex_set_gnt_wl(btcoexist, - BT_8703B_1ANT_GNT_BLOCK_RFC_BB, - BT_8703B_1ANT_GNT_TYPE_CTRL_BY_SW, - BT_8703B_1ANT_SIG_STA_SET_TO_HIGH); - - if (BTC_ANT_PATH_AUTO == ant_pos_type) - ant_pos_type = - BTC_ANT_PATH_WIFI; - - coex_sta->run_time_state = false; - break; - case BT_8703B_1ANT_PHASE_WLAN_OFF: - /* Disable LTE Coex Function in WiFi side */ - halbtc8703b1ant_ltecoex_enable(btcoexist, 0x0); - - /* set Path control owner to BT */ - halbtc8703b1ant_ltecoex_pathcontrol_owner( - btcoexist, - BT_8703B_1ANT_PCO_BTSIDE); - - if (BTC_ANT_PATH_AUTO == ant_pos_type) - ant_pos_type = BTC_ANT_PATH_BT; - - coex_sta->run_time_state = false; - break; - case BT_8703B_1ANT_PHASE_2G_RUNTIME: - halbtc8703b1ant_ltecoex_pathcontrol_owner( - btcoexist, - BT_8703B_1ANT_PCO_WLSIDE); - - /* set GNT_BT to PTA */ - halbtc8703b1ant_ltecoex_set_gnt_bt(btcoexist, - BT_8703B_1ANT_GNT_BLOCK_RFC_BB, - BT_8703B_1ANT_GNT_TYPE_CTRL_BY_PTA, - BT_8703B_1ANT_SIG_STA_SET_BY_HW); - /* Set GNT_WL to PTA */ - halbtc8703b1ant_ltecoex_set_gnt_wl(btcoexist, - BT_8703B_1ANT_GNT_BLOCK_RFC_BB, - BT_8703B_1ANT_GNT_TYPE_CTRL_BY_PTA, - BT_8703B_1ANT_SIG_STA_SET_BY_HW); - - if (BTC_ANT_PATH_AUTO == ant_pos_type) - ant_pos_type = BTC_ANT_PATH_PTA; - - coex_sta->run_time_state = true; - break; - case BT_8703B_1ANT_PHASE_BTMPMODE: - halbtc8703b1ant_ltecoex_pathcontrol_owner( - btcoexist, - BT_8703B_1ANT_PCO_WLSIDE); - - /* set GNT_BT to high */ - halbtc8703b1ant_ltecoex_set_gnt_bt(btcoexist, - BT_8703B_1ANT_GNT_BLOCK_RFC_BB, - BT_8703B_1ANT_GNT_TYPE_CTRL_BY_SW, - BT_8703B_1ANT_SIG_STA_SET_TO_HIGH); - /* Set GNT_WL to low */ - halbtc8703b1ant_ltecoex_set_gnt_wl(btcoexist, - BT_8703B_1ANT_GNT_BLOCK_RFC_BB, - BT_8703B_1ANT_GNT_TYPE_CTRL_BY_SW, - BT_8703B_1ANT_SIG_STA_SET_TO_LOW); - - if (BTC_ANT_PATH_AUTO == ant_pos_type) - ant_pos_type = BTC_ANT_PATH_BT; - - coex_sta->run_time_state = false; - break; - } - - -#if 1 - u32tmp1 = halbtc8703b1ant_ltecoex_indirect_read_reg(btcoexist, 0x38); - u32tmp2 = halbtc8703b1ant_ltecoex_indirect_read_reg(btcoexist, 0x54); - u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x73); - - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** (After Ant-Setup) 0x73 = 0x%x, 0x38= 0x%x, 0x54= 0x%x**********\n", - u8tmp, u32tmp1, u32tmp2); - BTC_TRACE(trace_buf); - -#endif -} - - -boolean halbtc8703b1ant_is_common_action(IN struct btc_coexist *btcoexist) -{ - boolean common = false, wifi_connected = false, wifi_busy = false; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - - if (!wifi_connected && - BT_8703B_1ANT_BT_STATUS_NON_CONNECTED_IDLE == - coex_dm->bt_status) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi non connected-idle + BT non connected-idle!!\n"); - BTC_TRACE(trace_buf); - common = true; - } else if (wifi_connected && - (BT_8703B_1ANT_BT_STATUS_NON_CONNECTED_IDLE == - coex_dm->bt_status)) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi connected + BT non connected-idle!!\n"); - BTC_TRACE(trace_buf); - common = true; - } else if (!wifi_connected && - (BT_8703B_1ANT_BT_STATUS_CONNECTED_IDLE == - coex_dm->bt_status)) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi non connected-idle + BT connected-idle!!\n"); - BTC_TRACE(trace_buf); - common = true; - } else if (wifi_connected && - (BT_8703B_1ANT_BT_STATUS_CONNECTED_IDLE == - coex_dm->bt_status)) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi connected + BT connected-idle!!\n"); - BTC_TRACE(trace_buf); - common = true; - } else if (!wifi_connected && - (BT_8703B_1ANT_BT_STATUS_CONNECTED_IDLE != - coex_dm->bt_status)) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi non connected-idle + BT Busy!!\n"); - BTC_TRACE(trace_buf); - common = true; - } else { - if (wifi_busy) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi Connected-Busy + BT Busy!!\n"); - BTC_TRACE(trace_buf); - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi Connected-Idle + BT Busy!!\n"); - BTC_TRACE(trace_buf); - } - - common = false; - } - - return common; -} - - -/* ********************************************* - * - * Non-Software Coex Mechanism start - * - * ********************************************* */ -u8 halbtc8703b1ant_action_algorithm(IN struct btc_coexist *btcoexist) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - boolean bt_hs_on = false; - u8 algorithm = BT_8703B_1ANT_COEX_ALGO_UNDEFINED; - u8 num_of_diff_profile = 0; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); - - if (!bt_link_info->bt_link_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], No BT link exists!!!\n"); - BTC_TRACE(trace_buf); - return algorithm; - } - - if (bt_link_info->sco_exist) - num_of_diff_profile++; - if (bt_link_info->hid_exist) - num_of_diff_profile++; - if (bt_link_info->pan_exist) - num_of_diff_profile++; - if (bt_link_info->a2dp_exist) - num_of_diff_profile++; - - if (num_of_diff_profile == 1) { - if (bt_link_info->sco_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = SCO only\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8703B_1ANT_COEX_ALGO_SCO; - } else { - if (bt_link_info->hid_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = HID only\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8703B_1ANT_COEX_ALGO_HID; - } else if (bt_link_info->a2dp_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = A2DP only\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8703B_1ANT_COEX_ALGO_A2DP; - } else if (bt_link_info->pan_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = PAN(HS) only\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8703B_1ANT_COEX_ALGO_PANHS; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = PAN(EDR) only\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8703B_1ANT_COEX_ALGO_PANEDR; - } - } - } - } else if (num_of_diff_profile == 2) { - if (bt_link_info->sco_exist) { - if (bt_link_info->hid_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = SCO + HID\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8703B_1ANT_COEX_ALGO_HID; - } else if (bt_link_info->a2dp_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = SCO + A2DP ==> SCO\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8703B_1ANT_COEX_ALGO_SCO; - } else if (bt_link_info->pan_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = SCO + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8703B_1ANT_COEX_ALGO_SCO; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = SCO + PAN(EDR)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8703B_1ANT_COEX_ALGO_PANEDR_HID; - } - } - } else { - if (bt_link_info->hid_exist && - bt_link_info->a2dp_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = HID + A2DP\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8703B_1ANT_COEX_ALGO_HID_A2DP; - } else if (bt_link_info->hid_exist && - bt_link_info->pan_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = HID + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8703B_1ANT_COEX_ALGO_HID_A2DP; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = HID + PAN(EDR)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8703B_1ANT_COEX_ALGO_PANEDR_HID; - } - } else if (bt_link_info->pan_exist && - bt_link_info->a2dp_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = A2DP + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8703B_1ANT_COEX_ALGO_A2DP_PANHS; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = A2DP + PAN(EDR)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8703B_1ANT_COEX_ALGO_PANEDR_A2DP; - } - } - } - } else if (num_of_diff_profile == 3) { - if (bt_link_info->sco_exist) { - if (bt_link_info->hid_exist && - bt_link_info->a2dp_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = SCO + HID + A2DP ==> HID\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8703B_1ANT_COEX_ALGO_HID; - } else if (bt_link_info->hid_exist && - bt_link_info->pan_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = SCO + HID + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8703B_1ANT_COEX_ALGO_HID_A2DP; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = SCO + HID + PAN(EDR)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8703B_1ANT_COEX_ALGO_PANEDR_HID; - } - } else if (bt_link_info->pan_exist && - bt_link_info->a2dp_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = SCO + A2DP + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8703B_1ANT_COEX_ALGO_SCO; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = SCO + A2DP + PAN(EDR) ==> HID\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8703B_1ANT_COEX_ALGO_PANEDR_HID; - } - } - } else { - if (bt_link_info->hid_exist && - bt_link_info->pan_exist && - bt_link_info->a2dp_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = HID + A2DP + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8703B_1ANT_COEX_ALGO_HID_A2DP; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = HID + A2DP + PAN(EDR)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8703B_1ANT_COEX_ALGO_HID_A2DP_PANEDR; - } - } - } - } else if (num_of_diff_profile >= 3) { - if (bt_link_info->sco_exist) { - if (bt_link_info->hid_exist && - bt_link_info->pan_exist && - bt_link_info->a2dp_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Error!!! BT Profile = SCO + HID + A2DP + PAN(HS)\n"); - BTC_TRACE(trace_buf); - - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = SCO + HID + A2DP + PAN(EDR)==>PAN(EDR)+HID\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8703B_1ANT_COEX_ALGO_PANEDR_HID; - } - } - } - } - - return algorithm; -} - -void halbtc8703b1ant_action_bt_whql_test(IN struct btc_coexist *btcoexist) -{ - halbtc8703b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8); - halbtc8703b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, NORMAL_EXEC, - BT_8703B_1ANT_PHASE_2G_RUNTIME); - halbtc8703b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); -} - -void halbtc8703b1ant_action_bt_hs(IN struct btc_coexist *btcoexist) -{ - halbtc8703b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 5); - halbtc8703b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2); -} - -void halbtc8703b1ant_action_bt_relink(IN struct btc_coexist *btcoexist) -{ - halbtc8703b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 5); - halbtc8703b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1); - coex_sta->bt_relink_downcount = 2; -} - -void halbtc8703b1ant_action_bt_idle(IN struct btc_coexist *btcoexist) -{ - boolean wifi_busy = false; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - - if (!wifi_busy) { - halbtc8703b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, - 8); - halbtc8703b1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 2); - } else {/* if wl busy */ - - if (BT_8703B_1ANT_BT_STATUS_NON_CONNECTED_IDLE == - coex_dm->bt_status) { - - if (coex_sta->is_hiPri_rx_overhead) - halbtc8703b1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 7); - else - halbtc8703b1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 8); - - halbtc8703b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 33); - } else { - - halbtc8703b1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 8); - halbtc8703b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 32); - } - } -} - -void halbtc8703b1ant_action_bt_inquiry(IN struct btc_coexist *btcoexist) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - boolean wifi_connected = false, wifi_busy = false, bt_busy = false; - boolean wifi_scan = false, wifi_link = false, wifi_roam = false; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bt_busy); - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &wifi_scan); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &wifi_link); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &wifi_roam); - - if ((coex_sta->bt_create_connection) && ((wifi_link) || (wifi_roam) - || (wifi_scan) || (wifi_busy) || (coex_sta->wifi_is_high_pri_task))) { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi link/roam/Scan/busy/hi-pri-task + BT Inq/Page!!\n"); - BTC_TRACE(trace_buf); - - halbtc8703b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1); - - if ((bt_link_info->a2dp_exist) && (!bt_link_info->pan_exist)) - halbtc8703b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 17); - else - halbtc8703b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 33); - } else if ((!wifi_connected) && (!wifi_scan)) { - - halbtc8703b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8); - - halbtc8703b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - } else if (bt_link_info->pan_exist) { - - halbtc8703b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 22); - - halbtc8703b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); - } else if (bt_link_info->a2dp_exist) { - - halbtc8703b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 16); - - halbtc8703b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); - } else { - - if ((wifi_link) || (wifi_roam) || (wifi_scan) || (wifi_busy) - || (coex_sta->wifi_is_high_pri_task)) - halbtc8703b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 21); - else - halbtc8703b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 23); - - halbtc8703b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); - } -} - - -void halbtc8703b1ant_action_bt_sco_hid_only_busy(IN struct btc_coexist - *btcoexist) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - boolean wifi_connected = false, wifi_busy = false; - u32 wifi_bw = 1; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, - &wifi_bw); - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - - - if (bt_link_info->sco_exist) { - halbtc8703b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 5); - halbtc8703b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 5); - } else if (coex_sta->hid_busy_num >= 2) {/*for 4/18 hid */ - /* if 11bg mode */ - if (wifi_bw == 0) { - - halbtc8703b1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 6); - halbtc8703b1ant_set_wltoggle_coex_table(btcoexist, - NORMAL_EXEC, - 0x1, 0xaa, - 0x5a, 0xaa, - 0xaa); - halbtc8703b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 11); - } else { - - if (wifi_busy) { - - halbtc8703b1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 6); - halbtc8703b1ant_set_wltoggle_coex_table(btcoexist, - NORMAL_EXEC, - 0x2, 0xaa, - 0x5a, 0xaa, - 0xaa); - halbtc8703b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 11); - } else { - - halbtc8703b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 6); - halbtc8703b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 3); - } - } - } else { - halbtc8703b1ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 6); - halbtc8703b1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 3); - } -} - - -void halbtc8703b1ant_action_wifi_only(IN struct btc_coexist *btcoexist) -{ - halbtc8703b1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 8); - halbtc8703b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, FORCE_EXEC, - BT_8703B_1ANT_PHASE_2G_RUNTIME); - halbtc8703b1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 0); -} - -void halbtc8703b1ant_action_wifi_multi_port(IN struct btc_coexist *btcoexist) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - - halbtc8703b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8); - halbtc8703b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, NORMAL_EXEC, - BT_8703B_1ANT_PHASE_2G_RUNTIME); - - if (!bt_link_info->pan_exist) - halbtc8703b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - else - halbtc8703b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2); -} - -void halbtc8703b1ant_action_wifi_linkscan_process(IN struct btc_coexist - *btcoexist) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - - if (bt_link_info->pan_exist) { - - halbtc8703b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 22); - - halbtc8703b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); - - } else if (bt_link_info->a2dp_exist) { - - halbtc8703b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 17); - - halbtc8703b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); - } else { - - halbtc8703b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 21); - - halbtc8703b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); - } -} - -void halbtc8703b1ant_action_wifi_connected_bt_acl_busy(IN struct btc_coexist - *btcoexist) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - boolean wifi_busy = false, wifi_turbo = false; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM, - &coex_sta->scan_ap_num); - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "############# [BTCoex], scan_ap_num = %d, wl_noisy_level = %d\n", - coex_sta->scan_ap_num, coex_sta->wl_noisy_level); - BTC_TRACE(trace_buf); - -#if 1 - if ((wifi_busy) && (coex_sta->wl_noisy_level == 0)) - wifi_turbo = true; -#endif - - if ((coex_sta->bt_relink_downcount != 0) - && (!bt_link_info->pan_exist) && (wifi_busy)) { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "############# [BTCoex], BT Re-Link + A2DP + WL busy\n"); - BTC_TRACE(trace_buf); - - /*halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32);*/ - halbtc8703b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8); - halbtc8703b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - - } else if (bt_link_info->a2dp_only) { /* A2DP */ - if (!wifi_busy) { - halbtc8703b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 32); - halbtc8703b1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 4); - } else { - - if (coex_sta->wl_noisy_level == 2) - halbtc8703b1ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 17); - else - halbtc8703b1ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 7); - - if (wifi_turbo) - halbtc8703b1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 8); - else - halbtc8703b1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 4); - } - } else if (((bt_link_info->a2dp_exist) && - (bt_link_info->pan_exist)) || - (bt_link_info->hid_exist && bt_link_info->a2dp_exist && - bt_link_info->pan_exist)) { /* A2DP+PAN(OPP,FTP), HID+A2DP+PAN(OPP,FTP) */ - - if ((bt_link_info->hid_exist) && (coex_sta->hid_busy_num >= 2)) { - halbtc8703b1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 6); - halbtc8703b1ant_set_wltoggle_coex_table(btcoexist, - NORMAL_EXEC, - 0x2, 0xaa, - 0x5a, 0xaa, - 0xaa); - halbtc8703b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 12); - } else if (wifi_busy) { - if (((coex_sta->a2dp_bit_pool > 40) && - (coex_sta->a2dp_bit_pool < 255)) || - (!coex_sta->is_A2DP_3M)) - halbtc8703b1ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 15); - else if (wifi_turbo) - halbtc8703b1ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 18); - else - halbtc8703b1ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 13); - } else - halbtc8703b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 14); - - if (bt_link_info->hid_exist) - halbtc8703b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1); - else if (wifi_turbo) - halbtc8703b1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 8); - else - halbtc8703b1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 4); - } else if (bt_link_info->hid_exist && - bt_link_info->a2dp_exist) {/* HID+A2DP */ - - if ((wifi_busy) && (coex_sta->hid_busy_num >= 2)) { /*for 4/18 hid */ - halbtc8703b1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 6); - halbtc8703b1ant_set_wltoggle_coex_table(btcoexist, - NORMAL_EXEC, - 0x2, 0xaa, - 0x5a, 0xaa, - 0xaa); - halbtc8703b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 9); - } else { - halbtc8703b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 8); - halbtc8703b1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 1); - } - - } else if ((bt_link_info->pan_only) - || (bt_link_info->hid_exist && bt_link_info->pan_exist)) { - /* PAN(OPP,FTP), HID+PAN(OPP,FTP) */ - - if ((bt_link_info->hid_exist) && (bt_link_info->pan_exist) && - (coex_sta->hid_busy_num >= 2)) { - - halbtc8703b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 6); - halbtc8703b1ant_set_wltoggle_coex_table(btcoexist, - NORMAL_EXEC, - 0x2, 0xaa, - 0x5a, 0xaa, - 0xaa); - halbtc8703b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 12); - } else { - - if (!wifi_busy) - halbtc8703b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 4); - else - halbtc8703b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 3); - - if (bt_link_info->hid_exist) - halbtc8703b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1); - else if (wifi_turbo) - halbtc8703b1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 8); - else - halbtc8703b1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 4); - } - } else { - /* BT no-profile busy (0x9) */ - halbtc8703b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 33); - halbtc8703b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); - } -} - -void halbtc8703b1ant_action_wifi_not_connected(IN struct btc_coexist *btcoexist) -{ - /* tdma and coex table */ - halbtc8703b1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 8); - halbtc8703b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); -} - -void halbtc8703b1ant_action_wifi_connected(IN struct btc_coexist *btcoexist) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - boolean wifi_busy = false; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], CoexForWifiConnect()===>\n"); - BTC_TRACE(trace_buf); - - halbtc8703b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, - NORMAL_EXEC, - BT_8703B_1ANT_PHASE_2G_RUNTIME); - - if (BT_8703B_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) { - - if (bt_link_info->hid_only)/* HID only */ - halbtc8703b1ant_action_bt_sco_hid_only_busy(btcoexist); - else - halbtc8703b1ant_action_wifi_connected_bt_acl_busy(btcoexist); - - } else if ((BT_8703B_1ANT_BT_STATUS_SCO_BUSY == - coex_dm->bt_status) || - (BT_8703B_1ANT_BT_STATUS_ACL_SCO_BUSY == - coex_dm->bt_status)) { - halbtc8703b1ant_action_bt_sco_hid_only_busy(btcoexist); - } else - halbtc8703b1ant_action_bt_idle(btcoexist); -} - - -void halbtc8703b1ant_run_sw_coexist_mechanism(IN struct btc_coexist *btcoexist) -{ - u8 algorithm = 0; - - algorithm = halbtc8703b1ant_action_algorithm(btcoexist); - coex_dm->cur_algorithm = algorithm; - - if (halbtc8703b1ant_is_common_action(btcoexist)) { - - } else { - switch (coex_dm->cur_algorithm) { - case BT_8703B_1ANT_COEX_ALGO_SCO: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action algorithm = SCO.\n"); - BTC_TRACE(trace_buf); - break; - case BT_8703B_1ANT_COEX_ALGO_HID: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action algorithm = HID.\n"); - BTC_TRACE(trace_buf); - break; - case BT_8703B_1ANT_COEX_ALGO_A2DP: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action algorithm = A2DP.\n"); - BTC_TRACE(trace_buf); - break; - case BT_8703B_1ANT_COEX_ALGO_A2DP_PANHS: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action algorithm = A2DP+PAN(HS).\n"); - BTC_TRACE(trace_buf); - break; - case BT_8703B_1ANT_COEX_ALGO_PANEDR: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action algorithm = PAN(EDR).\n"); - BTC_TRACE(trace_buf); - break; - case BT_8703B_1ANT_COEX_ALGO_PANHS: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action algorithm = HS mode.\n"); - BTC_TRACE(trace_buf); - break; - case BT_8703B_1ANT_COEX_ALGO_PANEDR_A2DP: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action algorithm = PAN+A2DP.\n"); - BTC_TRACE(trace_buf); - break; - case BT_8703B_1ANT_COEX_ALGO_PANEDR_HID: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action algorithm = PAN(EDR)+HID.\n"); - BTC_TRACE(trace_buf); - break; - case BT_8703B_1ANT_COEX_ALGO_HID_A2DP_PANEDR: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action algorithm = HID+A2DP+PAN.\n"); - BTC_TRACE(trace_buf); - break; - case BT_8703B_1ANT_COEX_ALGO_HID_A2DP: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action algorithm = HID+A2DP.\n"); - BTC_TRACE(trace_buf); - break; - default: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action algorithm = coexist All Off!!\n"); - BTC_TRACE(trace_buf); - break; - } - coex_dm->pre_algorithm = coex_dm->cur_algorithm; - } -} - -void halbtc8703b1ant_run_coexist_mechanism(IN struct btc_coexist *btcoexist) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - boolean wifi_connected = false, bt_hs_on = false; - boolean increase_scan_dev_num = false; - boolean bt_ctrl_agg_buf_size = false; - boolean miracast_plus_bt = false, wifi_under_5g = false; - u8 agg_buf_size = 5; - u32 wifi_link_status = 0; - u32 num_of_wifi_link = 0, wifi_bw; - u8 iot_peer = BTC_IOT_PEER_UNKNOWN; - boolean scan = false, link = false, roam = false, under_4way = false; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS, - &under_4way); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], RunCoexistMechanism()===>\n"); - BTC_TRACE(trace_buf); - - if (btcoexist->manual_control) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], RunCoexistMechanism(), return for Manual CTRL <===\n"); - BTC_TRACE(trace_buf); - return; - } - - if (btcoexist->stop_coex_dm) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], RunCoexistMechanism(), return for Stop Coex DM <===\n"); - BTC_TRACE(trace_buf); - return; - } - - if (coex_sta->under_ips) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], wifi is under IPS !!!\n"); - BTC_TRACE(trace_buf); - return; - } - - if (!coex_sta->run_time_state) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], return for run_time_state = false !!!\n"); - BTC_TRACE(trace_buf); - return; - } - - if (coex_sta->freeze_coexrun_by_btinfo) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), return for freeze_coexrun_by_btinfo\n"); - BTC_TRACE(trace_buf); - return; - } - - if (coex_sta->bt_whck_test) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT is under WHCK TEST!!!\n"); - BTC_TRACE(trace_buf); - halbtc8703b1ant_action_bt_whql_test(btcoexist); - return; - } - - if (coex_sta->bt_disabled) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT is disabled !!!\n"); - halbtc8703b1ant_action_wifi_only(btcoexist); - return; - } - - if (coex_sta->c2h_bt_inquiry_page) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT is under inquiry/page scan !!\n"); - BTC_TRACE(trace_buf); - halbtc8703b1ant_action_bt_inquiry(btcoexist); - return; - } - - if (coex_sta->is_setupLink) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT is re-link !!!\n"); - halbtc8703b1ant_action_bt_relink(btcoexist); - return; - } - - if ((BT_8703B_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) || - (BT_8703B_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) || - (BT_8703B_1ANT_BT_STATUS_ACL_SCO_BUSY == coex_dm->bt_status)) - increase_scan_dev_num = true; - - btcoexist->btc_set(btcoexist, BTC_SET_BL_INC_SCAN_DEV_NUM, - &increase_scan_dev_num); - - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS, - &wifi_link_status); - - num_of_wifi_link = wifi_link_status >> 16; - - if ((num_of_wifi_link >= 2) || - (wifi_link_status & WIFI_P2P_GO_CONNECTED)) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "############# [BTCoex], Multi-Port num_of_wifi_link = %d, wifi_link_status = 0x%x\n", - num_of_wifi_link, wifi_link_status); - BTC_TRACE(trace_buf); - - if (bt_link_info->bt_link_exist) - miracast_plus_bt = true; - else - miracast_plus_bt = false; - - btcoexist->btc_set(btcoexist, BTC_SET_BL_MIRACAST_PLUS_BT, - &miracast_plus_bt); - - halbtc8703b1ant_limited_rx(btcoexist, NORMAL_EXEC, false, - false, 0x5); - - if (scan || link || roam || under_4way) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], scan = %d, link = %d, roam = %d 4way = %d!!!\n", - scan, link, roam, under_4way); - BTC_TRACE(trace_buf); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], wifi is under linkscan process + Multi-Port !!\n"); - BTC_TRACE(trace_buf); - - halbtc8703b1ant_action_wifi_linkscan_process(btcoexist); - } else - halbtc8703b1ant_action_wifi_multi_port(btcoexist); - - return; - } else { - - miracast_plus_bt = false; - btcoexist->btc_set(btcoexist, BTC_SET_BL_MIRACAST_PLUS_BT, - &miracast_plus_bt); - } - - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, &wifi_connected); - - if ((bt_link_info->bt_link_exist) && (wifi_connected)) { - - btcoexist->btc_get(btcoexist, BTC_GET_U1_IOT_PEER, &iot_peer); - - if (BTC_IOT_PEER_CISCO == iot_peer) { - - if (BTC_WIFI_BW_HT40 == wifi_bw) - halbtc8703b1ant_limited_rx(btcoexist, - NORMAL_EXEC, false, true, 0x10); - else - halbtc8703b1ant_limited_rx(btcoexist, - NORMAL_EXEC, false, true, 0x8); - } else - halbtc8703b1ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, - 0x5); - } - - halbtc8703b1ant_run_sw_coexist_mechanism( - btcoexist); /* just print debug message */ - - btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); - - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "############# [BTCoex], BT Is hs\n"); - BTC_TRACE(trace_buf); - halbtc8703b1ant_action_bt_hs(btcoexist); - return; - } - - if ((BT_8703B_1ANT_BT_STATUS_NON_CONNECTED_IDLE == - coex_dm->bt_status) || - (BT_8703B_1ANT_BT_STATUS_CONNECTED_IDLE == - coex_dm->bt_status)) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "############# [BTCoex], BT Is idle\n"); - BTC_TRACE(trace_buf); - halbtc8703b1ant_action_bt_idle(btcoexist); - return; - } - - if (scan || link || roam || under_4way) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], scan = %d, link = %d, roam = %d 4way = %d!!!\n", - scan, link, roam, under_4way); - BTC_TRACE(trace_buf); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], wifi is under linkscan process!!\n"); - BTC_TRACE(trace_buf); - - halbtc8703b1ant_action_wifi_linkscan_process(btcoexist); - } else if (wifi_connected) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], wifi is under connected!!\n"); - BTC_TRACE(trace_buf); - - halbtc8703b1ant_action_wifi_connected(btcoexist); - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], wifi is under not-connected!!\n"); - BTC_TRACE(trace_buf); - - halbtc8703b1ant_action_wifi_not_connected(btcoexist); - } -} - - -void halbtc8703b1ant_init_coex_dm(IN struct btc_coexist *btcoexist) -{ - /* force to reset coex mechanism */ - - halbtc8703b1ant_low_penalty_ra(btcoexist, NORMAL_EXEC, false); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Coex Mechanism Init!!\n"); - BTC_TRACE(trace_buf); - - coex_sta->pop_event_cnt = 0; - coex_sta->cnt_RemoteNameReq = 0; - coex_sta->cnt_ReInit = 0; - coex_sta->cnt_setupLink = 0; - coex_sta->cnt_IgnWlanAct = 0; - coex_sta->cnt_Page = 0; -} - -void halbtc8703b1ant_init_hw_config(IN struct btc_coexist *btcoexist, - IN boolean back_up, IN boolean wifi_only) -{ - u32 u32tmp0 = 0, u32tmp1 = 0, u32tmp2 = 0; - u8 i = 0; - - u32tmp0 = btcoexist->btc_read_4byte(btcoexist, 0x70), - u32tmp1 = halbtc8703b1ant_ltecoex_indirect_read_reg(btcoexist, 0x38); - u32tmp2 = halbtc8703b1ant_ltecoex_indirect_read_reg(btcoexist, 0x54); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "\n [BTCoex], ********** 0x70/ 0x38/ 0x54 (Before Init HW config) = 0x%x/ 0x%x/ 0x%x**********\n", - u32tmp0, - u32tmp1, u32tmp2); - BTC_TRACE(trace_buf); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], 1Ant Init HW Config!!\n"); - BTC_TRACE(trace_buf); - - coex_sta->bt_coex_supported_feature = 0; - coex_sta->bt_coex_supported_version = 0; - coex_sta->bt_ble_scan_type = 0; - coex_sta->bt_ble_scan_para[0] = 0; - coex_sta->bt_ble_scan_para[1] = 0; - coex_sta->bt_ble_scan_para[2] = 0; - coex_sta->gnt_error_cnt = 0; - coex_sta->bt_relink_downcount = 0; - - for (i = 0; i <= 9; i++) - coex_sta->bt_afh_map[i] = 0; - - /* 0xf0[15:12] --> Chip Cut information */ - coex_sta->cut_version = (btcoexist->btc_read_1byte(btcoexist, - 0xf1) & 0xf0) >> 4; - - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x550, 0x8, - 0x1); /* enable TBTT nterrupt */ - - /* BT report packet sample rate */ - btcoexist->btc_write_1byte(btcoexist, 0x790, 0x5); - - /* Enable BT counter statistics */ - btcoexist->btc_write_1byte(btcoexist, 0x778, 0x1); - - /* Enable PTA (3-wire function form BT side) */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x40, 0x20, 0x1); - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x41, 0x02, 0x1); - - /* Enable PTA (tx/rx signal form WiFi side) */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4c6, 0x10, 0x1); - - halbtc8703b1ant_enable_gnt_to_gpio(btcoexist, false); - - if (btcoexist->btc_read_1byte(btcoexist, 0x80) == 0xc6) - halbtc8703b1ant_post_state_to_bt(btcoexist, - BT_8703B_1ANT_SCOREBOARD_ONOFF, true); - - halbtc8703b1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 8); - - /* Antenna config */ - if (wifi_only) { - coex_sta->concurrent_rx_mode_on = false; - halbtc8703b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_WIFI, - FORCE_EXEC, - BT_8703B_1ANT_PHASE_WLANONLY_INIT); - } else { - coex_sta->concurrent_rx_mode_on = true; - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x953, 0x2, 0x1); - /* RF 0x1[0] = 0->Set GNT_WL_RF_Rx always = 1 for con-current Rx */ - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0x1, 0x0); - halbtc8703b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, - FORCE_EXEC, - BT_8703B_1ANT_PHASE_COEX_INIT); - } - - /* PTA parameter */ - halbtc8703b1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 0); - - u32tmp0 = btcoexist->btc_read_4byte(btcoexist, 0x70), - u32tmp1 = halbtc8703b1ant_ltecoex_indirect_read_reg(btcoexist, 0x38); - u32tmp2 = halbtc8703b1ant_ltecoex_indirect_read_reg(btcoexist, 0x54); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** 0x70/ 0x38/ 0x54 (After Init HW config) = 0x%x/ 0x%x/ 0x%x**********\n", - u32tmp0, - u32tmp1, u32tmp2); - BTC_TRACE(trace_buf); - -} - - - -/* ************************************************************ - * work around function start with wa_halbtc8703b1ant_ - * ************************************************************ - * ************************************************************ - * extern function start with ex_halbtc8703b1ant_ - * ************************************************************ */ -void ex_halbtc8703b1ant_power_on_setting(IN struct btc_coexist *btcoexist) -{ - struct btc_board_info *board_info = &btcoexist->board_info; - u8 u8tmp = 0x0; - u16 u16tmp = 0x0; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx Execute 8703b 1-Ant PowerOn Setting xxxxxxxxxxxxxxxx!!\n"); - BTC_TRACE(trace_buf); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "Ant Det Finish = %s, Ant Det Number = %d\n", - (board_info->btdm_ant_det_finish ? "Yes" : "No"), - board_info->btdm_ant_num_by_ant_det); - BTC_TRACE(trace_buf); - - btcoexist->stop_coex_dm = true; - - /* enable BB, REG_SYS_FUNC_EN such that we can write BB/MAC reg correctly. */ - u16tmp = btcoexist->btc_read_2byte(btcoexist, 0x2); - btcoexist->btc_write_2byte(btcoexist, 0x2, u16tmp | BIT(0) | BIT(1)); - - /* set Path control owner to WiFi */ - halbtc8703b1ant_ltecoex_pathcontrol_owner(btcoexist, - BT_8703B_1ANT_PCO_WLSIDE); - - /* set GNT_BT to high */ - halbtc8703b1ant_ltecoex_set_gnt_bt(btcoexist, - BT_8703B_1ANT_GNT_BLOCK_RFC_BB, - BT_8703B_1ANT_GNT_TYPE_CTRL_BY_SW, - BT_8703B_1ANT_SIG_STA_SET_TO_HIGH); - /* Set GNT_WL to low */ - halbtc8703b1ant_ltecoex_set_gnt_wl(btcoexist, - BT_8703B_1ANT_GNT_BLOCK_RFC_BB, - BT_8703B_1ANT_GNT_TYPE_CTRL_BY_SW, - BT_8703B_1ANT_SIG_STA_SET_TO_LOW); - - /* set WLAN_ACT = 0 */ - btcoexist->btc_write_1byte(btcoexist, 0x76e, 0x4); - - halbtc8703b1ant_enable_gnt_to_gpio(btcoexist, false); - - /* */ - /* S0 or S1 setting and Local register setting(By the setting fw can get ant number, S0/S1, ... info) */ - /* Local setting bit define */ - /* BIT0: "0" for no antenna inverse; "1" for antenna inverse */ - /* BIT1: "0" for internal switch; "1" for external switch */ - /* BIT2: "0" for one antenna; "1" for two antenna */ - /* NOTE: here default all internal switch and 1-antenna ==> BIT1=0 and BIT2=0 */ - - u8tmp = 0; - board_info->btdm_ant_pos = BTC_ANTENNA_AT_MAIN_PORT; - - if (btcoexist->chip_interface == BTC_INTF_USB) - btcoexist->btc_write_local_reg_1byte(btcoexist, 0xfe08, u8tmp); - else if (btcoexist->chip_interface == BTC_INTF_SDIO) - btcoexist->btc_write_local_reg_1byte(btcoexist, 0x60, u8tmp); - - - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** 0x70(MAC)/0x38/0x54 (Power-On) =0x%x/ 0x%x/ 0x%x**********\n", - btcoexist->btc_read_4byte(btcoexist, 0x70), - halbtc8703b1ant_ltecoex_indirect_read_reg(btcoexist, 0x38), - halbtc8703b1ant_ltecoex_indirect_read_reg(btcoexist, 0x54)); - BTC_TRACE(trace_buf); - - -} - -void ex_halbtc8703b1ant_pre_load_firmware(IN struct btc_coexist *btcoexist) -{ -} - -void ex_halbtc8703b1ant_init_hw_config(IN struct btc_coexist *btcoexist, - IN boolean wifi_only) -{ - halbtc8703b1ant_init_hw_config(btcoexist, true, wifi_only); - btcoexist->stop_coex_dm = false; -} - -void ex_halbtc8703b1ant_init_coex_dm(IN struct btc_coexist *btcoexist) -{ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Coex Mechanism Init!!\n"); - BTC_TRACE(trace_buf); - - halbtc8703b1ant_init_coex_dm(btcoexist); -} - -void ex_halbtc8703b1ant_display_coex_info(IN struct btc_coexist *btcoexist) -{ - struct btc_board_info *board_info = &btcoexist->board_info; - struct btc_stack_info *stack_info = &btcoexist->stack_info; - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - u8 *cli_buf = btcoexist->cli_buf; - u8 u8tmp[4], i, bt_info_ext, ps_tdma_case = 0; - u16 u16tmp[4]; - u32 u32tmp[4]; - u32 fa_ofdm, fa_cck, cca_ofdm, cca_cck; - u32 fw_ver = 0, bt_patch_ver = 0, bt_coex_ver = 0; - static u8 pop_report_in_10s = 0; - u32 phyver = 0; - boolean lte_coex_on = false; - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n ============[BT Coexist info]============"); - CL_PRINTF(cli_buf); - - if (btcoexist->manual_control) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n ============[Under Manual Control]============"); - CL_PRINTF(cli_buf); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n =========================================="); - CL_PRINTF(cli_buf); - } - if (btcoexist->stop_coex_dm) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n ============[Coex is STOPPED]============"); - CL_PRINTF(cli_buf); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n =========================================="); - CL_PRINTF(cli_buf); - } - - if (psd_scan->ant_det_try_count == 0) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d", - "Ant PG Num/ Mech/ Pos", - board_info->pg_ant_num, board_info->btdm_ant_num, - board_info->btdm_ant_pos); - CL_PRINTF(cli_buf); - } else { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %d/ %d/ %d (%d/%d/%d)", - "Ant PG Num/ Mech(Ant_Det)/ Pos", - board_info->pg_ant_num, - board_info->btdm_ant_num_by_ant_det, - board_info->btdm_ant_pos, - psd_scan->ant_det_try_count, - psd_scan->ant_det_fail_count, - psd_scan->ant_det_result); - CL_PRINTF(cli_buf); - - if (board_info->btdm_ant_det_finish) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s", - "Ant Det PSD Value", - psd_scan->ant_det_peak_val); - CL_PRINTF(cli_buf); - } - } - - - /*bt_patch_ver = btcoexist->bt_info.bt_get_fw_ver;*/ - bt_patch_ver = btcoexist->bt_info.bt_get_fw_ver; - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, &fw_ver); - phyver = btcoexist->btc_get_bt_phydm_version(btcoexist); - - bt_coex_ver = ((coex_sta->bt_coex_supported_version & 0xff00) >> 8); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %d_%02x/ 0x%02x/ 0x%02x (%s)", - "CoexVer WL/ BT_Desired/ BT_Report", - glcoex_ver_date_8703b_1ant, glcoex_ver_8703b_1ant, - glcoex_ver_btdesired_8703b_1ant, - bt_coex_ver, - (bt_coex_ver == 0xff ? "Unknown" : - (bt_coex_ver >= glcoex_ver_btdesired_8703b_1ant ? - "Match":"Mis-Match"))); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = 0x%x/ 0x%x/ v%d/ %c", - "W_FW/ B_FW/ Phy/ Kt", - fw_ver, bt_patch_ver, phyver, - coex_sta->cut_version + 65); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x ", - "Wifi channel informed to BT", - coex_dm->wifi_chnl_info[0], coex_dm->wifi_chnl_info[1], - coex_dm->wifi_chnl_info[2]); - CL_PRINTF(cli_buf); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s/ %s", - "WifibHiPri/ Ccklock/ CckEverLock", - (coex_sta->wifi_is_high_pri_task ? "Yes" : "No"), - (coex_sta->cck_lock ? "Yes" : "No"), - (coex_sta->cck_ever_lock ? "Yes" : "No")); - CL_PRINTF(cli_buf); - - /* wifi status */ - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s", - "============[Wifi Status]============"); - CL_PRINTF(cli_buf); - btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_WIFI_STATUS); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s", - "============[BT Status]============"); - CL_PRINTF(cli_buf); - - pop_report_in_10s++; - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = [%s/ %d/ %d/ %d] ", - "BT [status/ rssi/ retryCnt/ popCnt]", - ((coex_sta->bt_disabled) ? ("disabled") : (( - coex_sta->c2h_bt_inquiry_page) ? ("inquiry/page") - : ((BT_8703B_1ANT_BT_STATUS_NON_CONNECTED_IDLE == - coex_dm->bt_status) ? "non-connected idle" : - ((BT_8703B_1ANT_BT_STATUS_CONNECTED_IDLE == coex_dm->bt_status) - ? "connected-idle" : "busy")))), - coex_sta->bt_rssi - 100, coex_sta->bt_retry_cnt, - coex_sta->pop_event_cnt); - CL_PRINTF(cli_buf); - - if (pop_report_in_10s >= 5) { - coex_sta->pop_event_cnt = 0; - pop_report_in_10s = 0; - } - - if (coex_sta->num_of_profile != 0) - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %s%s%s%s%s", - "Profiles", - ((bt_link_info->a2dp_exist) ? "A2DP," : ""), - ((bt_link_info->sco_exist) ? "SCO," : ""), - ((bt_link_info->hid_exist) ? - ((coex_sta->hid_busy_num >= 2) ? "HID(4/18)," : - "HID(2/18),") : ""), - ((bt_link_info->pan_exist) ? "PAN," : ""), - ((coex_sta->voice_over_HOGP) ? "Voice" : "")); - else - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = None", - "Profiles"); - - CL_PRINTF(cli_buf); - - if (bt_link_info->a2dp_exist) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %s", - "A2DP Rate/Bitpool/Auto_Slot", - ((coex_sta->is_A2DP_3M) ? "3M" : "No_3M"), - coex_sta->a2dp_bit_pool, - ((coex_sta->is_autoslot) ? "On" : "Off") - ); - CL_PRINTF(cli_buf); - } - - if (bt_link_info->hid_exist) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", - "HID PairNum/Forbid_Slot", - coex_sta->hid_pair_cnt, - coex_sta->forbidden_slot - ); - CL_PRINTF(cli_buf); - } - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s / %s/ 0x%x", - "Role/IgnWlanAct/Feature", - ((bt_link_info->slave_role) ? "Slave" : "Master"), - ((coex_dm->cur_ignore_wlan_act) ? "Yes" : "No"), - coex_sta->bt_coex_supported_feature); - CL_PRINTF(cli_buf); - - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d/ %d", - "ReInit/ReLink/IgnWlact/Page/NameReq", - coex_sta->cnt_ReInit, - coex_sta->cnt_setupLink, - coex_sta->cnt_IgnWlanAct, - coex_sta->cnt_Page, - coex_sta->cnt_RemoteNameReq - ); - CL_PRINTF(cli_buf); - - halbtc8703b1ant_read_score_board(btcoexist, &u16tmp[0]); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %04x", - "ScoreBoard[14:0] (from BT)", u16tmp[0]); - CL_PRINTF(cli_buf); - - if (coex_sta->num_of_profile > 0) { - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x", - "AFH MAP", - coex_sta->bt_afh_map[0], - coex_sta->bt_afh_map[1], - coex_sta->bt_afh_map[2], - coex_sta->bt_afh_map[3], - coex_sta->bt_afh_map[4], - coex_sta->bt_afh_map[5], - coex_sta->bt_afh_map[6], - coex_sta->bt_afh_map[7], - coex_sta->bt_afh_map[8], - coex_sta->bt_afh_map[9] - ); - CL_PRINTF(cli_buf); - } - - for (i = 0; i < BT_INFO_SRC_8703B_1ANT_MAX; i++) { - if (coex_sta->bt_info_c2h_cnt[i]) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %02x %02x %02x %02x %02x %02x %02x(%d)", - glbt_info_src_8703b_1ant[i], - coex_sta->bt_info_c2h[i][0], - coex_sta->bt_info_c2h[i][1], - coex_sta->bt_info_c2h[i][2], - coex_sta->bt_info_c2h[i][3], - coex_sta->bt_info_c2h[i][4], - coex_sta->bt_info_c2h[i][5], - coex_sta->bt_info_c2h[i][6], - coex_sta->bt_info_c2h_cnt[i]); - CL_PRINTF(cli_buf); - } - } - - if (btcoexist->manual_control) - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s", - "============[mechanisms] (before Manual)============"); - else - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s", - "============[mechanisms]============"); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d", - "SM[LowPenaltyRA]", - coex_dm->cur_low_penalty_ra); - CL_PRINTF(cli_buf); - - ps_tdma_case = coex_dm->cur_ps_tdma; - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %02x %02x %02x %02x %02x case-%d (%s,%s)", - "PS TDMA", - coex_dm->ps_tdma_para[0], coex_dm->ps_tdma_para[1], - coex_dm->ps_tdma_para[2], coex_dm->ps_tdma_para[3], - coex_dm->ps_tdma_para[4], ps_tdma_case, - (coex_dm->cur_ps_tdma_on ? "On" : "Off"), - (coex_dm->auto_tdma_adjust ? "Adj" : "Fix")); - - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d", - "WL/BT Coex Table Type", - coex_sta->coex_table_type); - CL_PRINTF(cli_buf); - - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x6c0); - u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x6c4); - u32tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0x6c8); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", - "0x6c0/0x6c4/0x6c8(coexTable)", - u32tmp[0], u32tmp[1], u32tmp[2]); - CL_PRINTF(cli_buf); - - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x778); - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x6cc); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", - "0x778/0x6cc/IgnWlanAct", - u8tmp[0], u32tmp[0], coex_dm->cur_ignore_wlan_act); - CL_PRINTF(cli_buf); - - u32tmp[0] = halbtc8703b1ant_ltecoex_indirect_read_reg(btcoexist, 0x38); - lte_coex_on = ((u32tmp[0] & BIT(7)) >> 7) ? true : false; - - if (lte_coex_on) { - u32tmp[0] = halbtc8703b1ant_ltecoex_indirect_read_reg(btcoexist, - 0xa0); - u32tmp[1] = halbtc8703b1ant_ltecoex_indirect_read_reg(btcoexist, - 0xa4); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", - "LTE Coex Table W_L/B_L", - u32tmp[0] & 0xffff, u32tmp[1] & 0xffff); - CL_PRINTF(cli_buf); - - u32tmp[0] = halbtc8703b1ant_ltecoex_indirect_read_reg(btcoexist, - 0xa8); - u32tmp[1] = halbtc8703b1ant_ltecoex_indirect_read_reg(btcoexist, - 0xac); - u32tmp[2] = halbtc8703b1ant_ltecoex_indirect_read_reg(btcoexist, - 0xb0); - u32tmp[3] = halbtc8703b1ant_ltecoex_indirect_read_reg(btcoexist, - 0xb4); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", - "LTE Break Table W_L/B_L/L_W/L_B", - u32tmp[0] & 0xffff, u32tmp[1] & 0xffff, - u32tmp[2] & 0xffff, u32tmp[3] & 0xffff); - CL_PRINTF(cli_buf); - } - /* Hw setting */ - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s", - "============[Hw setting]============"); - CL_PRINTF(cli_buf); - - u32tmp[0] = halbtc8703b1ant_ltecoex_indirect_read_reg(btcoexist, 0x38); - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x73); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %s", - "LTE CoexOn/Path Ctrl Owner", - (int)((u32tmp[0] & BIT(7)) >> 7), - ((u8tmp[0] & BIT(2)) ? "WL" : "BT")); - CL_PRINTF(cli_buf); - - if (lte_coex_on) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d", - "LTE 3Wire/OPMode/UART/UARTMode", - (int)((u32tmp[0] & BIT(6)) >> 6), - (int)((u32tmp[0] & (BIT(5) | BIT(4))) >> 4), - (int)((u32tmp[0] & BIT(3)) >> 3), - (int)(u32tmp[0] & (BIT(2) | BIT(1) | BIT(0)))); - CL_PRINTF(cli_buf); - } - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %s (BB:%s)/ %s (BB:%s)/ %s %d", - "GNT_WL_Ctrl/GNT_BT_Ctrl/Dbg", - ((u32tmp[0] & BIT(12)) ? "SW" : "HW"), - ((u32tmp[0] & BIT(8)) ? "SW" : "HW"), - ((u32tmp[0] & BIT(14)) ? "SW" : "HW"), - ((u32tmp[0] & BIT(10)) ? "SW" : "HW"), - ((u8tmp[0] & BIT(3)) ? "On" : "Off"), - coex_sta->gnt_error_cnt); - CL_PRINTF(cli_buf); - - u32tmp[0] = halbtc8703b1ant_ltecoex_indirect_read_reg(btcoexist, 0x54); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d", - "GNT_WL/GNT_BT/LTE_Busy/UART_Busy", - (int)((u32tmp[0] & BIT(2)) >> 2), - (int)((u32tmp[0] & BIT(3)) >> 3), - (int)((u32tmp[0] & BIT(1)) >> 1), (int)(u32tmp[0] & BIT(0))); - CL_PRINTF(cli_buf); - - - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x4c6); - u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0x40); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", - "0x4c6[4]/0x40[5] (WL/BT PTA)", - (int)((u8tmp[0] & BIT(4)) >> 4), - (int)((u8tmp[1] & BIT(5)) >> 5)); - CL_PRINTF(cli_buf); - - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x550); - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x522); - u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0x953); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ %s", - "0x550(bcn ctrl)/0x522/4-RxAGC", - u32tmp[0], u8tmp[0], (u8tmp[1] & 0x2) ? "On" : "Off"); - CL_PRINTF(cli_buf); - - fa_ofdm = btcoexist->btc_phydm_query_PHY_counter(btcoexist, PHYDM_INFO_FA_OFDM); - fa_cck = btcoexist->btc_phydm_query_PHY_counter(btcoexist, PHYDM_INFO_FA_CCK); - cca_ofdm = btcoexist->btc_phydm_query_PHY_counter(btcoexist, PHYDM_INFO_CCA_OFDM); - cca_cck = btcoexist->btc_phydm_query_PHY_counter(btcoexist, PHYDM_INFO_CCA_CCK); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", - "CCK-CCA/CCK-FA/OFDM-CCA/OFDM-FA", - cca_cck, fa_cck, cca_ofdm, fa_ofdm); - CL_PRINTF(cli_buf); - -#if 1 - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d", - "CRC_OK CCK/11g/11n/11n-agg", - coex_sta->crc_ok_cck, coex_sta->crc_ok_11g, - coex_sta->crc_ok_11n, coex_sta->crc_ok_11n_vht); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d", - "CRC_Err CCK/11g/11n/11n-agg", - coex_sta->crc_err_cck, coex_sta->crc_err_11g, - coex_sta->crc_err_11n, coex_sta->crc_err_11n_vht); - CL_PRINTF(cli_buf); -#endif - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s/ %s/ %d", - "WlHiPri/ Locking/ Locked/ Noisy", - (coex_sta->wifi_is_high_pri_task ? "Yes" : "No"), - (coex_sta->cck_lock ? "Yes" : "No"), - (coex_sta->cck_ever_lock ? "Yes" : "No"), - coex_sta->wl_noisy_level); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d %s", - "0x770(Hi-pri rx/tx)", - coex_sta->high_priority_rx, coex_sta->high_priority_tx, - (coex_sta->is_hiPri_rx_overhead ? "(scan overhead!!)" : "")); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d %s", - "0x774(Lo-pri rx/tx)", - coex_sta->low_priority_rx, coex_sta->low_priority_tx, - (bt_link_info->slave_role ? "(Slave!!)" : ( - coex_sta->is_tdma_btautoslot_hang ? "(auto-slot hang!!)" : ""))); - CL_PRINTF(cli_buf); - - btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_COEX_STATISTICS); -} - - -void ex_halbtc8703b1ant_ips_notify(IN struct btc_coexist *btcoexist, IN u8 type) -{ - if (btcoexist->manual_control || btcoexist->stop_coex_dm) - return; - - if (BTC_IPS_ENTER == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], IPS ENTER notify\n"); - BTC_TRACE(trace_buf); - coex_sta->under_ips = true; - coex_sta->under_lps = false; - - /* Write WL "Active" in Score-board for LPS off */ - halbtc8703b1ant_post_state_to_bt(btcoexist, - BT_8703B_1ANT_SCOREBOARD_ACTIVE, false); - - halbtc8703b1ant_post_state_to_bt(btcoexist, - BT_8703B_1ANT_SCOREBOARD_ONOFF, false); - - halbtc8703b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); - - halbtc8703b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, - FORCE_EXEC, - BT_8703B_1ANT_PHASE_WLAN_OFF); - - halbtc8703b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - } else if (BTC_IPS_LEAVE == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], IPS LEAVE notify\n"); - BTC_TRACE(trace_buf); - halbtc8703b1ant_post_state_to_bt(btcoexist, - BT_8703B_1ANT_SCOREBOARD_ACTIVE, true); - - halbtc8703b1ant_post_state_to_bt(btcoexist, - BT_8703B_1ANT_SCOREBOARD_ONOFF, true); - - halbtc8703b1ant_init_hw_config(btcoexist, false, false); - halbtc8703b1ant_init_coex_dm(btcoexist); - halbtc8703b1ant_query_bt_info(btcoexist); - - coex_sta->under_ips = false; - } -} - -void ex_halbtc8703b1ant_lps_notify(IN struct btc_coexist *btcoexist, IN u8 type) -{ - if (btcoexist->manual_control || btcoexist->stop_coex_dm) - return; - - if (BTC_LPS_ENABLE == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], LPS ENABLE notify\n"); - BTC_TRACE(trace_buf); - coex_sta->under_lps = true; - coex_sta->under_ips = false; - - if (coex_sta->force_lps_on == true) { /* LPS No-32K */ - /* Write WL "Active" in Score-board for PS-TDMA */ - halbtc8703b1ant_post_state_to_bt(btcoexist, - BT_8703B_1ANT_SCOREBOARD_ACTIVE, true); - - } else { /* LPS-32K, need check if this h2c 0x71 can work?? (2015/08/28) */ - /* Write WL "Non-Active" in Score-board for Native-PS */ - halbtc8703b1ant_post_state_to_bt(btcoexist, - BT_8703B_1ANT_SCOREBOARD_ACTIVE, false); - } - } else if (BTC_LPS_DISABLE == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], LPS DISABLE notify\n"); - BTC_TRACE(trace_buf); - coex_sta->under_lps = false; - - - /* Write WL "Active" in Score-board for LPS off */ - halbtc8703b1ant_post_state_to_bt(btcoexist, - BT_8703B_1ANT_SCOREBOARD_ACTIVE, true); - } -} - -void ex_halbtc8703b1ant_scan_notify(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - boolean wifi_connected = false; - - if (btcoexist->manual_control || - btcoexist->stop_coex_dm) - return; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - - halbtc8703b1ant_query_bt_info(btcoexist); - - if (BTC_SCAN_START == type) { - - coex_sta->wifi_is_high_pri_task = true; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCAN START notify\n"); - BTC_TRACE(trace_buf); - - halbtc8703b1ant_post_state_to_bt(btcoexist, - BT_8703B_1ANT_SCOREBOARD_SCAN, true); - halbtc8703b1ant_post_state_to_bt(btcoexist, - BT_8703B_1ANT_SCOREBOARD_ACTIVE, true); - - halbtc8703b1ant_ps_tdma(btcoexist, FORCE_EXEC, false, - 8); - - /* Force antenna setup for no scan result issue */ - halbtc8703b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, - FORCE_EXEC, - BT_8703B_1ANT_PHASE_2G_RUNTIME); - - halbtc8703b1ant_run_coexist_mechanism(btcoexist); - - } else { - - coex_sta->wifi_is_high_pri_task = false; - - btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM, - &coex_sta->scan_ap_num); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCAN FINISH notify (Scan-AP = %d)\n", - coex_sta->scan_ap_num); - BTC_TRACE(trace_buf); - - halbtc8703b1ant_run_coexist_mechanism(btcoexist); - } - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCAN START Notify() end\n"); - BTC_TRACE(trace_buf); - -} - -void ex_halbtc8703b1ant_connect_notify(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - boolean wifi_connected = false; - - if (btcoexist->manual_control || - btcoexist->stop_coex_dm) - return; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - - if (BTC_ASSOCIATE_START == type) { - coex_sta->wifi_is_high_pri_task = true; - - halbtc8703b1ant_post_state_to_bt(btcoexist, - BT_8703B_1ANT_SCOREBOARD_SCAN, true); - halbtc8703b1ant_post_state_to_bt(btcoexist, - BT_8703B_1ANT_SCOREBOARD_ACTIVE, true); - - halbtc8703b1ant_ps_tdma(btcoexist, FORCE_EXEC, false, - 8); - - /* Force antenna setup for no scan result issue */ - halbtc8703b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, - FORCE_EXEC, - BT_8703B_1ANT_PHASE_2G_RUNTIME); - /* psd_scan->ant_det_is_ant_det_available = true; */ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], CONNECT START notify\n"); - BTC_TRACE(trace_buf); - coex_dm->arp_cnt = 0; - - halbtc8703b1ant_run_coexist_mechanism(btcoexist); - } else { - coex_sta->wifi_is_high_pri_task = false; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], CONNECT FINISH notify\n"); - BTC_TRACE(trace_buf); - - halbtc8703b1ant_run_coexist_mechanism(btcoexist); - } - -} - -void ex_halbtc8703b1ant_media_status_notify(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - boolean wifi_under_b_mode = false; - - if (btcoexist->manual_control || - btcoexist->stop_coex_dm) - return; - - if (BTC_MEDIA_CONNECT == type) { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], MEDIA connect notify\n"); - BTC_TRACE(trace_buf); - - halbtc8703b1ant_post_state_to_bt(btcoexist, - BT_8703B_1ANT_SCOREBOARD_ACTIVE, true); - halbtc8703b1ant_ps_tdma(btcoexist, FORCE_EXEC, false, - 8); - - /* Force antenna setup for no scan result issue */ - halbtc8703b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, - FORCE_EXEC, - BT_8703B_1ANT_PHASE_2G_RUNTIME); - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_B_MODE, - &wifi_under_b_mode); - - /* Set CCK Tx/Rx high Pri except 11b mode */ - if (wifi_under_b_mode) { - btcoexist->btc_write_1byte(btcoexist, 0x6cd, - 0x00); /* CCK Tx */ - btcoexist->btc_write_1byte(btcoexist, 0x6cf, - 0x00); /* CCK Rx */ - } else { - /* btcoexist->btc_write_1byte(btcoexist, 0x6cd, 0x10); */ /*CCK Tx */ - /* btcoexist->btc_write_1byte(btcoexist, 0x6cf, 0x10); */ /*CCK Rx */ - btcoexist->btc_write_1byte(btcoexist, 0x6cd, - 0x00); /* CCK Tx */ - btcoexist->btc_write_1byte(btcoexist, 0x6cf, - 0x10); /* CCK Rx */ - } - - coex_dm->backup_arfr_cnt1 = btcoexist->btc_read_4byte(btcoexist, - 0x430); - coex_dm->backup_arfr_cnt2 = btcoexist->btc_read_4byte(btcoexist, - 0x434); - coex_dm->backup_retry_limit = btcoexist->btc_read_2byte( - btcoexist, 0x42a); - coex_dm->backup_ampdu_max_time = btcoexist->btc_read_1byte( - btcoexist, 0x456); - } else { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], MEDIA disconnect notify\n"); - BTC_TRACE(trace_buf); - - halbtc8703b1ant_post_state_to_bt(btcoexist, - BT_8703B_1ANT_SCOREBOARD_ACTIVE, false); - - btcoexist->btc_write_1byte(btcoexist, 0x6cd, 0x0); /* CCK Tx */ - btcoexist->btc_write_1byte(btcoexist, 0x6cf, 0x0); /* CCK Rx */ - - coex_sta->cck_ever_lock = false; - } - - halbtc8703b1ant_update_wifi_channel_info(btcoexist, type); - -} - -void ex_halbtc8703b1ant_specific_packet_notify(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - boolean under_4way = false; - - if (btcoexist->manual_control || - btcoexist->stop_coex_dm) - return; - - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS, - &under_4way); - - if (under_4way) { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], specific Packet ---- under_4way!!\n"); - BTC_TRACE(trace_buf); - - coex_sta->wifi_is_high_pri_task = true; - coex_sta->specific_pkt_period_cnt = 2; - } else if (BTC_PACKET_ARP == type) { - - coex_dm->arp_cnt++; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], specific Packet ARP notify -cnt = %d\n", - coex_dm->arp_cnt); - BTC_TRACE(trace_buf); - - } else { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], specific Packet DHCP or EAPOL notify [Type = %d]\n", - type); - BTC_TRACE(trace_buf); - - coex_sta->wifi_is_high_pri_task = true; - coex_sta->specific_pkt_period_cnt = 2; - } - - if (coex_sta->wifi_is_high_pri_task) { - halbtc8703b1ant_post_state_to_bt(btcoexist, - BT_8703B_1ANT_SCOREBOARD_SCAN, true); - halbtc8703b1ant_run_coexist_mechanism(btcoexist); - } -} - -void ex_halbtc8703b1ant_bt_info_notify(IN struct btc_coexist *btcoexist, - IN u8 *tmp_buf, IN u8 length) -{ - u8 i, rsp_source = 0; - boolean wifi_connected = false; - boolean wifi_scan = false, wifi_link = false, wifi_roam = false, - wifi_busy = false; - - - rsp_source = tmp_buf[0] & 0xf; - if (rsp_source >= BT_INFO_SRC_8703B_1ANT_MAX) - rsp_source = BT_INFO_SRC_8703B_1ANT_WIFI_FW; - coex_sta->bt_info_c2h_cnt[rsp_source]++; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Bt_info[%d], len=%d, data=[", rsp_source, - length); - BTC_TRACE(trace_buf); - - for (i = 0; i < length; i++) { - coex_sta->bt_info_c2h[rsp_source][i] = tmp_buf[i]; - - if (i == length - 1) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "0x%02x]\n", - tmp_buf[i]); - BTC_TRACE(trace_buf); - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "0x%02x, ", - tmp_buf[i]); - BTC_TRACE(trace_buf); - } - } - - coex_sta->bt_info = coex_sta->bt_info_c2h[rsp_source][1]; - coex_sta->bt_info_ext = coex_sta->bt_info_c2h[rsp_source][4]; - coex_sta->bt_info_ext2 = coex_sta->bt_info_c2h[rsp_source][5]; - - if (BT_INFO_SRC_8703B_1ANT_WIFI_FW != rsp_source) { - - /* if 0xff, it means BT is under WHCK test */ - coex_sta->bt_whck_test = ((coex_sta->bt_info == 0xff) ? true : - false); - - coex_sta->bt_create_connection = (( - coex_sta->bt_info_c2h[rsp_source][2] & 0x80) ? true : - false); - - /* unit: %, value-100 to translate to unit: dBm */ - coex_sta->bt_rssi = coex_sta->bt_info_c2h[rsp_source][3] * 2 + - 10; - - coex_sta->c2h_bt_remote_name_req = (( - coex_sta->bt_info_c2h[rsp_source][2] & 0x20) ? true : - false); - - coex_sta->is_A2DP_3M = ((coex_sta->bt_info_c2h[rsp_source][2] & - 0x10) ? true : false); - - coex_sta->acl_busy = ((coex_sta->bt_info_c2h[rsp_source][1] & - 0x9) ? true : false); - - coex_sta->voice_over_HOGP = ((coex_sta->bt_info_ext & 0x10) ? - true : false); - - coex_sta->c2h_bt_inquiry_page = ((coex_sta->bt_info & - BT_INFO_8703B_1ANT_B_INQ_PAGE) ? true : false); - - coex_sta->a2dp_bit_pool = ((( - coex_sta->bt_info_c2h[rsp_source][1] & 0x49) == 0x49) ? - coex_sta->bt_info_c2h[rsp_source][6] : 0); - - coex_sta->bt_retry_cnt = coex_sta->bt_info_c2h[rsp_source][2] & - 0xf; - - coex_sta->is_autoslot = coex_sta->bt_info_ext2 & 0x8; - - coex_sta->forbidden_slot = coex_sta->bt_info_ext2 & 0x7; - - coex_sta->hid_busy_num = (coex_sta->bt_info_ext2 & 0x30) >> 4; - - coex_sta->hid_pair_cnt = (coex_sta->bt_info_ext2 & 0xc0) >> 6; - - if (coex_sta->bt_retry_cnt >= 1) - coex_sta->pop_event_cnt++; - - if (coex_sta->c2h_bt_remote_name_req) - coex_sta->cnt_RemoteNameReq++; - - if (coex_sta->bt_info_ext & BIT(1)) - coex_sta->cnt_ReInit++; - - if (coex_sta->bt_info_ext & BIT(2)) { - coex_sta->cnt_setupLink++; - coex_sta->is_setupLink = true; - } else - coex_sta->is_setupLink = false; - - if (coex_sta->bt_info_ext & BIT(3)) - coex_sta->cnt_IgnWlanAct++; - - if (coex_sta->bt_create_connection) { - coex_sta->cnt_Page++; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &wifi_scan); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &wifi_link); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &wifi_roam); - - if ((wifi_link) || (wifi_roam) || (wifi_scan) || - (coex_sta->wifi_is_high_pri_task) || (wifi_busy)) { - - halbtc8703b1ant_post_state_to_bt(btcoexist, - BT_8703B_1ANT_SCOREBOARD_SCAN, true); - - } else { - - halbtc8703b1ant_post_state_to_bt(btcoexist, - BT_8703B_1ANT_SCOREBOARD_SCAN, false); - } - } else - halbtc8703b1ant_post_state_to_bt(btcoexist, - BT_8703B_1ANT_SCOREBOARD_SCAN, false); - - /* Here we need to resend some wifi info to BT */ - /* because bt is reset and loss of the info. */ - - if ((!btcoexist->manual_control) && - (!btcoexist->stop_coex_dm)) { - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - - /* Re-Init */ - if ((coex_sta->bt_info_ext & BIT(1))) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT ext info bit1 check, send wifi BW&Chnl to BT!!\n"); - BTC_TRACE(trace_buf); - if (wifi_connected) - halbtc8703b1ant_update_wifi_channel_info( - btcoexist, BTC_MEDIA_CONNECT); - else - halbtc8703b1ant_update_wifi_channel_info( - btcoexist, - BTC_MEDIA_DISCONNECT); - } - - - /* If Ignore_WLanAct && not SetUp_Link */ - if ((coex_sta->bt_info_ext & BIT(3)) && - (!(coex_sta->bt_info_ext & BIT(2))) && - (!(coex_sta->bt_info_ext & BIT(6)))) { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT ext info bit3 check, set BT NOT to ignore Wlan active!!\n"); - BTC_TRACE(trace_buf); - halbtc8703b1ant_ignore_wlan_act(btcoexist, - FORCE_EXEC, false); - } else { - if (coex_sta->bt_info_ext & BIT(2)) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT ignore Wlan active because Re-link!!\n"); - BTC_TRACE(trace_buf); - } else if (coex_sta->bt_info_ext & BIT(6)) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT ignore Wlan active because Role-Switch!!\n"); - BTC_TRACE(trace_buf); - } - } - } - - } - if ((coex_sta->bt_info_ext & BIT(5))) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT ext info bit4 check, query BLE Scan type!!\n"); - BTC_TRACE(trace_buf); - coex_sta->bt_ble_scan_type = btcoexist->btc_get_ble_scan_type_from_bt(btcoexist); - - if ((coex_sta->bt_ble_scan_type & 0x1) == 0x1) - coex_sta->bt_ble_scan_para[0] = btcoexist->btc_get_ble_scan_para_from_bt(btcoexist, 0x1); - if ((coex_sta->bt_ble_scan_type & 0x2) == 0x2) - coex_sta->bt_ble_scan_para[1] = btcoexist->btc_get_ble_scan_para_from_bt(btcoexist, 0x2); - if ((coex_sta->bt_ble_scan_type & 0x4) == 0x4) - coex_sta->bt_ble_scan_para[2] = btcoexist->btc_get_ble_scan_para_from_bt(btcoexist, 0x4); - } - - halbtc8703b1ant_update_bt_link_info(btcoexist); - - halbtc8703b1ant_run_coexist_mechanism(btcoexist); -} - - -void ex_halbtc8703b1ant_rf_status_notify(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], RF Status notify\n"); - BTC_TRACE(trace_buf); - - if (BTC_RF_ON == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], RF is turned ON!!\n"); - BTC_TRACE(trace_buf); - - btcoexist->stop_coex_dm = false; - - halbtc8703b1ant_post_state_to_bt(btcoexist, - BT_8703B_1ANT_SCOREBOARD_ACTIVE, true); - halbtc8703b1ant_post_state_to_bt(btcoexist, - BT_8703B_1ANT_SCOREBOARD_ONOFF, true); - - /* halbtc8703b1ant_init_hw_config(btcoexist, false, false); */ - } else if (BTC_RF_OFF == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], RF is turned OFF!!\n"); - BTC_TRACE(trace_buf); - halbtc8703b1ant_post_state_to_bt(btcoexist, - BT_8703B_1ANT_SCOREBOARD_ACTIVE, false); - halbtc8703b1ant_post_state_to_bt(btcoexist, - BT_8703B_1ANT_SCOREBOARD_ONOFF, false); - - halbtc8703b1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 0); - halbtc8703b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, - FORCE_EXEC, - BT_8703B_1ANT_PHASE_WLAN_OFF); - - btcoexist->stop_coex_dm = true; - - } -} - -void ex_halbtc8703b1ant_halt_notify(IN struct btc_coexist *btcoexist) -{ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], Halt notify\n"); - BTC_TRACE(trace_buf); - - halbtc8703b1ant_post_state_to_bt(btcoexist, - BT_8703B_1ANT_SCOREBOARD_ACTIVE, false); - halbtc8703b1ant_post_state_to_bt(btcoexist, - BT_8703B_1ANT_SCOREBOARD_ONOFF, false); - - halbtc8703b1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 0); - halbtc8703b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, FORCE_EXEC, - BT_8703B_1ANT_PHASE_WLAN_OFF); - - ex_halbtc8703b1ant_media_status_notify(btcoexist, BTC_MEDIA_DISCONNECT); - - halbtc8703b1ant_enable_gnt_to_gpio(btcoexist, false); - - btcoexist->stop_coex_dm = true; -} - -void ex_halbtc8703b1ant_pnp_notify(IN struct btc_coexist *btcoexist, - IN u8 pnp_state) -{ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], Pnp notify\n"); - BTC_TRACE(trace_buf); - - if ((BTC_WIFI_PNP_SLEEP == pnp_state) || - (BTC_WIFI_PNP_SLEEP_KEEP_ANT == pnp_state)) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Pnp notify to SLEEP\n"); - BTC_TRACE(trace_buf); - - halbtc8703b1ant_post_state_to_bt(btcoexist, - BT_8703B_1ANT_SCOREBOARD_ACTIVE, false); - halbtc8703b1ant_post_state_to_bt(btcoexist, - BT_8703B_1ANT_SCOREBOARD_ONOFF, false); - - if (BTC_WIFI_PNP_SLEEP_KEEP_ANT == pnp_state) { - - halbtc8703b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, - FORCE_EXEC, - BT_8703B_1ANT_PHASE_2G_RUNTIME); - } else { - - halbtc8703b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, - FORCE_EXEC, - BT_8703B_1ANT_PHASE_WLAN_OFF); - } - - btcoexist->stop_coex_dm = true; - } else if (BTC_WIFI_PNP_WAKE_UP == pnp_state) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Pnp notify to WAKE UP\n"); - BTC_TRACE(trace_buf); - halbtc8703b1ant_post_state_to_bt(btcoexist, - BT_8703B_1ANT_SCOREBOARD_ACTIVE, true); - halbtc8703b1ant_post_state_to_bt(btcoexist, - BT_8703B_1ANT_SCOREBOARD_ONOFF, true); - - btcoexist->stop_coex_dm = false; - } -} - -void ex_halbtc8703b1ant_coex_dm_reset(IN struct btc_coexist *btcoexist) -{ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], *****************Coex DM Reset*****************\n"); - BTC_TRACE(trace_buf); - - halbtc8703b1ant_init_hw_config(btcoexist, false, false); - halbtc8703b1ant_init_coex_dm(btcoexist); -} - -void ex_halbtc8703b1ant_periodical(IN struct btc_coexist *btcoexist) -{ - u32 bt_patch_ver; - boolean wifi_busy = false; - static u8 cnt = 0; - boolean bt_relink_finish = false; - -#if (BT_AUTO_REPORT_ONLY_8703B_1ANT == 0) - halbtc8703b1ant_query_bt_info(btcoexist); -#endif - - halbtc8703b1ant_monitor_bt_ctr(btcoexist); - halbtc8703b1ant_monitor_wifi_ctr(btcoexist); - - halbtc8703b1ant_monitor_bt_enable_disable(btcoexist); - -# if 1 - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - - /* halbtc8703b1ant_read_score_board(btcoexist, &bt_scoreboard_val); */ - - if (wifi_busy) { - halbtc8703b1ant_post_state_to_bt(btcoexist, - BT_8703B_1ANT_SCOREBOARD_UNDERTEST, true); - /* - halbtc8703b1ant_post_state_to_bt(btcoexist, - BT_8703B_1ANT_SCOREBOARD_WLBUSY, true); - - if (bt_scoreboard_val & BIT(6)) - halbtc8703b1ant_query_bt_info(btcoexist); */ - } else { - halbtc8703b1ant_post_state_to_bt(btcoexist, - BT_8703B_1ANT_SCOREBOARD_UNDERTEST, false); - /* - halbtc8703b1ant_post_state_to_bt(btcoexist, - BT_8703B_1ANT_SCOREBOARD_WLBUSY, - false); */ - } -#endif - - if (coex_sta->bt_relink_downcount != 0) { - coex_sta->bt_relink_downcount--; - - if (coex_sta->bt_relink_downcount == 0) - bt_relink_finish = true; - } - - /* for 4-way, DHCP, EAPOL packet */ - if (coex_sta->specific_pkt_period_cnt > 0) { - - coex_sta->specific_pkt_period_cnt--; - - if ((coex_sta->specific_pkt_period_cnt == 0) && - (coex_sta->wifi_is_high_pri_task)) - coex_sta->wifi_is_high_pri_task = false; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ***************** Hi-Pri Task = %s*****************\n", - (coex_sta->wifi_is_high_pri_task ? "Yes" : - "No")); - BTC_TRACE(trace_buf); - - } - - if (!coex_sta->bt_disabled) { - if (coex_sta->bt_coex_supported_feature == 0) - btcoexist->btc_get(btcoexist, BTC_GET_U4_SUPPORTED_FEATURE, - &coex_sta->bt_coex_supported_feature); - - if ((coex_sta->bt_coex_supported_version == 0) || - (coex_sta->bt_coex_supported_version == 0xffff)) - btcoexist->btc_get(btcoexist, BTC_GET_U4_SUPPORTED_VERSION, - &coex_sta->bt_coex_supported_version); - - btcoexist->btc_get(btcoexist, BTC_GET_U4_BT_PATCH_VER, &bt_patch_ver); - btcoexist->bt_info.bt_get_fw_ver = bt_patch_ver; - - if (coex_sta->num_of_profile > 0) { - cnt++; - - if (cnt >= 3) { - btcoexist->btc_get_bt_afh_map_from_bt(btcoexist, 0, - &coex_sta->bt_afh_map[0]); - cnt = 0; - } - } - } - - if (halbtc8703b1ant_is_wifibt_status_changed(btcoexist)) - halbtc8703b1ant_run_coexist_mechanism(btcoexist); -} - -void ex_halbtc8703b1ant_antenna_detection(IN struct btc_coexist *btcoexist, - IN u32 cent_freq, IN u32 offset, IN u32 span, IN u32 seconds) -{ - /* No Antenna Detection required because 8730b is only 1-Ant */ -} - -void ex_halbtc8703b1ant_antenna_isolation(IN struct btc_coexist *btcoexist, - IN u32 cent_freq, IN u32 offset, IN u32 span, IN u32 seconds) -{ - - -} - -void ex_halbtc8703b1ant_psd_scan(IN struct btc_coexist *btcoexist, - IN u32 cent_freq, IN u32 offset, IN u32 span, IN u32 seconds) -{ - - -} - -void ex_halbtc8703b1ant_display_ant_detection(IN struct btc_coexist *btcoexist) -{ - -} - -#endif - -#endif /* #if (BT_SUPPORT == 1 && COEX_SUPPORT == 1) */ - diff --git a/hal/btc/halbtc8703b1ant.h b/hal/btc/halbtc8703b1ant.h deleted file mode 100644 index ed5ebe0..0000000 --- a/hal/btc/halbtc8703b1ant.h +++ /dev/null @@ -1,404 +0,0 @@ - -#if (BT_SUPPORT == 1 && COEX_SUPPORT == 1) - -#if (RTL8703B_SUPPORT == 1) -/* ******************************************* - * The following is for 8703B 1ANT BT Co-exist definition - * ******************************************* */ -#define BT_AUTO_REPORT_ONLY_8703B_1ANT 1 -#define BT_8703B_1ANT_ENABLE_GNTBT_TO_GPIO14 0 - -#define BT_INFO_8703B_1ANT_B_FTP BIT(7) -#define BT_INFO_8703B_1ANT_B_A2DP BIT(6) -#define BT_INFO_8703B_1ANT_B_HID BIT(5) -#define BT_INFO_8703B_1ANT_B_SCO_BUSY BIT(4) -#define BT_INFO_8703B_1ANT_B_ACL_BUSY BIT(3) -#define BT_INFO_8703B_1ANT_B_INQ_PAGE BIT(2) -#define BT_INFO_8703B_1ANT_B_SCO_ESCO BIT(1) -#define BT_INFO_8703B_1ANT_B_CONNECTION BIT(0) - -#define BT_INFO_8703B_1ANT_A2DP_BASIC_RATE(_BT_INFO_EXT_) \ - (((_BT_INFO_EXT_&BIT(0))) ? true : false) - -#define BTC_RSSI_COEX_THRESH_TOL_8703B_1ANT 2 - -#define BT_8703B_1ANT_WIFI_NOISY_THRESH 50 /* max: 255 */ - -/* for Antenna detection */ -#define BT_8703B_1ANT_ANTDET_PSDTHRES_BACKGROUND 50 -#define BT_8703B_1ANT_ANTDET_PSDTHRES_2ANT_BADISOLATION 70 -#define BT_8703B_1ANT_ANTDET_PSDTHRES_2ANT_GOODISOLATION 55 -#define BT_8703B_1ANT_ANTDET_PSDTHRES_1ANT 35 -#define BT_8703B_1ANT_ANTDET_RETRY_INTERVAL 10 /* retry timer if ant det is fail, unit: second */ -#define BT_8703B_1ANT_ANTDET_SWEEPPOINT_DELAY 40000 -#define BT_8703B_1ANT_ANTDET_ENABLE 0 -#define BT_8703B_1ANT_ANTDET_COEXMECHANISMSWITCH_ENABLE 0 - -#define BT_8703B_1ANT_LTECOEX_INDIRECTREG_ACCESS_TIMEOUT 30000 - -enum bt_8703b_1ant_signal_state { - BT_8703B_1ANT_SIG_STA_SET_TO_LOW = 0x0, - BT_8703B_1ANT_SIG_STA_SET_BY_HW = 0x0, - BT_8703B_1ANT_SIG_STA_SET_TO_HIGH = 0x1, - BT_8703B_1ANT_SIG_STA_MAX -}; - -enum bt_8703b_1ant_path_ctrl_owner { - BT_8703B_1ANT_PCO_BTSIDE = 0x0, - BT_8703B_1ANT_PCO_WLSIDE = 0x1, - BT_8703B_1ANT_PCO_MAX -}; - -enum bt_8703b_1ant_gnt_ctrl_type { - BT_8703B_1ANT_GNT_TYPE_CTRL_BY_PTA = 0x0, - BT_8703B_1ANT_GNT_TYPE_CTRL_BY_SW = 0x1, - BT_8703B_1ANT_GNT_TYPE_MAX -}; - -enum bt_8703b_1ant_gnt_ctrl_block { - BT_8703B_1ANT_GNT_BLOCK_RFC_BB = 0x0, - BT_8703B_1ANT_GNT_BLOCK_RFC = 0x1, - BT_8703B_1ANT_GNT_BLOCK_BB = 0x2, - BT_8703B_1ANT_GNT_BLOCK_MAX -}; - -enum bt_8703b_1ant_lte_coex_table_type { - BT_8703B_1ANT_CTT_WL_VS_LTE = 0x0, - BT_8703B_1ANT_CTT_BT_VS_LTE = 0x1, - BT_8703B_1ANT_CTT_MAX -}; - -enum bt_8703b_1ant_lte_break_table_type { - BT_8703B_1ANT_LBTT_WL_BREAK_LTE = 0x0, - BT_8703B_1ANT_LBTT_BT_BREAK_LTE = 0x1, - BT_8703B_1ANT_LBTT_LTE_BREAK_WL = 0x2, - BT_8703B_1ANT_LBTT_LTE_BREAK_BT = 0x3, - BT_8703B_1ANT_LBTT_MAX -}; - -enum bt_info_src_8703b_1ant { - BT_INFO_SRC_8703B_1ANT_WIFI_FW = 0x0, - BT_INFO_SRC_8703B_1ANT_BT_RSP = 0x1, - BT_INFO_SRC_8703B_1ANT_BT_ACTIVE_SEND = 0x2, - BT_INFO_SRC_8703B_1ANT_MAX -}; - -enum bt_8703b_1ant_bt_status { - BT_8703B_1ANT_BT_STATUS_NON_CONNECTED_IDLE = 0x0, - BT_8703B_1ANT_BT_STATUS_CONNECTED_IDLE = 0x1, - BT_8703B_1ANT_BT_STATUS_INQ_PAGE = 0x2, - BT_8703B_1ANT_BT_STATUS_ACL_BUSY = 0x3, - BT_8703B_1ANT_BT_STATUS_SCO_BUSY = 0x4, - BT_8703B_1ANT_BT_STATUS_ACL_SCO_BUSY = 0x5, - BT_8703B_1ANT_BT_STATUS_MAX -}; - -enum bt_8703b_1ant_wifi_status { - BT_8703B_1ANT_WIFI_STATUS_NON_CONNECTED_IDLE = 0x0, - BT_8703B_1ANT_WIFI_STATUS_NON_CONNECTED_ASSO_AUTH_SCAN = 0x1, - BT_8703B_1ANT_WIFI_STATUS_CONNECTED_SCAN = 0x2, - BT_8703B_1ANT_WIFI_STATUS_CONNECTED_SPECIFIC_PKT = 0x3, - BT_8703B_1ANT_WIFI_STATUS_CONNECTED_IDLE = 0x4, - BT_8703B_1ANT_WIFI_STATUS_CONNECTED_BUSY = 0x5, - BT_8703B_1ANT_WIFI_STATUS_MAX -}; - -enum bt_8703b_1ant_coex_algo { - BT_8703B_1ANT_COEX_ALGO_UNDEFINED = 0x0, - BT_8703B_1ANT_COEX_ALGO_SCO = 0x1, - BT_8703B_1ANT_COEX_ALGO_HID = 0x2, - BT_8703B_1ANT_COEX_ALGO_A2DP = 0x3, - BT_8703B_1ANT_COEX_ALGO_A2DP_PANHS = 0x4, - BT_8703B_1ANT_COEX_ALGO_PANEDR = 0x5, - BT_8703B_1ANT_COEX_ALGO_PANHS = 0x6, - BT_8703B_1ANT_COEX_ALGO_PANEDR_A2DP = 0x7, - BT_8703B_1ANT_COEX_ALGO_PANEDR_HID = 0x8, - BT_8703B_1ANT_COEX_ALGO_HID_A2DP_PANEDR = 0x9, - BT_8703B_1ANT_COEX_ALGO_HID_A2DP = 0xa, - BT_8703B_1ANT_COEX_ALGO_MAX = 0xb, -}; - -enum bt_8703b_1ant_phase { - BT_8703B_1ANT_PHASE_COEX_INIT = 0x0, - BT_8703B_1ANT_PHASE_WLANONLY_INIT = 0x1, - BT_8703B_1ANT_PHASE_WLAN_OFF = 0x2, - BT_8703B_1ANT_PHASE_2G_RUNTIME = 0x3, - BT_8703B_1ANT_PHASE_5G_RUNTIME = 0x4, - BT_8703B_1ANT_PHASE_BTMPMODE = 0x5, - BT_8703B_1ANT_PHASE_ANTENNA_DET = 0x6, - BT_8703B_1ANT_PHASE_MAX -}; - -enum bt_8703b_1ant_Scoreboard { - BT_8703B_1ANT_SCOREBOARD_ACTIVE = BIT(0), - BT_8703B_1ANT_SCOREBOARD_ONOFF = BIT(1), - BT_8703B_1ANT_SCOREBOARD_SCAN = BIT(2), - BT_8703B_1ANT_SCOREBOARD_UNDERTEST = BIT(3), - BT_8703B_1ANT_SCOREBOARD_WLBUSY = BIT(6) -}; - - -struct coex_dm_8703b_1ant { - /* hw setting */ - u8 pre_ant_pos_type; - u8 cur_ant_pos_type; - /* fw mechanism */ - boolean cur_ignore_wlan_act; - boolean pre_ignore_wlan_act; - u8 pre_ps_tdma; - u8 cur_ps_tdma; - u8 ps_tdma_para[5]; - u8 ps_tdma_du_adj_type; - boolean auto_tdma_adjust; - boolean pre_ps_tdma_on; - boolean cur_ps_tdma_on; - boolean pre_bt_auto_report; - boolean cur_bt_auto_report; - u8 pre_lps; - u8 cur_lps; - u8 pre_rpwm; - u8 cur_rpwm; - - /* sw mechanism */ - boolean pre_low_penalty_ra; - boolean cur_low_penalty_ra; - u32 pre_val0x6c0; - u32 cur_val0x6c0; - u32 pre_val0x6c4; - u32 cur_val0x6c4; - u32 pre_val0x6c8; - u32 cur_val0x6c8; - u8 pre_val0x6cc; - u8 cur_val0x6cc; - boolean limited_dig; - - u32 backup_arfr_cnt1; /* Auto Rate Fallback Retry cnt */ - u32 backup_arfr_cnt2; /* Auto Rate Fallback Retry cnt */ - u16 backup_retry_limit; - u8 backup_ampdu_max_time; - - /* algorithm related */ - u8 pre_algorithm; - u8 cur_algorithm; - u8 bt_status; - u8 wifi_chnl_info[3]; - - u32 pre_ra_mask; - u32 cur_ra_mask; - u8 pre_arfr_type; - u8 cur_arfr_type; - u8 pre_retry_limit_type; - u8 cur_retry_limit_type; - u8 pre_ampdu_time_type; - u8 cur_ampdu_time_type; - u32 arp_cnt; - - u8 error_condition; -}; - -struct coex_sta_8703b_1ant { - boolean bt_disabled; - boolean bt_link_exist; - boolean sco_exist; - boolean a2dp_exist; - boolean hid_exist; - boolean pan_exist; - boolean bt_hi_pri_link_exist; - u8 num_of_profile; - - boolean under_lps; - boolean under_ips; - u32 specific_pkt_period_cnt; - u32 high_priority_tx; - u32 high_priority_rx; - u32 low_priority_tx; - u32 low_priority_rx; - boolean is_hiPri_rx_overhead; - s8 bt_rssi; - boolean bt_tx_rx_mask; - u8 pre_bt_rssi_state; - u8 pre_wifi_rssi_state[4]; - u8 bt_info_c2h[BT_INFO_SRC_8703B_1ANT_MAX][10]; - u32 bt_info_c2h_cnt[BT_INFO_SRC_8703B_1ANT_MAX]; - boolean bt_whck_test; - boolean c2h_bt_inquiry_page; - boolean c2h_bt_remote_name_req; - boolean c2h_bt_page; /* Add for win8.1 page out issue */ - boolean wifi_is_high_pri_task; /* Add for win8.1 page out issue */ - u8 bt_retry_cnt; - u8 bt_info_ext; - u8 bt_info_ext2; - u32 pop_event_cnt; - u8 scan_ap_num; - - u32 crc_ok_cck; - u32 crc_ok_11g; - u32 crc_ok_11n; - u32 crc_ok_11n_vht; - - u32 crc_err_cck; - u32 crc_err_11g; - u32 crc_err_11n; - u32 crc_err_11n_vht; - - boolean cck_lock; - boolean pre_ccklock; - boolean cck_ever_lock; - u8 coex_table_type; - - boolean force_lps_on; - - boolean concurrent_rx_mode_on; - - u16 score_board; - u8 isolation_btween_wb; /* 0~ 50 */ - - u8 a2dp_bit_pool; - u8 cut_version; - boolean acl_busy; - boolean bt_create_connection; - - u32 bt_coex_supported_feature; - u32 bt_coex_supported_version; - - u8 bt_ble_scan_type; - u32 bt_ble_scan_para[3]; - - boolean run_time_state; - boolean freeze_coexrun_by_btinfo; - - boolean is_A2DP_3M; - boolean voice_over_HOGP; - u8 bt_info; - boolean is_autoslot; - u8 forbidden_slot; - u8 hid_busy_num; - u8 hid_pair_cnt; - - u32 cnt_RemoteNameReq; - u32 cnt_setupLink; - u32 cnt_ReInit; - u32 cnt_IgnWlanAct; - u32 cnt_Page; - - u16 bt_reg_vendor_ac; - u16 bt_reg_vendor_ae; - - boolean is_setupLink; - u8 wl_noisy_level; - u32 gnt_error_cnt; - - u8 bt_afh_map[10]; - u8 bt_relink_downcount; - boolean is_tdma_btautoslot; - boolean is_tdma_btautoslot_hang; -}; - -#define BT_8703B_1ANT_ANTDET_PSD_POINTS 256 /* MAX:1024 */ -#define BT_8703B_1ANT_ANTDET_PSD_AVGNUM 1 /* MAX:3 */ -#define BT_8703B_1ANT_ANTDET_BUF_LEN 16 - -struct psdscan_sta_8703b_1ant { - - u32 ant_det_bt_le_channel; /* BT LE Channel ex:2412 */ - u32 ant_det_bt_tx_time; - u32 ant_det_pre_psdscan_peak_val; - boolean ant_det_is_ant_det_available; - u32 ant_det_psd_scan_peak_val; - boolean ant_det_is_btreply_available; - u32 ant_det_psd_scan_peak_freq; - - u8 ant_det_result; - u8 ant_det_peak_val[BT_8703B_1ANT_ANTDET_BUF_LEN]; - u8 ant_det_peak_freq[BT_8703B_1ANT_ANTDET_BUF_LEN]; - u32 ant_det_try_count; - u32 ant_det_fail_count; - u32 ant_det_inteval_count; - u32 ant_det_thres_offset; - - u32 real_cent_freq; - s32 real_offset; - u32 real_span; - - u32 psd_band_width; /* unit: Hz */ - u32 psd_point; /* 128/256/512/1024 */ - u32 psd_report[1024]; /* unit:dB (20logx), 0~255 */ - u32 psd_report_max_hold[1024]; /* unit:dB (20logx), 0~255 */ - u32 psd_start_point; - u32 psd_stop_point; - u32 psd_max_value_point; - u32 psd_max_value; - u32 psd_start_base; - u32 psd_avg_num; /* 1/8/16/32 */ - u32 psd_gen_count; - boolean is_psd_running; - boolean is_psd_show_max_only; -}; - -/* ******************************************* - * The following is interface which will notify coex module. - * ******************************************* */ -void ex_halbtc8703b1ant_power_on_setting(IN struct btc_coexist *btcoexist); -void ex_halbtc8703b1ant_pre_load_firmware(IN struct btc_coexist *btcoexist); -void ex_halbtc8703b1ant_init_hw_config(IN struct btc_coexist *btcoexist, - IN boolean wifi_only); -void ex_halbtc8703b1ant_init_coex_dm(IN struct btc_coexist *btcoexist); -void ex_halbtc8703b1ant_ips_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8703b1ant_lps_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8703b1ant_scan_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8703b1ant_connect_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8703b1ant_media_status_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8703b1ant_specific_packet_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8703b1ant_bt_info_notify(IN struct btc_coexist *btcoexist, - IN u8 *tmp_buf, IN u8 length); -void ex_halbtc8703b1ant_rf_status_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8703b1ant_halt_notify(IN struct btc_coexist *btcoexist); -void ex_halbtc8703b1ant_pnp_notify(IN struct btc_coexist *btcoexist, - IN u8 pnp_state); -void ex_halbtc8703b1ant_coex_dm_reset(IN struct btc_coexist *btcoexist); -void ex_halbtc8703b1ant_periodical(IN struct btc_coexist *btcoexist); -void ex_halbtc8703b1ant_display_coex_info(IN struct btc_coexist *btcoexist); -void ex_halbtc8703b1ant_antenna_detection(IN struct btc_coexist *btcoexist, - IN u32 cent_freq, IN u32 offset, IN u32 span, IN u32 seconds); -void ex_halbtc8703b1ant_antenna_isolation(IN struct btc_coexist *btcoexist, - IN u32 cent_freq, IN u32 offset, IN u32 span, IN u32 seconds); - -void ex_halbtc8703b1ant_psd_scan(IN struct btc_coexist *btcoexist, - IN u32 cent_freq, IN u32 offset, IN u32 span, IN u32 seconds); -void ex_halbtc8703b1ant_display_ant_detection(IN struct btc_coexist *btcoexist); - -#else -#define ex_halbtc8703b1ant_power_on_setting(btcoexist) -#define ex_halbtc8703b1ant_pre_load_firmware(btcoexist) -#define ex_halbtc8703b1ant_init_hw_config(btcoexist, wifi_only) -#define ex_halbtc8703b1ant_init_coex_dm(btcoexist) -#define ex_halbtc8703b1ant_ips_notify(btcoexist, type) -#define ex_halbtc8703b1ant_lps_notify(btcoexist, type) -#define ex_halbtc8703b1ant_scan_notify(btcoexist, type) -#define ex_halbtc8703b1ant_connect_notify(btcoexist, type) -#define ex_halbtc8703b1ant_media_status_notify(btcoexist, type) -#define ex_halbtc8703b1ant_specific_packet_notify(btcoexist, type) -#define ex_halbtc8703b1ant_bt_info_notify(btcoexist, tmp_buf, length) -#define ex_halbtc8703b1ant_rf_status_notify(btcoexist, type) -#define ex_halbtc8703b1ant_halt_notify(btcoexist) -#define ex_halbtc8703b1ant_pnp_notify(btcoexist, pnp_state) -#define ex_halbtc8703b1ant_coex_dm_reset(btcoexist) -#define ex_halbtc8703b1ant_periodical(btcoexist) -#define ex_halbtc8703b1ant_display_coex_info(btcoexist) -#define ex_halbtc8703b1ant_antenna_detection(btcoexist, cent_freq, offset, span, seconds) -#define ex_halbtc8703b1ant_antenna_isolation(btcoexist, cent_freq, offset, span, seconds) -#define ex_halbtc8703b1ant_psd_scan(btcoexist, cent_freq, offset, span, seconds) -#define ex_halbtc8703b1ant_display_ant_detection(btcoexist) - -#endif - - -#endif - diff --git a/hal/btc/halbtc8723b1ant.c b/hal/btc/halbtc8723b1ant.c deleted file mode 100644 index 862c1d7..0000000 --- a/hal/btc/halbtc8723b1ant.c +++ /dev/null @@ -1,4970 +0,0 @@ -/* ************************************************************ - * Description: - * - * This file is for RTL8723B Co-exist mechanism - * - * History - * 2012/11/15 Cosa first check in. - * - * ************************************************************ */ - -/* ************************************************************ - * include files - * ************************************************************ */ -#include "mp_precomp.h" - -#if (BT_SUPPORT == 1 && COEX_SUPPORT == 1) - -#if (RTL8723B_SUPPORT == 1) -/* ************************************************************ - * Global variables, these are static variables - * ************************************************************ */ -static u8 *trace_buf = &gl_btc_trace_buf[0]; -static struct coex_dm_8723b_1ant glcoex_dm_8723b_1ant; -static struct coex_dm_8723b_1ant *coex_dm = &glcoex_dm_8723b_1ant; -static struct coex_sta_8723b_1ant glcoex_sta_8723b_1ant; -static struct coex_sta_8723b_1ant *coex_sta = &glcoex_sta_8723b_1ant; -static struct psdscan_sta_8723b_1ant gl_psd_scan_8723b_1ant; -static struct psdscan_sta_8723b_1ant *psd_scan = &gl_psd_scan_8723b_1ant; - -const char *const glbt_info_src_8723b_1ant[] = { - "BT Info[wifi fw]", - "BT Info[bt rsp]", - "BT Info[bt auto report]", -}; - -u32 glcoex_ver_date_8723b_1ant = 20161007; -u32 glcoex_ver_8723b_1ant = 0x69; -u32 glcoex_ver_btdesired_8723b_1ant = 0x69; - -/* ************************************************************ - * local function proto type if needed - * ************************************************************ - * ************************************************************ - * local function start with halbtc8723b1ant_ - * ************************************************************ */ - -void halbtc8723b1ant_update_ra_mask(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u32 dis_rate_mask) -{ - coex_dm->cur_ra_mask = dis_rate_mask; - - if (force_exec || (coex_dm->pre_ra_mask != coex_dm->cur_ra_mask)) - btcoexist->btc_set(btcoexist, BTC_SET_ACT_UPDATE_RAMASK, - &coex_dm->cur_ra_mask); - coex_dm->pre_ra_mask = coex_dm->cur_ra_mask; -} - -void halbtc8723b1ant_auto_rate_fallback_retry(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 type) -{ - boolean wifi_under_b_mode = false; - - coex_dm->cur_arfr_type = type; - - if (force_exec || (coex_dm->pre_arfr_type != coex_dm->cur_arfr_type)) { - switch (coex_dm->cur_arfr_type) { - case 0: /* normal mode */ - btcoexist->btc_write_4byte(btcoexist, 0x430, - coex_dm->backup_arfr_cnt1); - btcoexist->btc_write_4byte(btcoexist, 0x434, - coex_dm->backup_arfr_cnt2); - break; - case 1: - btcoexist->btc_get(btcoexist, - BTC_GET_BL_WIFI_UNDER_B_MODE, - &wifi_under_b_mode); - if (wifi_under_b_mode) { - btcoexist->btc_write_4byte(btcoexist, - 0x430, 0x0); - btcoexist->btc_write_4byte(btcoexist, - 0x434, 0x01010101); - } else { - btcoexist->btc_write_4byte(btcoexist, - 0x430, 0x0); - btcoexist->btc_write_4byte(btcoexist, - 0x434, 0x04030201); - } - break; - default: - break; - } - } - - coex_dm->pre_arfr_type = coex_dm->cur_arfr_type; -} - -void halbtc8723b1ant_retry_limit(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 type) -{ - coex_dm->cur_retry_limit_type = type; - - if (force_exec || - (coex_dm->pre_retry_limit_type != - coex_dm->cur_retry_limit_type)) { - switch (coex_dm->cur_retry_limit_type) { - case 0: /* normal mode */ - btcoexist->btc_write_2byte(btcoexist, 0x42a, - coex_dm->backup_retry_limit); - break; - case 1: /* retry limit=8 */ - btcoexist->btc_write_2byte(btcoexist, 0x42a, - 0x0808); - break; - default: - break; - } - } - - coex_dm->pre_retry_limit_type = coex_dm->cur_retry_limit_type; -} - -void halbtc8723b1ant_ampdu_max_time(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 type) -{ - coex_dm->cur_ampdu_time_type = type; - - if (force_exec || - (coex_dm->pre_ampdu_time_type != coex_dm->cur_ampdu_time_type)) { - switch (coex_dm->cur_ampdu_time_type) { - case 0: /* normal mode */ - btcoexist->btc_write_1byte(btcoexist, 0x456, - coex_dm->backup_ampdu_max_time); - break; - case 1: /* AMPDU timw = 0x38 * 32us */ - btcoexist->btc_write_1byte(btcoexist, 0x456, - 0x38); - break; - default: - break; - } - } - - coex_dm->pre_ampdu_time_type = coex_dm->cur_ampdu_time_type; -} - -void halbtc8723b1ant_limited_tx(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 ra_mask_type, IN u8 arfr_type, - IN u8 retry_limit_type, IN u8 ampdu_time_type) -{ - switch (ra_mask_type) { - case 0: /* normal mode */ - halbtc8723b1ant_update_ra_mask(btcoexist, force_exec, - 0x0); - break; - case 1: /* disable cck 1/2 */ - halbtc8723b1ant_update_ra_mask(btcoexist, force_exec, - 0x00000003); - break; - case 2: /* disable cck 1/2/5.5, ofdm 6/9/12/18/24, mcs 0/1/2/3/4 */ - halbtc8723b1ant_update_ra_mask(btcoexist, force_exec, - 0x0001f1f7); - break; - default: - break; - } - - halbtc8723b1ant_auto_rate_fallback_retry(btcoexist, force_exec, - arfr_type); - halbtc8723b1ant_retry_limit(btcoexist, force_exec, retry_limit_type); - halbtc8723b1ant_ampdu_max_time(btcoexist, force_exec, ampdu_time_type); -} - -void halbtc8723b1ant_limited_rx(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean rej_ap_agg_pkt, - IN boolean bt_ctrl_agg_buf_size, IN u8 agg_buf_size) -{ - boolean reject_rx_agg = rej_ap_agg_pkt; - boolean bt_ctrl_rx_agg_size = bt_ctrl_agg_buf_size; - u8 rx_agg_size = agg_buf_size; - - /* ============================================ */ - /* Rx Aggregation related setting */ - /* ============================================ */ - btcoexist->btc_set(btcoexist, BTC_SET_BL_TO_REJ_AP_AGG_PKT, - &reject_rx_agg); - /* decide BT control aggregation buf size or not */ - btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_CTRL_AGG_SIZE, - &bt_ctrl_rx_agg_size); - /* aggregation buf size, only work when BT control Rx aggregation size. */ - btcoexist->btc_set(btcoexist, BTC_SET_U1_AGG_BUF_SIZE, &rx_agg_size); - /* real update aggregation setting */ - btcoexist->btc_set(btcoexist, BTC_SET_ACT_AGGREGATE_CTRL, NULL); - -} - -void halbtc8723b1ant_query_bt_info(IN struct btc_coexist *btcoexist) -{ - u8 h2c_parameter[1] = {0}; - - coex_sta->c2h_bt_info_req_sent = true; - - h2c_parameter[0] |= BIT(0); /* trigger */ - - btcoexist->btc_fill_h2c(btcoexist, 0x61, 1, h2c_parameter); -} - -void halbtc8723b1ant_monitor_bt_ctr(IN struct btc_coexist *btcoexist) -{ - u32 reg_hp_txrx, reg_lp_txrx, u32tmp; - u32 reg_hp_tx = 0, reg_hp_rx = 0, reg_lp_tx = 0, reg_lp_rx = 0; - static u32 num_of_bt_counter_chk = 0; - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - - /* to avoid 0x76e[3] = 1 (WLAN_Act control by PTA) during IPS */ - /* if (! (btcoexist->btc_read_1byte(btcoexist, 0x76e) & 0x8) ) */ - - reg_hp_txrx = 0x770; - reg_lp_txrx = 0x774; - - u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_hp_txrx); - reg_hp_tx = u32tmp & MASKLWORD; - reg_hp_rx = (u32tmp & MASKHWORD) >> 16; - - u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_lp_txrx); - reg_lp_tx = u32tmp & MASKLWORD; - reg_lp_rx = (u32tmp & MASKHWORD) >> 16; - - coex_sta->high_priority_tx = reg_hp_tx; - coex_sta->high_priority_rx = reg_hp_rx; - coex_sta->low_priority_tx = reg_lp_tx; - coex_sta->low_priority_rx = reg_lp_rx; - - if ((coex_sta->high_priority_tx + coex_sta->high_priority_rx < 50) && - (bt_link_info->hid_exist == true)) - bt_link_info->hid_exist = false; - - if ((coex_sta->low_priority_tx > 1050) && - (!coex_sta->c2h_bt_inquiry_page)) - coex_sta->pop_event_cnt++; - - if ((coex_sta->low_priority_rx >= 950) && (!coex_sta->under_ips) - && (coex_sta->low_priority_rx >= - coex_sta->low_priority_tx) && - (!coex_sta->c2h_bt_inquiry_page)) - bt_link_info->slave_role = true; - else - bt_link_info->slave_role = false; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Hi-Pri Rx/Tx: %d/%d, Lo-Pri Rx/Tx: %d/%d\n", - reg_hp_rx, reg_hp_tx, reg_lp_rx, reg_lp_tx); - BTC_TRACE(trace_buf); - - /* reset counter */ - btcoexist->btc_write_1byte(btcoexist, 0x76e, 0xc); - - /* This part is for wifi FW and driver to update BT's status as disabled. */ - /* The flow is as the following */ - /* 1. disable BT */ - /* 2. if all BT Tx/Rx counter=0, after 6 sec we query bt info */ - /* 3. Because BT will not rsp from mailbox, so wifi fw will know BT is disabled */ - /* 4. FW will rsp c2h for BT that driver will know BT is disabled. */ - if ((reg_hp_tx == 0) && (reg_hp_rx == 0) && (reg_lp_tx == 0) && - (reg_lp_rx == 0)) { - num_of_bt_counter_chk++; - if (num_of_bt_counter_chk >= 3) { - halbtc8723b1ant_query_bt_info(btcoexist); - num_of_bt_counter_chk = 0; - } - } - -} - -void halbtc8723b1ant_monitor_wifi_ctr(IN struct btc_coexist *btcoexist) -{ - s32 wifi_rssi = 0; - boolean wifi_busy = false, wifi_under_b_mode = false; - static u8 cck_lock_counter = 0; - u32 total_cnt; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_B_MODE, - &wifi_under_b_mode); - -#if 1 - - coex_sta->crc_ok_cck = btcoexist->btc_phydm_query_PHY_counter( - btcoexist, - PHYDM_INFO_CRC32_OK_CCK); - coex_sta->crc_ok_11g = btcoexist->btc_phydm_query_PHY_counter( - btcoexist, - PHYDM_INFO_CRC32_OK_LEGACY); - coex_sta->crc_ok_11n = btcoexist->btc_phydm_query_PHY_counter( - btcoexist, - PHYDM_INFO_CRC32_OK_HT); - coex_sta->crc_ok_11n_vht = - btcoexist->btc_phydm_query_PHY_counter( - btcoexist, - PHYDM_INFO_CRC32_OK_VHT); - - coex_sta->crc_err_cck = btcoexist->btc_phydm_query_PHY_counter( - btcoexist, - PHYDM_INFO_CRC32_ERROR_CCK); - coex_sta->crc_err_11g = btcoexist->btc_phydm_query_PHY_counter( - btcoexist, - PHYDM_INFO_CRC32_ERROR_LEGACY); - coex_sta->crc_err_11n = btcoexist->btc_phydm_query_PHY_counter( - btcoexist, - PHYDM_INFO_CRC32_ERROR_HT); - coex_sta->crc_err_11n_vht = - btcoexist->btc_phydm_query_PHY_counter( - btcoexist, - PHYDM_INFO_CRC32_ERROR_VHT); - -#endif - - if ((wifi_busy) && (wifi_rssi >= 30) && (!wifi_under_b_mode)) { - total_cnt = coex_sta->crc_ok_cck + coex_sta->crc_ok_11g + - coex_sta->crc_ok_11n + - coex_sta->crc_ok_11n_vht; - - if ((coex_dm->bt_status == BT_8723B_1ANT_BT_STATUS_ACL_BUSY) || - (coex_dm->bt_status == - BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY) || - (coex_dm->bt_status == - BT_8723B_1ANT_BT_STATUS_SCO_BUSY)) { - if (coex_sta->crc_ok_cck > (total_cnt - - coex_sta->crc_ok_cck)) { - if (cck_lock_counter < 3) - cck_lock_counter++; - } else { - if (cck_lock_counter > 0) - cck_lock_counter--; - } - - } else { - if (cck_lock_counter > 0) - cck_lock_counter--; - } - } else { - if (cck_lock_counter > 0) - cck_lock_counter--; - } - - if (!coex_sta->pre_ccklock) { - - if (cck_lock_counter >= 3) - coex_sta->cck_lock = true; - else - coex_sta->cck_lock = false; - } else { - if (cck_lock_counter == 0) - coex_sta->cck_lock = false; - else - coex_sta->cck_lock = true; - } - - if (coex_sta->cck_lock) - coex_sta->cck_ever_lock = true; - - coex_sta->pre_ccklock = coex_sta->cck_lock; - -} - -boolean halbtc8723b1ant_is_wifi_status_changed(IN struct btc_coexist *btcoexist) -{ - static boolean pre_wifi_busy = false, pre_under_4way = false, - pre_bt_hs_on = false; - boolean wifi_busy = false, under_4way = false, bt_hs_on = false; - boolean wifi_connected = false; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS, - &under_4way); - - if (wifi_connected) { - if (wifi_busy != pre_wifi_busy) { - pre_wifi_busy = wifi_busy; - return true; - } - if (under_4way != pre_under_4way) { - pre_under_4way = under_4way; - return true; - } - if (bt_hs_on != pre_bt_hs_on) { - pre_bt_hs_on = bt_hs_on; - return true; - } - - } - - return false; -} - -void halbtc8723b1ant_monitor_bt_enable_disable(IN struct btc_coexist *btcoexist) -{ - static u32 bt_disable_cnt = 0; - boolean bt_active = true, bt_disabled = false, bt_change = false; - - /* This function check if bt is disabled */ - - if (coex_sta->high_priority_tx == 0 && - coex_sta->high_priority_rx == 0 && - coex_sta->low_priority_tx == 0 && - coex_sta->low_priority_rx == 0) - bt_active = false; - if (coex_sta->high_priority_tx == 0xffff && - coex_sta->high_priority_rx == 0xffff && - coex_sta->low_priority_tx == 0xffff && - coex_sta->low_priority_rx == 0xffff) - bt_active = false; - if (bt_active) { - bt_disable_cnt = 0; - bt_disabled = false; - } else { - bt_disable_cnt++; - if (bt_disable_cnt >= 10) - bt_disabled = true; - } - if (coex_sta->bt_disabled != bt_disabled) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT is from %s to %s!!\n", - (coex_sta->bt_disabled ? "disabled" : "enabled"), - (bt_disabled ? "disabled" : "enabled")); - BTC_TRACE(trace_buf); - bt_change = true; - - btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_DISABLE, - &bt_disabled); - - btcoexist->btc_set(btcoexist, - BTC_SET_BL_BT_ENABLE_DISABLE_CHANGE, - &bt_change); - - coex_sta->bt_disabled = bt_disabled; - } else { - btcoexist->btc_set(btcoexist, - BTC_SET_BL_BT_ENABLE_DISABLE_CHANGE, - &bt_change); - } -} - -void halbtc8723b1ant_update_bt_link_info(IN struct btc_coexist *btcoexist) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - boolean bt_hs_on = false; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); - - bt_link_info->bt_link_exist = coex_sta->bt_link_exist; - bt_link_info->sco_exist = coex_sta->sco_exist; - bt_link_info->a2dp_exist = coex_sta->a2dp_exist; - bt_link_info->pan_exist = coex_sta->pan_exist; - bt_link_info->hid_exist = coex_sta->hid_exist; - bt_link_info->bt_hi_pri_link_exist = coex_sta->bt_hi_pri_link_exist; - - /* work around for HS mode. */ - if (bt_hs_on) { - bt_link_info->pan_exist = true; - bt_link_info->bt_link_exist = true; - } - - /* check if Sco only */ - if (bt_link_info->sco_exist && - !bt_link_info->a2dp_exist && - !bt_link_info->pan_exist && - !bt_link_info->hid_exist) - bt_link_info->sco_only = true; - else - bt_link_info->sco_only = false; - - /* check if A2dp only */ - if (!bt_link_info->sco_exist && - bt_link_info->a2dp_exist && - !bt_link_info->pan_exist && - !bt_link_info->hid_exist) - bt_link_info->a2dp_only = true; - else - bt_link_info->a2dp_only = false; - - /* check if Pan only */ - if (!bt_link_info->sco_exist && - !bt_link_info->a2dp_exist && - bt_link_info->pan_exist && - !bt_link_info->hid_exist) - bt_link_info->pan_only = true; - else - bt_link_info->pan_only = false; - - /* check if Hid only */ - if (!bt_link_info->sco_exist && - !bt_link_info->a2dp_exist && - !bt_link_info->pan_exist && - bt_link_info->hid_exist) - bt_link_info->hid_only = true; - else - bt_link_info->hid_only = false; -} - -void halbtc8723b1ant_set_bt_auto_report(IN struct btc_coexist *btcoexist, - IN boolean enable_auto_report) -{ - u8 h2c_parameter[1] = {0}; - - h2c_parameter[0] = 0; - - if (enable_auto_report) - h2c_parameter[0] |= BIT(0); - - btcoexist->btc_fill_h2c(btcoexist, 0x68, 1, h2c_parameter); -} - -void halbtc8723b1ant_bt_auto_report(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean enable_auto_report) -{ - coex_dm->cur_bt_auto_report = enable_auto_report; - - if (!force_exec) { - if (coex_dm->pre_bt_auto_report == coex_dm->cur_bt_auto_report) - return; - } - halbtc8723b1ant_set_bt_auto_report(btcoexist, - coex_dm->cur_bt_auto_report); - - coex_dm->pre_bt_auto_report = coex_dm->cur_bt_auto_report; -} - -void halbtc8723b1ant_set_sw_penalty_tx_rate_adaptive(IN struct btc_coexist - *btcoexist, IN boolean low_penalty_ra) -{ - u8 h2c_parameter[6] = {0}; - - h2c_parameter[0] = 0x6; /* op_code, 0x6= Retry_Penalty */ - - if (low_penalty_ra) { - h2c_parameter[1] |= BIT(0); - h2c_parameter[2] = - 0x00; /* normal rate except MCS7/6/5, OFDM54/48/36 */ - h2c_parameter[3] = 0xf7; /* MCS7 or OFDM54 */ - h2c_parameter[4] = 0xf8; /* MCS6 or OFDM48 */ - h2c_parameter[5] = 0xf9; /* MCS5 or OFDM36 */ - } - - btcoexist->btc_fill_h2c(btcoexist, 0x69, 6, h2c_parameter); -} - -void halbtc8723b1ant_low_penalty_ra(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean low_penalty_ra) -{ - coex_dm->cur_low_penalty_ra = low_penalty_ra; - - if (!force_exec) { - if (coex_dm->pre_low_penalty_ra == coex_dm->cur_low_penalty_ra) - return; - } - halbtc8723b1ant_set_sw_penalty_tx_rate_adaptive(btcoexist, - coex_dm->cur_low_penalty_ra); - - coex_dm->pre_low_penalty_ra = coex_dm->cur_low_penalty_ra; -} - -void halbtc8723b1ant_sw_mechanism(IN struct btc_coexist *btcoexist, - IN boolean low_penalty_ra) -{ - halbtc8723b1ant_low_penalty_ra(btcoexist, NORMAL_EXEC, low_penalty_ra); -} - -void halbtc8723b1ant_set_coex_table(IN struct btc_coexist *btcoexist, - IN u32 val0x6c0, IN u32 val0x6c4, IN u32 val0x6c8, IN u8 val0x6cc) -{ - btcoexist->btc_write_4byte(btcoexist, 0x6c0, val0x6c0); - - btcoexist->btc_write_4byte(btcoexist, 0x6c4, val0x6c4); - - btcoexist->btc_write_4byte(btcoexist, 0x6c8, val0x6c8); - - btcoexist->btc_write_1byte(btcoexist, 0x6cc, val0x6cc); -} - -void halbtc8723b1ant_coex_table(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u32 val0x6c0, IN u32 val0x6c4, - IN u32 val0x6c8, IN u8 val0x6cc) -{ - coex_dm->cur_val0x6c0 = val0x6c0; - coex_dm->cur_val0x6c4 = val0x6c4; - coex_dm->cur_val0x6c8 = val0x6c8; - coex_dm->cur_val0x6cc = val0x6cc; - - if (!force_exec) { - if ((coex_dm->pre_val0x6c0 == coex_dm->cur_val0x6c0) && - (coex_dm->pre_val0x6c4 == coex_dm->cur_val0x6c4) && - (coex_dm->pre_val0x6c8 == coex_dm->cur_val0x6c8) && - (coex_dm->pre_val0x6cc == coex_dm->cur_val0x6cc)) - return; - } - halbtc8723b1ant_set_coex_table(btcoexist, val0x6c0, val0x6c4, val0x6c8, - val0x6cc); - - coex_dm->pre_val0x6c0 = coex_dm->cur_val0x6c0; - coex_dm->pre_val0x6c4 = coex_dm->cur_val0x6c4; - coex_dm->pre_val0x6c8 = coex_dm->cur_val0x6c8; - coex_dm->pre_val0x6cc = coex_dm->cur_val0x6cc; -} - -void halbtc8723b1ant_coex_table_with_type(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 type) -{ - struct btc_board_info *board_info = &btcoexist->board_info; - -#if BT_8723B_1ANT_ANTDET_ENABLE -#if BT_8723B_1ANT_ANTDET_COEXMECHANISMSWITCH_ENABLE - if (board_info->btdm_ant_num_by_ant_det == 2) { - if (type == 3) - type = 14; - else if (type == 4) - type = 13; - else if (type == 5) - type = 8; - } -#endif -#endif - - coex_sta->coex_table_type = type; - - switch (type) { - case 0: - halbtc8723b1ant_coex_table(btcoexist, force_exec, - 0x55555555, 0x55555555, 0xffffff, 0x3); - break; - case 1: - halbtc8723b1ant_coex_table(btcoexist, force_exec, - 0x55555555, 0x5a5a5a5a, 0xffffff, 0x3); - break; - case 2: - halbtc8723b1ant_coex_table(btcoexist, force_exec, - 0x5a5a5a5a, 0x5a5a5a5a, 0xffffff, 0x3); - break; - case 3: - halbtc8723b1ant_coex_table(btcoexist, force_exec, - 0x55555555, 0x5a5a5a5a, 0xffffff, 0x3); - break; - case 4: - if ((coex_sta->cck_ever_lock) && - (coex_sta->scan_ap_num <= 5)) - halbtc8723b1ant_coex_table(btcoexist, - force_exec, 0x55555555, 0xaaaa5a5a, - 0xffffff, 0x3); - else - halbtc8723b1ant_coex_table(btcoexist, - force_exec, 0x55555555, 0x5a5a5a5a, - 0xffffff, 0x3); - break; - case 5: - if ((coex_sta->cck_ever_lock) && - (coex_sta->scan_ap_num <= 5)) - halbtc8723b1ant_coex_table(btcoexist, - force_exec, 0x5a5a5a5a, 0x5aaa5a5a, - 0xffffff, 0x3); - else - halbtc8723b1ant_coex_table(btcoexist, - force_exec, 0x5a5a5a5a, 0x5aaa5a5a, - 0xffffff, 0x3); - break; - case 6: - halbtc8723b1ant_coex_table(btcoexist, force_exec, - 0x55555555, 0xaaaaaaaa, 0xffffff, 0x3); - break; - case 7: - halbtc8723b1ant_coex_table(btcoexist, force_exec, - 0xaaaaaaaa, 0xaaaaaaaa, 0xffffff, 0x3); - break; - case 8: - halbtc8723b1ant_coex_table(btcoexist, force_exec, - 0x55dd55dd, 0x5ada5ada, 0xffffff, 0x3); - break; - case 9: - halbtc8723b1ant_coex_table(btcoexist, force_exec, - 0x55dd55dd, 0x5ada5ada, 0xffffff, 0x3); - break; - case 10: - halbtc8723b1ant_coex_table(btcoexist, force_exec, - 0x55dd55dd, 0x5ada5ada, 0xffffff, 0x3); - break; - case 11: - halbtc8723b1ant_coex_table(btcoexist, force_exec, - 0x55dd55dd, 0x5ada5ada, 0xffffff, 0x3); - break; - case 12: - halbtc8723b1ant_coex_table(btcoexist, force_exec, - 0x55dd55dd, 0x5ada5ada, 0xffffff, 0x3); - break; - case 13: - halbtc8723b1ant_coex_table(btcoexist, force_exec, - 0x5fff5fff, 0xaaaaaaaa, 0xffffff, 0x3); - break; - case 14: - halbtc8723b1ant_coex_table(btcoexist, force_exec, - 0x5fff5fff, 0x5ada5ada, 0xffffff, 0x3); - break; - case 15: - halbtc8723b1ant_coex_table(btcoexist, force_exec, - 0x55dd55dd, 0xaaaaaaaa, 0xffffff, 0x3); - break; - default: - break; - } -} - -void halbtc8723b1ant_set_fw_ignore_wlan_act(IN struct btc_coexist *btcoexist, - IN boolean enable) -{ - u8 h2c_parameter[1] = {0}; - - if (enable) - h2c_parameter[0] |= BIT(0); /* function enable */ - - btcoexist->btc_fill_h2c(btcoexist, 0x63, 1, h2c_parameter); -} - -void halbtc8723b1ant_ignore_wlan_act(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean enable) -{ - coex_dm->cur_ignore_wlan_act = enable; - - if (!force_exec) { - if (coex_dm->pre_ignore_wlan_act == - coex_dm->cur_ignore_wlan_act) - return; - } - halbtc8723b1ant_set_fw_ignore_wlan_act(btcoexist, enable); - - coex_dm->pre_ignore_wlan_act = coex_dm->cur_ignore_wlan_act; -} - -void halbtc8723b1ant_set_lps_rpwm(IN struct btc_coexist *btcoexist, - IN u8 lps_val, IN u8 rpwm_val) -{ - u8 lps = lps_val; - u8 rpwm = rpwm_val; - - btcoexist->btc_set(btcoexist, BTC_SET_U1_LPS_VAL, &lps); - btcoexist->btc_set(btcoexist, BTC_SET_U1_RPWM_VAL, &rpwm); -} - -void halbtc8723b1ant_lps_rpwm(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 lps_val, IN u8 rpwm_val) -{ - coex_dm->cur_lps = lps_val; - coex_dm->cur_rpwm = rpwm_val; - - if (!force_exec) { - if ((coex_dm->pre_lps == coex_dm->cur_lps) && - (coex_dm->pre_rpwm == coex_dm->cur_rpwm)) - return; - } - halbtc8723b1ant_set_lps_rpwm(btcoexist, lps_val, rpwm_val); - - coex_dm->pre_lps = coex_dm->cur_lps; - coex_dm->pre_rpwm = coex_dm->cur_rpwm; -} - -void halbtc8723b1ant_set_ant_path(IN struct btc_coexist *btcoexist, - IN u8 ant_pos_type, IN boolean force_exec, IN boolean init_hwcfg, - IN boolean wifi_off) -{ - struct btc_board_info *board_info = &btcoexist->board_info; - u32 fw_ver = 0, u32tmp = 0, cnt_bt_cal_chk = 0; - boolean pg_ext_switch = false; - boolean use_ext_switch = false; - boolean is_in_mp_mode = false; - u8 h2c_parameter[2] = {0}, u8tmp = 0; - u32 u32tmp_1[4]; - boolean is_fw_ready; - - coex_dm->cur_ant_pos_type = ant_pos_type; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_EXT_SWITCH, &pg_ext_switch); - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, - &fw_ver); /* [31:16]=fw ver, [15:0]=fw sub ver */ - - if ((fw_ver > 0 && fw_ver < 0xc0000) || pg_ext_switch) - use_ext_switch = true; - -#if BT_8723B_1ANT_ANTDET_ENABLE -#if BT_8723B_1ANT_ANTDET_COEXMECHANISMSWITCH_ENABLE - if (ant_pos_type == BTC_ANT_PATH_PTA) { - if ((board_info->btdm_ant_det_finish) && - (board_info->btdm_ant_num_by_ant_det == 2)) { - if (board_info->btdm_ant_pos == - BTC_ANTENNA_AT_MAIN_PORT) - ant_pos_type = BTC_ANT_PATH_WIFI; - else - ant_pos_type = BTC_ANT_PATH_BT; - } - } -#endif -#endif - - if (init_hwcfg) { - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, - 0x780); /* WiFi TRx Mask on */ - /* remove due to interrupt is disabled that polling c2h will fail and delay 100ms. */ - /* btcoexist->btc_set_bt_reg(btcoexist, BTC_BT_REG_RF, 0x3c, 0x15); */ /*BT TRx Mask on */ - - if (fw_ver >= 0x180000) { - /* Use H2C to set GNT_BT to HIGH */ - h2c_parameter[0] = 1; - btcoexist->btc_fill_h2c(btcoexist, 0x6E, 1, - h2c_parameter); - - cnt_bt_cal_chk = 0; - while (1) { - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_FW_READY, &is_fw_ready); - if (is_fw_ready == false) { - BTC_SPRINTF(trace_buf , BT_TMP_BUF_SIZE, - ("halbtc8723b1ant_set_ant_path(): we don't need to wait for H2C command completion because of Fw download fail!!!\n")); - BTC_TRACE(trace_buf); - break; - } - - if (btcoexist->btc_read_1byte(btcoexist, - 0x765) == 0x18) - break; - - cnt_bt_cal_chk++; - if (cnt_bt_cal_chk > 20) - break; - } - } else { - /* set grant_bt to high */ - btcoexist->btc_write_1byte(btcoexist, 0x765, 0x18); - } - /* set wlan_act control by PTA */ - btcoexist->btc_write_1byte(btcoexist, 0x76e, 0x4); - - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, 0x20, - 0x0); /* BT select s0/s1 is controlled by BT */ - - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x39, 0x8, 0x1); - btcoexist->btc_write_1byte(btcoexist, 0x974, 0xff); - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x944, 0x3, 0x3); - btcoexist->btc_write_1byte(btcoexist, 0x930, 0x77); - } else if (wifi_off) { - if (fw_ver >= 0x180000) { - /* Use H2C to set GNT_BT to HIGH */ - h2c_parameter[0] = 1; - btcoexist->btc_fill_h2c(btcoexist, 0x6E, 1, - h2c_parameter); - - cnt_bt_cal_chk = 0; - while (1) { - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_FW_READY, &is_fw_ready); - if (is_fw_ready == false) { - BTC_SPRINTF(trace_buf , BT_TMP_BUF_SIZE, - ("halbtc8723b1ant_set_ant_path(): we don't need to wait for H2C command completion because of Fw download fail!!!\n")); - BTC_TRACE(trace_buf); - break; - } - - if (btcoexist->btc_read_1byte(btcoexist, - 0x765) == 0x18) - break; - - cnt_bt_cal_chk++; - if (cnt_bt_cal_chk > 20) - break; - } - } else { - /* set grant_bt to high */ - btcoexist->btc_write_1byte(btcoexist, 0x765, 0x18); - } - /* set wlan_act to always low */ - btcoexist->btc_write_1byte(btcoexist, 0x76e, 0x4); - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_IS_IN_MP_MODE, - &is_in_mp_mode); - if (!is_in_mp_mode) - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, - 0x20, 0x0); /* BT select s0/s1 is controlled by BT */ - else - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, - 0x20, 0x1); /* BT select s0/s1 is controlled by WiFi */ - - /* 0x4c[24:23]=00, Set Antenna control by BT_RFE_CTRL BT Vendor 0xac=0xf002 */ - u32tmp = btcoexist->btc_read_4byte(btcoexist, 0x4c); - u32tmp &= ~BIT(23); - u32tmp &= ~BIT(24); - btcoexist->btc_write_4byte(btcoexist, 0x4c, u32tmp); - } else { - /* Use H2C to set GNT_BT to LOW */ - if (fw_ver >= 0x180000) { - if (btcoexist->btc_read_1byte(btcoexist, 0x765) != 0) { - h2c_parameter[0] = 0; - btcoexist->btc_fill_h2c(btcoexist, 0x6E, 1, - h2c_parameter); - - cnt_bt_cal_chk = 0; - while (1) { - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_FW_READY, &is_fw_ready); - if (is_fw_ready == false) { - BTC_SPRINTF(trace_buf , - BT_TMP_BUF_SIZE, - ("halbtc8723b1ant_set_ant_path(): we don't need to wait for H2C command completion because of Fw download fail!!!\n")); - BTC_TRACE(trace_buf); - break; - } - - if (btcoexist->btc_read_1byte(btcoexist, - 0x765) == 0x0) - break; - - cnt_bt_cal_chk++; - if (cnt_bt_cal_chk > 20) - break; - } - } - } else { - /* BT calibration check */ - while (cnt_bt_cal_chk <= 20) { - u8tmp = btcoexist->btc_read_1byte(btcoexist, - 0x49d); - cnt_bt_cal_chk++; - if (u8tmp & BIT(0)) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ########### BT is calibrating (wait cnt=%d) ###########\n", - cnt_bt_cal_chk); - BTC_TRACE(trace_buf); - delay_ms(50); - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** BT is NOT calibrating (wait cnt=%d)**********\n", - cnt_bt_cal_chk); - BTC_TRACE(trace_buf); - break; - } - } - - /* set grant_bt to PTA */ - btcoexist->btc_write_1byte(btcoexist, 0x765, 0x0); - } - - if (btcoexist->btc_read_1byte(btcoexist, 0x76e) != 0xc) { - /* set wlan_act control by PTA */ - btcoexist->btc_write_1byte(btcoexist, 0x76e, 0xc); - } - - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, 0x20, - 0x1); /* BT select s0/s1 is controlled by WiFi */ - } - - if (use_ext_switch) { - if (init_hwcfg) { - /* 0x4c[23]=0, 0x4c[24]=1 Antenna control by WL/BT */ - u32tmp = btcoexist->btc_read_4byte(btcoexist, 0x4c); - u32tmp &= ~BIT(23); - u32tmp |= BIT(24); - btcoexist->btc_write_4byte(btcoexist, 0x4c, u32tmp); - - u32tmp_1[0] = btcoexist->btc_read_4byte(btcoexist, - 0x948); - if ((u32tmp_1[0] == 0x40) || (u32tmp_1[0] == 0x240)) - btcoexist->btc_write_4byte(btcoexist, 0x948, - u32tmp_1[0]); - else - btcoexist->btc_write_4byte(btcoexist, 0x948, - 0x0); - - if (board_info->btdm_ant_pos == - BTC_ANTENNA_AT_MAIN_PORT) { - /* tell firmware "no antenna inverse" */ - h2c_parameter[0] = 0; - h2c_parameter[1] = 1; /* ext switch type */ - btcoexist->btc_fill_h2c(btcoexist, 0x65, 2, - h2c_parameter); - } else { - /* tell firmware "antenna inverse" */ - h2c_parameter[0] = 1; - h2c_parameter[1] = 1; /* ext switch type */ - btcoexist->btc_fill_h2c(btcoexist, 0x65, 2, - h2c_parameter); - } - } - - if (force_exec || - (coex_dm->cur_ant_pos_type != - coex_dm->pre_ant_pos_type)) { - /* ext switch setting */ - switch (ant_pos_type) { - case BTC_ANT_PATH_WIFI: - if (board_info->btdm_ant_pos == - BTC_ANTENNA_AT_MAIN_PORT) - btcoexist->btc_write_1byte_bitmask( - btcoexist, 0x92c, 0x3, - 0x1); - else - btcoexist->btc_write_1byte_bitmask( - btcoexist, 0x92c, 0x3, - 0x2); - break; - case BTC_ANT_PATH_BT: - if (board_info->btdm_ant_pos == - BTC_ANTENNA_AT_MAIN_PORT) - btcoexist->btc_write_1byte_bitmask( - btcoexist, 0x92c, 0x3, - 0x2); - else - btcoexist->btc_write_1byte_bitmask( - btcoexist, 0x92c, 0x3, - 0x1); - break; - default: - case BTC_ANT_PATH_PTA: - if (board_info->btdm_ant_pos == - BTC_ANTENNA_AT_MAIN_PORT) - btcoexist->btc_write_1byte_bitmask( - btcoexist, 0x92c, 0x3, - 0x1); - else - btcoexist->btc_write_1byte_bitmask( - btcoexist, 0x92c, 0x3, - 0x2); - break; - } - } - } else { - if (init_hwcfg) { - /* 0x4c[23]=1, 0x4c[24]=0 Antenna control by 0x64 */ - u32tmp = btcoexist->btc_read_4byte(btcoexist, 0x4c); - u32tmp |= BIT(23); - u32tmp &= ~BIT(24); - btcoexist->btc_write_4byte(btcoexist, 0x4c, u32tmp); - - /* Fix Ext switch Main->S1, Aux->S0 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x64, 0x1, - 0x0); - - if (board_info->btdm_ant_pos == - BTC_ANTENNA_AT_MAIN_PORT) { - - /* tell firmware "no antenna inverse" */ - h2c_parameter[0] = 0; - h2c_parameter[1] = - 0; /* internal switch type */ - btcoexist->btc_fill_h2c(btcoexist, 0x65, 2, - h2c_parameter); - } else { - - /* tell firmware "antenna inverse" */ - h2c_parameter[0] = 1; - h2c_parameter[1] = - 0; /* internal switch type */ - btcoexist->btc_fill_h2c(btcoexist, 0x65, 2, - h2c_parameter); - } - } - - if (force_exec || - (coex_dm->cur_ant_pos_type != - coex_dm->pre_ant_pos_type)) { - /* internal switch setting */ - switch (ant_pos_type) { - case BTC_ANT_PATH_WIFI: - if (board_info->btdm_ant_pos == - BTC_ANTENNA_AT_MAIN_PORT) { - u32tmp_1[0] = btcoexist->btc_read_4byte( - btcoexist, 0x948); - if ((u32tmp_1[0] == 0x40) || - (u32tmp_1[0] == 0x240)) - btcoexist->btc_write_4byte( - btcoexist, 0x948, - u32tmp_1[0]); - else - btcoexist->btc_write_4byte( - btcoexist, 0x948, 0x0); - } else { - u32tmp_1[0] = btcoexist->btc_read_4byte( - btcoexist, 0x948); - if ((u32tmp_1[0] == 0x40) || - (u32tmp_1[0] == 0x240)) - btcoexist->btc_write_4byte( - btcoexist, 0x948, - u32tmp_1[0]); - else - btcoexist->btc_write_4byte( - btcoexist, 0x948, - 0x280); - } - break; - case BTC_ANT_PATH_BT: - if (board_info->btdm_ant_pos == - BTC_ANTENNA_AT_MAIN_PORT) { - u32tmp_1[0] = btcoexist->btc_read_4byte( - btcoexist, 0x948); - if ((u32tmp_1[0] == 0x40) || - (u32tmp_1[0] == 0x240)) - btcoexist->btc_write_4byte( - btcoexist, 0x948, - u32tmp_1[0]); - else - btcoexist->btc_write_4byte( - btcoexist, 0x948, - 0x280); - } else { - u32tmp_1[0] = btcoexist->btc_read_4byte( - btcoexist, 0x948); - if ((u32tmp_1[0] == 0x40) || - (u32tmp_1[0] == 0x240)) - btcoexist->btc_write_4byte( - btcoexist, 0x948, - u32tmp_1[0]); - else - btcoexist->btc_write_4byte( - btcoexist, 0x948, 0x0); - } - break; - default: - case BTC_ANT_PATH_PTA: - if (board_info->btdm_ant_pos == - BTC_ANTENNA_AT_MAIN_PORT) - btcoexist->btc_write_4byte( - btcoexist, 0x948, - 0x200); - else - btcoexist->btc_write_4byte( - btcoexist, 0x948, 0x80); - break; - } - } - } - - coex_dm->pre_ant_pos_type = coex_dm->cur_ant_pos_type; -} - -void halbtc8723b1ant_ps_tdma_check_for_power_save_state( - IN struct btc_coexist *btcoexist, IN boolean new_ps_state) -{ - u8 lps_mode = 0x0; - u8 h2c_parameter[5] = {0x8, 0, 0, 0, 0}; - - btcoexist->btc_get(btcoexist, BTC_GET_U1_LPS_MODE, &lps_mode); - - if (lps_mode) { /* already under LPS state */ - if (new_ps_state) { - /* keep state under LPS, do nothing. */ - } else { - /* will leave LPS state, turn off psTdma first */ - /* halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, - 8); */ - btcoexist->btc_fill_h2c(btcoexist, 0x60, 5, - h2c_parameter); - } - } else { /* NO PS state */ - if (new_ps_state) { - /* will enter LPS state, turn off psTdma first */ - /* halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, - 8); */ - btcoexist->btc_fill_h2c(btcoexist, 0x60, 5, - h2c_parameter); - } else { - /* keep state under NO PS state, do nothing. */ - } - } -} - -void halbtc8723b1ant_power_save_state(IN struct btc_coexist *btcoexist, - IN u8 ps_type, IN u8 lps_val, IN u8 rpwm_val) -{ - boolean low_pwr_disable = false; - - switch (ps_type) { - case BTC_PS_WIFI_NATIVE: - /* recover to original 32k low power setting */ - low_pwr_disable = false; - btcoexist->btc_set(btcoexist, - BTC_SET_ACT_DISABLE_LOW_POWER, - &low_pwr_disable); - btcoexist->btc_set(btcoexist, BTC_SET_ACT_NORMAL_LPS, - NULL); - coex_sta->force_lps_on = false; - break; - case BTC_PS_LPS_ON: - halbtc8723b1ant_ps_tdma_check_for_power_save_state( - btcoexist, true); - halbtc8723b1ant_lps_rpwm(btcoexist, NORMAL_EXEC, - lps_val, rpwm_val); - /* when coex force to enter LPS, do not enter 32k low power. */ - low_pwr_disable = true; - btcoexist->btc_set(btcoexist, - BTC_SET_ACT_DISABLE_LOW_POWER, - &low_pwr_disable); - /* power save must executed before psTdma. */ - btcoexist->btc_set(btcoexist, BTC_SET_ACT_ENTER_LPS, - NULL); - coex_sta->force_lps_on = true; - break; - case BTC_PS_LPS_OFF: - halbtc8723b1ant_ps_tdma_check_for_power_save_state( - btcoexist, false); - btcoexist->btc_set(btcoexist, BTC_SET_ACT_LEAVE_LPS, - NULL); - coex_sta->force_lps_on = false; - break; - default: - break; - } -} - -void halbtc8723b1ant_set_fw_pstdma(IN struct btc_coexist *btcoexist, - IN u8 byte1, IN u8 byte2, IN u8 byte3, IN u8 byte4, IN u8 byte5) -{ - u8 h2c_parameter[5] = {0}; - u8 real_byte1 = byte1, real_byte5 = byte5; - boolean ap_enable = false; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, - &ap_enable); - - if (ap_enable) { - if (byte1 & BIT(4) && !(byte1 & BIT(5))) { - real_byte1 &= ~BIT(4); - real_byte1 |= BIT(5); - - real_byte5 |= BIT(5); - real_byte5 &= ~BIT(6); - - halbtc8723b1ant_power_save_state(btcoexist, - BTC_PS_WIFI_NATIVE, 0x0, 0x0); - } - } else if (byte1 & BIT(4) && !(byte1 & BIT(5))) { - halbtc8723b1ant_power_save_state(btcoexist, - BTC_PS_LPS_ON, 0x50, 0x4); - - } else { - halbtc8723b1ant_power_save_state(btcoexist, - BTC_PS_WIFI_NATIVE, 0x0, 0x0); - } - - h2c_parameter[0] = real_byte1; - h2c_parameter[1] = byte2; - h2c_parameter[2] = byte3; - h2c_parameter[3] = byte4; - h2c_parameter[4] = real_byte5; - - coex_dm->ps_tdma_para[0] = real_byte1; - coex_dm->ps_tdma_para[1] = byte2; - coex_dm->ps_tdma_para[2] = byte3; - coex_dm->ps_tdma_para[3] = byte4; - coex_dm->ps_tdma_para[4] = real_byte5; - - btcoexist->btc_fill_h2c(btcoexist, 0x60, 5, h2c_parameter); -} - -void halbtc8723b1ant_ps_tdma(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean turn_on, IN u8 type) -{ - struct btc_board_info *board_info = &btcoexist->board_info; - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - boolean wifi_busy = false; - u8 rssi_adjust_val = 0; - u8 ps_tdma_byte4_val = 0x50, ps_tdma_byte0_val = 0x51, - ps_tdma_byte3_val = 0x10; - s8 wifi_duration_adjust = 0x0; - static boolean pre_wifi_busy = false; - - coex_dm->cur_ps_tdma_on = turn_on; - coex_dm->cur_ps_tdma = type; - -#if BT_8723B_1ANT_ANTDET_ENABLE -#if BT_8723B_1ANT_ANTDET_COEXMECHANISMSWITCH_ENABLE - if (board_info->btdm_ant_num_by_ant_det == 2) { - if (turn_on) - type = type + - 100; /* for WiFi RSSI low or BT RSSI low */ - else - type = 1; /* always translate to TDMA(off,1) for TDMA-off case */ - } - -#endif -#endif - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - - if (wifi_busy != pre_wifi_busy) { - force_exec = true; - pre_wifi_busy = wifi_busy; - } - - if (!force_exec) { - if ((coex_dm->pre_ps_tdma_on == coex_dm->cur_ps_tdma_on) && - (coex_dm->pre_ps_tdma == coex_dm->cur_ps_tdma)) - return; - } - - if (coex_sta->scan_ap_num <= 5) { - wifi_duration_adjust = 5; - - if (coex_sta->a2dp_bit_pool >= 35) - wifi_duration_adjust = -10; - else if (coex_sta->a2dp_bit_pool >= 45) - wifi_duration_adjust = -15; - } else if (coex_sta->scan_ap_num >= 40) { - wifi_duration_adjust = -15; - - if (coex_sta->a2dp_bit_pool < 35) - wifi_duration_adjust = -5; - else if (coex_sta->a2dp_bit_pool < 45) - wifi_duration_adjust = -10; - } else if (coex_sta->scan_ap_num >= 20) { - wifi_duration_adjust = -10; - - if (coex_sta->a2dp_bit_pool >= 45) - wifi_duration_adjust = -15; - } else { - wifi_duration_adjust = 0; - - if (coex_sta->a2dp_bit_pool >= 35) - wifi_duration_adjust = -10; - else if (coex_sta->a2dp_bit_pool >= 45) - wifi_duration_adjust = -15; - } - - if ((type == 1) || (type == 2) || (type == 9) || (type == 11) || - (type == 101) - || (type == 102) || (type == 109) || (type == 101)) { - if (!coex_sta->force_lps_on) { /* Native power save TDMA, only for A2DP-only case 1/2/9/11 while wifi noisy threshold > 30 */ - ps_tdma_byte0_val = 0x61; /* no null-pkt */ - ps_tdma_byte3_val = 0x11; /* no tx-pause at BT-slot */ - ps_tdma_byte4_val = - 0x10; /* 0x778 = d/1 toggle, no dynamic slot */ - } else { - ps_tdma_byte0_val = 0x51; /* null-pkt */ - ps_tdma_byte3_val = 0x10; /* tx-pause at BT-slot */ - ps_tdma_byte4_val = - 0x50; /* 0x778 = d/1 toggle, dynamic slot */ - } - } else if ((type == 3) || (type == 13) || (type == 14) || - (type == 103) || (type == 113) || (type == 114)) { - ps_tdma_byte0_val = 0x51; /* null-pkt */ - ps_tdma_byte3_val = 0x10; /* tx-pause at BT-slot */ - ps_tdma_byte4_val = - 0x10; /* 0x778 = d/1 toggle, no dynamic slot */ - } else { /* native power save case */ - ps_tdma_byte0_val = 0x61; /* no null-pkt */ - ps_tdma_byte3_val = 0x11; /* no tx-pause at BT-slot */ - ps_tdma_byte4_val = - 0x11; /* 0x778 = d/1 toggle, no dynamic slot */ - /* psTdmaByte4Va is not defne for 0x778 = d/1, 1/1 case */ - } - - /* if (bt_link_info->slave_role == true) */ - if ((bt_link_info->slave_role == true) && (bt_link_info->a2dp_exist)) - ps_tdma_byte4_val = ps_tdma_byte4_val | - 0x1; /* 0x778 = 0x1 at wifi slot (no blocking BT Low-Pri pkts) */ - - if (type > 100) { - ps_tdma_byte0_val = ps_tdma_byte0_val | - 0x82; /* set antenna control by SW */ - ps_tdma_byte3_val = ps_tdma_byte3_val | - 0x60; /* set antenna no toggle, control by antenna diversity */ - } - - if (turn_on) { - switch (type) { - default: - halbtc8723b1ant_set_fw_pstdma(btcoexist, 0x51, - 0x1a, 0x1a, 0x0, ps_tdma_byte4_val); - break; - case 1: - halbtc8723b1ant_set_fw_pstdma(btcoexist, - ps_tdma_byte0_val, 0x3a + - wifi_duration_adjust, 0x03, - ps_tdma_byte3_val, ps_tdma_byte4_val); - break; - case 2: - halbtc8723b1ant_set_fw_pstdma(btcoexist, - ps_tdma_byte0_val, 0x2d + - wifi_duration_adjust, 0x03, - ps_tdma_byte3_val, ps_tdma_byte4_val); - break; - case 3: - halbtc8723b1ant_set_fw_pstdma(btcoexist, - ps_tdma_byte0_val, 0x30, 0x03, - ps_tdma_byte3_val, ps_tdma_byte4_val); - break; - case 4: - halbtc8723b1ant_set_fw_pstdma(btcoexist, 0x93, - 0x15, 0x3, 0x14, 0x0); - break; - case 5: - halbtc8723b1ant_set_fw_pstdma(btcoexist, - ps_tdma_byte0_val, 0x1f, 0x3, - ps_tdma_byte3_val, 0x11); - break; - case 6: - halbtc8723b1ant_set_fw_pstdma(btcoexist, - ps_tdma_byte0_val, 0x20, 0x3, - ps_tdma_byte3_val, 0x11); - break; - case 7: - halbtc8723b1ant_set_fw_pstdma(btcoexist, 0x13, - 0xc, 0x5, 0x0, 0x0); - break; - case 8: - halbtc8723b1ant_set_fw_pstdma(btcoexist, 0x93, - 0x25, 0x3, 0x10, 0x0); - break; - case 9: - halbtc8723b1ant_set_fw_pstdma(btcoexist, - ps_tdma_byte0_val, 0x21, 0x3, - ps_tdma_byte3_val, ps_tdma_byte4_val); - break; - case 10: - halbtc8723b1ant_set_fw_pstdma(btcoexist, 0x13, - 0xa, 0xa, 0x0, 0x40); - break; - case 11: - halbtc8723b1ant_set_fw_pstdma(btcoexist, - ps_tdma_byte0_val, 0x21, 0x03, - ps_tdma_byte3_val, ps_tdma_byte4_val); - break; - case 12: - halbtc8723b1ant_set_fw_pstdma(btcoexist, 0x51, - 0x0a, 0x0a, 0x0, 0x50); - break; - case 13: - if (coex_sta->scan_ap_num <= 3) - halbtc8723b1ant_set_fw_pstdma(btcoexist, - ps_tdma_byte0_val, 0x40, 0x3, - ps_tdma_byte3_val, - ps_tdma_byte4_val); - else - halbtc8723b1ant_set_fw_pstdma(btcoexist, - ps_tdma_byte0_val, 0x21, 0x3, - ps_tdma_byte3_val, - ps_tdma_byte4_val); - break; - case 14: - if (coex_sta->scan_ap_num <= 3) - halbtc8723b1ant_set_fw_pstdma(btcoexist, - 0x51, 0x30, 0x3, 0x10, 0x50); - else - halbtc8723b1ant_set_fw_pstdma(btcoexist, - ps_tdma_byte0_val, 0x21, 0x3, - ps_tdma_byte3_val, - ps_tdma_byte4_val); - break; - case 15: - halbtc8723b1ant_set_fw_pstdma(btcoexist, 0x13, - 0xa, 0x3, 0x8, 0x0); - break; - case 16: - halbtc8723b1ant_set_fw_pstdma(btcoexist, 0x93, - 0x15, 0x3, 0x10, 0x0); - break; - case 18: - halbtc8723b1ant_set_fw_pstdma(btcoexist, 0x93, - 0x25, 0x3, 0x10, 0x0); - break; - case 20: - halbtc8723b1ant_set_fw_pstdma(btcoexist, - ps_tdma_byte0_val, 0x3f, 0x03, - ps_tdma_byte3_val, 0x10); - break; - case 21: - halbtc8723b1ant_set_fw_pstdma(btcoexist, 0x61, - 0x25, 0x03, 0x11, 0x11); - break; - case 22: - halbtc8723b1ant_set_fw_pstdma(btcoexist, - ps_tdma_byte0_val, 0x25, 0x03, - ps_tdma_byte3_val, 0x10); - break; - case 23: - halbtc8723b1ant_set_fw_pstdma(btcoexist, 0xe3, - 0x25, 0x3, 0x31, 0x18); - break; - case 24: - halbtc8723b1ant_set_fw_pstdma(btcoexist, 0xe3, - 0x15, 0x3, 0x31, 0x18); - break; - case 25: - halbtc8723b1ant_set_fw_pstdma(btcoexist, 0xe3, - 0xa, 0x3, 0x31, 0x18); - break; - case 26: - halbtc8723b1ant_set_fw_pstdma(btcoexist, 0xe3, - 0xa, 0x3, 0x31, 0x18); - break; - case 27: - halbtc8723b1ant_set_fw_pstdma(btcoexist, 0xe3, - 0x25, 0x3, 0x31, 0x98); - break; - case 28: - halbtc8723b1ant_set_fw_pstdma(btcoexist, 0x69, - 0x25, 0x3, 0x31, 0x0); - break; - case 29: - halbtc8723b1ant_set_fw_pstdma(btcoexist, 0xab, - 0x1a, 0x1a, 0x1, 0x10); - break; - case 30: - halbtc8723b1ant_set_fw_pstdma(btcoexist, 0x51, - 0x30, 0x3, 0x10, 0x10); - break; - case 31: - halbtc8723b1ant_set_fw_pstdma(btcoexist, 0xd3, - 0x1a, 0x1a, 0, 0x58); - break; - case 32: - halbtc8723b1ant_set_fw_pstdma(btcoexist, - ps_tdma_byte0_val, 0x35, 0x3, - ps_tdma_byte3_val, ps_tdma_byte4_val); - break; - case 33: - halbtc8723b1ant_set_fw_pstdma(btcoexist, - ps_tdma_byte0_val, 0x35, 0x3, - ps_tdma_byte3_val, 0x10); - break; - case 34: - halbtc8723b1ant_set_fw_pstdma(btcoexist, 0x53, - 0x1a, 0x1a, 0x0, 0x10); - break; - case 35: - halbtc8723b1ant_set_fw_pstdma(btcoexist, 0x63, - 0x1a, 0x1a, 0x0, 0x10); - break; - case 36: - halbtc8723b1ant_set_fw_pstdma(btcoexist, 0xd3, - 0x12, 0x3, 0x14, 0x50); - break; - case 40: /* SoftAP only with no sta associated,BT disable ,TDMA mode for power saving */ - /* here softap mode screen off will cost 70-80mA for phone */ - halbtc8723b1ant_set_fw_pstdma(btcoexist, 0x23, - 0x18, 0x00, 0x10, 0x24); - break; - - /* for 1-Ant translate to 2-Ant */ - case 101: - halbtc8723b1ant_set_fw_pstdma(btcoexist, - ps_tdma_byte0_val, 0x3a + - wifi_duration_adjust, 0x03, - ps_tdma_byte3_val, ps_tdma_byte4_val); - break; - case 102: - halbtc8723b1ant_set_fw_pstdma(btcoexist, - ps_tdma_byte0_val, 0x2d + - wifi_duration_adjust, 0x03, - ps_tdma_byte3_val, ps_tdma_byte4_val); - break; - case 103: - /* halbtc8723b1ant_set_fw_pstdma(btcoexist, 0x51, 0x1d, 0x1d, 0x0, ps_tdma_byte4_val); */ - halbtc8723b1ant_set_fw_pstdma(btcoexist, - ps_tdma_byte0_val, 0x3a, 0x03, - ps_tdma_byte3_val, ps_tdma_byte4_val); - break; - case 105: - halbtc8723b1ant_set_fw_pstdma(btcoexist, - ps_tdma_byte0_val, 0x15, 0x3, - ps_tdma_byte3_val, 0x11); - break; - case 106: - halbtc8723b1ant_set_fw_pstdma(btcoexist, - ps_tdma_byte0_val, 0x20, 0x3, - ps_tdma_byte3_val, 0x11); - break; - case 109: - halbtc8723b1ant_set_fw_pstdma(btcoexist, - ps_tdma_byte0_val, 0x21, 0x3, - ps_tdma_byte3_val, ps_tdma_byte4_val); - break; - case 111: - halbtc8723b1ant_set_fw_pstdma(btcoexist, - ps_tdma_byte0_val, 0x21, 0x03, - ps_tdma_byte3_val, ps_tdma_byte4_val); - break; - case 113: - /* halbtc8723b1ant_set_fw_pstdma(btcoexist, 0x51, 0x12, 0x12, 0x0, ps_tdma_byte4_val); */ - halbtc8723b1ant_set_fw_pstdma(btcoexist, - ps_tdma_byte0_val, 0x21, 0x3, - ps_tdma_byte3_val, ps_tdma_byte4_val); - break; - case 114: - halbtc8723b1ant_set_fw_pstdma(btcoexist, - ps_tdma_byte0_val, 0x21, 0x3, - ps_tdma_byte3_val, ps_tdma_byte4_val); - break; - case 120: - halbtc8723b1ant_set_fw_pstdma(btcoexist, - ps_tdma_byte0_val, 0x3f, 0x03, - ps_tdma_byte3_val, 0x10); - break; - case 122: - halbtc8723b1ant_set_fw_pstdma(btcoexist, - ps_tdma_byte0_val, 0x25, 0x03, - ps_tdma_byte3_val, 0x10); - break; - case 132: - halbtc8723b1ant_set_fw_pstdma(btcoexist, - ps_tdma_byte0_val, 0x25, 0x03, - ps_tdma_byte3_val, ps_tdma_byte4_val); - break; - case 133: - halbtc8723b1ant_set_fw_pstdma(btcoexist, - ps_tdma_byte0_val, 0x25, 0x03, - ps_tdma_byte3_val, 0x11); - break; - - } - } else { - - /* disable PS tdma */ - switch (type) { - case 8: /* PTA Control */ - halbtc8723b1ant_set_fw_pstdma(btcoexist, 0x8, - 0x0, 0x0, 0x0, 0x0); - break; - case 0: - default: /* Software control, Antenna at BT side */ - halbtc8723b1ant_set_fw_pstdma(btcoexist, 0x0, - 0x0, 0x0, 0x0, 0x0); - break; - case 1: /* 2-Ant, 0x778=3, antenna control by antenna diversity */ - halbtc8723b1ant_set_fw_pstdma(btcoexist, 0x0, - 0x0, 0x0, 0x48, 0x0); - break; - } - } - rssi_adjust_val = 0; - btcoexist->btc_set(btcoexist, - BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE, &rssi_adjust_val); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "############# [BTCoex], 0x948=0x%x, 0x765=0x%x, 0x67=0x%x\n", - btcoexist->btc_read_4byte(btcoexist, 0x948), - btcoexist->btc_read_1byte(btcoexist, 0x765), - btcoexist->btc_read_1byte(btcoexist, 0x67)); - BTC_TRACE(trace_buf); - - /* update pre state */ - coex_dm->pre_ps_tdma_on = coex_dm->cur_ps_tdma_on; - coex_dm->pre_ps_tdma = coex_dm->cur_ps_tdma; -} - -void halbtc8723b1ant_tdma_duration_adjust_for_acl(IN struct btc_coexist - *btcoexist, IN u8 wifi_status) -{ - static s32 up, dn, m, n, wait_count; - s32 result; /* 0: no change, +1: increase WiFi duration, -1: decrease WiFi duration */ - u8 retry_count = 0, bt_info_ext; - boolean wifi_busy = false; - - if (BT_8723B_1ANT_WIFI_STATUS_CONNECTED_BUSY == wifi_status) - wifi_busy = true; - else - wifi_busy = false; - - if ((BT_8723B_1ANT_WIFI_STATUS_NON_CONNECTED_ASSO_AUTH_SCAN == - wifi_status) || - (BT_8723B_1ANT_WIFI_STATUS_CONNECTED_SCAN == wifi_status) || - (BT_8723B_1ANT_WIFI_STATUS_CONNECTED_SPECIFIC_PKT == - wifi_status)) { - if (coex_dm->cur_ps_tdma != 1 && - coex_dm->cur_ps_tdma != 2 && - coex_dm->cur_ps_tdma != 3 && - coex_dm->cur_ps_tdma != 9) { - halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 9); - coex_dm->ps_tdma_du_adj_type = 9; - - up = 0; - dn = 0; - m = 1; - n = 3; - result = 0; - wait_count = 0; - } - return; - } - - if (!coex_dm->auto_tdma_adjust) { - coex_dm->auto_tdma_adjust = true; - - halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 2); - coex_dm->ps_tdma_du_adj_type = 2; - /* ============ */ - up = 0; - dn = 0; - m = 1; - n = 3; - result = 0; - wait_count = 0; - } else { - /* acquire the BT TRx retry count from BT_Info byte2 */ - retry_count = coex_sta->bt_retry_cnt; - bt_info_ext = coex_sta->bt_info_ext; - - if ((coex_sta->low_priority_tx) > 1050 || - (coex_sta->low_priority_rx) > 1250) - retry_count++; - - result = 0; - wait_count++; - - if (retry_count == - 0) { /* no retry in the last 2-second duration */ - up++; - dn--; - - if (dn <= 0) - dn = 0; - - if (up >= n) { /* if retry count during continuous n*2 seconds is 0, enlarge WiFi duration */ - wait_count = 0; - n = 3; - up = 0; - dn = 0; - result = 1; - } - } else if (retry_count <= - 3) { /* <=3 retry in the last 2-second duration */ - up--; - dn++; - - if (up <= 0) - up = 0; - - if (dn == 2) { /* if continuous 2 retry count(every 2 seconds) >0 and < 3, reduce WiFi duration */ - if (wait_count <= 2) - m++; /* to avoid loop between the two levels */ - else - m = 1; - - if (m >= 20) /* maximum of m = 20 ' will recheck if need to adjust wifi duration in maximum time interval 120 seconds */ - m = 20; - - n = 3 * m; - up = 0; - dn = 0; - wait_count = 0; - result = -1; - } - } else { /* retry count > 3, once retry count > 3, to reduce WiFi duration */ - if (wait_count == 1) - m++; /* to avoid loop between the two levels */ - else - m = 1; - - if (m >= 20) /* maximum of m = 20 ' will recheck if need to adjust wifi duration in maximum time interval 120 seconds */ - m = 20; - - n = 3 * m; - up = 0; - dn = 0; - wait_count = 0; - result = -1; - } - - if (result == -1) { - /* if( (BT_INFO_8723B_1ANT_A2DP_BASIC_RATE(bt_info_ext)) && - ((coex_dm->cur_ps_tdma == 1) ||(coex_dm->cur_ps_tdma == 2)) ) - { - halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 9); - coex_dm->ps_tdma_du_adj_type = 9; - } - else */ if (coex_dm->cur_ps_tdma == 1) { - halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 2); - coex_dm->ps_tdma_du_adj_type = 2; - } else if (coex_dm->cur_ps_tdma == 2) { - halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 9); - coex_dm->ps_tdma_du_adj_type = 9; - } else if (coex_dm->cur_ps_tdma == 9) { - halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 11); - coex_dm->ps_tdma_du_adj_type = 11; - } - } else if (result == 1) { - /* if( (BT_INFO_8723B_1ANT_A2DP_BASIC_RATE(bt_info_ext)) && - ((coex_dm->cur_ps_tdma == 1) ||(coex_dm->cur_ps_tdma == 2)) ) - { - halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 9); - coex_dm->ps_tdma_du_adj_type = 9; - } - else */ if (coex_dm->cur_ps_tdma == 11) { - halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 9); - coex_dm->ps_tdma_du_adj_type = 9; - } else if (coex_dm->cur_ps_tdma == 9) { - halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 2); - coex_dm->ps_tdma_du_adj_type = 2; - } else if (coex_dm->cur_ps_tdma == 2) { - halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 1); - coex_dm->ps_tdma_du_adj_type = 1; - } - } else { /* no change */ - /* Bryant Modify - if(wifi_busy != pre_wifi_busy) - { - pre_wifi_busy = wifi_busy; - halbtc8723b1ant_ps_tdma(btcoexist, FORCE_EXEC, true, coex_dm->cur_ps_tdma); - } - */ - - } - - if (coex_dm->cur_ps_tdma != 1 && - coex_dm->cur_ps_tdma != 2 && - coex_dm->cur_ps_tdma != 9 && - coex_dm->cur_ps_tdma != 11) { - /* recover to previous adjust type */ - halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - coex_dm->ps_tdma_du_adj_type); - } - } -} - -/* ********************************************* - * - * Non-Software Coex Mechanism start - * - * ********************************************* */ -void halbtc8723b1ant_action_bt_whck_test(IN struct btc_coexist *btcoexist) -{ - halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8); - halbtc8723b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA, NORMAL_EXEC, - false, false); - halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); -} - -void halbtc8723b1ant_action_hs(IN struct btc_coexist *btcoexist) -{ - halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 5); - halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2); -} - -void halbtc8723b1ant_action_bt_inquiry(IN struct btc_coexist *btcoexist) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - boolean wifi_connected = false, ap_enable = false, wifi_busy = false, - bt_busy = false; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, - &ap_enable); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bt_busy); - - if (coex_sta->bt_abnormal_scan) { - halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 33); - halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7); - } else if ((!wifi_connected) && (!coex_sta->wifi_is_high_pri_task)) { - halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8); - halbtc8723b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA, - NORMAL_EXEC, false, false); - halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - } else if ((bt_link_info->sco_exist) || (bt_link_info->hid_exist) || - (bt_link_info->a2dp_exist)) { - /* SCO/HID/A2DP busy */ - - if (coex_sta->c2h_bt_remote_name_req) - halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 33); - else - halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 32); - - halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); - } else if ((bt_link_info->pan_exist) || (wifi_busy)) { - - if (coex_sta->c2h_bt_remote_name_req) - halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 33); - else - halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 32); - - halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); - } else { - - halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8); - halbtc8723b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA, - NORMAL_EXEC, false, false); - halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7); - - } -} - -void halbtc8723b1ant_action_bt_sco_hid_only_busy(IN struct btc_coexist - *btcoexist, IN u8 wifi_status) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - boolean wifi_connected = false; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - - /* tdma and coex table */ - - if (bt_link_info->sco_exist) { - halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 5); - halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 5); - } else { /* HID */ - halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 6); - halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 5); - } -} - -void halbtc8723b1ant_action_wifi_only(IN struct btc_coexist *btcoexist) -{ - halbtc8723b1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 0); - halbtc8723b1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 8); - halbtc8723b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA, FORCE_EXEC, - false, false); -} - -void halbtc8723b1ant_action_wifi_multi_port(IN struct btc_coexist *btcoexist) -{ - halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8); - halbtc8723b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA, NORMAL_EXEC, - false, false); - halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2); -} - -void halbtc8723b1ant_action_wifi_connected_bt_acl_busy(IN struct btc_coexist - *btcoexist, IN u8 wifi_status) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - - if ((coex_sta->low_priority_rx >= 950) && (!coex_sta->under_ips)) - bt_link_info->slave_role = true; - else - bt_link_info->slave_role = false; - - if (bt_link_info->hid_only) { /* HID */ - halbtc8723b1ant_action_bt_sco_hid_only_busy(btcoexist, - wifi_status); - coex_dm->auto_tdma_adjust = false; - return; - } else if (bt_link_info->a2dp_only) { /* A2DP */ - if (BT_8723B_1ANT_WIFI_STATUS_CONNECTED_IDLE == wifi_status) { - halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 32); - halbtc8723b1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 4); - coex_dm->auto_tdma_adjust = false; - } else { - halbtc8723b1ant_tdma_duration_adjust_for_acl(btcoexist, - wifi_status); - halbtc8723b1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 4); - coex_dm->auto_tdma_adjust = true; - } - } else if (((bt_link_info->a2dp_exist) && (bt_link_info->pan_exist)) || - (bt_link_info->hid_exist && bt_link_info->a2dp_exist && - bt_link_info->pan_exist)) { /* A2DP+PAN(OPP,FTP), HID+A2DP+PAN(OPP,FTP) */ - halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 13); - halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); - coex_dm->auto_tdma_adjust = false; - } else if (bt_link_info->hid_exist && - bt_link_info->a2dp_exist) { /* HID+A2DP */ - halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 14); - coex_dm->auto_tdma_adjust = false; - - halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); - } else if ((bt_link_info->pan_only) || (bt_link_info->hid_exist && - bt_link_info->pan_exist)) { /* PAN(OPP,FTP), HID+PAN(OPP,FTP) */ - - if (BT_8723B_1ANT_WIFI_STATUS_CONNECTED_IDLE == wifi_status) - halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 9); - else - halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 3); - - halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); - coex_dm->auto_tdma_adjust = false; - } else { - /* BT no-profile busy (0x9) */ - halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 33); - halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); - coex_dm->auto_tdma_adjust = false; - } -} - -void halbtc8723b1ant_action_wifi_not_connected(IN struct btc_coexist *btcoexist) -{ - - /* tdma and coex table */ - halbtc8723b1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 8); - halbtc8723b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA, NORMAL_EXEC, - false, false); - halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); -} - -void halbtc8723b1ant_action_wifi_not_connected_scan(IN struct btc_coexist - *btcoexist) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - - /* tdma and coex table */ - if (BT_8723B_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) { - if (bt_link_info->a2dp_exist) { - halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 32); - halbtc8723b1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 4); - } else if (bt_link_info->a2dp_exist && - bt_link_info->pan_exist) { - halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 22); - halbtc8723b1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 4); - } else { - halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 20); - halbtc8723b1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 4); - } - } else if ((BT_8723B_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) || - (BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY == - coex_dm->bt_status)) { - halbtc8723b1ant_action_bt_sco_hid_only_busy(btcoexist, - BT_8723B_1ANT_WIFI_STATUS_CONNECTED_SCAN); - } else { - /* Bryant Add */ - halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8); - halbtc8723b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA, - NORMAL_EXEC, false, false); - halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2); - } -} - -void halbtc8723b1ant_action_wifi_not_connected_asso_auth( - IN struct btc_coexist *btcoexist) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - - /* tdma and coex table */ - if ((bt_link_info->sco_exist) || (bt_link_info->hid_exist) || - (bt_link_info->a2dp_exist)) { - halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32); - halbtc8723b1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 4); - } else if (bt_link_info->pan_exist) { - halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20); - halbtc8723b1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 4); - } else { - halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8); - halbtc8723b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA, - NORMAL_EXEC, false, false); - halbtc8723b1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 2); - } -} - -void halbtc8723b1ant_action_wifi_connected_scan(IN struct btc_coexist - *btcoexist) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - - /* tdma and coex table */ - if (BT_8723B_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) { - if (bt_link_info->a2dp_exist) { - halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 32); - halbtc8723b1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 4); - } else if (bt_link_info->a2dp_exist && - bt_link_info->pan_exist) { - halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 22); - halbtc8723b1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 4); - } else { - halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 20); - halbtc8723b1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 4); - } - } else if ((BT_8723B_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) || - (BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY == - coex_dm->bt_status)) { - halbtc8723b1ant_action_bt_sco_hid_only_busy(btcoexist, - BT_8723B_1ANT_WIFI_STATUS_CONNECTED_SCAN); - } else { - /* Bryant Add */ - halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8); - halbtc8723b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA, - NORMAL_EXEC, false, false); - halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2); - } -} - -void halbtc8723b1ant_action_wifi_connected_specific_packet( - IN struct btc_coexist *btcoexist) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - boolean wifi_busy = false; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - - /* no specific packet process for both WiFi and BT very busy */ - if ((wifi_busy) && ((bt_link_info->pan_exist) || - (coex_sta->num_of_profile >= 2))) - return; - - /* tdma and coex table */ - if ((bt_link_info->sco_exist) || (bt_link_info->hid_exist)) { - halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32); - halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 5); - } else if (bt_link_info->a2dp_exist) { - halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32); - halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); - } else if (bt_link_info->pan_exist) { - halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20); - halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); - } else { - halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8); - halbtc8723b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA, - NORMAL_EXEC, false, false); - halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2); - } -} - -void halbtc8723b1ant_action_wifi_connected(IN struct btc_coexist *btcoexist) -{ - boolean wifi_busy = false; - boolean scan = false, link = false, roam = false; - boolean under_4way = false, ap_enable = false; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], CoexForWifiConnect()===>\n"); - BTC_TRACE(trace_buf); - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS, - &under_4way); - if (under_4way) { - halbtc8723b1ant_action_wifi_connected_specific_packet( - btcoexist); - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], CoexForWifiConnect(), return for wifi is under 4way<===\n"); - BTC_TRACE(trace_buf); - return; - } - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam); - if (scan || link || roam) { - if (scan) - halbtc8723b1ant_action_wifi_connected_scan(btcoexist); - else - halbtc8723b1ant_action_wifi_connected_specific_packet( - btcoexist); - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], CoexForWifiConnect(), return for wifi is under scan<===\n"); - BTC_TRACE(trace_buf); - return; - } - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, - &ap_enable); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - - /* tdma and coex table */ - if (!wifi_busy) { - if (BT_8723B_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) { - halbtc8723b1ant_action_wifi_connected_bt_acl_busy( - btcoexist, - BT_8723B_1ANT_WIFI_STATUS_CONNECTED_IDLE); - } else if ((BT_8723B_1ANT_BT_STATUS_SCO_BUSY == - coex_dm->bt_status) || - (BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY == - coex_dm->bt_status)) { - halbtc8723b1ant_action_bt_sco_hid_only_busy(btcoexist, - BT_8723B_1ANT_WIFI_STATUS_CONNECTED_IDLE); - } else { - halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, - 8); - halbtc8723b1ant_set_ant_path(btcoexist, - BTC_ANT_PATH_PTA, NORMAL_EXEC, false, false); - /* if ((coex_sta->high_priority_tx) + - (coex_sta->high_priority_rx) <= 60) */ - halbtc8723b1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 2); - /* else - halbtc8723b1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 7); */ - } - } else { - if (BT_8723B_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) { - halbtc8723b1ant_action_wifi_connected_bt_acl_busy( - btcoexist, - BT_8723B_1ANT_WIFI_STATUS_CONNECTED_BUSY); - } else if ((BT_8723B_1ANT_BT_STATUS_SCO_BUSY == - coex_dm->bt_status) || - (BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY == - coex_dm->bt_status)) { - halbtc8723b1ant_action_bt_sco_hid_only_busy(btcoexist, - BT_8723B_1ANT_WIFI_STATUS_CONNECTED_BUSY); - } else { - /* halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, - 8); - halbtc8723b1ant_set_ant_path(btcoexist, - BTC_ANT_PATH_PTA, NORMAL_EXEC, false, false); - if ((coex_sta->high_priority_tx) + - (coex_sta->high_priority_rx) <= 60) - halbtc8723b1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 2); - else - halbtc8723b1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 7); */ - halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 32); - halbtc8723b1ant_set_ant_path(btcoexist, - BTC_ANT_PATH_PTA, NORMAL_EXEC, false, false); - halbtc8723b1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 4); - - } - } -} - -void halbtc8723b1ant_run_coexist_mechanism(IN struct btc_coexist *btcoexist) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - boolean wifi_connected = false, bt_hs_on = false, wifi_busy = false; - boolean increase_scan_dev_num = false; - boolean bt_ctrl_agg_buf_size = false; - boolean miracast_plus_bt = false; - u8 agg_buf_size = 5; - u32 wifi_link_status = 0; - u32 num_of_wifi_link = 0, wifi_bw; - u8 iot_peer = BTC_IOT_PEER_UNKNOWN; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], RunCoexistMechanism()===>\n"); - BTC_TRACE(trace_buf); - - if (btcoexist->manual_control) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], RunCoexistMechanism(), return for Manual CTRL <===\n"); - BTC_TRACE(trace_buf); - return; - } - - if (btcoexist->stop_coex_dm) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], RunCoexistMechanism(), return for Stop Coex DM <===\n"); - BTC_TRACE(trace_buf); - return; - } - - if (coex_sta->under_ips) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], wifi is under IPS !!!\n"); - BTC_TRACE(trace_buf); - return; - } - - if (coex_sta->bt_whck_test) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT is under WHCK TEST!!!\n"); - BTC_TRACE(trace_buf); - halbtc8723b1ant_action_bt_whck_test(btcoexist); - return; - } - - if ((BT_8723B_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) || - (BT_8723B_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) || - (BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY == coex_dm->bt_status)) - increase_scan_dev_num = true; - - btcoexist->btc_set(btcoexist, BTC_SET_BL_INC_SCAN_DEV_NUM, - &increase_scan_dev_num); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS, - &wifi_link_status); - num_of_wifi_link = wifi_link_status >> 16; - - if ((num_of_wifi_link >= 2) || - (wifi_link_status & WIFI_P2P_GO_CONNECTED)) { - if (bt_link_info->bt_link_exist) { - halbtc8723b1ant_limited_tx(btcoexist, NORMAL_EXEC, 1, 1, - 0, 1); - miracast_plus_bt = true; - } else { - halbtc8723b1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, - 0, 0); - miracast_plus_bt = false; - } - btcoexist->btc_set(btcoexist, BTC_SET_BL_MIRACAST_PLUS_BT, - &miracast_plus_bt); - halbtc8723b1ant_limited_rx(btcoexist, NORMAL_EXEC, false, - bt_ctrl_agg_buf_size, agg_buf_size); - - if (((bt_link_info->a2dp_exist) || (wifi_busy)) && - (coex_sta->c2h_bt_inquiry_page)) - halbtc8723b1ant_action_bt_inquiry(btcoexist); - else - halbtc8723b1ant_action_wifi_multi_port(btcoexist); - - return; - } - - miracast_plus_bt = false; - btcoexist->btc_set(btcoexist, BTC_SET_BL_MIRACAST_PLUS_BT, - &miracast_plus_bt); - - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw); - - if ((bt_link_info->bt_link_exist) && (wifi_connected)) { - halbtc8723b1ant_limited_tx(btcoexist, NORMAL_EXEC, 1, 1, 0, 1); - - btcoexist->btc_get(btcoexist, BTC_GET_U1_IOT_PEER, &iot_peer); - - /* if(BTC_IOT_PEER_CISCO != iot_peer) */ - if ((BTC_IOT_PEER_CISCO != iot_peer) && - (BTC_IOT_PEER_BROADCOM != iot_peer)) { - if (bt_link_info->sco_exist) /* if (bt_link_info->bt_hi_pri_link_exist) */ - /* halbtc8723b1ant_limited_rx(btcoexist, NORMAL_EXEC, true, false, 0x5); */ - halbtc8723b1ant_limited_rx(btcoexist, - NORMAL_EXEC, true, false, 0x5); - else - halbtc8723b1ant_limited_rx(btcoexist, - NORMAL_EXEC, false, false, 0x5); - /* halbtc8723b1ant_limited_rx(btcoexist, NORMAL_EXEC, false, true, 0x8); */ - } else { - if (bt_link_info->sco_exist) - halbtc8723b1ant_limited_rx(btcoexist, - NORMAL_EXEC, true, false, 0x5); - else if (bt_link_info->hid_exist) - halbtc8723b1ant_limited_rx(btcoexist, - NORMAL_EXEC, false, true, 0x3); - else { - if (BTC_WIFI_BW_HT40 == wifi_bw) - halbtc8723b1ant_limited_rx(btcoexist, - NORMAL_EXEC, false, true, 0x10); - else - halbtc8723b1ant_limited_rx(btcoexist, - NORMAL_EXEC, false, true, 0x8); - } - } - - halbtc8723b1ant_sw_mechanism(btcoexist, true); - - /* low pelnaty ra in pcr ra */ - btcoexist->btc_phydm_modify_RA_PCR_threshold(btcoexist, 0, 35); - - } else { - halbtc8723b1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0); - - halbtc8723b1ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, - 0x5); - - halbtc8723b1ant_sw_mechanism(btcoexist, false); - } - - btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); - if (coex_sta->c2h_bt_inquiry_page) { - halbtc8723b1ant_action_bt_inquiry(btcoexist); - return; - } else if (bt_hs_on) { - halbtc8723b1ant_action_hs(btcoexist); - return; - } - - if (!wifi_connected) { - boolean scan = false, link = false, roam = false; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], wifi is non connected-idle !!!\n"); - BTC_TRACE(trace_buf); - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam); - - if (scan || link || roam) { - if (scan) - halbtc8723b1ant_action_wifi_not_connected_scan( - btcoexist); - else - halbtc8723b1ant_action_wifi_not_connected_asso_auth( - btcoexist); - } else - halbtc8723b1ant_action_wifi_not_connected(btcoexist); - } else /* wifi LPS/Busy */ - halbtc8723b1ant_action_wifi_connected(btcoexist); -} - -void halbtc8723b1ant_init_coex_dm(IN struct btc_coexist *btcoexist) -{ - /* force to reset coex mechanism */ - - /* sw all off */ - halbtc8723b1ant_sw_mechanism(btcoexist, false); - - /* halbtc8723b1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 8); */ - /* halbtc8723b1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 0); */ - - coex_sta->pop_event_cnt = 0; -} - -void halbtc8723b1ant_init_hw_config(IN struct btc_coexist *btcoexist, - IN boolean back_up, IN boolean wifi_only) -{ - u32 u32tmp = 0; /* , fw_ver; */ - u8 u8tmpa = 0, u8tmpb = 0; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], 1Ant Init HW Config!!\n"); - BTC_TRACE(trace_buf); - - psd_scan->ant_det_is_ant_det_available = false; - - /* Give bt_coex_supported_version the default value */ - coex_sta->bt_coex_supported_version = 0; - - /* 0xf0[15:12] --> Chip Cut information */ - coex_sta->cut_version = (btcoexist->btc_read_1byte(btcoexist, - 0xf1) & 0xf0) >> 4; - - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x550, 0x8, - 0x1); /* enable TBTT nterrupt */ - - /* 0x790[5:0]=0x5 */ - btcoexist->btc_write_1byte(btcoexist, 0x790, 0x5); - - /* Enable counter statistics */ - /* btcoexist->btc_write_1byte(btcoexist, 0x76e, 0xc); */ /*0x76e[3] =1, WLAN_Act control by PTA */ - btcoexist->btc_write_1byte(btcoexist, 0x778, 0x1); - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x40, 0x20, 0x1); - - /* btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, 0x20, 0x1); */ /*BT select s0/s1 is controlled by WiFi */ - - halbtc8723b1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 8); - - /* Antenna config */ - if (wifi_only) - halbtc8723b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_WIFI, - FORCE_EXEC, true, false); - else - halbtc8723b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT, - FORCE_EXEC, true, false); - - /* PTA parameter */ - halbtc8723b1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 0); - - u32tmp = btcoexist->btc_read_4byte(btcoexist, 0x948); - u8tmpa = btcoexist->btc_read_1byte(btcoexist, 0x765); - u8tmpb = btcoexist->btc_read_1byte(btcoexist, 0x67); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "############# [BTCoex], 0x948=0x%x, 0x765=0x%x, 0x67=0x%x\n", - u32tmp, u8tmpa, u8tmpb); - BTC_TRACE(trace_buf); - -} - -/* Donot remove optimize off flag, otherwise antenna detection would trigger BT collapsed */ -void halbtc8723b1ant_mechanism_switch(IN struct btc_coexist *btcoexist, - IN boolean bSwitchTo2Antenna) -{ - - if (bSwitchTo2Antenna) { - - /* BT TRx mask off */ - btcoexist->btc_set_bt_trx_mask(btcoexist, 0); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "############# [BTCoex], BT TRx Mask off for mechanism_switch\n"); - - BTC_TRACE(trace_buf); - - } else { - - /* BT TRx mask on */ - btcoexist->btc_set_bt_trx_mask(btcoexist, 1); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "############# [BTCoex], BT TRx Mask on for mechanism_switch\n"); - - BTC_TRACE(trace_buf); - } -} - -u32 halbtc8723b1ant_psd_log2base(IN struct btc_coexist *btcoexist, IN u32 val) -{ - u8 j; - u32 tmp, tmp2, val_integerd_b = 0, tindex, shiftcount = 0; - u32 result, val_fractiond_b = 0, table_fraction[21] = {0, 432, 332, 274, 232, 200, - 174, 151, 132, 115, 100, 86, 74, 62, 51, 42, - 32, 23, 15, 7, 0 - }; - - if (val == 0) - return 0; - - tmp = val; - - while (1) { - if (tmp == 1) - break; - - tmp = (tmp >> 1); - shiftcount++; - } - - val_integerd_b = shiftcount + 1; - - tmp2 = 1; - for (j = 1; j <= val_integerd_b; j++) - tmp2 = tmp2 * 2; - - tmp = (val * 100) / tmp2; - tindex = tmp / 5; - - if (tindex > 20) - tindex = 20; - - val_fractiond_b = table_fraction[tindex]; - - result = val_integerd_b * 100 - val_fractiond_b; - - return result; - -} - -void halbtc8723b1ant_psd_show_antenna_detect_result(IN struct btc_coexist - *btcoexist) -{ - u8 *cli_buf = btcoexist->cli_buf; - struct btc_board_info *board_info = &btcoexist->board_info; - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n============[Antenna Detection info] ============\n"); - CL_PRINTF(cli_buf); - - if (psd_scan->ant_det_result == 1) - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s (>%d)", - "Ant Det Result", "2-Antenna (Bad-Isolation)", - BT_8723B_1ANT_ANTDET_PSDTHRES_2ANT_BADISOLATION); - else if (psd_scan->ant_det_result == 2) - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s (%d~%d)", - "Ant Det Result", "2-Antenna (Good-Isolation)", - BT_8723B_1ANT_ANTDET_PSDTHRES_2ANT_GOODISOLATION - + psd_scan->ant_det_thres_offset, - BT_8723B_1ANT_ANTDET_PSDTHRES_2ANT_BADISOLATION); - else - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s (%d~%d)", - "Ant Det Result", "1-Antenna", - BT_8723B_1ANT_ANTDET_PSDTHRES_1ANT, - BT_8723B_1ANT_ANTDET_PSDTHRES_2ANT_GOODISOLATION - + psd_scan->ant_det_thres_offset); - - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s ", - "Antenna Detection Finish", - (board_info->btdm_ant_det_finish - ? "Yes" : "No")); - CL_PRINTF(cli_buf); - - switch (psd_scan->ant_det_result) { - case 0: - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "(BT is not available)"); - break; - case 1: /* 2-Ant bad-isolation */ - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "(BT is available)"); - break; - case 2: /* 2-Ant good-isolation */ - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "(BT is available)"); - break; - case 3: /* 1-Ant */ - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "(BT is available)"); - break; - case 4: - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "(Uncertainty result)"); - break; - case 5: - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "(Pre-Scan fai)"); - break; - case 6: - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "(WiFi is Scanning)"); - break; - case 7: - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "(BT is not idle)"); - break; - case 8: - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "(Abort by WiFi Scanning)"); - break; - case 9: - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "(Antenna Init is not ready)"); - break; - case 10: - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "(BT is Inquiry or page)"); - break; - case 11: - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "(BT is Disabled)"); - break; - } - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d", - "Ant Detect Total Count", psd_scan->ant_det_try_count); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d", - "Ant Detect Fail Count", psd_scan->ant_det_fail_count); - CL_PRINTF(cli_buf); - - if ((!board_info->btdm_ant_det_finish) && - (psd_scan->ant_det_result != 5)) - return; - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s", "BT Response", - (psd_scan->ant_det_result ? "ok" : "fail")); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d ms", "BT Tx Time", - psd_scan->ant_det_bt_tx_time); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d", "BT Tx Ch", - psd_scan->ant_det_bt_le_channel); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d", - "WiFi PSD Cent-Ch/Offset/Span", - psd_scan->real_cent_freq, psd_scan->real_offset, - psd_scan->real_span); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d dB", - "PSD Pre-Scan Peak Value", - psd_scan->ant_det_pre_psdscan_peak_val / 100); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s (<= %d)", - "PSD Pre-Scan result", - (psd_scan->ant_det_result != 5 ? "ok" : "fail"), - BT_8723B_1ANT_ANTDET_PSDTHRES_BACKGROUND - + psd_scan->ant_det_thres_offset); - CL_PRINTF(cli_buf); - - if (psd_scan->ant_det_result == 5) - return; - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s dB", - "PSD Scan Peak Value", psd_scan->ant_det_peak_val); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s MHz", - "PSD Scan Peak Freq", psd_scan->ant_det_peak_freq); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s", "TFBGA Package", - (board_info->tfbga_package) ? "Yes" : "No"); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d", - "PSD Threshold Offset", psd_scan->ant_det_thres_offset); - CL_PRINTF(cli_buf); - -} - -void halbtc8723b1ant_psd_showdata(IN struct btc_coexist *btcoexist) -{ - u8 *cli_buf = btcoexist->cli_buf; - u32 delta_freq_per_point; - u32 freq, freq1, freq2, n = 0, i = 0, j = 0, m = 0, psd_rep1, psd_rep2; - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n\n============[PSD info] (%d)============\n", - psd_scan->psd_gen_count); - CL_PRINTF(cli_buf); - - if (psd_scan->psd_gen_count == 0) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n No data !!\n"); - CL_PRINTF(cli_buf); - return; - } - - if (psd_scan->psd_point == 0) - delta_freq_per_point = 0; - else - delta_freq_per_point = psd_scan->psd_band_width / - psd_scan->psd_point; - - /* if (psd_scan->is_psd_show_max_only) */ - if (0) { - psd_rep1 = psd_scan->psd_max_value / 100; - psd_rep2 = psd_scan->psd_max_value - psd_rep1 * 100; - - freq = ((psd_scan->real_cent_freq - 20) * 1000000 + - psd_scan->psd_max_value_point * delta_freq_per_point); - freq1 = freq / 1000000; - freq2 = freq / 1000 - freq1 * 1000; - - if (freq2 < 100) - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n Freq = %d.0%d MHz", - freq1, freq2); - else - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n Freq = %d.%d MHz", - freq1, freq2); - - if (psd_rep2 < 10) - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - ", Value = %d.0%d dB, (%d)\n", - psd_rep1, psd_rep2, psd_scan->psd_max_value); - else - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - ", Value = %d.%d dB, (%d)\n", - psd_rep1, psd_rep2, psd_scan->psd_max_value); - - CL_PRINTF(cli_buf); - } else { - m = psd_scan->psd_start_point; - n = psd_scan->psd_start_point; - i = 1; - j = 1; - - while (1) { - do { - freq = ((psd_scan->real_cent_freq - 20) * - 1000000 + m * - delta_freq_per_point); - freq1 = freq / 1000000; - freq2 = freq / 1000 - freq1 * 1000; - - if (i == 1) { - if (freq2 == 0) - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "\r\n Freq%6d.000", - freq1); - else if (freq2 < 100) - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "\r\n Freq%6d.0%2d", - freq1, - freq2); - else - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "\r\n Freq%6d.%3d", - freq1, - freq2); - } else if ((i % 8 == 0) || - (m == psd_scan->psd_stop_point)) { - if (freq2 == 0) - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "%6d.000\n", freq1); - else if (freq2 < 100) - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "%6d.0%2d\n", freq1, - freq2); - else - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "%6d.%3d\n", freq1, - freq2); - } else { - if (freq2 == 0) - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "%6d.000", freq1); - else if (freq2 < 100) - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "%6d.0%2d", freq1, - freq2); - else - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "%6d.%3d", freq1, - freq2); - } - - i++; - m++; - CL_PRINTF(cli_buf); - - } while ((i <= 8) && (m <= psd_scan->psd_stop_point)); - - do { - psd_rep1 = psd_scan->psd_report_max_hold[n] / - 100; - psd_rep2 = psd_scan->psd_report_max_hold[n] - - psd_rep1 * - 100; - - if (j == 1) { - if (psd_rep2 < 10) - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "\r\n Val %7d.0%d", - psd_rep1, - psd_rep2); - else - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "\r\n Val %7d.%d", - psd_rep1, - psd_rep2); - } else if ((j % 8 == 0) || - (n == psd_scan->psd_stop_point)) { - if (psd_rep2 < 10) - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "%7d.0%d\n", psd_rep1, - psd_rep2); - else - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "%7d.%d\n", psd_rep1, - psd_rep2); - } else { - if (psd_rep2 < 10) - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "%7d.0%d", psd_rep1, - psd_rep2); - else - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "%7d.%d", psd_rep1, - psd_rep2); - } - - j++; - n++; - CL_PRINTF(cli_buf); - - } while ((j <= 8) && (n <= psd_scan->psd_stop_point)); - - if ((m > psd_scan->psd_stop_point) || - (n > psd_scan->psd_stop_point)) - break; - - i = 1; - j = 1; - } - } - -} - -void halbtc8723b1ant_psd_max_holddata(IN struct btc_coexist *btcoexist, - IN u32 gen_count) -{ - u32 i = 0, i_max = 0, val_max = 0; - - if (gen_count == 1) { - memcpy(psd_scan->psd_report_max_hold, - psd_scan->psd_report, - BT_8723B_1ANT_ANTDET_PSD_POINTS * sizeof(u32)); - - psd_scan->psd_max_value_point = 0; - psd_scan->psd_max_value = 0; - - } else { - for (i = psd_scan->psd_start_point; - i <= psd_scan->psd_stop_point; i++) { - if (psd_scan->psd_report[i] > - psd_scan->psd_report_max_hold[i]) - psd_scan->psd_report_max_hold[i] = - psd_scan->psd_report[i]; - - /* search Max Value */ - if (i == psd_scan->psd_start_point) { - i_max = i; - val_max = psd_scan->psd_report_max_hold[i]; - } else { - if (psd_scan->psd_report_max_hold[i] > - val_max) { - i_max = i; - val_max = psd_scan->psd_report_max_hold[i]; - } - } - - } - - psd_scan->psd_max_value_point = i_max; - psd_scan->psd_max_value = val_max; - - } - -} - -u32 halbtc8723b1ant_psd_getdata(IN struct btc_coexist *btcoexist, IN u32 point) -{ - /* reg 0x808[9:0]: FFT data x */ - /* reg 0x808[22]: 0-->1 to get 1 FFT data y */ - /* reg 0x8b4[15:0]: FFT data y report */ - - u32 val = 0, psd_report = 0; - int k = 0; - - val = btcoexist->btc_read_4byte(btcoexist, 0x808); - - val &= 0xffbffc00; - val |= point; - - btcoexist->btc_write_4byte(btcoexist, 0x808, val); - - val |= 0x00400000; - btcoexist->btc_write_4byte(btcoexist, 0x808, val); - - while (1) { - if (k++ > BT_8723B_1ANT_ANTDET_SWEEPPOINT_DELAY) - break; - } - - val = btcoexist->btc_read_4byte(btcoexist, 0x8b4); - - psd_report = val & 0x0000ffff; - - return psd_report; -} - -boolean halbtc8723b1ant_psd_sweep_point(IN struct btc_coexist *btcoexist, - IN u32 cent_freq, IN s32 offset, IN u32 span, IN u32 points, - IN u32 avgnum, IN u32 loopcnt) -{ - u32 i, val, n, k = 0, j, point_index = 0; - u32 points1 = 0, psd_report = 0; - u32 start_p = 0, stop_p = 0, delta_freq_per_point = 156250; - u32 psd_center_freq = 20 * 10 ^ 6; - boolean outloop = false, scan , roam, is_sweep_ok = true; - u8 flag = 0; - u32 tmp; - u32 wifi_original_channel = 1; - - psd_scan->is_psd_running = true; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx PSD Sweep Start!!\n"); - BTC_TRACE(trace_buf); - - do { - switch (flag) { - case 0: /* Get PSD parameters */ - default: - - psd_scan->psd_band_width = 40 * 1000000; - psd_scan->psd_point = points; - psd_scan->psd_start_base = points / 2; - psd_scan->psd_avg_num = avgnum; - psd_scan->real_cent_freq = cent_freq; - psd_scan->real_offset = offset; - psd_scan->real_span = span; - - points1 = psd_scan->psd_point; - delta_freq_per_point = psd_scan->psd_band_width / - psd_scan->psd_point; - - /* PSD point setup */ - val = btcoexist->btc_read_4byte(btcoexist, 0x808); - val &= 0xffff0fff; - - switch (psd_scan->psd_point) { - case 128: - val |= 0x0; - break; - case 256: - default: - val |= 0x00004000; - break; - case 512: - val |= 0x00008000; - break; - case 1024: - val |= 0x0000c000; - break; - } - - switch (psd_scan->psd_avg_num) { - case 1: - val |= 0x0; - break; - case 8: - val |= 0x00001000; - break; - case 16: - val |= 0x00002000; - break; - case 32: - default: - val |= 0x00003000; - break; - } - btcoexist->btc_write_4byte(btcoexist, 0x808, val); - - flag = 1; - break; - case 1: /* calculate the PSD point index from freq/offset/span */ - psd_center_freq = psd_scan->psd_band_width / 2 + - offset * (1000000); - - start_p = psd_scan->psd_start_base + (psd_center_freq - - span * (1000000) / 2) / delta_freq_per_point; - psd_scan->psd_start_point = start_p - - psd_scan->psd_start_base; - - stop_p = psd_scan->psd_start_base + (psd_center_freq + - span * (1000000) / 2) / delta_freq_per_point; - psd_scan->psd_stop_point = stop_p - - psd_scan->psd_start_base - 1; - - flag = 2; - break; - case 2: /* set RF channel/BW/Mode */ - - /* set 3-wire off */ - val = btcoexist->btc_read_4byte(btcoexist, 0x88c); - val |= 0x00300000; - btcoexist->btc_write_4byte(btcoexist, 0x88c, val); - - /* CCK off */ - val = btcoexist->btc_read_4byte(btcoexist, 0x800); - val &= 0xfeffffff; - btcoexist->btc_write_4byte(btcoexist, 0x800, val); - - /* store WiFi original channel */ - wifi_original_channel = btcoexist->btc_get_rf_reg( - btcoexist, BTC_RF_A, 0x18, 0x3ff); - - /* Set RF channel */ - if (cent_freq == 2484) - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, - 0x18, 0x3ff, 0xe); - else - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, - 0x18, 0x3ff, (cent_freq - 2412) / 5 + - 1); /* WiFi TRx Mask on */ - - /* Set RF Rx filter corner */ - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1e, - 0xfffff, 0x3e4); - - /* Set TRx mask off */ - /* un-lock TRx Mask setup */ - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0xdd, - 0x80, 0x1); - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0xdf, - 0x1, 0x1); - - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, - 0xfffff, 0x0); - - /* Set RF mode = Rx, RF Gain = 0x8a0 */ - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x0, - 0xfffff, 0x308a0); - - while (1) { - if (k++ > BT_8723B_1ANT_ANTDET_SWEEPPOINT_DELAY) - break; - } - flag = 3; - break; - case 3: - psd_scan->psd_gen_count = 0; - for (j = 1; j <= loopcnt; j++) { - - btcoexist->btc_get(btcoexist, - BTC_GET_BL_WIFI_SCAN, &scan); - btcoexist->btc_get(btcoexist, - BTC_GET_BL_WIFI_ROAM, &roam); - - if (scan || roam) { - is_sweep_ok = false; - break; - } - memset(psd_scan->psd_report, 0, - psd_scan->psd_point * sizeof(u32)); - start_p = psd_scan->psd_start_point + - psd_scan->psd_start_base; - stop_p = psd_scan->psd_stop_point + - psd_scan->psd_start_base + 1; - - i = start_p; - point_index = 0; - - while (i < stop_p) { - if (i >= points1) - psd_report = - halbtc8723b1ant_psd_getdata( - btcoexist, i - points1); - else - psd_report = - halbtc8723b1ant_psd_getdata( - btcoexist, i); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "Point=%d, psd_raw_data = 0x%08x\n", - i, psd_report); - BTC_TRACE(trace_buf); - if (psd_report == 0) - tmp = 0; - else - /* tmp = 20*log10((double)psd_report); */ - /* 20*log2(x)/log2(10), log2Base return theresult of the psd_report*100 */ - tmp = 6 * halbtc8723b1ant_psd_log2base( - btcoexist, psd_report); - - n = i - psd_scan->psd_start_base; - psd_scan->psd_report[n] = tmp; - - halbtc8723b1ant_psd_max_holddata( - btcoexist, j); - - i++; - - } - - psd_scan->psd_gen_count = j; - } - - flag = 100; - break; - case 99: /* error */ - - outloop = true; - break; - case 100: /* recovery */ - - /* set 3-wire on */ - val = btcoexist->btc_read_4byte(btcoexist, 0x88c); - val &= 0xffcfffff; - btcoexist->btc_write_4byte(btcoexist, 0x88c, val); - - /* CCK on */ - val = btcoexist->btc_read_4byte(btcoexist, 0x800); - val |= 0x01000000; - btcoexist->btc_write_4byte(btcoexist, 0x800, val); - - /* PSD off */ - val = btcoexist->btc_read_4byte(btcoexist, 0x808); - val &= 0xffbfffff; - btcoexist->btc_write_4byte(btcoexist, 0x808, val); - - /* TRx Mask on */ - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, - 0xfffff, 0x780); - - /* lock TRx Mask setup */ - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0xdd, - 0x80, 0x0); - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0xdf, - 0x1, 0x0); - - /* Set RF Rx filter corner */ - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1e, - 0xfffff, 0x0); - - /* restore WiFi original channel */ - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x18, - 0x3ff, wifi_original_channel); - - outloop = true; - break; - - } - - } while (!outloop); - - psd_scan->is_psd_running = false; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx PSD Sweep Stop!!\n"); - BTC_TRACE(trace_buf); - return is_sweep_ok; - -} - -void halbtc8723b1ant_psd_antenna_detection(IN struct btc_coexist *btcoexist, - IN u32 bt_tx_time, IN u32 bt_le_channel) -{ - u32 i = 0; - u32 wlpsd_cent_freq = 2484, wlpsd_span = 2, wlpsd_sweep_count = 50; - s32 wlpsd_offset = -4; - u8 bt_le_ch[13] = {3, 6, 8, 11, 13, 16, 18, 21, 23, 26, 28, 31, 33}; - - u8 h2c_parameter[3] = {0}, u8tmpa, u8tmpb; - - u8 state = 0; - boolean outloop = false, bt_resp = false; - u32 freq, freq1, freq2, psd_rep1, psd_rep2, delta_freq_per_point, - u32tmp; - struct btc_board_info *board_info = &btcoexist->board_info; - - board_info->btdm_ant_det_finish = false; - memset(psd_scan->ant_det_peak_val, 0, 16 * sizeof(u8)); - memset(psd_scan->ant_det_peak_freq, 0, 16 * sizeof(u8)); - - if (board_info->tfbga_package) /* for TFBGA */ - psd_scan->ant_det_thres_offset = 5; - else - psd_scan->ant_det_thres_offset = 0; - - do { - switch (state) { - case 0: - if (bt_le_channel == 39) - wlpsd_cent_freq = 2484; - else { - for (i = 1; i <= 13; i++) { - if (bt_le_ch[i - 1] == - bt_le_channel) { - wlpsd_cent_freq = 2412 - + (i - 1) * 5; - break; - } - } - - if (i == 14) { - - BTC_SPRINTF(trace_buf, - BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Abort!!, Invalid LE channel = %d\n ", - bt_le_channel); - BTC_TRACE(trace_buf); - outloop = true; - break; - } - } - - wlpsd_sweep_count = bt_tx_time * 238 / - 100; /* bt_tx_time/0.42 */ - wlpsd_sweep_count = wlpsd_sweep_count / 5; - - if (wlpsd_sweep_count % 5 != 0) - wlpsd_sweep_count = (wlpsd_sweep_count / - 5 + 1) * 5; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), BT_LETxTime=%d, BT_LECh = %d\n", - bt_tx_time, bt_le_channel); - BTC_TRACE(trace_buf); - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), wlpsd_cent_freq=%d, wlpsd_offset = %d, wlpsd_span = %d, wlpsd_sweep_count = %d\n", - wlpsd_cent_freq, - wlpsd_offset, - wlpsd_span, - wlpsd_sweep_count); - BTC_TRACE(trace_buf); - - state = 1; - break; - case 1: /* stop coex DM & set antenna path */ - /* Stop Coex DM */ - - /* - btcoexist->stop_coex_dm = true; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Stop Coex DM!!\n"); - BTC_TRACE(trace_buf); */ - - /* Set TDMA off, */ - halbtc8723b1ant_ps_tdma(btcoexist, FORCE_EXEC, - false, 0); - - /* Set coex table */ - halbtc8723b1ant_coex_table_with_type(btcoexist, - FORCE_EXEC, 0); - - if (board_info->btdm_ant_pos == - BTC_ANTENNA_AT_MAIN_PORT) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Antenna at Main Port\n"); - BTC_TRACE(trace_buf); - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Antenna at Aux Port\n"); - BTC_TRACE(trace_buf); - } - - /* Set Antenna path, switch WiFi to un-certain antenna port */ - halbtc8723b1ant_set_ant_path(btcoexist, - BTC_ANT_PATH_BT, FORCE_EXEC, false, - false); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Set Antenna to BT!!\n"); - BTC_TRACE(trace_buf); - - /* Set AFH mask on at WiFi channel 2472MHz +/- 10MHz */ - h2c_parameter[0] = 0x1; - h2c_parameter[1] = 0xd; - h2c_parameter[2] = 0x14; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Set AFH on, Cent-Ch= %d, Mask=%d\n", - h2c_parameter[1], - h2c_parameter[2]); - BTC_TRACE(trace_buf); - - btcoexist->btc_fill_h2c(btcoexist, 0x66, 3, - h2c_parameter); - - u32tmp = btcoexist->btc_read_4byte(btcoexist, - 0x948); - u8tmpa = btcoexist->btc_read_1byte(btcoexist, 0x765); - u8tmpb = btcoexist->btc_read_1byte(btcoexist, - 0x778); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "############# [BTCoex], 0x948=0x%x, 0x765=0x%x, 0x778=0x%x\n", - u32tmp, u8tmpa, u8tmpb); - BTC_TRACE(trace_buf); - - state = 2; - break; - case 2: /* Pre-sweep background psd */ - if (!halbtc8723b1ant_psd_sweep_point(btcoexist, - wlpsd_cent_freq, wlpsd_offset, wlpsd_span, - BT_8723B_1ANT_ANTDET_PSD_POINTS, - BT_8723B_1ANT_ANTDET_PSD_AVGNUM, 3)) { - board_info->btdm_ant_det_finish = false; - board_info->btdm_ant_num_by_ant_det = 1; - psd_scan->ant_det_result = 8; - state = 99; - break; - } - - psd_scan->ant_det_pre_psdscan_peak_val = - psd_scan->psd_max_value; - - if (psd_scan->psd_max_value > - (BT_8723B_1ANT_ANTDET_PSDTHRES_BACKGROUND - + psd_scan->ant_det_thres_offset) * 100) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Abort Antenna Detection!! becaus background = %d > thres (%d)\n", - psd_scan->psd_max_value / 100, - BT_8723B_1ANT_ANTDET_PSDTHRES_BACKGROUND - + psd_scan->ant_det_thres_offset); - BTC_TRACE(trace_buf); - board_info->btdm_ant_det_finish = false; - board_info->btdm_ant_num_by_ant_det = 1; - psd_scan->ant_det_result = 5; - state = 99; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Start Antenna Detection!! becaus background = %d <= thres (%d)\n", - psd_scan->psd_max_value / 100, - BT_8723B_1ANT_ANTDET_PSDTHRES_BACKGROUND - + psd_scan->ant_det_thres_offset); - BTC_TRACE(trace_buf); - state = 3; - } - break; - case 3: - bt_resp = btcoexist->btc_set_bt_ant_detection( - btcoexist, (u8)(bt_tx_time & 0xff), - (u8)(bt_le_channel & 0xff)); - - if (!halbtc8723b1ant_psd_sweep_point(btcoexist, - wlpsd_cent_freq, wlpsd_offset, - wlpsd_span, - BT_8723B_1ANT_ANTDET_PSD_POINTS, - BT_8723B_1ANT_ANTDET_PSD_AVGNUM, - wlpsd_sweep_count)) { - board_info->btdm_ant_det_finish = false; - board_info->btdm_ant_num_by_ant_det = 1; - psd_scan->ant_det_result = 8; - state = 99; - break; - } - - psd_scan->ant_det_psd_scan_peak_val = - psd_scan->psd_max_value; - psd_scan->ant_det_psd_scan_peak_freq = - psd_scan->psd_max_value_point; - state = 4; - break; - case 4: - - if (psd_scan->psd_point == 0) - delta_freq_per_point = 0; - else - delta_freq_per_point = - psd_scan->psd_band_width / - psd_scan->psd_point; - - psd_rep1 = psd_scan->psd_max_value / 100; - psd_rep2 = psd_scan->psd_max_value - psd_rep1 * - 100; - - freq = ((psd_scan->real_cent_freq - 20) * - 1000000 + psd_scan->psd_max_value_point - * delta_freq_per_point); - freq1 = freq / 1000000; - freq2 = freq / 1000 - freq1 * 1000; - - if (freq2 < 100) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Max Value: Freq = %d.0%d MHz", - freq1, freq2); - BTC_TRACE(trace_buf); - CL_SPRINTF(psd_scan->ant_det_peak_freq, - BT_8723B_1ANT_ANTDET_BUF_LEN, - "%d.0%d", freq1, freq2); - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Max Value: Freq = %d.%d MHz", - freq1, freq2); - BTC_TRACE(trace_buf); - CL_SPRINTF(psd_scan->ant_det_peak_freq, - BT_8723B_1ANT_ANTDET_BUF_LEN, - "%d.%d", freq1, freq2); - } - - if (psd_rep2 < 10) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - ", Value = %d.0%d dB\n", - psd_rep1, psd_rep2); - BTC_TRACE(trace_buf); - CL_SPRINTF(psd_scan->ant_det_peak_val, - BT_8723B_1ANT_ANTDET_BUF_LEN, - "%d.0%d", psd_rep1, psd_rep2); - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - ", Value = %d.%d dB\n", - psd_rep1, psd_rep2); - BTC_TRACE(trace_buf); - CL_SPRINTF(psd_scan->ant_det_peak_val, - BT_8723B_1ANT_ANTDET_BUF_LEN, - "%d.%d", psd_rep1, psd_rep2); - } - - psd_scan->ant_det_is_btreply_available = true; - - if (bt_resp == false) { - psd_scan->ant_det_is_btreply_available = - false; - psd_scan->ant_det_result = 0; - board_info->btdm_ant_det_finish = false; - board_info->btdm_ant_num_by_ant_det = 1; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), BT Response = Fail\n "); - BTC_TRACE(trace_buf); - } else if (psd_scan->psd_max_value > - (BT_8723B_1ANT_ANTDET_PSDTHRES_2ANT_BADISOLATION) - * 100) { - psd_scan->ant_det_result = 1; - board_info->btdm_ant_det_finish = true; - board_info->btdm_ant_det_already_init_phydm = - true; - board_info->btdm_ant_num_by_ant_det = 2; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Detect Result = 2-Ant, Bad-Isolation!!\n"); - BTC_TRACE(trace_buf); - } else if (psd_scan->psd_max_value > - (BT_8723B_1ANT_ANTDET_PSDTHRES_2ANT_GOODISOLATION - + psd_scan->ant_det_thres_offset) * 100) { - psd_scan->ant_det_result = 2; - board_info->btdm_ant_det_finish = true; - board_info->btdm_ant_det_already_init_phydm = - true; - board_info->btdm_ant_num_by_ant_det = 2; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Detect Result = 2-Ant, Good-Isolation!!\n"); - BTC_TRACE(trace_buf); - } else if (psd_scan->psd_max_value > - (BT_8723B_1ANT_ANTDET_PSDTHRES_1ANT) * - 100) { - psd_scan->ant_det_result = 3; - board_info->btdm_ant_det_finish = true; - board_info->btdm_ant_det_already_init_phydm = - true; - board_info->btdm_ant_num_by_ant_det = 1; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Detect Result = 1-Ant!!\n"); - BTC_TRACE(trace_buf); - } else { - psd_scan->ant_det_result = 4; - board_info->btdm_ant_det_finish = false; - board_info->btdm_ant_num_by_ant_det = 1; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Detect Result = 1-Ant, un-certainity!!\n"); - BTC_TRACE(trace_buf); - } - - state = 99; - break; - case 99: /* restore setup */ - - /* Set AFH mask off at WiFi channel 2472MHz +/- 10MHz */ - h2c_parameter[0] = 0x0; - h2c_parameter[1] = 0x0; - h2c_parameter[2] = 0x0; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Set AFH on, Cent-Ch= %d, Mask=%d\n", - h2c_parameter[1], h2c_parameter[2]); - BTC_TRACE(trace_buf); - - btcoexist->btc_fill_h2c(btcoexist, 0x66, 3, - h2c_parameter); - - /* Set Antenna Path */ - halbtc8723b1ant_set_ant_path(btcoexist, - BTC_ANT_PATH_PTA, FORCE_EXEC, false, - false); - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Set Antenna to PTA\n!!"); - BTC_TRACE(trace_buf); - - /* Resume Coex DM */ - /* - btcoexist->stop_coex_dm = false; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Resume Coex DM\n!!"); - BTC_TRACE(trace_buf); */ - - /* stimulate coex running */ - /* - halbtc8723b1ant_run_coexist_mechanism( - btcoexist); - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Stimulate Coex running\n!!"); - BTC_TRACE(trace_buf); - */ - - outloop = true; - break; - } - - } while (!outloop); - -} - -void halbtc8723b1ant_psd_antenna_detection_check(IN struct btc_coexist - *btcoexist) -{ - static u32 ant_det_count = 0, ant_det_fail_count = 0; - struct btc_board_info *board_info = &btcoexist->board_info; - - boolean scan, roam; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam); - - /* psd_scan->ant_det_bt_tx_time = 20; */ - psd_scan->ant_det_bt_tx_time = - BT_8723B_1ANT_ANTDET_BTTXTIME; /* 0.42ms*50 = 20ms (0.42ms = 1 PSD sweep) */ - psd_scan->ant_det_bt_le_channel = BT_8723B_1ANT_ANTDET_BTTXCHANNEL; - - ant_det_count++; - - psd_scan->ant_det_try_count = ant_det_count; - - if (scan || roam) { - board_info->btdm_ant_det_finish = false; - psd_scan->ant_det_result = 6; - } else if (coex_sta->bt_disabled) { - board_info->btdm_ant_det_finish = false; - psd_scan->ant_det_result = 11; - } else if (coex_sta->num_of_profile >= 1) { - board_info->btdm_ant_det_finish = false; - psd_scan->ant_det_result = 7; - } else if ( - !psd_scan->ant_det_is_ant_det_available) { /* Antenna initial setup is not ready */ - board_info->btdm_ant_det_finish = false; - psd_scan->ant_det_result = 9; - } else if (coex_sta->c2h_bt_inquiry_page) { - board_info->btdm_ant_det_finish = false; - psd_scan->ant_det_result = 10; - } else { - btcoexist->stop_coex_dm = true; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Stop Coex DM!!\n"); - BTC_TRACE(trace_buf); - - halbtc8723b1ant_psd_antenna_detection(btcoexist, - psd_scan->ant_det_bt_tx_time, - psd_scan->ant_det_bt_le_channel); - - delay_ms(psd_scan->ant_det_bt_tx_time); - - btcoexist->stop_coex_dm = false; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Resume Coex DM\n!!"); - BTC_TRACE(trace_buf); - - /* stimulate coex running */ - - halbtc8723b1ant_run_coexist_mechanism( - btcoexist); - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Stimulate Coex running\n!!"); - BTC_TRACE(trace_buf); - } - - board_info->ant_det_result = psd_scan->ant_det_result; - if (!board_info->btdm_ant_det_finish) - ant_det_fail_count++; - - psd_scan->ant_det_fail_count = ant_det_fail_count; - -} - -/* ************************************************************ - * work around function start with wa_halbtc8723b1ant_ - * ************************************************************ - * ************************************************************ - * extern function start with ex_halbtc8723b1ant_ - * ************************************************************ */ -void ex_halbtc8723b1ant_power_on_setting(IN struct btc_coexist *btcoexist) -{ - struct btc_board_info *board_info = &btcoexist->board_info; - u8 u8tmp = 0x0; - u16 u16tmp = 0x0; - u32 value; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx Execute 8723b 1-Ant PowerOn Setting xxxxxxxxxxxxxxxx!!\n"); - BTC_TRACE(trace_buf); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "Ant Det Finish = %s, Ant Det Number = %d\n", - (board_info->btdm_ant_det_finish ? "Yes" : "No"), - board_info->btdm_ant_num_by_ant_det); - BTC_TRACE(trace_buf); - - btcoexist->stop_coex_dm = true; - - btcoexist->btc_write_1byte(btcoexist, 0x67, 0x20); - - /* enable BB, REG_SYS_FUNC_EN such that we can write 0x948 correctly. */ - u16tmp = btcoexist->btc_read_2byte(btcoexist, 0x2); - btcoexist->btc_write_2byte(btcoexist, 0x2, u16tmp | BIT(0) | BIT(1)); - - /* set GRAN_BT = 1 */ - btcoexist->btc_write_1byte(btcoexist, 0x765, 0x18); - /* set WLAN_ACT = 0 */ - btcoexist->btc_write_1byte(btcoexist, 0x76e, 0x4); - - /* */ - /* S0 or S1 setting and Local register setting(By the setting fw can get ant number, S0/S1, ... info) */ - /* Local setting bit define */ - /* BIT0: "0" for no antenna inverse; "1" for antenna inverse */ - /* BIT1: "0" for internal switch; "1" for external switch */ - /* BIT2: "0" for one antenna; "1" for two antenna */ - /* NOTE: here default all internal switch and 1-antenna ==> BIT1=0 and BIT2=0 */ - if (btcoexist->chip_interface == BTC_INTF_USB) { - /* fixed at S0 for USB interface */ - btcoexist->btc_write_4byte(btcoexist, 0x948, 0x0); - - u8tmp |= 0x1; /* antenna inverse */ - btcoexist->btc_write_local_reg_1byte(btcoexist, 0xfe08, u8tmp); - - board_info->btdm_ant_pos = BTC_ANTENNA_AT_AUX_PORT; - } else { - /* for PCIE and SDIO interface, we check efuse 0xc3[6] */ - if (board_info->single_ant_path == 0) { - /* set to S1 */ - btcoexist->btc_write_4byte(btcoexist, 0x948, 0x280); - board_info->btdm_ant_pos = BTC_ANTENNA_AT_MAIN_PORT; - value = 1; - } else if (board_info->single_ant_path == 1) { - /* set to S0 */ - btcoexist->btc_write_4byte(btcoexist, 0x948, 0x0); - u8tmp |= 0x1; /* antenna inverse */ - board_info->btdm_ant_pos = BTC_ANTENNA_AT_AUX_PORT; - value = 0; - } - - btcoexist->btc_set(btcoexist, BTC_SET_ACT_ANTPOSREGRISTRY_CTRL, - &value); - - if (btcoexist->chip_interface == BTC_INTF_PCI) - btcoexist->btc_write_local_reg_1byte(btcoexist, 0x384, - u8tmp); - else if (btcoexist->chip_interface == BTC_INTF_SDIO) - btcoexist->btc_write_local_reg_1byte(btcoexist, 0x60, - u8tmp); - } -} - -void ex_halbtc8723b1ant_pre_load_firmware(IN struct btc_coexist *btcoexist) -{ -} - -void ex_halbtc8723b1ant_init_hw_config(IN struct btc_coexist *btcoexist, - IN boolean wifi_only) -{ - halbtc8723b1ant_init_hw_config(btcoexist, true, wifi_only); - btcoexist->stop_coex_dm = false; -} - -void ex_halbtc8723b1ant_init_coex_dm(IN struct btc_coexist *btcoexist) -{ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Coex Mechanism Init!!\n"); - BTC_TRACE(trace_buf); - - btcoexist->stop_coex_dm = false; - - halbtc8723b1ant_init_coex_dm(btcoexist); - - halbtc8723b1ant_query_bt_info(btcoexist); -} - -void ex_halbtc8723b1ant_display_coex_info(IN struct btc_coexist *btcoexist) -{ - struct btc_board_info *board_info = &btcoexist->board_info; - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - u8 *cli_buf = btcoexist->cli_buf; - u8 u8tmp[4], i, bt_info_ext, ps_tdma_case = 0; - u16 u16tmp[4]; - u32 u32tmp[4]; - u32 fa_ofdm, fa_cck, cca_ofdm, cca_cck; - u32 fw_ver = 0, bt_patch_ver = 0; - u32 bt_coex_ver = 0; - static u8 pop_report_in_10s = 0; - u32 phyver = 0; - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n ============[BT Coexist info]============"); - CL_PRINTF(cli_buf); - - if (btcoexist->manual_control) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n ============[Under Manual Control]============"); - CL_PRINTF(cli_buf); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n =========================================="); - CL_PRINTF(cli_buf); - } - if (btcoexist->stop_coex_dm) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n ============[Coex is STOPPED]============"); - CL_PRINTF(cli_buf); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n =========================================="); - CL_PRINTF(cli_buf); - } - - if (psd_scan->ant_det_try_count == 0) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d", - "Ant PG Num/ Mech/ Pos", - board_info->pg_ant_num, board_info->btdm_ant_num, - board_info->btdm_ant_pos); - CL_PRINTF(cli_buf); - } else { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %d/ %d/ %d (%d/%d/%d)", - "Ant PG Num/ Mech(Ant_Det)/ Pos", - board_info->pg_ant_num, - board_info->btdm_ant_num_by_ant_det, - board_info->btdm_ant_pos, - psd_scan->ant_det_try_count, - psd_scan->ant_det_fail_count, - psd_scan->ant_det_result); - CL_PRINTF(cli_buf); - - if (board_info->btdm_ant_det_finish) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s", - "Ant Det PSD Value", - psd_scan->ant_det_peak_val); - CL_PRINTF(cli_buf); - } - } - - if (board_info->ant_det_result_five_complete) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %d", - "Ant number by AntDet", - board_info->btdm_ant_num_by_ant_det); - CL_PRINTF(cli_buf); - } - - /* btcoexist->btc_get(btcoexist, BTC_GET_U4_BT_PATCH_VER, &bt_patch_ver); */ - bt_patch_ver = btcoexist->bt_info.bt_get_fw_ver; - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, &fw_ver); - phyver = btcoexist->btc_get_bt_phydm_version(btcoexist); - bt_coex_ver = ((coex_sta->bt_coex_supported_version & 0xff00) >> 8); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %d_%02x/ 0x%02x/ 0x%02x (%s)", - "CoexVer WL/ BT_Desired/ BT_Report", - glcoex_ver_date_8723b_1ant, glcoex_ver_8723b_1ant, - glcoex_ver_btdesired_8723b_1ant, - bt_coex_ver, - (bt_coex_ver == 0xff ? "Unknown" : - (bt_coex_ver >= glcoex_ver_btdesired_8723b_1ant ? - "Match" : "Mis-Match"))); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = 0x%x/ 0x%x/ v%d/ %c", - "W_FW/ B_FW/ Phy/ Kt", - fw_ver, bt_patch_ver, phyver, - coex_sta->cut_version + 65); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x ", - "Wifi channel informed to BT", - coex_dm->wifi_chnl_info[0], coex_dm->wifi_chnl_info[1], - coex_dm->wifi_chnl_info[2]); - CL_PRINTF(cli_buf); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s/ %s", - "WifibHiPri/ Ccklock/ CckEverLock", - (coex_sta->wifi_is_high_pri_task ? "Yes" : "No"), - (coex_sta->cck_lock ? "Yes" : "No"), - (coex_sta->cck_ever_lock ? "Yes" : "No")); - CL_PRINTF(cli_buf); - - /* wifi status */ - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s", - "============[Wifi Status]============"); - CL_PRINTF(cli_buf); - btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_WIFI_STATUS); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s", - "============[BT Status]============"); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s", - "BT Abnormal scan", - (coex_sta->bt_abnormal_scan) ? "Yes" : "No"); - CL_PRINTF(cli_buf); - - pop_report_in_10s++; - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = [%s/ %d/ %d/ %d] ", - "BT [status/ rssi/ retryCnt/ popCnt]", - ((coex_sta->bt_disabled) ? ("disabled") : (( - coex_sta->c2h_bt_inquiry_page) ? ("inquiry/page scan") - : ((BT_8723B_1ANT_BT_STATUS_NON_CONNECTED_IDLE == - coex_dm->bt_status) ? "non-connected idle" : - ((BT_8723B_1ANT_BT_STATUS_CONNECTED_IDLE == coex_dm->bt_status) - ? "connected-idle" : "busy")))), - coex_sta->bt_rssi, coex_sta->bt_retry_cnt, - coex_sta->pop_event_cnt); - CL_PRINTF(cli_buf); - - if (pop_report_in_10s >= 5) { - coex_sta->pop_event_cnt = 0; - pop_report_in_10s = 0; - } - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %d / %d / %d / %d / %d / %d", - "SCO/HID/PAN/A2DP/NameReq/WHQL", - bt_link_info->sco_exist, bt_link_info->hid_exist, - bt_link_info->pan_exist, bt_link_info->a2dp_exist, - coex_sta->c2h_bt_remote_name_req, - coex_sta->bt_whck_test); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s", - "BT Role", - (bt_link_info->slave_role) ? "Slave" : "Master"); - CL_PRINTF(cli_buf); - - bt_info_ext = coex_sta->bt_info_ext; - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d", - "A2DP Rate/Bitpool", - (bt_info_ext & BIT(0)) ? "BR" : "EDR", coex_sta->a2dp_bit_pool); - CL_PRINTF(cli_buf); - - for (i = 0; i < BT_INFO_SRC_8723B_1ANT_MAX; i++) { - if (coex_sta->bt_info_c2h_cnt[i]) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %02x %02x %02x %02x %02x %02x %02x(%d)", - glbt_info_src_8723b_1ant[i], - coex_sta->bt_info_c2h[i][0], - coex_sta->bt_info_c2h[i][1], - coex_sta->bt_info_c2h[i][2], - coex_sta->bt_info_c2h[i][3], - coex_sta->bt_info_c2h[i][4], - coex_sta->bt_info_c2h[i][5], - coex_sta->bt_info_c2h[i][6], - coex_sta->bt_info_c2h_cnt[i]); - CL_PRINTF(cli_buf); - } - } - - if (btcoexist->manual_control) - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s", - "============[mechanisms] (before Manual)============"); - else - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s", - "============[mechanisms]============"); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d", - "SM[LowPenaltyRA]", - coex_dm->cur_low_penalty_ra); - CL_PRINTF(cli_buf); - - ps_tdma_case = coex_dm->cur_ps_tdma; - if (board_info->btdm_ant_num_by_ant_det == 2) { - if (coex_dm->cur_ps_tdma_on) - ps_tdma_case = ps_tdma_case + - 100; /* for WiFi RSSI low or BT RSSI low */ - else - ps_tdma_case = - 1; /* always translate to TDMA(off,1) for TDMA-off case */ - } - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %02x %02x %02x %02x %02x case-%d (%s,%s)", - "PS TDMA", - coex_dm->ps_tdma_para[0], coex_dm->ps_tdma_para[1], - coex_dm->ps_tdma_para[2], coex_dm->ps_tdma_para[3], - coex_dm->ps_tdma_para[4], ps_tdma_case, - (coex_dm->cur_ps_tdma_on ? "On" : "Off"), - (coex_dm->auto_tdma_adjust ? "Adj" : "Fix")); - - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d", - "Coex Table Type", - coex_sta->coex_table_type); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d", - "IgnWlanAct", - coex_dm->cur_ignore_wlan_act); - CL_PRINTF(cli_buf); - - /* - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x ", "Latest error condition(should be 0)", - coex_dm->error_condition); - CL_PRINTF(cli_buf); - */ - - /* Hw setting */ - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s", - "============[Hw setting]============"); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/0x%x/0x%x/0x%x", - "backup ARFR1/ARFR2/RL/AMaxTime", - coex_dm->backup_arfr_cnt1, coex_dm->backup_arfr_cnt2, - coex_dm->backup_retry_limit, - coex_dm->backup_ampdu_max_time); - CL_PRINTF(cli_buf); - - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x430); - u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x434); - u16tmp[0] = btcoexist->btc_read_2byte(btcoexist, 0x42a); - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x456); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/0x%x/0x%x/0x%x", - "0x430/0x434/0x42a/0x456", - u32tmp[0], u32tmp[1], u16tmp[0], u8tmp[0]); - CL_PRINTF(cli_buf); - - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x778); - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x6cc); - u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x880); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", - "0x778/0x6cc/0x880[29:25]", - u8tmp[0], u32tmp[0], (u32tmp[1] & 0x3e000000) >> 25); - CL_PRINTF(cli_buf); - - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x948); - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x67); - u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x764); - u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0x76e); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", - "0x948/ 0x67[5] / 0x764 / 0x76e", - u32tmp[0], ((u8tmp[0] & 0x20) >> 5), (u32tmp[1] & 0xffff), - u8tmp[1]); - CL_PRINTF(cli_buf); - - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x92c); - u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x930); - u32tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0x944); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", - "0x92c[1:0]/ 0x930[7:0]/0x944[1:0]", - u32tmp[0] & 0x3, u32tmp[1] & 0xff, u32tmp[2] & 0x3); - CL_PRINTF(cli_buf); - - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x39); - u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0x40); - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x4c); - u8tmp[2] = btcoexist->btc_read_1byte(btcoexist, 0x64); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", - "0x38[11]/0x40/0x4c[24:23]/0x64[0]", - ((u8tmp[0] & 0x8) >> 3), u8tmp[1], - ((u32tmp[0] & 0x01800000) >> 23), u8tmp[2] & 0x1); - CL_PRINTF(cli_buf); - - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x550); - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x522); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", - "0x550(bcn ctrl)/0x522", - u32tmp[0], u8tmp[0]); - CL_PRINTF(cli_buf); - - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xc50); - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x49c); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", - "0xc50(dig)/0x49c(null-drop)", - u32tmp[0] & 0xff, u8tmp[0]); - CL_PRINTF(cli_buf); - - fa_ofdm = btcoexist->btc_phydm_query_PHY_counter(btcoexist, - PHYDM_INFO_FA_OFDM); - fa_cck = btcoexist->btc_phydm_query_PHY_counter(btcoexist, - PHYDM_INFO_FA_CCK); - cca_ofdm = btcoexist->btc_phydm_query_PHY_counter(btcoexist, - PHYDM_INFO_CCA_OFDM); - cca_cck = btcoexist->btc_phydm_query_PHY_counter(btcoexist, - PHYDM_INFO_CCA_CCK); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", - "CCK-CCA/CCK-FA/OFDM-CCA/OFDM-FA", - cca_cck, fa_cck, cca_ofdm, fa_ofdm); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d", - "CRC_OK CCK/11g/11n/11n-agg", - coex_sta->crc_ok_cck, coex_sta->crc_ok_11g, - coex_sta->crc_ok_11n, coex_sta->crc_ok_11n_vht); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d", - "CRC_Err CCK/11g/11n/11n-agg", - coex_sta->crc_err_cck, coex_sta->crc_err_11g, - coex_sta->crc_err_11n, coex_sta->crc_err_11n_vht); - CL_PRINTF(cli_buf); - - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x6c0); - u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x6c4); - u32tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0x6c8); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", - "0x6c0/0x6c4/0x6c8(coexTable)", - u32tmp[0], u32tmp[1], u32tmp[2]); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", - "0x770(high-pri rx/tx)", - coex_sta->high_priority_rx, coex_sta->high_priority_tx); - CL_PRINTF(cli_buf); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", - "0x774(low-pri rx/tx)", - coex_sta->low_priority_rx, coex_sta->low_priority_tx); - CL_PRINTF(cli_buf); -#if (BT_AUTO_REPORT_ONLY_8723B_1ANT == 1) - /* halbtc8723b1ant_monitor_bt_ctr(btcoexist); */ -#endif - btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_COEX_STATISTICS); -} - -void ex_halbtc8723b1ant_ips_notify(IN struct btc_coexist *btcoexist, IN u8 type) -{ - if (btcoexist->manual_control || btcoexist->stop_coex_dm) - return; - - if (BTC_IPS_ENTER == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], IPS ENTER notify\n"); - BTC_TRACE(trace_buf); - coex_sta->under_ips = true; - - halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); - halbtc8723b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT, - FORCE_EXEC, false, true); - halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - } else if (BTC_IPS_LEAVE == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], IPS LEAVE notify\n"); - BTC_TRACE(trace_buf); - - halbtc8723b1ant_init_hw_config(btcoexist, false, false); - halbtc8723b1ant_init_coex_dm(btcoexist); - halbtc8723b1ant_query_bt_info(btcoexist); - - coex_sta->under_ips = false; - } -} - -void ex_halbtc8723b1ant_lps_notify(IN struct btc_coexist *btcoexist, IN u8 type) -{ - if (btcoexist->manual_control || btcoexist->stop_coex_dm) - return; - - if (BTC_LPS_ENABLE == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], LPS ENABLE notify\n"); - BTC_TRACE(trace_buf); - coex_sta->under_lps = true; - } else if (BTC_LPS_DISABLE == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], LPS DISABLE notify\n"); - BTC_TRACE(trace_buf); - coex_sta->under_lps = false; - } -} - -void ex_halbtc8723b1ant_scan_notify(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - boolean wifi_connected = false, bt_hs_on = false; - u32 wifi_link_status = 0; - u32 num_of_wifi_link = 0; - boolean bt_ctrl_agg_buf_size = false; - u8 agg_buf_size = 5; - - u8 u8tmpa, u8tmpb; - u32 u32tmp; - - if (btcoexist->manual_control || - btcoexist->stop_coex_dm) - return; - - if (BTC_SCAN_START == type) { - coex_sta->wifi_is_high_pri_task = true; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCAN START notify\n"); - BTC_TRACE(trace_buf); - psd_scan->ant_det_is_ant_det_available = true; - halbtc8723b1ant_ps_tdma(btcoexist, FORCE_EXEC, false, - 8); /* Force antenna setup for no scan result issue */ - halbtc8723b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA, - FORCE_EXEC, false, false); - u32tmp = btcoexist->btc_read_4byte(btcoexist, 0x948); - u8tmpa = btcoexist->btc_read_1byte(btcoexist, 0x765); - u8tmpb = btcoexist->btc_read_1byte(btcoexist, 0x67); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], 0x948=0x%x, 0x765=0x%x, 0x67=0x%x\n", - u32tmp, u8tmpa, u8tmpb); - BTC_TRACE(trace_buf); - } else { - coex_sta->wifi_is_high_pri_task = false; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCAN FINISH notify\n"); - BTC_TRACE(trace_buf); - - btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM, - &coex_sta->scan_ap_num); - } - - if (coex_sta->bt_disabled) - return; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - - halbtc8723b1ant_query_bt_info(btcoexist); - - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS, - &wifi_link_status); - num_of_wifi_link = wifi_link_status >> 16; - if (num_of_wifi_link >= 2) { - halbtc8723b1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0); - halbtc8723b1ant_limited_rx(btcoexist, NORMAL_EXEC, false, - bt_ctrl_agg_buf_size, agg_buf_size); - halbtc8723b1ant_action_wifi_multi_port(btcoexist); - return; - } - - if (coex_sta->c2h_bt_inquiry_page) { - halbtc8723b1ant_action_bt_inquiry(btcoexist); - return; - } else if (bt_hs_on) { - halbtc8723b1ant_action_hs(btcoexist); - return; - } - - if (BTC_SCAN_START == type) { - if (!wifi_connected) /* non-connected scan */ - halbtc8723b1ant_action_wifi_not_connected_scan( - btcoexist); - else /* wifi is connected */ - halbtc8723b1ant_action_wifi_connected_scan(btcoexist); - } else if (BTC_SCAN_FINISH == type) { - if (!wifi_connected) /* non-connected scan */ - halbtc8723b1ant_action_wifi_not_connected(btcoexist); - else - halbtc8723b1ant_action_wifi_connected(btcoexist); - } -} - -void ex_halbtc8723b1ant_set_antenna_notify(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - struct btc_board_info *board_info = &btcoexist->board_info; - - if (btcoexist->manual_control || btcoexist->stop_coex_dm) - return; - - if (type == 2) /* two antenna */ - halbtc8723b1ant_mechanism_switch(btcoexist, true); - else /* one antenna */ - halbtc8723b1ant_mechanism_switch(btcoexist, false); -} - -void ex_halbtc8723b1ant_connect_notify(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - boolean wifi_connected = false, bt_hs_on = false; - u32 wifi_link_status = 0; - u32 num_of_wifi_link = 0; - boolean bt_ctrl_agg_buf_size = false; - u8 agg_buf_size = 5; - - if (btcoexist->manual_control || - btcoexist->stop_coex_dm) - return; - - if (BTC_ASSOCIATE_START == type) { - coex_sta->wifi_is_high_pri_task = true; - psd_scan->ant_det_is_ant_det_available = true; - halbtc8723b1ant_ps_tdma(btcoexist, FORCE_EXEC, false, - 8); /* Force antenna setup for no scan result issue */ - halbtc8723b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA, - FORCE_EXEC, false, false); - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], CONNECT START notify\n"); - BTC_TRACE(trace_buf); - coex_dm->arp_cnt = 0; - } else { - coex_sta->wifi_is_high_pri_task = false; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], CONNECT FINISH notify\n"); - BTC_TRACE(trace_buf); - /* coex_dm->arp_cnt = 0; */ - } - - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS, - &wifi_link_status); - num_of_wifi_link = wifi_link_status >> 16; - if (num_of_wifi_link >= 2) { - halbtc8723b1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0); - halbtc8723b1ant_limited_rx(btcoexist, NORMAL_EXEC, false, - bt_ctrl_agg_buf_size, agg_buf_size); - halbtc8723b1ant_action_wifi_multi_port(btcoexist); - return; - } - - btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); - if (coex_sta->c2h_bt_inquiry_page) { - halbtc8723b1ant_action_bt_inquiry(btcoexist); - return; - } else if (bt_hs_on) { - halbtc8723b1ant_action_hs(btcoexist); - return; - } - - if (BTC_ASSOCIATE_START == type) - halbtc8723b1ant_action_wifi_not_connected_asso_auth(btcoexist); - else if (BTC_ASSOCIATE_FINISH == type) { - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - if (!wifi_connected) /* non-connected scan */ - halbtc8723b1ant_action_wifi_not_connected(btcoexist); - else - halbtc8723b1ant_action_wifi_connected(btcoexist); - } -} - -void ex_halbtc8723b1ant_media_status_notify(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - u8 h2c_parameter[3] = {0}; - u32 wifi_bw; - u8 wifi_central_chnl; - boolean wifi_under_b_mode = false; - - if (btcoexist->manual_control || - btcoexist->stop_coex_dm) - return; - - if (BTC_MEDIA_CONNECT == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], MEDIA connect notify\n"); - BTC_TRACE(trace_buf); - halbtc8723b1ant_ps_tdma(btcoexist, FORCE_EXEC, false, - 8); /* Force antenna setup for no scan result issue */ - halbtc8723b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA, - FORCE_EXEC, false, false); - psd_scan->ant_det_is_ant_det_available = true; - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_B_MODE, - &wifi_under_b_mode); - - /* Set CCK Tx/Rx high Pri except 11b mode */ - if (wifi_under_b_mode) { - btcoexist->btc_write_1byte(btcoexist, 0x6cd, - 0x00); /* CCK Tx */ - btcoexist->btc_write_1byte(btcoexist, 0x6cf, - 0x00); /* CCK Rx */ - } else { - btcoexist->btc_write_1byte(btcoexist, 0x6cd, - 0x00); /* CCK Tx */ - btcoexist->btc_write_1byte(btcoexist, 0x6cf, - 0x10); /* CCK Rx */ - } - - coex_dm->backup_arfr_cnt1 = btcoexist->btc_read_4byte(btcoexist, - 0x430); - coex_dm->backup_arfr_cnt2 = btcoexist->btc_read_4byte(btcoexist, - 0x434); - coex_dm->backup_retry_limit = btcoexist->btc_read_2byte( - btcoexist, 0x42a); - coex_dm->backup_ampdu_max_time = btcoexist->btc_read_1byte( - btcoexist, 0x456); - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], MEDIA disconnect notify\n"); - BTC_TRACE(trace_buf); - coex_dm->arp_cnt = 0; - - btcoexist->btc_write_1byte(btcoexist, 0x6cd, 0x0); /* CCK Tx */ - btcoexist->btc_write_1byte(btcoexist, 0x6cf, 0x0); /* CCK Rx */ - - coex_sta->cck_ever_lock = false; - } - - /* only 2.4G we need to inform bt the chnl mask */ - btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_CENTRAL_CHNL, - &wifi_central_chnl); - if ((BTC_MEDIA_CONNECT == type) && - (wifi_central_chnl <= 14)) { - /* h2c_parameter[0] = 0x1; */ - h2c_parameter[0] = 0x0; - h2c_parameter[1] = wifi_central_chnl; - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw); - if (BTC_WIFI_BW_HT40 == wifi_bw) - h2c_parameter[2] = 0x30; - else - h2c_parameter[2] = 0x20; - } - - coex_dm->wifi_chnl_info[0] = h2c_parameter[0]; - coex_dm->wifi_chnl_info[1] = h2c_parameter[1]; - coex_dm->wifi_chnl_info[2] = h2c_parameter[2]; - - btcoexist->btc_fill_h2c(btcoexist, 0x66, 3, h2c_parameter); -} - -void ex_halbtc8723b1ant_specific_packet_notify(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - boolean bt_hs_on = false; - u32 wifi_link_status = 0; - u32 num_of_wifi_link = 0; - boolean bt_ctrl_agg_buf_size = false, under_4way = false; - u8 agg_buf_size = 5; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS, - &under_4way); - - if (btcoexist->manual_control || - btcoexist->stop_coex_dm) - return; - - if (BTC_PACKET_DHCP == type || - BTC_PACKET_EAPOL == type || - BTC_PACKET_ARP == type) { - if (BTC_PACKET_ARP == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], specific Packet ARP notify\n"); - BTC_TRACE(trace_buf); - - coex_dm->arp_cnt++; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ARP Packet Count = %d\n", - coex_dm->arp_cnt); - BTC_TRACE(trace_buf); - - if ((coex_dm->arp_cnt >= 10) && - (!under_4way)) /* if APR PKT > 10 after connect, do not go to ActionWifiConnectedSpecificPacket(btcoexist) */ - coex_sta->wifi_is_high_pri_task = false; - else - coex_sta->wifi_is_high_pri_task = true; - } else { - coex_sta->wifi_is_high_pri_task = true; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], specific Packet DHCP or EAPOL notify\n"); - BTC_TRACE(trace_buf); - } - } else { - coex_sta->wifi_is_high_pri_task = false; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], specific Packet [Type = %d] notify\n", type); - BTC_TRACE(trace_buf); - } - - coex_sta->specific_pkt_period_cnt = 0; - - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS, - &wifi_link_status); - num_of_wifi_link = wifi_link_status >> 16; - if (num_of_wifi_link >= 2) { - halbtc8723b1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0); - halbtc8723b1ant_limited_rx(btcoexist, NORMAL_EXEC, false, - bt_ctrl_agg_buf_size, agg_buf_size); - halbtc8723b1ant_action_wifi_multi_port(btcoexist); - return; - } - - btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); - if (coex_sta->c2h_bt_inquiry_page) { - halbtc8723b1ant_action_bt_inquiry(btcoexist); - return; - } else if (bt_hs_on) { - halbtc8723b1ant_action_hs(btcoexist); - return; - } - - if (BTC_PACKET_DHCP == type || - BTC_PACKET_EAPOL == type || - ((BTC_PACKET_ARP == type) && (coex_sta->wifi_is_high_pri_task))) - halbtc8723b1ant_action_wifi_connected_specific_packet( - btcoexist); -} - -/* Donot remove optimize off flag, otherwise antenna detection would trigger BT collapsed */ -void ex_halbtc8723b1ant_bt_info_notify(IN struct btc_coexist *btcoexist, - IN u8 *tmp_buf, IN u8 length) -{ - u8 bt_info = 0; - u8 i, rsp_source = 0; - boolean wifi_connected = false; - boolean bt_busy = false; - struct btc_board_info *board_info = &btcoexist->board_info; - - coex_sta->c2h_bt_info_req_sent = false; - - rsp_source = tmp_buf[0] & 0xf; - if (rsp_source >= BT_INFO_SRC_8723B_1ANT_MAX) - rsp_source = BT_INFO_SRC_8723B_1ANT_WIFI_FW; - coex_sta->bt_info_c2h_cnt[rsp_source]++; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Bt info[%d], length=%d, hex data=[", rsp_source, - length); - BTC_TRACE(trace_buf); - for (i = 0; i < length; i++) { - coex_sta->bt_info_c2h[rsp_source][i] = tmp_buf[i]; - if (i == 1) - bt_info = tmp_buf[i]; - if (i == length - 1) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "0x%02x]\n", - tmp_buf[i]); - BTC_TRACE(trace_buf); - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "0x%02x, ", - tmp_buf[i]); - BTC_TRACE(trace_buf); - } - } - - /* if 0xff, it means BT is under WHCK test */ - if (bt_info == 0xff) - coex_sta->bt_whck_test = true; - else - coex_sta->bt_whck_test = false; - - if (BT_INFO_SRC_8723B_1ANT_WIFI_FW != rsp_source) { - coex_sta->bt_retry_cnt = /* [3:0] */ - coex_sta->bt_info_c2h[rsp_source][2] & 0xf; - - if (coex_sta->bt_retry_cnt >= 1) - coex_sta->pop_event_cnt++; - - if (coex_sta->bt_info_c2h[rsp_source][2] & 0x20) - coex_sta->c2h_bt_remote_name_req = true; - else - coex_sta->c2h_bt_remote_name_req = false; - - coex_sta->bt_rssi = - coex_sta->bt_info_c2h[rsp_source][3] * 2 - 90; - /* coex_sta->bt_info_c2h[rsp_source][3]*2+10; */ - - coex_sta->bt_info_ext = - coex_sta->bt_info_c2h[rsp_source][4]; - - if (coex_sta->bt_info_c2h[rsp_source][1] == 0x49) { - coex_sta->a2dp_bit_pool = - coex_sta->bt_info_c2h[rsp_source][6]; - } else - coex_sta->a2dp_bit_pool = 0; - - coex_sta->bt_tx_rx_mask = (coex_sta->bt_info_c2h[rsp_source][2] - & 0x40); - btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TX_RX_MASK, - &coex_sta->bt_tx_rx_mask); - - if (btcoexist->stop_coex_dm) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "############# [BTCoex], BT info Notify() return because stop_coex_dm\n"); - BTC_TRACE(trace_buf); - - return; - } - -#if BT_8723B_1ANT_ANTDET_ENABLE -#if BT_8723B_1ANT_ANTDET_COEXMECHANISMSWITCH_ENABLE - if ((board_info->btdm_ant_det_finish) && - (board_info->btdm_ant_num_by_ant_det == 2)) { - if (coex_sta->bt_tx_rx_mask) { - - /* BT TRx mask off */ - btcoexist->btc_set_bt_trx_mask(btcoexist, 0); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "############# [BTCoex], BT TRx Mask off for BT Info Notify\n"); - BTC_TRACE(trace_buf); - } - } else -#endif -#endif - - { - if (!coex_sta->bt_tx_rx_mask) { - - /* BT TRx mask on */ - btcoexist->btc_set_bt_trx_mask(btcoexist, 1); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "############# [BTCoex], BT TRx Mask on for BT Info Notify\n"); - BTC_TRACE(trace_buf); - } - } - - /* Here we need to resend some wifi info to BT */ - /* because bt is reset and loss of the info. */ - if (coex_sta->bt_info_ext & BIT(1)) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT ext info bit1 check, send wifi BW&Chnl to BT!!\n"); - BTC_TRACE(trace_buf); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - if (wifi_connected) - ex_halbtc8723b1ant_media_status_notify( - btcoexist, BTC_MEDIA_CONNECT); - else - ex_halbtc8723b1ant_media_status_notify( - btcoexist, BTC_MEDIA_DISCONNECT); - } - - if (coex_sta->bt_info_ext & BIT(3)) { - if (!btcoexist->manual_control && - !btcoexist->stop_coex_dm) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT ext info bit3 check, set BT NOT to ignore Wlan active!!\n"); - BTC_TRACE(trace_buf); - halbtc8723b1ant_ignore_wlan_act(btcoexist, - FORCE_EXEC, false); - } - } else { - /* BT already NOT ignore Wlan active, do nothing here. */ - } -#if (BT_AUTO_REPORT_ONLY_8723B_1ANT == 0) - if ((coex_sta->bt_info_ext & BIT(4))) { - /* BT auto report already enabled, do nothing */ - } else - halbtc8723b1ant_bt_auto_report(btcoexist, FORCE_EXEC, - true); -#endif - } - - /* check BIT2 first ==> check if bt is under inquiry or page scan */ - if (bt_info & BT_INFO_8723B_1ANT_B_INQ_PAGE) - coex_sta->c2h_bt_inquiry_page = true; - else - coex_sta->c2h_bt_inquiry_page = false; - - coex_sta->num_of_profile = 0; - - /* set link exist status */ - if (!(bt_info & BT_INFO_8723B_1ANT_B_CONNECTION)) { - coex_sta->bt_link_exist = false; - coex_sta->pan_exist = false; - coex_sta->a2dp_exist = false; - coex_sta->hid_exist = false; - coex_sta->sco_exist = false; - - coex_sta->bt_hi_pri_link_exist = false; - } else { /* connection exists */ - coex_sta->bt_link_exist = true; - if (bt_info & BT_INFO_8723B_1ANT_B_FTP) { - coex_sta->pan_exist = true; - coex_sta->num_of_profile++; - } else - coex_sta->pan_exist = false; - if (bt_info & BT_INFO_8723B_1ANT_B_A2DP) { - coex_sta->a2dp_exist = true; - coex_sta->num_of_profile++; - } else - coex_sta->a2dp_exist = false; - if (bt_info & BT_INFO_8723B_1ANT_B_HID) { - coex_sta->hid_exist = true; - coex_sta->num_of_profile++; - } else - coex_sta->hid_exist = false; - if (bt_info & BT_INFO_8723B_1ANT_B_SCO_ESCO) { - coex_sta->sco_exist = true; - coex_sta->num_of_profile++; - } else - coex_sta->sco_exist = false; - - if ((coex_sta->hid_exist == false) && - (coex_sta->c2h_bt_inquiry_page == false) && - (coex_sta->sco_exist == false)) { - if (coex_sta->high_priority_tx + - coex_sta->high_priority_rx >= 160) { - coex_sta->hid_exist = true; - coex_sta->wrong_profile_notification++; - coex_sta->num_of_profile++; - bt_info = bt_info | 0x28; - } - } - - /* Add Hi-Pri Tx/Rx counter to avoid false detection */ - if (((coex_sta->hid_exist) || (coex_sta->sco_exist)) && - (coex_sta->high_priority_tx + - coex_sta->high_priority_rx >= 160) - && (!coex_sta->c2h_bt_inquiry_page)) - coex_sta->bt_hi_pri_link_exist = true; - - if ((bt_info & BT_INFO_8723B_1ANT_B_ACL_BUSY) && - (coex_sta->num_of_profile == 0)) { - if (coex_sta->low_priority_tx + - coex_sta->low_priority_rx >= 160) { - coex_sta->pan_exist = true; - coex_sta->num_of_profile++; - coex_sta->wrong_profile_notification++; - bt_info = bt_info | 0x88; - } - } - } - - halbtc8723b1ant_update_bt_link_info(btcoexist); - - bt_info = bt_info & - 0x1f; /* mask profile bit for connect-ilde identification ( for CSR case: A2DP idle --> 0x41) */ - - if (!(bt_info & BT_INFO_8723B_1ANT_B_CONNECTION)) - coex_dm->bt_status = BT_8723B_1ANT_BT_STATUS_NON_CONNECTED_IDLE; - else if (bt_info == - BT_INFO_8723B_1ANT_B_CONNECTION) /* connection exists but no busy */ - coex_dm->bt_status = BT_8723B_1ANT_BT_STATUS_CONNECTED_IDLE; - else if ((bt_info & BT_INFO_8723B_1ANT_B_SCO_ESCO) || - (bt_info & BT_INFO_8723B_1ANT_B_SCO_BUSY)) - coex_dm->bt_status = BT_8723B_1ANT_BT_STATUS_SCO_BUSY; - else if (bt_info & BT_INFO_8723B_1ANT_B_ACL_BUSY) { - if (BT_8723B_1ANT_BT_STATUS_ACL_BUSY != coex_dm->bt_status) - coex_dm->auto_tdma_adjust = false; - coex_dm->bt_status = BT_8723B_1ANT_BT_STATUS_ACL_BUSY; - } else - coex_dm->bt_status = BT_8723B_1ANT_BT_STATUS_MAX; - - if ((BT_8723B_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) || - (BT_8723B_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) || - (BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY == coex_dm->bt_status)) - bt_busy = true; - else - bt_busy = false; - btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bt_busy); - - halbtc8723b1ant_run_coexist_mechanism(btcoexist); -} - -void ex_halbtc8723b1ant_rf_status_notify(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - u32 u32tmp; - u8 u8tmpa, u8tmpb, u8tmpc; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], RF Status notify\n"); - BTC_TRACE(trace_buf); - - if (BTC_RF_ON == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], RF is turned ON!!\n"); - BTC_TRACE(trace_buf); - btcoexist->stop_coex_dm = false; - } else if (BTC_RF_OFF == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], RF is turned OFF!!\n"); - BTC_TRACE(trace_buf); - - halbtc8723b1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 0); - halbtc8723b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT, - FORCE_EXEC, false, true); - - halbtc8723b1ant_ignore_wlan_act(btcoexist, FORCE_EXEC, true); - btcoexist->stop_coex_dm = true; - - u32tmp = btcoexist->btc_read_4byte(btcoexist, 0x948); - u8tmpa = btcoexist->btc_read_1byte(btcoexist, 0x765); - u8tmpb = btcoexist->btc_read_1byte(btcoexist, 0x67); - u8tmpc = btcoexist->btc_read_1byte(btcoexist, 0x76e); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "############# [BTCoex], 0x948=0x%x, 0x765=0x%x, 0x67=0x%x, 0x76e=0x%x\n", - u32tmp, u8tmpa, u8tmpb, u8tmpc); - BTC_TRACE(trace_buf); - - } -} - -void ex_halbtc8723b1ant_halt_notify(IN struct btc_coexist *btcoexist) -{ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], Halt notify\n"); - BTC_TRACE(trace_buf); - - halbtc8723b1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 0); - halbtc8723b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT, FORCE_EXEC, - false, true); - - halbtc8723b1ant_ignore_wlan_act(btcoexist, FORCE_EXEC, true); - - ex_halbtc8723b1ant_media_status_notify(btcoexist, BTC_MEDIA_DISCONNECT); - - btcoexist->stop_coex_dm = true; -} - -void ex_halbtc8723b1ant_pnp_notify(IN struct btc_coexist *btcoexist, - IN u8 pnp_state) -{ - if (BTC_WIFI_PNP_SLEEP == pnp_state) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Pnp notify to SLEEP\n"); - BTC_TRACE(trace_buf); - - halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); - halbtc8723b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT, - FORCE_EXEC, false, true); - halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2); - - /* Sinda 20150819, workaround for driver skip leave IPS/LPS to speed up sleep time. */ - /* Driver do not leave IPS/LPS when driver is going to sleep, so BTCoexistence think wifi is still under IPS/LPS */ - /* BT should clear UnderIPS/UnderLPS state to avoid mismatch state after wakeup. */ - coex_sta->under_ips = false; - coex_sta->under_lps = false; - btcoexist->stop_coex_dm = true; - } else if (BTC_WIFI_PNP_WAKE_UP == pnp_state) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Pnp notify to WAKE UP\n"); - BTC_TRACE(trace_buf); - btcoexist->stop_coex_dm = false; - halbtc8723b1ant_init_hw_config(btcoexist, false, false); - halbtc8723b1ant_init_coex_dm(btcoexist); - halbtc8723b1ant_query_bt_info(btcoexist); - } -} - -void ex_halbtc8723b1ant_coex_dm_reset(IN struct btc_coexist *btcoexist) -{ - - halbtc8723b1ant_init_hw_config(btcoexist, false, false); - /* btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0); */ - /* btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x2, 0xfffff, 0x0); */ - halbtc8723b1ant_init_coex_dm(btcoexist); -} - -void ex_halbtc8723b1ant_periodical(IN struct btc_coexist *btcoexist) -{ - u32 bt_patch_ver; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ==========================Periodical===========================\n"); - BTC_TRACE(trace_buf); - -#if (BT_AUTO_REPORT_ONLY_8723B_1ANT == 0) - halbtc8723b1ant_query_bt_info(btcoexist); -#endif - halbtc8723b1ant_monitor_bt_ctr(btcoexist); - halbtc8723b1ant_monitor_wifi_ctr(btcoexist); - - halbtc8723b1ant_monitor_bt_enable_disable(btcoexist); - - if (halbtc8723b1ant_is_wifi_status_changed(btcoexist) || - coex_dm->auto_tdma_adjust || - btcoexist->bt_info.bt_enable_disable_change) - halbtc8723b1ant_run_coexist_mechanism(btcoexist); - - if (((coex_sta->bt_coex_supported_version == 0) || - (coex_sta->bt_coex_supported_version == 0xffff)) && (!coex_sta->bt_disabled)) - btcoexist->btc_get(btcoexist, BTC_GET_U4_SUPPORTED_VERSION, &coex_sta->bt_coex_supported_version); - - btcoexist->btc_get(btcoexist, BTC_GET_U4_BT_PATCH_VER, &bt_patch_ver); - btcoexist->bt_info.bt_get_fw_ver = bt_patch_ver; - coex_sta->specific_pkt_period_cnt++; - - /* sample to set bt to execute Ant detection */ - /* btcoexist->btc_set_bt_ant_detection(btcoexist, 20, 14); - * - if (psd_scan->is_ant_det_enable) - { - if (psd_scan->psd_gen_count > psd_scan->realseconds) - psd_scan->psd_gen_count = 0; - - halbtc8723b1ant_antenna_detection(btcoexist, psd_scan->realcent_freq, psd_scan->realoffset, psd_scan->realspan, psd_scan->realseconds); - psd_scan->psd_gen_total_count +=2; - psd_scan->psd_gen_count += 2; - } - */ -} - -/* Donot remove optimize off flag, otherwise antenna detection would trigger BT collapsed */ -void ex_halbtc8723b1ant_antenna_detection(IN struct btc_coexist *btcoexist, - IN u32 cent_freq, IN u32 offset, IN u32 span, IN u32 seconds) -{ -#if BT_8723B_1ANT_ANTDET_ENABLE - static u32 ant_det_count = 0, ant_det_fail_count = 0; - struct btc_board_info *board_info = &btcoexist->board_info; - /*boolean scan, roam;*/ - - if (seconds == 0) { - psd_scan->ant_det_try_count = 0; - psd_scan->ant_det_fail_count = 0; - ant_det_count = 0; - ant_det_fail_count = 0; - board_info->btdm_ant_det_finish = false; - board_info->btdm_ant_num_by_ant_det = 1; - return; - } - - if (!board_info->btdm_ant_det_finish) { - psd_scan->ant_det_inteval_count = - psd_scan->ant_det_inteval_count + 2; - - if (psd_scan->ant_det_inteval_count >= - BT_8723B_1ANT_ANTDET_RETRY_INTERVAL) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Antenna Det Timer is up, Try Detect!!\n"); - BTC_TRACE(trace_buf); - halbtc8723b1ant_psd_antenna_detection_check(btcoexist); - - if (board_info->btdm_ant_det_finish) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Antenna Det Success!!\n"); - BTC_TRACE(trace_buf); - -#if 1 - if (board_info->btdm_ant_num_by_ant_det == 2) - halbtc8723b1ant_mechanism_switch( - btcoexist, true); - else - halbtc8723b1ant_mechanism_switch( - btcoexist, false); -#endif - - board_info->btdm_ant_det_complete_fail = false; - - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Antenna Det Fail!!\n"); - BTC_TRACE(trace_buf); - - board_info->btdm_ant_det_complete_fail = true; - } - psd_scan->ant_det_inteval_count = 0; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Antenna Det Timer is not up! (%d)\n", - psd_scan->ant_det_inteval_count); - BTC_TRACE(trace_buf); - } - - } -#endif - - /* - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam); - - psd_scan->ant_det_bt_tx_time = seconds; - psd_scan->ant_det_bt_le_channel = cent_freq; - - if (seconds == 0) - { - psd_scan->ant_det_try_count = 0; - psd_scan->ant_det_fail_count = 0; - ant_det_count = 0; - ant_det_fail_count = 0; - board_info->btdm_ant_det_finish = false; - board_info->btdm_ant_num_by_ant_det = 1; - return; - } - else - { - ant_det_count++; - - psd_scan->ant_det_try_count = ant_det_count; - - if (scan ||roam) - { - board_info->btdm_ant_det_finish = false; - psd_scan->ant_det_result = 6; - } - else if (coex_sta->num_of_profile >= 1) - { - board_info->btdm_ant_det_finish = false; - psd_scan->ant_det_result = 7; - } - else if (!psd_scan->ant_det_is_ant_det_available) - { - board_info->btdm_ant_det_finish = false; - psd_scan->ant_det_result = 9; - } - else if (coex_sta->c2h_bt_inquiry_page) - { - board_info->btdm_ant_det_finish = false; - psd_scan->ant_det_result = 10; - } - else - { - - } - - if (!board_info->btdm_ant_det_finish) - ant_det_fail_count++; - - psd_scan->ant_det_fail_count = ant_det_fail_count; - } - */ -} - -void ex_halbtc8723b1ant_display_ant_detection(IN struct btc_coexist *btcoexist) -{ -#if BT_8723B_1ANT_ANTDET_ENABLE - struct btc_board_info *board_info = &btcoexist->board_info; - - if (psd_scan->ant_det_try_count != 0) { - halbtc8723b1ant_psd_show_antenna_detect_result(btcoexist); - - if (board_info->btdm_ant_det_finish) - halbtc8723b1ant_psd_showdata(btcoexist); - return; - } -#endif - - /* halbtc8723b1ant_show_psd_data(btcoexist); */ -} - -#endif - -#endif /* #if (BT_SUPPORT == 1 && COEX_SUPPORT == 1) */ diff --git a/hal/btc/halbtc8723b1ant.h b/hal/btc/halbtc8723b1ant.h deleted file mode 100644 index af476d9..0000000 --- a/hal/btc/halbtc8723b1ant.h +++ /dev/null @@ -1,293 +0,0 @@ - -#if (BT_SUPPORT == 1 && COEX_SUPPORT == 1) - -#if (RTL8723B_SUPPORT == 1) -/* ******************************************* - * The following is for 8723B 1ANT BT Co-exist definition - * ******************************************* */ -#define BT_AUTO_REPORT_ONLY_8723B_1ANT 1 - -#define BT_INFO_8723B_1ANT_B_FTP BIT(7) -#define BT_INFO_8723B_1ANT_B_A2DP BIT(6) -#define BT_INFO_8723B_1ANT_B_HID BIT(5) -#define BT_INFO_8723B_1ANT_B_SCO_BUSY BIT(4) -#define BT_INFO_8723B_1ANT_B_ACL_BUSY BIT(3) -#define BT_INFO_8723B_1ANT_B_INQ_PAGE BIT(2) -#define BT_INFO_8723B_1ANT_B_SCO_ESCO BIT(1) -#define BT_INFO_8723B_1ANT_B_CONNECTION BIT(0) - -#define BT_INFO_8723B_1ANT_A2DP_BASIC_RATE(_BT_INFO_EXT_) \ - (((_BT_INFO_EXT_&BIT(0))) ? true : false) - -#define BTC_RSSI_COEX_THRESH_TOL_8723B_1ANT 2 - -#define BT_8723B_1ANT_WIFI_NOISY_THRESH 50 /* 30 /max: 255 */ - -/* for Antenna detection */ -#define BT_8723B_1ANT_ANTDET_PSDTHRES_BACKGROUND 50 -#define BT_8723B_1ANT_ANTDET_PSDTHRES_2ANT_BADISOLATION 70 -#define BT_8723B_1ANT_ANTDET_PSDTHRES_2ANT_GOODISOLATION 48 -#define BT_8723B_1ANT_ANTDET_PSDTHRES_1ANT 32 -#define BT_8723B_1ANT_ANTDET_RETRY_INTERVAL 10 /* retry timer if ant det is fail, unit: second */ -#define BT_8723B_1ANT_ANTDET_SWEEPPOINT_DELAY 40000 -#define BT_8723B_1ANT_ANTDET_ENABLE 1 -#define BT_8723B_1ANT_ANTDET_COEXMECHANISMSWITCH_ENABLE 1 -#define BT_8723B_1ANT_ANTDET_BTTXTIME 100 -#define BT_8723B_1ANT_ANTDET_BTTXCHANNEL 39 - -enum bt_info_src_8723b_1ant { - BT_INFO_SRC_8723B_1ANT_WIFI_FW = 0x0, - BT_INFO_SRC_8723B_1ANT_BT_RSP = 0x1, - BT_INFO_SRC_8723B_1ANT_BT_ACTIVE_SEND = 0x2, - BT_INFO_SRC_8723B_1ANT_MAX -}; - -enum bt_8723b_1ant_bt_status { - BT_8723B_1ANT_BT_STATUS_NON_CONNECTED_IDLE = 0x0, - BT_8723B_1ANT_BT_STATUS_CONNECTED_IDLE = 0x1, - BT_8723B_1ANT_BT_STATUS_INQ_PAGE = 0x2, - BT_8723B_1ANT_BT_STATUS_ACL_BUSY = 0x3, - BT_8723B_1ANT_BT_STATUS_SCO_BUSY = 0x4, - BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY = 0x5, - BT_8723B_1ANT_BT_STATUS_MAX -}; - -enum bt_8723b_1ant_wifi_status { - BT_8723B_1ANT_WIFI_STATUS_NON_CONNECTED_IDLE = 0x0, - BT_8723B_1ANT_WIFI_STATUS_NON_CONNECTED_ASSO_AUTH_SCAN = 0x1, - BT_8723B_1ANT_WIFI_STATUS_CONNECTED_SCAN = 0x2, - BT_8723B_1ANT_WIFI_STATUS_CONNECTED_SPECIFIC_PKT = 0x3, - BT_8723B_1ANT_WIFI_STATUS_CONNECTED_IDLE = 0x4, - BT_8723B_1ANT_WIFI_STATUS_CONNECTED_BUSY = 0x5, - BT_8723B_1ANT_WIFI_STATUS_MAX -}; - -enum bt_8723b_1ant_coex_algo { - BT_8723B_1ANT_COEX_ALGO_UNDEFINED = 0x0, - BT_8723B_1ANT_COEX_ALGO_SCO = 0x1, - BT_8723B_1ANT_COEX_ALGO_HID = 0x2, - BT_8723B_1ANT_COEX_ALGO_A2DP = 0x3, - BT_8723B_1ANT_COEX_ALGO_A2DP_PANHS = 0x4, - BT_8723B_1ANT_COEX_ALGO_PANEDR = 0x5, - BT_8723B_1ANT_COEX_ALGO_PANHS = 0x6, - BT_8723B_1ANT_COEX_ALGO_PANEDR_A2DP = 0x7, - BT_8723B_1ANT_COEX_ALGO_PANEDR_HID = 0x8, - BT_8723B_1ANT_COEX_ALGO_HID_A2DP_PANEDR = 0x9, - BT_8723B_1ANT_COEX_ALGO_HID_A2DP = 0xa, - BT_8723B_1ANT_COEX_ALGO_MAX = 0xb, -}; - -struct coex_dm_8723b_1ant { - /* hw setting */ - u8 pre_ant_pos_type; - u8 cur_ant_pos_type; - /* fw mechanism */ - boolean cur_ignore_wlan_act; - boolean pre_ignore_wlan_act; - u8 pre_ps_tdma; - u8 cur_ps_tdma; - u8 ps_tdma_para[5]; - u8 ps_tdma_du_adj_type; - boolean auto_tdma_adjust; - boolean pre_ps_tdma_on; - boolean cur_ps_tdma_on; - boolean pre_bt_auto_report; - boolean cur_bt_auto_report; - u8 pre_lps; - u8 cur_lps; - u8 pre_rpwm; - u8 cur_rpwm; - - /* sw mechanism */ - boolean pre_low_penalty_ra; - boolean cur_low_penalty_ra; - u32 pre_val0x6c0; - u32 cur_val0x6c0; - u32 pre_val0x6c4; - u32 cur_val0x6c4; - u32 pre_val0x6c8; - u32 cur_val0x6c8; - u8 pre_val0x6cc; - u8 cur_val0x6cc; - - u32 backup_arfr_cnt1; /* Auto Rate Fallback Retry cnt */ - u32 backup_arfr_cnt2; /* Auto Rate Fallback Retry cnt */ - u16 backup_retry_limit; - u8 backup_ampdu_max_time; - - /* algorithm related */ - u8 bt_status; - u8 wifi_chnl_info[3]; - - u32 pre_ra_mask; - u32 cur_ra_mask; - u8 pre_arfr_type; - u8 cur_arfr_type; - u8 pre_retry_limit_type; - u8 cur_retry_limit_type; - u8 pre_ampdu_time_type; - u8 cur_ampdu_time_type; - u32 arp_cnt; - - u8 error_condition; -}; - -struct coex_sta_8723b_1ant { - boolean bt_disabled; - boolean bt_enable_disable_change; - boolean bt_link_exist; - boolean sco_exist; - boolean a2dp_exist; - boolean hid_exist; - boolean pan_exist; - boolean bt_hi_pri_link_exist; - u8 num_of_profile; - boolean bt_abnormal_scan; - - boolean under_lps; - boolean under_ips; - u32 specific_pkt_period_cnt; - u32 high_priority_tx; - u32 high_priority_rx; - u32 low_priority_tx; - u32 low_priority_rx; - s8 bt_rssi; - boolean bt_tx_rx_mask; - boolean c2h_bt_info_req_sent; - u8 bt_info_c2h[BT_INFO_SRC_8723B_1ANT_MAX][10]; - u32 bt_info_c2h_cnt[BT_INFO_SRC_8723B_1ANT_MAX]; - boolean bt_whck_test; - boolean c2h_bt_inquiry_page; - boolean c2h_bt_remote_name_req; - boolean wifi_is_high_pri_task; /* Add for win8.1 page out issue */ - u8 bt_retry_cnt; - u8 bt_info_ext; - u32 pop_event_cnt; - u8 scan_ap_num; - - u32 crc_ok_cck; - u32 crc_ok_11g; - u32 crc_ok_11n; - u32 crc_ok_11n_vht; - - u32 crc_err_cck; - u32 crc_err_11g; - u32 crc_err_11n; - u32 crc_err_11n_vht; - - boolean cck_lock; - boolean pre_ccklock; - boolean cck_ever_lock; - u8 coex_table_type; - - boolean force_lps_on; - u32 wrong_profile_notification; - u32 bt_coex_supported_version; - u8 a2dp_bit_pool; - u8 cut_version; -}; - -#define BT_8723B_1ANT_ANTDET_PSD_POINTS 256 /* MAX:1024 */ -#define BT_8723B_1ANT_ANTDET_PSD_AVGNUM 1 /* MAX:3 */ -#define BT_8723B_1ANT_ANTDET_BUF_LEN 16 - -struct psdscan_sta_8723b_1ant { - - u32 ant_det_bt_le_channel; /* BT LE Channel ex:2412 */ - u32 ant_det_bt_tx_time; - u32 ant_det_pre_psdscan_peak_val; - boolean ant_det_is_ant_det_available; - u32 ant_det_psd_scan_peak_val; - boolean ant_det_is_btreply_available; - u32 ant_det_psd_scan_peak_freq; - - u8 ant_det_result; - u8 ant_det_peak_val[BT_8723B_1ANT_ANTDET_BUF_LEN]; - u8 ant_det_peak_freq[BT_8723B_1ANT_ANTDET_BUF_LEN]; - u32 ant_det_try_count; - u32 ant_det_fail_count; - u32 ant_det_inteval_count; - u32 ant_det_thres_offset; - - u32 real_cent_freq; - s32 real_offset; - u32 real_span; - - u32 psd_band_width; /* unit: Hz */ - u32 psd_point; /* 128/256/512/1024 */ - u32 psd_report[1024]; /* unit:dB (20logx), 0~255 */ - u32 psd_report_max_hold[1024]; /* unit:dB (20logx), 0~255 */ - u32 psd_start_point; - u32 psd_stop_point; - u32 psd_max_value_point; - u32 psd_max_value; - u32 psd_start_base; - u32 psd_avg_num; /* 1/8/16/32 */ - u32 psd_gen_count; - boolean is_psd_running; - boolean is_psd_show_max_only; -}; - -/* ******************************************* - * The following is interface which will notify coex module. - * ******************************************* */ -void ex_halbtc8723b1ant_power_on_setting(IN struct btc_coexist *btcoexist); -void ex_halbtc8723b1ant_pre_load_firmware(IN struct btc_coexist *btcoexist); -void ex_halbtc8723b1ant_init_hw_config(IN struct btc_coexist *btcoexist, - IN boolean wifi_only); -void ex_halbtc8723b1ant_init_coex_dm(IN struct btc_coexist *btcoexist); -void ex_halbtc8723b1ant_ips_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8723b1ant_lps_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8723b1ant_scan_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8723b1ant_set_antenna_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8723b1ant_connect_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8723b1ant_media_status_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8723b1ant_specific_packet_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8723b1ant_bt_info_notify(IN struct btc_coexist *btcoexist, - IN u8 *tmp_buf, IN u8 length); -void ex_halbtc8723b1ant_rf_status_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8723b1ant_halt_notify(IN struct btc_coexist *btcoexist); -void ex_halbtc8723b1ant_pnp_notify(IN struct btc_coexist *btcoexist, - IN u8 pnp_state); -void ex_halbtc8723b1ant_coex_dm_reset(IN struct btc_coexist *btcoexist); -void ex_halbtc8723b1ant_periodical(IN struct btc_coexist *btcoexist); -void ex_halbtc8723b1ant_display_coex_info(IN struct btc_coexist *btcoexist); -void ex_halbtc8723b1ant_antenna_detection(IN struct btc_coexist *btcoexist, - IN u32 cent_freq, IN u32 offset, IN u32 span, IN u32 seconds); - -void ex_halbtc8723b1ant_display_ant_detection(IN struct btc_coexist *btcoexist); - -#else -#define ex_halbtc8723b1ant_power_on_setting(btcoexist) -#define ex_halbtc8723b1ant_pre_load_firmware(btcoexist) -#define ex_halbtc8723b1ant_init_hw_config(btcoexist, wifi_only) -#define ex_halbtc8723b1ant_init_coex_dm(btcoexist) -#define ex_halbtc8723b1ant_ips_notify(btcoexist, type) -#define ex_halbtc8723b1ant_lps_notify(btcoexist, type) -#define ex_halbtc8723b1ant_scan_notify(btcoexist, type) -#define ex_halbtc8723b1ant_set_antenna_notify(btcoexist, type) -#define ex_halbtc8723b1ant_connect_notify(btcoexist, type) -#define ex_halbtc8723b1ant_media_status_notify(btcoexist, type) -#define ex_halbtc8723b1ant_specific_packet_notify(btcoexist, type) -#define ex_halbtc8723b1ant_bt_info_notify(btcoexist, tmp_buf, length) -#define ex_halbtc8723b1ant_rf_status_notify(btcoexist, type) -#define ex_halbtc8723b1ant_halt_notify(btcoexist) -#define ex_halbtc8723b1ant_pnp_notify(btcoexist, pnp_state) -#define ex_halbtc8723b1ant_coex_dm_reset(btcoexist) -#define ex_halbtc8723b1ant_periodical(btcoexist) -#define ex_halbtc8723b1ant_display_coex_info(btcoexist) -#define ex_halbtc8723b1ant_antenna_detection(btcoexist, cent_freq, offset, span, seconds) -#define ex_halbtc8723b1ant_display_ant_detection(btcoexist) - -#endif - -#endif - diff --git a/hal/btc/halbtc8723b2ant.c b/hal/btc/halbtc8723b2ant.c deleted file mode 100644 index 3b1dd4a..0000000 --- a/hal/btc/halbtc8723b2ant.c +++ /dev/null @@ -1,4958 +0,0 @@ -/* ************************************************************ - * Description: - * - * This file is for RTL8723B Co-exist mechanism - * - * History - * 2012/11/15 Cosa first check in. - * - * ************************************************************ */ - -/* ************************************************************ - * include files - * ************************************************************ */ -#include "mp_precomp.h" - -#if (BT_SUPPORT == 1 && COEX_SUPPORT == 1) - -#if (RTL8723B_SUPPORT == 1) -/* ************************************************************ - * Global variables, these are static variables - * ************************************************************ */ -static u8 *trace_buf = &gl_btc_trace_buf[0]; -static struct coex_dm_8723b_2ant glcoex_dm_8723b_2ant; -static struct coex_dm_8723b_2ant *coex_dm = &glcoex_dm_8723b_2ant; -static struct coex_sta_8723b_2ant glcoex_sta_8723b_2ant; -static struct coex_sta_8723b_2ant *coex_sta = &glcoex_sta_8723b_2ant; - -const char *const glbt_info_src_8723b_2ant[] = { - "BT Info[wifi fw]", - "BT Info[bt rsp]", - "BT Info[bt auto report]", -}; - -u32 glcoex_ver_date_8723b_2ant = 20161007; -u32 glcoex_ver_8723b_2ant = 0x4c; -u32 glcoex_ver_btdesired_8723b_2ant = 0x4c; - -/* ************************************************************ - * local function proto type if needed - * ************************************************************ - * ************************************************************ - * local function start with halbtc8723b2ant_ - * ************************************************************ */ -u8 halbtc8723b2ant_bt_rssi_state(u8 *ppre_bt_rssi_state, u8 level_num, - u8 rssi_thresh, u8 rssi_thresh1) -{ - s32 bt_rssi = 0; - u8 bt_rssi_state = *ppre_bt_rssi_state; - - bt_rssi = coex_sta->bt_rssi; - - if (level_num == 2) { - if ((*ppre_bt_rssi_state == BTC_RSSI_STATE_LOW) || - (*ppre_bt_rssi_state == BTC_RSSI_STATE_STAY_LOW)) { - if (bt_rssi >= (rssi_thresh + - BTC_RSSI_COEX_THRESH_TOL_8723B_2ANT)) - bt_rssi_state = BTC_RSSI_STATE_HIGH; - else - bt_rssi_state = BTC_RSSI_STATE_STAY_LOW; - } else { - if (bt_rssi < rssi_thresh) - bt_rssi_state = BTC_RSSI_STATE_LOW; - else - bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH; - } - } else if (level_num == 3) { - if (rssi_thresh > rssi_thresh1) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Rssi thresh error!!\n"); - BTC_TRACE(trace_buf); - return *ppre_bt_rssi_state; - } - - if ((*ppre_bt_rssi_state == BTC_RSSI_STATE_LOW) || - (*ppre_bt_rssi_state == BTC_RSSI_STATE_STAY_LOW)) { - if (bt_rssi >= (rssi_thresh + - BTC_RSSI_COEX_THRESH_TOL_8723B_2ANT)) - bt_rssi_state = BTC_RSSI_STATE_MEDIUM; - else - bt_rssi_state = BTC_RSSI_STATE_STAY_LOW; - } else if ((*ppre_bt_rssi_state == BTC_RSSI_STATE_MEDIUM) || - (*ppre_bt_rssi_state == BTC_RSSI_STATE_STAY_MEDIUM)) { - if (bt_rssi >= (rssi_thresh1 + - BTC_RSSI_COEX_THRESH_TOL_8723B_2ANT)) - bt_rssi_state = BTC_RSSI_STATE_HIGH; - else if (bt_rssi < rssi_thresh) - bt_rssi_state = BTC_RSSI_STATE_LOW; - else - bt_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM; - } else { - if (bt_rssi < rssi_thresh1) - bt_rssi_state = BTC_RSSI_STATE_MEDIUM; - else - bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH; - } - } - - *ppre_bt_rssi_state = bt_rssi_state; - - return bt_rssi_state; -} - -u8 halbtc8723b2ant_wifi_rssi_state(IN struct btc_coexist *btcoexist, - IN u8 *pprewifi_rssi_state, IN u8 level_num, IN u8 rssi_thresh, - IN u8 rssi_thresh1) -{ - s32 wifi_rssi = 0; - u8 wifi_rssi_state = *pprewifi_rssi_state; - - btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi); - - if (level_num == 2) { - if ((*pprewifi_rssi_state == BTC_RSSI_STATE_LOW) || - (*pprewifi_rssi_state == BTC_RSSI_STATE_STAY_LOW)) { - if (wifi_rssi >= (rssi_thresh + - BTC_RSSI_COEX_THRESH_TOL_8723B_2ANT)) - wifi_rssi_state = BTC_RSSI_STATE_HIGH; - else - wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW; - } else { - if (wifi_rssi < rssi_thresh) - wifi_rssi_state = BTC_RSSI_STATE_LOW; - else - wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH; - } - } else if (level_num == 3) { - if (rssi_thresh > rssi_thresh1) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], wifi RSSI thresh error!!\n"); - BTC_TRACE(trace_buf); - return *pprewifi_rssi_state; - } - - if ((*pprewifi_rssi_state == BTC_RSSI_STATE_LOW) || - (*pprewifi_rssi_state == BTC_RSSI_STATE_STAY_LOW)) { - if (wifi_rssi >= (rssi_thresh + - BTC_RSSI_COEX_THRESH_TOL_8723B_2ANT)) - wifi_rssi_state = BTC_RSSI_STATE_MEDIUM; - else - wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW; - } else if ((*pprewifi_rssi_state == BTC_RSSI_STATE_MEDIUM) || - (*pprewifi_rssi_state == BTC_RSSI_STATE_STAY_MEDIUM)) { - if (wifi_rssi >= (rssi_thresh1 + - BTC_RSSI_COEX_THRESH_TOL_8723B_2ANT)) - wifi_rssi_state = BTC_RSSI_STATE_HIGH; - else if (wifi_rssi < rssi_thresh) - wifi_rssi_state = BTC_RSSI_STATE_LOW; - else - wifi_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM; - } else { - if (wifi_rssi < rssi_thresh1) - wifi_rssi_state = BTC_RSSI_STATE_MEDIUM; - else - wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH; - } - } - - *pprewifi_rssi_state = wifi_rssi_state; - - return wifi_rssi_state; -} - -void halbtc8723b2ant_monitor_bt_enable_disable(IN struct btc_coexist *btcoexist) -{ - static u32 bt_disable_cnt = 0; - boolean bt_active = true, bt_disabled = false; - - /* This function check if bt is disabled */ - - if (coex_sta->high_priority_tx == 0 && - coex_sta->high_priority_rx == 0 && - coex_sta->low_priority_tx == 0 && - coex_sta->low_priority_rx == 0) - bt_active = false; - if (coex_sta->high_priority_tx == 0xffff && - coex_sta->high_priority_rx == 0xffff && - coex_sta->low_priority_tx == 0xffff && - coex_sta->low_priority_rx == 0xffff) - bt_active = false; - if (bt_active) { - bt_disable_cnt = 0; - bt_disabled = false; - } else { - bt_disable_cnt++; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], bt all counters=0, %d times!!\n", - bt_disable_cnt); - BTC_TRACE(trace_buf); - if (bt_disable_cnt >= 10) - bt_disabled = true; - } - if (coex_sta->bt_disabled != bt_disabled) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT is from %s to %s!!\n", - (coex_sta->bt_disabled ? "disabled" : "enabled"), - (bt_disabled ? "disabled" : "enabled")); - BTC_TRACE(trace_buf); - - coex_sta->bt_disabled = bt_disabled; - btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_DISABLE, - &bt_disabled); - if (bt_disabled) { - btcoexist->btc_set(btcoexist, BTC_SET_ACT_LEAVE_LPS, - NULL); - btcoexist->btc_set(btcoexist, BTC_SET_ACT_NORMAL_LPS, - NULL); - } - } -} - - -void halbtc8723b2ant_limited_rx(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean rej_ap_agg_pkt, - IN boolean bt_ctrl_agg_buf_size, IN u8 agg_buf_size) -{ - boolean reject_rx_agg = rej_ap_agg_pkt; - boolean bt_ctrl_rx_agg_size = bt_ctrl_agg_buf_size; - u8 rx_agg_size = agg_buf_size; - - /* ============================================ */ - /* Rx Aggregation related setting */ - /* ============================================ */ - btcoexist->btc_set(btcoexist, BTC_SET_BL_TO_REJ_AP_AGG_PKT, - &reject_rx_agg); - /* decide BT control aggregation buf size or not */ - btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_CTRL_AGG_SIZE, - &bt_ctrl_rx_agg_size); - /* aggregation buf size, only work when BT control Rx aggregation size. */ - btcoexist->btc_set(btcoexist, BTC_SET_U1_AGG_BUF_SIZE, &rx_agg_size); - /* real update aggregation setting */ - btcoexist->btc_set(btcoexist, BTC_SET_ACT_AGGREGATE_CTRL, NULL); -} - -void halbtc8723b2ant_monitor_bt_ctr(IN struct btc_coexist *btcoexist) -{ - u32 reg_hp_txrx, reg_lp_txrx, u32tmp; - u32 reg_hp_tx = 0, reg_hp_rx = 0, reg_lp_tx = 0, reg_lp_rx = 0; - - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - - reg_hp_txrx = 0x770; - reg_lp_txrx = 0x774; - - u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_hp_txrx); - reg_hp_tx = u32tmp & MASKLWORD; - reg_hp_rx = (u32tmp & MASKHWORD) >> 16; - - u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_lp_txrx); - reg_lp_tx = u32tmp & MASKLWORD; - reg_lp_rx = (u32tmp & MASKHWORD) >> 16; - - coex_sta->high_priority_tx = reg_hp_tx; - coex_sta->high_priority_rx = reg_hp_rx; - coex_sta->low_priority_tx = reg_lp_tx; - coex_sta->low_priority_rx = reg_lp_rx; - - if ((coex_sta->low_priority_tx > 1050) && - (!coex_sta->c2h_bt_inquiry_page)) - coex_sta->pop_event_cnt++; - - if ((coex_sta->low_priority_rx >= 950) && - (coex_sta->low_priority_rx >= coex_sta->low_priority_tx) && - (!coex_sta->under_ips)) - bt_link_info->slave_role = true; - else - bt_link_info->slave_role = false; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], High Priority Tx/Rx (reg 0x%x)=0x%x(%d)/0x%x(%d)\n", - reg_hp_txrx, reg_hp_tx, reg_hp_tx, reg_hp_rx, reg_hp_rx); - BTC_TRACE(trace_buf); - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Low Priority Tx/Rx (reg 0x%x)=0x%x(%d)/0x%x(%d)\n", - reg_lp_txrx, reg_lp_tx, reg_lp_tx, reg_lp_rx, reg_lp_rx); - BTC_TRACE(trace_buf); - - /* reset counter */ - btcoexist->btc_write_1byte(btcoexist, 0x76e, 0xc); -} - -void halbtc8723b2ant_monitor_wifi_ctr(IN struct btc_coexist *btcoexist) -{ -#if 1 - - coex_sta->crc_ok_cck = btcoexist->btc_phydm_query_PHY_counter( - btcoexist, - PHYDM_INFO_CRC32_OK_CCK); - coex_sta->crc_ok_11g = btcoexist->btc_phydm_query_PHY_counter( - btcoexist, - PHYDM_INFO_CRC32_OK_LEGACY); - coex_sta->crc_ok_11n = btcoexist->btc_phydm_query_PHY_counter( - btcoexist, - PHYDM_INFO_CRC32_OK_HT); - coex_sta->crc_ok_11n_vht = - btcoexist->btc_phydm_query_PHY_counter( - btcoexist, - PHYDM_INFO_CRC32_OK_VHT); - - coex_sta->crc_err_cck = btcoexist->btc_phydm_query_PHY_counter( - btcoexist, - PHYDM_INFO_CRC32_ERROR_CCK); - coex_sta->crc_err_11g = btcoexist->btc_phydm_query_PHY_counter( - btcoexist, - PHYDM_INFO_CRC32_ERROR_LEGACY); - coex_sta->crc_err_11n = btcoexist->btc_phydm_query_PHY_counter( - btcoexist, - PHYDM_INFO_CRC32_ERROR_HT); - coex_sta->crc_err_11n_vht = - btcoexist->btc_phydm_query_PHY_counter( - btcoexist, - PHYDM_INFO_CRC32_ERROR_VHT); - -#endif -} - -void halbtc8723b2ant_query_bt_info(IN struct btc_coexist *btcoexist) -{ - u8 h2c_parameter[1] = {0}; - - coex_sta->c2h_bt_info_req_sent = true; - - h2c_parameter[0] |= BIT(0); /* trigger */ - - btcoexist->btc_fill_h2c(btcoexist, 0x61, 1, h2c_parameter); -} - -boolean halbtc8723b2ant_is_wifi_status_changed(IN struct btc_coexist *btcoexist) -{ - static boolean pre_wifi_busy = false, pre_under_4way = false, - pre_bt_hs_on = false; - static u8 prewifi_rssi_state = BTC_RSSI_STATE_LOW; - boolean wifi_busy = false, under_4way = false, bt_hs_on = false; - boolean wifi_connected = false; - u8 wifi_rssi_state = BTC_RSSI_STATE_HIGH; - - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS, - &under_4way); - - if (wifi_connected) { - if (wifi_busy != pre_wifi_busy) { - pre_wifi_busy = wifi_busy; - return true; - } - if (under_4way != pre_under_4way) { - pre_under_4way = under_4way; - return true; - } - if (bt_hs_on != pre_bt_hs_on) { - pre_bt_hs_on = bt_hs_on; - return true; - } - - - wifi_rssi_state = halbtc8723b2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state, 2, - BT_8723B_2ANT_WIFI_RSSI_COEXSWITCH_THRES - - coex_dm->switch_thres_offset, 0); - - if ((BTC_RSSI_STATE_HIGH == wifi_rssi_state) || - (BTC_RSSI_STATE_LOW == wifi_rssi_state)) - return true; - - } - - return false; -} - -void halbtc8723b2ant_update_bt_link_info(IN struct btc_coexist *btcoexist) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - boolean bt_hs_on = false; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); - - bt_link_info->bt_link_exist = coex_sta->bt_link_exist; - bt_link_info->sco_exist = coex_sta->sco_exist; - bt_link_info->a2dp_exist = coex_sta->a2dp_exist; - bt_link_info->pan_exist = coex_sta->pan_exist; - bt_link_info->hid_exist = coex_sta->hid_exist; - - /* work around for HS mode. */ - if (bt_hs_on) { - bt_link_info->pan_exist = true; - bt_link_info->bt_link_exist = true; - } - - /* check if Sco only */ - if (bt_link_info->sco_exist && - !bt_link_info->a2dp_exist && - !bt_link_info->pan_exist && - !bt_link_info->hid_exist) - bt_link_info->sco_only = true; - else - bt_link_info->sco_only = false; - - /* check if A2dp only */ - if (!bt_link_info->sco_exist && - bt_link_info->a2dp_exist && - !bt_link_info->pan_exist && - !bt_link_info->hid_exist) - bt_link_info->a2dp_only = true; - else - bt_link_info->a2dp_only = false; - - /* check if Pan only */ - if (!bt_link_info->sco_exist && - !bt_link_info->a2dp_exist && - bt_link_info->pan_exist && - !bt_link_info->hid_exist) - bt_link_info->pan_only = true; - else - bt_link_info->pan_only = false; - - /* check if Hid only */ - if (!bt_link_info->sco_exist && - !bt_link_info->a2dp_exist && - !bt_link_info->pan_exist && - bt_link_info->hid_exist) - bt_link_info->hid_only = true; - else - bt_link_info->hid_only = false; -} - -u8 halbtc8723b2ant_action_algorithm(IN struct btc_coexist *btcoexist) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - boolean bt_hs_on = false; - u8 algorithm = BT_8723B_2ANT_COEX_ALGO_UNDEFINED; - u8 num_of_diff_profile = 0; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); - - if (!bt_link_info->bt_link_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], No BT link exists!!!\n"); - BTC_TRACE(trace_buf); - return algorithm; - } - - if (bt_link_info->sco_exist) - num_of_diff_profile++; - if (bt_link_info->hid_exist) - num_of_diff_profile++; - if (bt_link_info->pan_exist) - num_of_diff_profile++; - if (bt_link_info->a2dp_exist) - num_of_diff_profile++; - - if (num_of_diff_profile == 1) { - if (bt_link_info->sco_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCO only\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8723B_2ANT_COEX_ALGO_SCO; - } else { - if (bt_link_info->hid_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], HID only\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8723B_2ANT_COEX_ALGO_HID; - } else if (bt_link_info->a2dp_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], A2DP only\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8723B_2ANT_COEX_ALGO_A2DP; - } else if (bt_link_info->pan_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], PAN(HS) only\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8723B_2ANT_COEX_ALGO_PANHS; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], PAN(EDR) only\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8723B_2ANT_COEX_ALGO_PANEDR; - } - } - } - } else if (num_of_diff_profile == 2) { - if (bt_link_info->sco_exist) { - if (bt_link_info->hid_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCO + HID\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8723B_2ANT_COEX_ALGO_PANEDR_HID; - } else if (bt_link_info->a2dp_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCO + A2DP ==> SCO\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8723B_2ANT_COEX_ALGO_PANEDR_HID; - } else if (bt_link_info->pan_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCO + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8723B_2ANT_COEX_ALGO_SCO; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCO + PAN(EDR)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8723B_2ANT_COEX_ALGO_PANEDR_HID; - } - } - } else { - if (bt_link_info->hid_exist && - bt_link_info->a2dp_exist) { - { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], HID + A2DP\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8723B_2ANT_COEX_ALGO_HID_A2DP; - } - } else if (bt_link_info->hid_exist && - bt_link_info->pan_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], HID + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8723B_2ANT_COEX_ALGO_HID; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], HID + PAN(EDR)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8723B_2ANT_COEX_ALGO_PANEDR_HID; - } - } else if (bt_link_info->pan_exist && - bt_link_info->a2dp_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], A2DP + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8723B_2ANT_COEX_ALGO_A2DP_PANHS; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], A2DP + PAN(EDR)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8723B_2ANT_COEX_ALGO_PANEDR_A2DP; - } - } - } - } else if (num_of_diff_profile == 3) { - if (bt_link_info->sco_exist) { - if (bt_link_info->hid_exist && - bt_link_info->a2dp_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCO + HID + A2DP ==> HID\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8723B_2ANT_COEX_ALGO_PANEDR_HID; - } else if (bt_link_info->hid_exist && - bt_link_info->pan_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCO + HID + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8723B_2ANT_COEX_ALGO_PANEDR_HID; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCO + HID + PAN(EDR)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8723B_2ANT_COEX_ALGO_PANEDR_HID; - } - } else if (bt_link_info->pan_exist && - bt_link_info->a2dp_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCO + A2DP + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8723B_2ANT_COEX_ALGO_PANEDR_HID; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCO + A2DP + PAN(EDR) ==> HID\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8723B_2ANT_COEX_ALGO_PANEDR_HID; - } - } - } else { - if (bt_link_info->hid_exist && - bt_link_info->pan_exist && - bt_link_info->a2dp_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], HID + A2DP + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8723B_2ANT_COEX_ALGO_HID_A2DP; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], HID + A2DP + PAN(EDR)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8723B_2ANT_COEX_ALGO_HID_A2DP_PANEDR; - } - } - } - } else if (num_of_diff_profile >= 3) { - if (bt_link_info->sco_exist) { - if (bt_link_info->hid_exist && - bt_link_info->pan_exist && - bt_link_info->a2dp_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Error!!! SCO + HID + A2DP + PAN(HS)\n"); - BTC_TRACE(trace_buf); - - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCO + HID + A2DP + PAN(EDR)==>PAN(EDR)+HID\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8723B_2ANT_COEX_ALGO_PANEDR_HID; - } - } - } - } - - return algorithm; -} - -void halbtc8723b2ant_set_fw_dac_swing_level(IN struct btc_coexist *btcoexist, - IN u8 dac_swing_lvl) -{ - u8 h2c_parameter[1] = {0}; - - /* There are several type of dacswing */ - /* 0x18/ 0x10/ 0xc/ 0x8/ 0x4/ 0x6 */ - h2c_parameter[0] = dac_swing_lvl; - - btcoexist->btc_fill_h2c(btcoexist, 0x64, 1, h2c_parameter); -} - -void halbtc8723b2ant_set_fw_dec_bt_pwr(IN struct btc_coexist *btcoexist, - IN u8 dec_bt_pwr_lvl) -{ - u8 h2c_parameter[1] = {0}; - - h2c_parameter[0] = dec_bt_pwr_lvl; - - btcoexist->btc_fill_h2c(btcoexist, 0x62, 1, h2c_parameter); -} - -void halbtc8723b2ant_dec_bt_pwr(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 dec_bt_pwr_lvl) -{ - coex_dm->cur_bt_dec_pwr_lvl = dec_bt_pwr_lvl; - - if (!force_exec) { - if (coex_dm->pre_bt_dec_pwr_lvl == coex_dm->cur_bt_dec_pwr_lvl) - return; - } - halbtc8723b2ant_set_fw_dec_bt_pwr(btcoexist, - coex_dm->cur_bt_dec_pwr_lvl); - - coex_dm->pre_bt_dec_pwr_lvl = coex_dm->cur_bt_dec_pwr_lvl; -} - -void halbtc8723b2ant_set_bt_auto_report(IN struct btc_coexist *btcoexist, - IN boolean enable_auto_report) -{ - u8 h2c_parameter[1] = {0}; - - h2c_parameter[0] = 0; - - if (enable_auto_report) - h2c_parameter[0] |= BIT(0); - - btcoexist->btc_fill_h2c(btcoexist, 0x68, 1, h2c_parameter); -} - -void halbtc8723b2ant_bt_auto_report(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean enable_auto_report) -{ - coex_dm->cur_bt_auto_report = enable_auto_report; - - if (!force_exec) { - if (coex_dm->pre_bt_auto_report == coex_dm->cur_bt_auto_report) - return; - } - halbtc8723b2ant_set_bt_auto_report(btcoexist, - coex_dm->cur_bt_auto_report); - - coex_dm->pre_bt_auto_report = coex_dm->cur_bt_auto_report; -} - -void halbtc8723b2ant_fw_dac_swing_lvl(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 fw_dac_swing_lvl) -{ - coex_dm->cur_fw_dac_swing_lvl = fw_dac_swing_lvl; - - if (!force_exec) { - if (coex_dm->pre_fw_dac_swing_lvl == - coex_dm->cur_fw_dac_swing_lvl) - return; - } - - halbtc8723b2ant_set_fw_dac_swing_level(btcoexist, - coex_dm->cur_fw_dac_swing_lvl); - - coex_dm->pre_fw_dac_swing_lvl = coex_dm->cur_fw_dac_swing_lvl; -} - -void halbtc8723b2ant_set_sw_rf_rx_lpf_corner(IN struct btc_coexist *btcoexist, - IN boolean rx_rf_shrink_on) -{ - if (rx_rf_shrink_on) { - /* Shrink RF Rx LPF corner */ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Shrink RF Rx LPF corner!!\n"); - BTC_TRACE(trace_buf); - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1e, 0xfffff, - 0xffffc); - } else { - /* Resume RF Rx LPF corner */ - /* After initialized, we can use coex_dm->bt_rf_0x1e_backup */ - if (btcoexist->initilized) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Resume RF Rx LPF corner!!\n"); - BTC_TRACE(trace_buf); - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1e, - 0xfffff, coex_dm->bt_rf_0x1e_backup); - } - } -} - -void halbtc8723b2ant_rf_shrink(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean rx_rf_shrink_on) -{ - coex_dm->cur_rf_rx_lpf_shrink = rx_rf_shrink_on; - - if (!force_exec) { - if (coex_dm->pre_rf_rx_lpf_shrink == - coex_dm->cur_rf_rx_lpf_shrink) - return; - } - halbtc8723b2ant_set_sw_rf_rx_lpf_corner(btcoexist, - coex_dm->cur_rf_rx_lpf_shrink); - - coex_dm->pre_rf_rx_lpf_shrink = coex_dm->cur_rf_rx_lpf_shrink; -} - -void halbtc8723b2ant_set_sw_penalty_tx_rate_adaptive(IN struct btc_coexist - *btcoexist, IN boolean low_penalty_ra) -{ - u8 h2c_parameter[6] = {0}; - - h2c_parameter[0] = 0x6; /* op_code, 0x6= Retry_Penalty */ - - if (low_penalty_ra) { - h2c_parameter[1] |= BIT(0); - h2c_parameter[2] = - 0x00; /* normal rate except MCS7/6/5, OFDM54/48/36 */ - h2c_parameter[3] = 0xf4; /* MCS7 or OFDM54 */ - h2c_parameter[4] = 0xf5; /* MCS6 or OFDM48 */ - h2c_parameter[5] = 0xf6; /* MCS5 or OFDM36 */ - } - - btcoexist->btc_fill_h2c(btcoexist, 0x69, 6, h2c_parameter); -} - -void halbtc8723b2ant_low_penalty_ra(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean low_penalty_ra) -{ - coex_dm->cur_low_penalty_ra = low_penalty_ra; - - if (!force_exec) { - if (coex_dm->pre_low_penalty_ra == coex_dm->cur_low_penalty_ra) - return; - } - halbtc8723b2ant_set_sw_penalty_tx_rate_adaptive(btcoexist, - coex_dm->cur_low_penalty_ra); - - coex_dm->pre_low_penalty_ra = coex_dm->cur_low_penalty_ra; -} - -void halbtc8723b2ant_set_dac_swing_reg(IN struct btc_coexist *btcoexist, - IN u32 level) -{ - u8 val = (u8)level; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Write SwDacSwing = 0x%x\n", level); - BTC_TRACE(trace_buf); - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x883, 0x3e, val); -} - -void halbtc8723b2ant_set_sw_full_time_dac_swing(IN struct btc_coexist - *btcoexist, IN boolean sw_dac_swing_on, IN u32 sw_dac_swing_lvl) -{ - if (sw_dac_swing_on) - halbtc8723b2ant_set_dac_swing_reg(btcoexist, sw_dac_swing_lvl); - else - halbtc8723b2ant_set_dac_swing_reg(btcoexist, 0x18); -} - - -void halbtc8723b2ant_dac_swing(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean dac_swing_on, IN u32 dac_swing_lvl) -{ - coex_dm->cur_dac_swing_on = dac_swing_on; - coex_dm->cur_dac_swing_lvl = dac_swing_lvl; - - if (!force_exec) { - if ((coex_dm->pre_dac_swing_on == coex_dm->cur_dac_swing_on) && - (coex_dm->pre_dac_swing_lvl == - coex_dm->cur_dac_swing_lvl)) - return; - } - delay_ms(30); - halbtc8723b2ant_set_sw_full_time_dac_swing(btcoexist, dac_swing_on, - dac_swing_lvl); - - coex_dm->pre_dac_swing_on = coex_dm->cur_dac_swing_on; - coex_dm->pre_dac_swing_lvl = coex_dm->cur_dac_swing_lvl; -} - -void halbtc8723b2ant_set_adc_back_off(IN struct btc_coexist *btcoexist, - IN boolean adc_back_off) -{ - if (adc_back_off) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BB BackOff Level On!\n"); - BTC_TRACE(trace_buf); - btcoexist->btc_write_1byte_bitmask(btcoexist, 0xc05, 0x30, 0x3); - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BB BackOff Level Off!\n"); - BTC_TRACE(trace_buf); - btcoexist->btc_write_1byte_bitmask(btcoexist, 0xc05, 0x30, 0x1); - } -} - -void halbtc8723b2ant_adc_back_off(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean adc_back_off) -{ - coex_dm->cur_adc_back_off = adc_back_off; - - if (!force_exec) { - if (coex_dm->pre_adc_back_off == coex_dm->cur_adc_back_off) - return; - } - halbtc8723b2ant_set_adc_back_off(btcoexist, coex_dm->cur_adc_back_off); - - coex_dm->pre_adc_back_off = coex_dm->cur_adc_back_off; -} - -void halbtc8723b2ant_set_agc_table(IN struct btc_coexist *btcoexist, - IN boolean agc_table_en) -{ - u8 rssi_adjust_val = 0; - - /* =================BB AGC Gain Table */ - if (agc_table_en) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BB Agc Table On!\n"); - BTC_TRACE(trace_buf); - btcoexist->btc_write_4byte(btcoexist, 0xc78, 0x6e1A0001); - btcoexist->btc_write_4byte(btcoexist, 0xc78, 0x6d1B0001); - btcoexist->btc_write_4byte(btcoexist, 0xc78, 0x6c1C0001); - btcoexist->btc_write_4byte(btcoexist, 0xc78, 0x6b1D0001); - btcoexist->btc_write_4byte(btcoexist, 0xc78, 0x6a1E0001); - btcoexist->btc_write_4byte(btcoexist, 0xc78, 0x691F0001); - btcoexist->btc_write_4byte(btcoexist, 0xc78, 0x68200001); - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BB Agc Table Off!\n"); - BTC_TRACE(trace_buf); - btcoexist->btc_write_4byte(btcoexist, 0xc78, 0xaa1A0001); - btcoexist->btc_write_4byte(btcoexist, 0xc78, 0xa91B0001); - btcoexist->btc_write_4byte(btcoexist, 0xc78, 0xa81C0001); - btcoexist->btc_write_4byte(btcoexist, 0xc78, 0xa71D0001); - btcoexist->btc_write_4byte(btcoexist, 0xc78, 0xa61E0001); - btcoexist->btc_write_4byte(btcoexist, 0xc78, 0xa51F0001); - btcoexist->btc_write_4byte(btcoexist, 0xc78, 0xa4200001); - } - - - /* =================RF Gain */ - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0xef, 0xfffff, 0x02000); - if (agc_table_en) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Agc Table On!\n"); - BTC_TRACE(trace_buf); - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x3b, 0xfffff, - 0x38fff); - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x3b, 0xfffff, - 0x38ffe); - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Agc Table Off!\n"); - BTC_TRACE(trace_buf); - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x3b, 0xfffff, - 0x380c3); - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x3b, 0xfffff, - 0x28ce6); - } - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0xef, 0xfffff, 0x0); - - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0xed, 0xfffff, 0x1); - if (agc_table_en) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Agc Table On!\n"); - BTC_TRACE(trace_buf); - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x40, 0xfffff, - 0x38fff); - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x40, 0xfffff, - 0x38ffe); - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Agc Table Off!\n"); - BTC_TRACE(trace_buf); - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x40, 0xfffff, - 0x380c3); - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x40, 0xfffff, - 0x28ce6); - } - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0xed, 0xfffff, 0x0); - - /* set rssi_adjust_val for wifi module. */ - if (agc_table_en) - rssi_adjust_val = 8; - btcoexist->btc_set(btcoexist, BTC_SET_U1_RSSI_ADJ_VAL_FOR_AGC_TABLE_ON, - &rssi_adjust_val); -} - -void halbtc8723b2ant_agc_table(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean agc_table_en) -{ - coex_dm->cur_agc_table_en = agc_table_en; - - if (!force_exec) { - if (coex_dm->pre_agc_table_en == coex_dm->cur_agc_table_en) - return; - } - halbtc8723b2ant_set_agc_table(btcoexist, agc_table_en); - - coex_dm->pre_agc_table_en = coex_dm->cur_agc_table_en; -} - -void halbtc8723b2ant_sw_mechanism1(IN struct btc_coexist *btcoexist, - IN boolean shrink_rx_lpf, IN boolean low_penalty_ra, - IN boolean limited_dig, IN boolean bt_lna_constrain) -{ - /* - u32 wifi_bw; - - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw); - - if(BTC_WIFI_BW_HT40 != wifi_bw) - { - if (shrink_rx_lpf) - shrink_rx_lpf = false; - } - */ - - /* halbtc8723b2ant_rf_shrink(btcoexist, NORMAL_EXEC, shrink_rx_lpf); */ - halbtc8723b2ant_low_penalty_ra(btcoexist, NORMAL_EXEC, low_penalty_ra); -} - -void halbtc8723b2ant_sw_mechanism2(IN struct btc_coexist *btcoexist, - IN boolean agc_table_shift, IN boolean adc_back_off, - IN boolean sw_dac_swing, IN u32 dac_swing_lvl) -{ - /* halbtc8723b2ant_agc_table(btcoexist, NORMAL_EXEC, agc_table_shift); */ - /* halbtc8723b2ant_adc_back_off(btcoexist, NORMAL_EXEC, adc_back_off); */ - /* halbtc8723b2ant_dac_swing(btcoexist, NORMAL_EXEC, sw_dac_swing, dac_swing_lvl); */ -} - -void halbtc8723b2ant_set_coex_table(IN struct btc_coexist *btcoexist, - IN u32 val0x6c0, IN u32 val0x6c4, IN u32 val0x6c8, IN u8 val0x6cc) -{ - btcoexist->btc_write_4byte(btcoexist, 0x6c0, val0x6c0); - - btcoexist->btc_write_4byte(btcoexist, 0x6c4, val0x6c4); - - btcoexist->btc_write_4byte(btcoexist, 0x6c8, val0x6c8); - - btcoexist->btc_write_1byte(btcoexist, 0x6cc, val0x6cc); -} - -void halbtc8723b2ant_coex_table(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u32 val0x6c0, IN u32 val0x6c4, - IN u32 val0x6c8, IN u8 val0x6cc) -{ - coex_dm->cur_val0x6c0 = val0x6c0; - coex_dm->cur_val0x6c4 = val0x6c4; - coex_dm->cur_val0x6c8 = val0x6c8; - coex_dm->cur_val0x6cc = val0x6cc; - - if (!force_exec) { - if ((coex_dm->pre_val0x6c0 == coex_dm->cur_val0x6c0) && - (coex_dm->pre_val0x6c4 == coex_dm->cur_val0x6c4) && - (coex_dm->pre_val0x6c8 == coex_dm->cur_val0x6c8) && - (coex_dm->pre_val0x6cc == coex_dm->cur_val0x6cc)) - return; - } - halbtc8723b2ant_set_coex_table(btcoexist, val0x6c0, val0x6c4, val0x6c8, - val0x6cc); - - coex_dm->pre_val0x6c0 = coex_dm->cur_val0x6c0; - coex_dm->pre_val0x6c4 = coex_dm->cur_val0x6c4; - coex_dm->pre_val0x6c8 = coex_dm->cur_val0x6c8; - coex_dm->pre_val0x6cc = coex_dm->cur_val0x6cc; -} - -void halbtc8723b2ant_coex_table_with_type(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 type) -{ - coex_sta->coex_table_type = type; - - switch (type) { - case 0: - halbtc8723b2ant_coex_table(btcoexist, force_exec, - 0x55555555, 0x55555555, 0xffffff, 0x3); - break; - case 1: - halbtc8723b2ant_coex_table(btcoexist, force_exec, - 0x55555555, 0x5afa5afa, 0xffffff, 0x3); - break; - case 2: - halbtc8723b2ant_coex_table(btcoexist, force_exec, - 0x5ada5ada, 0x5ada5ada, 0xffffff, 0x3); - break; - case 3: - halbtc8723b2ant_coex_table(btcoexist, force_exec, - 0xaaaaaaaa, 0xaaaaaaaa, 0xffffff, 0x3); - break; - case 4: - halbtc8723b2ant_coex_table(btcoexist, force_exec, - 0xffffffff, 0xffffffff, 0xffffff, 0x3); - break; - case 5: - halbtc8723b2ant_coex_table(btcoexist, force_exec, - 0x5fff5fff, 0x5fff5fff, 0xffffff, 0x3); - break; - case 6: - halbtc8723b2ant_coex_table(btcoexist, force_exec, - 0x55ff55ff, 0x5a5a5a5a, 0xffffff, 0x3); - break; - case 7: - halbtc8723b2ant_coex_table(btcoexist, force_exec, - 0x55dd55dd, 0x5ada5ada, 0xffffff, 0x3); - break; - case 8: - halbtc8723b2ant_coex_table(btcoexist, force_exec, - 0x55dd55dd, 0x5ada5ada, 0xffffff, 0x3); - break; - case 9: - halbtc8723b2ant_coex_table(btcoexist, force_exec, - 0x55dd55dd, 0x5ada5ada, 0xffffff, 0x3); - break; - case 10: - halbtc8723b2ant_coex_table(btcoexist, force_exec, - 0x55dd55dd, 0x5ada5ada, 0xffffff, 0x3); - break; - case 11: - halbtc8723b2ant_coex_table(btcoexist, force_exec, - 0x55dd55dd, 0x5ada5ada, 0xffffff, 0x3); - break; - case 12: - halbtc8723b2ant_coex_table(btcoexist, force_exec, - 0x55dd55dd, 0x5ada5ada, 0xffffff, 0x3); - break; - case 13: - halbtc8723b2ant_coex_table(btcoexist, force_exec, - 0x5fff5fff, 0xaaaaaaaa, 0xffffff, 0x3); - break; - case 14: - halbtc8723b2ant_coex_table(btcoexist, force_exec, - 0x5fff5fff, 0x5ada5ada, 0xffffff, 0x3); - break; - case 15: - halbtc8723b2ant_coex_table(btcoexist, force_exec, - 0x55dd55dd, 0xaaaaaaaa, 0xffffff, 0x3); - break; - default: - break; - } -} - -void halbtc8723b2ant_set_fw_ignore_wlan_act(IN struct btc_coexist *btcoexist, - IN boolean enable) -{ - u8 h2c_parameter[1] = {0}; - - if (enable) - h2c_parameter[0] |= BIT(0); /* function enable */ - - btcoexist->btc_fill_h2c(btcoexist, 0x63, 1, h2c_parameter); -} - -void halbtc8723b2ant_ignore_wlan_act(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean enable) -{ - coex_dm->cur_ignore_wlan_act = enable; - - if (!force_exec) { - if (coex_dm->pre_ignore_wlan_act == - coex_dm->cur_ignore_wlan_act) - return; - } - halbtc8723b2ant_set_fw_ignore_wlan_act(btcoexist, enable); - - coex_dm->pre_ignore_wlan_act = coex_dm->cur_ignore_wlan_act; -} - -void halbtc8723b2ant_set_lps_rpwm(IN struct btc_coexist *btcoexist, - IN u8 lps_val, IN u8 rpwm_val) -{ - u8 lps = lps_val; - u8 rpwm = rpwm_val; - - btcoexist->btc_set(btcoexist, BTC_SET_U1_LPS_VAL, &lps); - btcoexist->btc_set(btcoexist, BTC_SET_U1_RPWM_VAL, &rpwm); -} - -void halbtc8723b2ant_lps_rpwm(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 lps_val, IN u8 rpwm_val) -{ - coex_dm->cur_lps = lps_val; - coex_dm->cur_rpwm = rpwm_val; - - if (!force_exec) { - if ((coex_dm->pre_lps == coex_dm->cur_lps) && - (coex_dm->pre_rpwm == coex_dm->cur_rpwm)) - return; - } - halbtc8723b2ant_set_lps_rpwm(btcoexist, lps_val, rpwm_val); - - coex_dm->pre_lps = coex_dm->cur_lps; - coex_dm->pre_rpwm = coex_dm->cur_rpwm; -} - -void halbtc8723b2ant_ps_tdma_check_for_power_save_state( - IN struct btc_coexist *btcoexist, IN boolean new_ps_state) -{ - u8 lps_mode = 0x0; - u8 h2c_parameter[5] = {0x0, 0, 0, 48, 0}; - - btcoexist->btc_get(btcoexist, BTC_GET_U1_LPS_MODE, &lps_mode); - - if (lps_mode) { /* already under LPS state */ - if (new_ps_state) { - /* keep state under LPS, do nothing. */ - } else { - /* will leave LPS state, turn off psTdma first */ - /* halbtc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, - 1); */ - btcoexist->btc_fill_h2c(btcoexist, 0x60, 5, - h2c_parameter); - } - } else { /* NO PS state */ - if (new_ps_state) { - /* will enter LPS state, turn off psTdma first */ - /* halbtc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, - 1); */ - btcoexist->btc_fill_h2c(btcoexist, 0x60, 5, - h2c_parameter); - } else { - /* keep state under NO PS state, do nothing. */ - } - } -} - -void halbtc8723b2ant_power_save_state(IN struct btc_coexist *btcoexist, - IN u8 ps_type, IN u8 lps_val, IN u8 rpwm_val) -{ - boolean low_pwr_disable = false; - - switch (ps_type) { - case BTC_PS_WIFI_NATIVE: - /* recover to original 32k low power setting */ - low_pwr_disable = false; - btcoexist->btc_set(btcoexist, - BTC_SET_ACT_DISABLE_LOW_POWER, - &low_pwr_disable); - btcoexist->btc_set(btcoexist, BTC_SET_ACT_NORMAL_LPS, - NULL); - coex_sta->force_lps_on = false; - break; - case BTC_PS_LPS_ON: - halbtc8723b2ant_ps_tdma_check_for_power_save_state( - btcoexist, true); - halbtc8723b2ant_lps_rpwm(btcoexist, NORMAL_EXEC, - lps_val, rpwm_val); - /* when coex force to enter LPS, do not enter 32k low power. */ - low_pwr_disable = true; - btcoexist->btc_set(btcoexist, - BTC_SET_ACT_DISABLE_LOW_POWER, - &low_pwr_disable); - /* power save must executed before psTdma. */ - btcoexist->btc_set(btcoexist, BTC_SET_ACT_ENTER_LPS, - NULL); - coex_sta->force_lps_on = true; - break; - case BTC_PS_LPS_OFF: - halbtc8723b2ant_ps_tdma_check_for_power_save_state( - btcoexist, false); - btcoexist->btc_set(btcoexist, BTC_SET_ACT_LEAVE_LPS, - NULL); - coex_sta->force_lps_on = false; - break; - default: - break; - } -} - - -void halbtc8723b2ant_set_fw_pstdma(IN struct btc_coexist *btcoexist, - IN u8 byte1, IN u8 byte2, IN u8 byte3, IN u8 byte4, IN u8 byte5) -{ - u8 h2c_parameter[5] = {0}; - u8 real_byte1 = byte1, real_byte5 = byte5; - boolean ap_enable = false; - - if ((coex_sta->a2dp_exist) && (coex_sta->hid_exist)) - byte5 = byte5 | 0x1; - - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, - &ap_enable); - - if (ap_enable) { - if (byte1 & BIT(4) && !(byte1 & BIT(5))) { - real_byte1 &= ~BIT(4); - real_byte1 |= BIT(5); - - real_byte5 |= BIT(5); - real_byte5 &= ~BIT(6); - - halbtc8723b2ant_power_save_state(btcoexist, - BTC_PS_WIFI_NATIVE, 0x0, 0x0); - } - } else if (byte1 & BIT(4) && !(byte1 & BIT(5))) { - halbtc8723b2ant_power_save_state(btcoexist, - BTC_PS_LPS_ON, 0x50, 0x4); - - } else { - halbtc8723b2ant_power_save_state(btcoexist, - BTC_PS_WIFI_NATIVE, 0x0, 0x0); - } - - h2c_parameter[0] = byte1; - h2c_parameter[1] = byte2; - h2c_parameter[2] = byte3; - h2c_parameter[3] = byte4; - h2c_parameter[4] = byte5; - - coex_dm->ps_tdma_para[0] = byte1; - coex_dm->ps_tdma_para[1] = byte2; - coex_dm->ps_tdma_para[2] = byte3; - coex_dm->ps_tdma_para[3] = byte4; - coex_dm->ps_tdma_para[4] = byte5; - - btcoexist->btc_fill_h2c(btcoexist, 0x60, 5, h2c_parameter); -} - -void halbtc8723b2ant_ps_tdma(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean turn_on, IN u8 type) -{ - static u8 prewifi_rssi_state = BTC_RSSI_STATE_LOW; - static u8 pre_bt_rssi_state = BTC_RSSI_STATE_LOW; - u8 wifi_rssi_state1, bt_rssi_state; - s8 wifi_duration_adjust = 0x0; - u8 psTdmaByte4Modify = 0x0; - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - - wifi_rssi_state1 = halbtc8723b2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state, 2, BT_8723B_2ANT_WIFI_RSSI_COEXSWITCH_THRES - - coex_dm->switch_thres_offset, 0); - bt_rssi_state = halbtc8723b2ant_bt_rssi_state(&pre_bt_rssi_state, 2, - BT_8723B_2ANT_BT_RSSI_COEXSWITCH_THRES - - coex_dm->switch_thres_offset, 0); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], %s turn %s PS TDMA, type=%d\n", - (force_exec ? "force to" : ""), (turn_on ? "ON" : "OFF"), type); - BTC_TRACE(trace_buf); - coex_dm->cur_ps_tdma_on = turn_on; - coex_dm->cur_ps_tdma = type; - - if (!(BTC_RSSI_HIGH(wifi_rssi_state1) && - BTC_RSSI_HIGH(bt_rssi_state)) && turn_on) - /* if (halbtc8723b2ant_CoexSwitchThresCheck(btcoexist) && turn_on) */ - { - type = type + 100; /* for WiFi RSSI low or BT RSSI low */ - coex_dm->is_switch_to_1dot5_ant = true; - } else - coex_dm->is_switch_to_1dot5_ant = false; - - - if (!force_exec) { - if ((coex_dm->pre_ps_tdma_on == coex_dm->cur_ps_tdma_on) && - (coex_dm->pre_ps_tdma == coex_dm->cur_ps_tdma)) - return; - } - - if (coex_sta->scan_ap_num <= 5) { - if (coex_sta->a2dp_bit_pool >= 45) - wifi_duration_adjust = -15; - else if (coex_sta->a2dp_bit_pool >= 35) - wifi_duration_adjust = -10; - else - wifi_duration_adjust = 5; - } else if (coex_sta->scan_ap_num <= 20) { - if (coex_sta->a2dp_bit_pool >= 45) - wifi_duration_adjust = -15; - else if (coex_sta->a2dp_bit_pool >= 35) - wifi_duration_adjust = -10; - else - wifi_duration_adjust = 0; - } else if (coex_sta->scan_ap_num <= 40) { - if (coex_sta->a2dp_bit_pool >= 45) - wifi_duration_adjust = -15; - else if (coex_sta->a2dp_bit_pool >= 35) - wifi_duration_adjust = -10; - else - wifi_duration_adjust = -5; - } else { - if (coex_sta->a2dp_bit_pool >= 45) - wifi_duration_adjust = -15; - else if (coex_sta->a2dp_bit_pool >= 35) - wifi_duration_adjust = -10; - else - wifi_duration_adjust = -10; - } - - if ((bt_link_info->slave_role == true) && (bt_link_info->a2dp_exist)) - psTdmaByte4Modify = - 0x1; /* 0x778 = 0x1 at wifi slot (no blocking BT Low-Pri pkts) */ - - - if (turn_on) { - switch (type) { - case 1: - default: - halbtc8723b2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x3c + wifi_duration_adjust, 0x03, 0xf1, - 0x90 | psTdmaByte4Modify); - break; - case 2: - halbtc8723b2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x2d + wifi_duration_adjust, 0x03, 0xf1, - 0x90 | psTdmaByte4Modify); - break; - case 3: - halbtc8723b2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x1c, 0x3, 0xf1, 0x90 | - psTdmaByte4Modify); - break; - case 4: - halbtc8723b2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x10, 0x03, 0xf1, 0x90 | - psTdmaByte4Modify); - break; - case 5: - halbtc8723b2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x3c + wifi_duration_adjust, 0x3, 0x70, - 0x90 | psTdmaByte4Modify); - break; - case 6: - halbtc8723b2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x2d + wifi_duration_adjust, 0x3, 0x70, - 0x90 | psTdmaByte4Modify); - break; - case 7: - halbtc8723b2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x1c, 0x3, 0x70, 0x90 | - psTdmaByte4Modify); - break; - case 8: - halbtc8723b2ant_set_fw_pstdma(btcoexist, 0xa3, - 0x10, 0x3, 0x70, 0x90 | - psTdmaByte4Modify); - break; - case 9: - /* - halbtc8723b2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x3c + wifi_duration_adjust, 0x03, 0xf1, - 0x90 | psTdmaByte4Modify); - */ - /* Bryant Modify for BT no-profile busy case */ - halbtc8723b2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x3c + wifi_duration_adjust, 0x03, 0xf1, - 0x91); - - break; - case 10: - halbtc8723b2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x2d + wifi_duration_adjust, 0x03, 0xf1, - 0x90 | psTdmaByte4Modify); - break; - case 11: - halbtc8723b2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x1c, 0x3, 0xf1, 0x90 | - psTdmaByte4Modify); - break; - case 12: - halbtc8723b2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x10, 0x3, 0xf1, 0x90 | - psTdmaByte4Modify); - break; - case 13: - /* - halbtc8723b2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x3c + wifi_duration_adjust, 0x3, 0x70, - 0x90 | psTdmaByte4Modify); - */ - /* Bryant Modify for BT no-profile busy case */ - halbtc8723b2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x3c + wifi_duration_adjust, 0x3, 0x70, - 0x91); - break; - case 14: - halbtc8723b2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x2d + wifi_duration_adjust, 0x3, 0x70, - 0x90 | psTdmaByte4Modify); - break; - case 15: - halbtc8723b2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x1c, 0x3, 0x70, 0x90 | - psTdmaByte4Modify); - break; - case 16: - halbtc8723b2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x10, 0x3, 0x70, 0x90 | - psTdmaByte4Modify); - break; - case 17: - halbtc8723b2ant_set_fw_pstdma(btcoexist, 0xa3, - 0x2f, 0x2f, 0x60, 0x90); - break; - case 18: - halbtc8723b2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x5, 0x5, 0xe1, 0x90); - break; - case 19: - halbtc8723b2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x25, 0x25, 0xe1, 0x90); - break; - case 20: - halbtc8723b2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x25, 0x25, 0x60, 0x90); - break; - case 21: - halbtc8723b2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x15, 0x03, 0x70, 0x90); - break; - case 22: - halbtc8723b2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x35, 0x03, 0xf1, 0x90); - break; - case 23: - halbtc8723b2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x35, 0x03, 0x71, 0x10); - break; - - case 25: - halbtc8723b2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x30, 0x03, 0x71, 0x10); - break; - - case 33: - halbtc8723b2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x1c, 0x3, 0xf1, 0x91); - - break; - case 71: - halbtc8723b2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x3c + wifi_duration_adjust, 0x03, 0xf1, - 0x90); - break; - case 101: - case 105: - case 113: - case 171: - halbtc8723b2ant_set_fw_pstdma(btcoexist, 0xd3, - 0x3a + wifi_duration_adjust, 0x03, 0x70, - 0x50 | psTdmaByte4Modify); - break; - case 102: - case 106: - case 110: - case 114: - halbtc8723b2ant_set_fw_pstdma(btcoexist, 0xd3, - 0x2d + wifi_duration_adjust, 0x03, 0x70, - 0x50 | psTdmaByte4Modify); - break; - case 103: - case 107: - case 111: - case 115: - halbtc8723b2ant_set_fw_pstdma(btcoexist, 0xd3, - 0x1c, 0x03, 0x70, 0x50 | - psTdmaByte4Modify); - break; - case 104: - case 108: - case 112: - case 116: - halbtc8723b2ant_set_fw_pstdma(btcoexist, 0xd3, - 0x10, 0x03, 0x70, 0x50 | - psTdmaByte4Modify); - break; - case 109: - halbtc8723b2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x3c, 0x03, 0xf1, 0x90 | - psTdmaByte4Modify); - break; - /* case 113: - halbtc8723b2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x3c, 0x03, 0x70, 0x90 | - psTdmaByte4Modify); - break; */ - case 121: - halbtc8723b2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x15, 0x03, 0x70, 0x90 | - psTdmaByte4Modify); - break; - case 122: - halbtc8723b2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x35, 0x03, 0x71, 0x11); - break; - case 123: - halbtc8723b2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x35, 0x03, 0x71, 0x10); - break; - case 125: - halbtc8723b2ant_set_fw_pstdma(btcoexist, 0xd3, - 0x30, 0x03, 0x70, 0x51); - break; - - case 133: - halbtc8723b2ant_set_fw_pstdma(btcoexist, 0xd3, - 0x1c, 0x3, 0x70, 0x51); - - break; - } - } else { - /* disable PS tdma */ - switch (type) { - case 0: - halbtc8723b2ant_set_fw_pstdma(btcoexist, 0x0, - 0x0, 0x0, 0x40, 0x0); - break; - case 1: - halbtc8723b2ant_set_fw_pstdma(btcoexist, 0x0, - 0x0, 0x0, 0x48, 0x0); - break; - default: - halbtc8723b2ant_set_fw_pstdma(btcoexist, 0x0, - 0x0, 0x0, 0x40, 0x0); - break; - } - } - - /* update pre state */ - coex_dm->pre_ps_tdma_on = coex_dm->cur_ps_tdma_on; - coex_dm->pre_ps_tdma = coex_dm->cur_ps_tdma; -} - - -void halbtc8723b2ant_set_ant_path(IN struct btc_coexist *btcoexist, - IN u8 ant_pos_type, IN boolean init_hwcfg, IN boolean wifi_off) -{ - struct btc_board_info *board_info = &btcoexist->board_info; - u32 fw_ver = 0, u32tmp = 0, cnt_bt_cal_chk = 0; - boolean pg_ext_switch = false; - boolean use_ext_switch = false; - u8 h2c_parameter[2] = {0}; - u32 u32tmp_1[4]; - boolean is_fw_ready; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_EXT_SWITCH, &pg_ext_switch); - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, - &fw_ver); /* [31:16]=fw ver, [15:0]=fw sub ver */ - - if ((fw_ver > 0 && fw_ver < 0xc0000) || pg_ext_switch) - use_ext_switch = true; - - if (init_hwcfg) { - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x39, 0x8, 0x1); - btcoexist->btc_write_1byte(btcoexist, 0x974, 0xff); - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x944, 0x3, 0x3); - btcoexist->btc_write_1byte(btcoexist, 0x930, 0x77); - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, 0x20, 0x1); - - if (fw_ver >= 0x180000) { - /* Use H2C to set GNT_BT to High to avoid A2DP click */ - h2c_parameter[0] = 1; - btcoexist->btc_fill_h2c(btcoexist, 0x6E, 1, - h2c_parameter); - - cnt_bt_cal_chk = 0; - while (1) { - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_FW_READY, &is_fw_ready); - if (is_fw_ready == false) - break; - - if (btcoexist->btc_read_1byte(btcoexist, - 0x765) == 0x18) - break; - - cnt_bt_cal_chk++; - if (cnt_bt_cal_chk > 20) - break; - } - } else - btcoexist->btc_write_1byte(btcoexist, 0x765, 0x18); - u32tmp_1[0] = btcoexist->btc_read_4byte(btcoexist, 0x948); - if ((u32tmp_1[0] == 0x40) || (u32tmp_1[0] == 0x240)) - btcoexist->btc_write_4byte(btcoexist, 0x948, - u32tmp_1[0]); - else - btcoexist->btc_write_4byte(btcoexist, 0x948, 0x0); - - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, - 0x0); /* WiFi TRx Mask off */ - /* remove due to interrupt is disabled that polling c2h will fail and delay 100ms. */ - /* btcoexist->btc_set_bt_reg(btcoexist, BTC_BT_REG_RF, 0x3c, 0x01); */ /*BT TRx Mask off */ - - if (board_info->btdm_ant_pos == BTC_ANTENNA_AT_MAIN_PORT) { - /* tell firmware "no antenna inverse" */ - h2c_parameter[0] = 0; - } else { - /* tell firmware "antenna inverse" */ - h2c_parameter[0] = 1; - } - - if (use_ext_switch) { - /* ext switch type */ - h2c_parameter[1] = 1; - } else { - /* int switch type */ - h2c_parameter[1] = 0; - } - btcoexist->btc_fill_h2c(btcoexist, 0x65, 2, h2c_parameter); - } else { - if (fw_ver >= 0x180000) { - /* Use H2C to set GNT_BT to "Control by PTA"*/ - h2c_parameter[0] = 0; - btcoexist->btc_fill_h2c(btcoexist, 0x6E, 1, - h2c_parameter); - - cnt_bt_cal_chk = 0; - while (1) { - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_FW_READY, &is_fw_ready); - if (is_fw_ready == false) - break; - - if (btcoexist->btc_read_1byte(btcoexist, - 0x765) == 0x0) - break; - - cnt_bt_cal_chk++; - if (cnt_bt_cal_chk > 20) - break; - } - } else - btcoexist->btc_write_1byte(btcoexist, 0x765, 0x0); - } - - /* ext switch setting */ - if (use_ext_switch) { - if (init_hwcfg) { - /* 0x4c[23]=0, 0x4c[24]=1 Antenna control by WL/BT */ - u32tmp = btcoexist->btc_read_4byte(btcoexist, 0x4c); - u32tmp &= ~BIT(23); - u32tmp |= BIT(24); - btcoexist->btc_write_4byte(btcoexist, 0x4c, u32tmp); - } - u32tmp_1[0] = btcoexist->btc_read_4byte(btcoexist, 0x948); - if ((u32tmp_1[0] == 0x40) || (u32tmp_1[0] == 0x240)) - btcoexist->btc_write_4byte(btcoexist, 0x948, - u32tmp_1[0]); - else - btcoexist->btc_write_4byte(btcoexist, 0x948, 0x0); - - switch (ant_pos_type) { - case BTC_ANT_WIFI_AT_MAIN: - btcoexist->btc_write_1byte_bitmask(btcoexist, - 0x92c, 0x3, - 0x1); /* ext switch main at wifi */ - break; - case BTC_ANT_WIFI_AT_AUX: - btcoexist->btc_write_1byte_bitmask(btcoexist, - 0x92c, 0x3, - 0x2); /* ext switch aux at wifi */ - break; - } - } else { /* internal switch */ - if (init_hwcfg) { - /* 0x4c[23]=0, 0x4c[24]=1 Antenna control by WL/BT */ - u32tmp = btcoexist->btc_read_4byte(btcoexist, 0x4c); - u32tmp |= BIT(23); - u32tmp &= ~BIT(24); - btcoexist->btc_write_4byte(btcoexist, 0x4c, u32tmp); - } - - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x64, 0x1, - 0x0); /* fixed external switch S1->Main, S0->Aux */ - switch (ant_pos_type) { - case BTC_ANT_WIFI_AT_MAIN: - u32tmp_1[0] = btcoexist->btc_read_4byte(btcoexist, - 0x948); - if ((u32tmp_1[0] == 0x40) || (u32tmp_1[0] == 0x240)) - btcoexist->btc_write_4byte(btcoexist, 0x948, - u32tmp_1[0]); - else - btcoexist->btc_write_4byte(btcoexist, 0x948, - 0x0); - break; - case BTC_ANT_WIFI_AT_AUX: - u32tmp_1[0] = btcoexist->btc_read_4byte(btcoexist, - 0x948); - if ((u32tmp_1[0] == 0x40) || (u32tmp_1[0] == 0x240)) - btcoexist->btc_write_4byte(btcoexist, 0x948, - u32tmp_1[0]); - else - btcoexist->btc_write_4byte(btcoexist, 0x948, - 0x280); - break; - } - } -} -#if 0 -boolean halbtc8723b2ant_CoexSwitchThresCheck(IN struct btc_coexist *btcoexist) -{ - static u8 prewifi_rssi_state = BTC_RSSI_STATE_LOW; - static u8 pre_bt_rssi_state = BTC_RSSI_STATE_LOW; - u8 wifi_rssi_state1, bt_rssi_state; - u32 vendor; - u8 offset = 0; - - btcoexist->btc_get(btcoexist, BTC_GET_U4_VENDOR, &vendor); - - /* if (vendor == BTC_VENDOR_LENOVO) */ - /* offset = 20; */ - - wifi_rssi_state1 = halbtc8723b2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state, 2, BT_8723B_2ANT_WIFI_RSSI_COEXSWITCH_THRES - - coex_dm->switch_thres_offset, 0); - bt_rssi_state = halbtc8723b2ant_bt_rssi_state(&pre_bt_rssi_state, 2, - BT_8723B_2ANT_BT_RSSI_COEXSWITCH_THRES - - coex_dm->switch_thres_offset, 0); - - if (BTC_RSSI_LOW(wifi_rssi_state1) || BTC_RSSI_LOW(bt_rssi_state)) - return true; - - return false; -} -#endif - - -void halbtc8723b2ant_coex_all_off(IN struct btc_coexist *btcoexist) -{ - /* fw all off */ - halbtc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1); - halbtc8723b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6); - halbtc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - /* sw all off */ - halbtc8723b2ant_sw_mechanism1(btcoexist, false, false, false, false); - halbtc8723b2ant_sw_mechanism2(btcoexist, false, false, false, 0x18); - - /* hw all off */ - /* btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0); */ - halbtc8723b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); -} - -void halbtc8723b2ant_init_coex_dm(IN struct btc_coexist *btcoexist) -{ - /* force to reset coex mechanism */ - halbtc8723b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - - halbtc8723b2ant_ps_tdma(btcoexist, FORCE_EXEC, false, 1); - halbtc8723b2ant_fw_dac_swing_lvl(btcoexist, FORCE_EXEC, 6); - halbtc8723b2ant_dec_bt_pwr(btcoexist, FORCE_EXEC, 0); - - halbtc8723b2ant_sw_mechanism1(btcoexist, false, false, false, false); - halbtc8723b2ant_sw_mechanism2(btcoexist, false, false, false, 0x18); - - coex_sta->pop_event_cnt = 0; - -} - -void halbtc8723b2ant_action_bt_inquiry(IN struct btc_coexist *btcoexist) -{ - static u8 prewifi_rssi_state = BTC_RSSI_STATE_LOW, - prewifi_rssi_state1 = BTC_RSSI_STATE_LOW; - static u8 pre_bt_rssi_state = BTC_RSSI_STATE_LOW; - u8 wifi_rssi_state, wifi_rssi_state1, bt_rssi_state; - boolean wifi_connected = false; - boolean low_pwr_disable = true; - boolean scan = false, link = false, roam = false; - boolean wifi_busy = false; - - - wifi_rssi_state = halbtc8723b2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state, 2, 15, 0); - wifi_rssi_state1 = halbtc8723b2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state1, 2, - BT_8723B_2ANT_WIFI_RSSI_COEXSWITCH_THRES - - coex_dm->switch_thres_offset, 0); - bt_rssi_state = halbtc8723b2ant_bt_rssi_state(&pre_bt_rssi_state, 2, - BT_8723B_2ANT_BT_RSSI_COEXSWITCH_THRES - - coex_dm->switch_thres_offset, 0); - - btcoexist->btc_set(btcoexist, BTC_SET_ACT_DISABLE_LOW_POWER, - &low_pwr_disable); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - - - if (coex_sta->bt_abnormal_scan) { - halbtc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 23); - halbtc8723b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 3); - } else if (scan || link || roam) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi link process + BT Inq/Page!!\n"); - BTC_TRACE(trace_buf); - halbtc8723b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, - 7); - halbtc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 3); - } else if (wifi_connected) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi connected + BT Inq/Page!!\n"); - BTC_TRACE(trace_buf); - halbtc8723b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, - 7); - - if (wifi_busy) - halbtc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 3); - else - halbtc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 33); - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi no-link + BT Inq/Page!!\n"); - BTC_TRACE(trace_buf); - halbtc8723b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - halbtc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1); - } - - halbtc8723b2ant_fw_dac_swing_lvl(btcoexist, FORCE_EXEC, 6); - halbtc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - halbtc8723b2ant_sw_mechanism1(btcoexist, false, false, false, false); - halbtc8723b2ant_sw_mechanism2(btcoexist, false, false, false, 0x18); - /* - coex_dm->need_recover0x948 = true; - coex_dm->backup0x948 = btcoexist->btc_read_4byte(btcoexist, 0x948); - - halbtc8723b2ant_set_ant_path(btcoexist, BTC_ANT_WIFI_AT_AUX, false, false); - */ -} - - -void halbtc8723b2ant_action_wifi_link_process(IN struct btc_coexist *btcoexist) -{ - u32 u32tmp; - u8 u8tmpa, u8tmpb; - - halbtc8723b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 15); - halbtc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 22); - - halbtc8723b2ant_sw_mechanism1(btcoexist, false, false, false, false); - halbtc8723b2ant_sw_mechanism2(btcoexist, false, false, false, 0x18); - - - u32tmp = btcoexist->btc_read_4byte(btcoexist, 0x948); - u8tmpa = btcoexist->btc_read_1byte(btcoexist, 0x765); - u8tmpb = btcoexist->btc_read_1byte(btcoexist, 0x76e); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "############# [BTCoex], 0x948=0x%x, 0x765=0x%x, 0x76e=0x%x\n", - u32tmp, u8tmpa, u8tmpb); - BTC_TRACE(trace_buf); -} - -boolean halbtc8723b2ant_action_wifi_idle_process(IN struct btc_coexist - *btcoexist) -{ - static u8 prewifi_rssi_state = BTC_RSSI_STATE_LOW, - prewifi_rssi_state1 = BTC_RSSI_STATE_LOW; - static u8 pre_bt_rssi_state = BTC_RSSI_STATE_LOW; - u8 wifi_rssi_state, wifi_rssi_state1, bt_rssi_state; - u8 ap_num = 0; - - wifi_rssi_state = halbtc8723b2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state, 2, 15, 0); - /* wifi_rssi_state1 = halbtc8723b2ant_wifi_rssi_state(btcoexist, 1, 2, BT_8723B_2ANT_WIFI_RSSI_COEXSWITCH_THRES-coex_dm->switch_thres_offset-coex_dm->switch_thres_offset, 0); */ - wifi_rssi_state1 = halbtc8723b2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state1, 2, - BT_8723B_2ANT_WIFI_RSSI_COEXSWITCH_THRES - - coex_dm->switch_thres_offset - coex_dm->switch_thres_offset, 0); - bt_rssi_state = halbtc8723b2ant_bt_rssi_state(&pre_bt_rssi_state, 2, - BT_8723B_2ANT_BT_RSSI_COEXSWITCH_THRES - - coex_dm->switch_thres_offset - coex_dm->switch_thres_offset, 0); - - btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM, &ap_num); - - /* define the office environment */ - if (BTC_RSSI_HIGH(wifi_rssi_state1) && - (coex_sta->hid_exist == true) && - (coex_sta->a2dp_exist == true)) { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi idle process for BT HID+A2DP exist!!\n"); - BTC_TRACE(trace_buf); - - halbtc8723b2ant_dac_swing(btcoexist, NORMAL_EXEC, true, 0x6); - halbtc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - /* sw all off */ - halbtc8723b2ant_sw_mechanism1(btcoexist, false, false, false, - false); - halbtc8723b2ant_sw_mechanism2(btcoexist, false, false, false, - 0x18); - - halbtc8723b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - - halbtc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1); - - return true; - } - - halbtc8723b2ant_dac_swing(btcoexist, NORMAL_EXEC, true, 0x18); - return false; -} - - - -boolean halbtc8723b2ant_is_common_action(IN struct btc_coexist *btcoexist) -{ - boolean common = false, wifi_connected = false, wifi_busy = false; - boolean bt_hs_on = false, low_pwr_disable = false; - boolean asus_8723b = false; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - - if (!wifi_connected) { - low_pwr_disable = false; - btcoexist->btc_set(btcoexist, BTC_SET_ACT_DISABLE_LOW_POWER, - &low_pwr_disable); - halbtc8723b2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, - 0x8); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi non-connected idle!!\n"); - BTC_TRACE(trace_buf); - - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, - 0x0); - halbtc8723b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - - halbtc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1); - halbtc8723b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6); - halbtc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - halbtc8723b2ant_sw_mechanism1(btcoexist, false, false, false, - false); - halbtc8723b2ant_sw_mechanism2(btcoexist, false, false, false, - 0x18); - - common = true; - } else { - if (BT_8723B_2ANT_BT_STATUS_NON_CONNECTED_IDLE == - coex_dm->bt_status) { - low_pwr_disable = false; - btcoexist->btc_set(btcoexist, - BTC_SET_ACT_DISABLE_LOW_POWER, - &low_pwr_disable); - halbtc8723b2ant_limited_rx(btcoexist, NORMAL_EXEC, - false, false, 0x8); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi connected + BT non connected-idle!!\n"); - BTC_TRACE(trace_buf); - - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, - 0xfffff, 0x0); - halbtc8723b2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 0); - - halbtc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, - 1); - halbtc8723b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, - 0xb); - halbtc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - halbtc8723b2ant_sw_mechanism1(btcoexist, false, false, - false, - false); - halbtc8723b2ant_sw_mechanism2(btcoexist, false, false, - false, 0x18); - - common = true; - } else if (BT_8723B_2ANT_BT_STATUS_CONNECTED_IDLE == - coex_dm->bt_status) { - low_pwr_disable = true; - btcoexist->btc_set(btcoexist, - BTC_SET_ACT_DISABLE_LOW_POWER, - &low_pwr_disable); - - if (bt_hs_on) - return false; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi connected + BT connected-idle!!\n"); - BTC_TRACE(trace_buf); - halbtc8723b2ant_limited_rx(btcoexist, NORMAL_EXEC, - false, false, 0x8); - - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, - 0xfffff, 0x0); - halbtc8723b2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 0); - halbtc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, - 1); - halbtc8723b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, - 0xb); - halbtc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - halbtc8723b2ant_sw_mechanism1(btcoexist, true, false, - false, false); - halbtc8723b2ant_sw_mechanism2(btcoexist, false, false, - false, 0x18); - - common = true; - } else { - low_pwr_disable = true; - btcoexist->btc_set(btcoexist, - BTC_SET_ACT_DISABLE_LOW_POWER, - &low_pwr_disable); - - if (wifi_busy) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi Connected-Busy + BT Busy!!\n"); - BTC_TRACE(trace_buf); - /* btcoexist->btc_get(btcoexist, - BTC_GET_BL_IS_ASUS_8723B, &asus_8723b); - if (!asus_8723b) - common = false; - else - common = halbtc8723b2ant_action_wifi_idle_process( - btcoexist); */ - common = false; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi Connected-Idle + BT Busy!!\n"); - BTC_TRACE(trace_buf); - /* common = false; */ - common = halbtc8723b2ant_action_wifi_idle_process( - btcoexist); - } - } - } - - return common; -} -void halbtc8723b2ant_tdma_duration_adjust(IN struct btc_coexist *btcoexist, - IN boolean sco_hid, IN boolean tx_pause, IN u8 max_interval) -{ - static s32 up, dn, m, n, wait_count; - s32 result; /* 0: no change, +1: increase WiFi duration, -1: decrease WiFi duration */ - u8 retry_count = 0; - - if (!coex_dm->auto_tdma_adjust) { - coex_dm->auto_tdma_adjust = true; - { - if (sco_hid) { - if (tx_pause) { - if (max_interval == 1) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 13); - coex_dm->ps_tdma_du_adj_type = - 13; - } else if (max_interval == 2) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 14); - coex_dm->ps_tdma_du_adj_type = - 14; - } else if (max_interval == 3) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 15); - coex_dm->ps_tdma_du_adj_type = - 15; - } else { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 15); - coex_dm->ps_tdma_du_adj_type = - 15; - } - } else { - if (max_interval == 1) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 9); - coex_dm->ps_tdma_du_adj_type = - 9; - } else if (max_interval == 2) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 10); - coex_dm->ps_tdma_du_adj_type = - 10; - } else if (max_interval == 3) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 11); - coex_dm->ps_tdma_du_adj_type = - 11; - } else { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 11); - coex_dm->ps_tdma_du_adj_type = - 11; - } - } - } else { - if (tx_pause) { - if (max_interval == 1) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 5); - coex_dm->ps_tdma_du_adj_type = - 5; - } else if (max_interval == 2) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 6); - coex_dm->ps_tdma_du_adj_type = - 6; - } else if (max_interval == 3) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 7); - coex_dm->ps_tdma_du_adj_type = - 7; - } else { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 7); - coex_dm->ps_tdma_du_adj_type = - 7; - } - } else { - if (max_interval == 1) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 1); - coex_dm->ps_tdma_du_adj_type = - 1; - } else if (max_interval == 2) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 2); - coex_dm->ps_tdma_du_adj_type = - 2; - } else if (max_interval == 3) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 3); - coex_dm->ps_tdma_du_adj_type = - 3; - } else { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 3); - coex_dm->ps_tdma_du_adj_type = - 3; - } - } - } - } - /* ============ */ - up = 0; - dn = 0; - m = 1; - n = 3; - result = 0; - wait_count = 0; - } else { - /* acquire the BT TRx retry count from BT_Info byte2 */ - retry_count = coex_sta->bt_retry_cnt; - - if ((coex_sta->low_priority_tx) > 1050 || - (coex_sta->low_priority_rx) > 1250) - retry_count++; - - result = 0; - wait_count++; - - if (retry_count == - 0) { /* no retry in the last 2-second duration */ - up++; - dn--; - - if (dn <= 0) - dn = 0; - - if (up >= n) { /* if retry count during continuous n*2 seconds is 0, enlarge WiFi duration */ - wait_count = 0; - n = 3; - up = 0; - dn = 0; - result = 1; - } - } else if (retry_count <= - 3) { /* <=3 retry in the last 2-second duration */ - up--; - dn++; - - if (up <= 0) - up = 0; - - if (dn == 2) {/* if continuous 2 retry count(every 2 seconds) >0 and < 3, reduce WiFi duration */ - if (wait_count <= 2) - m++; /* to avoid loop between the two levels */ - else - m = 1; - - if (m >= 20) /* maximum of m = 20 ' will recheck if need to adjust wifi duration in maximum time interval 120 seconds */ - m = 20; - - n = 3 * m; - up = 0; - dn = 0; - wait_count = 0; - result = -1; - } - } else { /* retry count > 3, once retry count > 3, to reduce WiFi duration */ - if (wait_count == 1) - m++; /* to avoid loop between the two levels */ - else - m = 1; - - if (m >= 20) /* maximum of m = 20 ' will recheck if need to adjust wifi duration in maximum time interval 120 seconds */ - m = 20; - - n = 3 * m; - up = 0; - dn = 0; - wait_count = 0; - result = -1; - } - - if (max_interval == 1) { - if (tx_pause) { - if (coex_dm->cur_ps_tdma == 71) { - halbtc8723b2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 5); - coex_dm->ps_tdma_du_adj_type = 5; - } else if (coex_dm->cur_ps_tdma == 1) { - halbtc8723b2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 5); - coex_dm->ps_tdma_du_adj_type = 5; - } else if (coex_dm->cur_ps_tdma == 2) { - halbtc8723b2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 6); - coex_dm->ps_tdma_du_adj_type = 6; - } else if (coex_dm->cur_ps_tdma == 3) { - halbtc8723b2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 7); - coex_dm->ps_tdma_du_adj_type = 7; - } else if (coex_dm->cur_ps_tdma == 4) { - halbtc8723b2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 8); - coex_dm->ps_tdma_du_adj_type = 8; - } - if (coex_dm->cur_ps_tdma == 9) { - halbtc8723b2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 13); - coex_dm->ps_tdma_du_adj_type = 13; - } else if (coex_dm->cur_ps_tdma == 10) { - halbtc8723b2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 14); - coex_dm->ps_tdma_du_adj_type = 14; - } else if (coex_dm->cur_ps_tdma == 11) { - halbtc8723b2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 15); - coex_dm->ps_tdma_du_adj_type = 15; - } else if (coex_dm->cur_ps_tdma == 12) { - halbtc8723b2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 16); - coex_dm->ps_tdma_du_adj_type = 16; - } - - if (result == -1) { - if (coex_dm->cur_ps_tdma == 5) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 6); - coex_dm->ps_tdma_du_adj_type = - 6; - } else if (coex_dm->cur_ps_tdma == 6) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 7); - coex_dm->ps_tdma_du_adj_type = - 7; - } else if (coex_dm->cur_ps_tdma == 7) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 8); - coex_dm->ps_tdma_du_adj_type = - 8; - } else if (coex_dm->cur_ps_tdma == 13) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 14); - coex_dm->ps_tdma_du_adj_type = - 14; - } else if (coex_dm->cur_ps_tdma == 14) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 15); - coex_dm->ps_tdma_du_adj_type = - 15; - } else if (coex_dm->cur_ps_tdma == 15) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 16); - coex_dm->ps_tdma_du_adj_type = - 16; - } - } else if (result == 1) { - if (coex_dm->cur_ps_tdma == 8) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 7); - coex_dm->ps_tdma_du_adj_type = - 7; - } else if (coex_dm->cur_ps_tdma == 7) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 6); - coex_dm->ps_tdma_du_adj_type = - 6; - } else if (coex_dm->cur_ps_tdma == 6) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 5); - coex_dm->ps_tdma_du_adj_type = - 5; - } else if (coex_dm->cur_ps_tdma == 16) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 15); - coex_dm->ps_tdma_du_adj_type = - 15; - } else if (coex_dm->cur_ps_tdma == 15) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 14); - coex_dm->ps_tdma_du_adj_type = - 14; - } else if (coex_dm->cur_ps_tdma == 14) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 13); - coex_dm->ps_tdma_du_adj_type = - 13; - } - } - } else { - if (coex_dm->cur_ps_tdma == 5) { - halbtc8723b2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 71); - coex_dm->ps_tdma_du_adj_type = 71; - } else if (coex_dm->cur_ps_tdma == 6) { - halbtc8723b2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 2); - coex_dm->ps_tdma_du_adj_type = 2; - } else if (coex_dm->cur_ps_tdma == 7) { - halbtc8723b2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 3); - coex_dm->ps_tdma_du_adj_type = 3; - } else if (coex_dm->cur_ps_tdma == 8) { - halbtc8723b2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 4); - coex_dm->ps_tdma_du_adj_type = 4; - } - if (coex_dm->cur_ps_tdma == 13) { - halbtc8723b2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 9); - coex_dm->ps_tdma_du_adj_type = 9; - } else if (coex_dm->cur_ps_tdma == 14) { - halbtc8723b2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 10); - coex_dm->ps_tdma_du_adj_type = 10; - } else if (coex_dm->cur_ps_tdma == 15) { - halbtc8723b2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 11); - coex_dm->ps_tdma_du_adj_type = 11; - } else if (coex_dm->cur_ps_tdma == 16) { - halbtc8723b2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 12); - coex_dm->ps_tdma_du_adj_type = 12; - } - - if (result == -1) { - if (coex_dm->cur_ps_tdma == 71) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 1); - coex_dm->ps_tdma_du_adj_type = - 1; - } else if (coex_dm->cur_ps_tdma == 1) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 2); - coex_dm->ps_tdma_du_adj_type = - 2; - } else if (coex_dm->cur_ps_tdma == 2) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 3); - coex_dm->ps_tdma_du_adj_type = - 3; - } else if (coex_dm->cur_ps_tdma == 3) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 4); - coex_dm->ps_tdma_du_adj_type = - 4; - } else if (coex_dm->cur_ps_tdma == 9) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 10); - coex_dm->ps_tdma_du_adj_type = - 10; - } else if (coex_dm->cur_ps_tdma == 10) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 11); - coex_dm->ps_tdma_du_adj_type = - 11; - } else if (coex_dm->cur_ps_tdma == 11) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 12); - coex_dm->ps_tdma_du_adj_type = - 12; - } - } else if (result == 1) { - if (coex_dm->cur_ps_tdma == 4) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 3); - coex_dm->ps_tdma_du_adj_type = - 3; - } else if (coex_dm->cur_ps_tdma == 3) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 2); - coex_dm->ps_tdma_du_adj_type = - 2; - } else if (coex_dm->cur_ps_tdma == 2) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 1); - coex_dm->ps_tdma_du_adj_type = - 1; - } else if (coex_dm->cur_ps_tdma == 1) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 71); - coex_dm->ps_tdma_du_adj_type = - 71; - } else if (coex_dm->cur_ps_tdma == 12) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 11); - coex_dm->ps_tdma_du_adj_type = - 11; - } else if (coex_dm->cur_ps_tdma == 11) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 10); - coex_dm->ps_tdma_du_adj_type = - 10; - } else if (coex_dm->cur_ps_tdma == 10) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 9); - coex_dm->ps_tdma_du_adj_type = - 9; - } - } - } - } else if (max_interval == 2) { - if (tx_pause) { - if (coex_dm->cur_ps_tdma == 1) { - halbtc8723b2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 6); - coex_dm->ps_tdma_du_adj_type = 6; - } else if (coex_dm->cur_ps_tdma == 2) { - halbtc8723b2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 6); - coex_dm->ps_tdma_du_adj_type = 6; - } else if (coex_dm->cur_ps_tdma == 3) { - halbtc8723b2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 7); - coex_dm->ps_tdma_du_adj_type = 7; - } else if (coex_dm->cur_ps_tdma == 4) { - halbtc8723b2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 8); - coex_dm->ps_tdma_du_adj_type = 8; - } - if (coex_dm->cur_ps_tdma == 9) { - halbtc8723b2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 14); - coex_dm->ps_tdma_du_adj_type = 14; - } else if (coex_dm->cur_ps_tdma == 10) { - halbtc8723b2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 14); - coex_dm->ps_tdma_du_adj_type = 14; - } else if (coex_dm->cur_ps_tdma == 11) { - halbtc8723b2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 15); - coex_dm->ps_tdma_du_adj_type = 15; - } else if (coex_dm->cur_ps_tdma == 12) { - halbtc8723b2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 16); - coex_dm->ps_tdma_du_adj_type = 16; - } - if (result == -1) { - if (coex_dm->cur_ps_tdma == 5) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 6); - coex_dm->ps_tdma_du_adj_type = - 6; - } else if (coex_dm->cur_ps_tdma == 6) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 7); - coex_dm->ps_tdma_du_adj_type = - 7; - } else if (coex_dm->cur_ps_tdma == 7) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 8); - coex_dm->ps_tdma_du_adj_type = - 8; - } else if (coex_dm->cur_ps_tdma == 13) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 14); - coex_dm->ps_tdma_du_adj_type = - 14; - } else if (coex_dm->cur_ps_tdma == 14) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 15); - coex_dm->ps_tdma_du_adj_type = - 15; - } else if (coex_dm->cur_ps_tdma == 15) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 16); - coex_dm->ps_tdma_du_adj_type = - 16; - } - } else if (result == 1) { - if (coex_dm->cur_ps_tdma == 8) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 7); - coex_dm->ps_tdma_du_adj_type = - 7; - } else if (coex_dm->cur_ps_tdma == 7) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 6); - coex_dm->ps_tdma_du_adj_type = - 6; - } else if (coex_dm->cur_ps_tdma == 6) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 6); - coex_dm->ps_tdma_du_adj_type = - 6; - } else if (coex_dm->cur_ps_tdma == 16) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 15); - coex_dm->ps_tdma_du_adj_type = - 15; - } else if (coex_dm->cur_ps_tdma == 15) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 14); - coex_dm->ps_tdma_du_adj_type = - 14; - } else if (coex_dm->cur_ps_tdma == 14) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 14); - coex_dm->ps_tdma_du_adj_type = - 14; - } - } - } else { - if (coex_dm->cur_ps_tdma == 5) { - halbtc8723b2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 2); - coex_dm->ps_tdma_du_adj_type = 2; - } else if (coex_dm->cur_ps_tdma == 6) { - halbtc8723b2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 2); - coex_dm->ps_tdma_du_adj_type = 2; - } else if (coex_dm->cur_ps_tdma == 7) { - halbtc8723b2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 3); - coex_dm->ps_tdma_du_adj_type = 3; - } else if (coex_dm->cur_ps_tdma == 8) { - halbtc8723b2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 4); - coex_dm->ps_tdma_du_adj_type = 4; - } - if (coex_dm->cur_ps_tdma == 13) { - halbtc8723b2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 10); - coex_dm->ps_tdma_du_adj_type = 10; - } else if (coex_dm->cur_ps_tdma == 14) { - halbtc8723b2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 10); - coex_dm->ps_tdma_du_adj_type = 10; - } else if (coex_dm->cur_ps_tdma == 15) { - halbtc8723b2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 11); - coex_dm->ps_tdma_du_adj_type = 11; - } else if (coex_dm->cur_ps_tdma == 16) { - halbtc8723b2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 12); - coex_dm->ps_tdma_du_adj_type = 12; - } - if (result == -1) { - if (coex_dm->cur_ps_tdma == 1) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 2); - coex_dm->ps_tdma_du_adj_type = - 2; - } else if (coex_dm->cur_ps_tdma == 2) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 3); - coex_dm->ps_tdma_du_adj_type = - 3; - } else if (coex_dm->cur_ps_tdma == 3) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 4); - coex_dm->ps_tdma_du_adj_type = - 4; - } else if (coex_dm->cur_ps_tdma == 9) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 10); - coex_dm->ps_tdma_du_adj_type = - 10; - } else if (coex_dm->cur_ps_tdma == 10) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 11); - coex_dm->ps_tdma_du_adj_type = - 11; - } else if (coex_dm->cur_ps_tdma == 11) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 12); - coex_dm->ps_tdma_du_adj_type = - 12; - } - } else if (result == 1) { - if (coex_dm->cur_ps_tdma == 4) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 3); - coex_dm->ps_tdma_du_adj_type = - 3; - } else if (coex_dm->cur_ps_tdma == 3) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 2); - coex_dm->ps_tdma_du_adj_type = - 2; - } else if (coex_dm->cur_ps_tdma == 2) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 2); - coex_dm->ps_tdma_du_adj_type = - 2; - } else if (coex_dm->cur_ps_tdma == 12) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 11); - coex_dm->ps_tdma_du_adj_type = - 11; - } else if (coex_dm->cur_ps_tdma == 11) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 10); - coex_dm->ps_tdma_du_adj_type = - 10; - } else if (coex_dm->cur_ps_tdma == 10) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 10); - coex_dm->ps_tdma_du_adj_type = - 10; - } - } - } - } else if (max_interval == 3) { - if (tx_pause) { - if (coex_dm->cur_ps_tdma == 1) { - halbtc8723b2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 7); - coex_dm->ps_tdma_du_adj_type = 7; - } else if (coex_dm->cur_ps_tdma == 2) { - halbtc8723b2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 7); - coex_dm->ps_tdma_du_adj_type = 7; - } else if (coex_dm->cur_ps_tdma == 3) { - halbtc8723b2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 7); - coex_dm->ps_tdma_du_adj_type = 7; - } else if (coex_dm->cur_ps_tdma == 4) { - halbtc8723b2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 8); - coex_dm->ps_tdma_du_adj_type = 8; - } - if (coex_dm->cur_ps_tdma == 9) { - halbtc8723b2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 15); - coex_dm->ps_tdma_du_adj_type = 15; - } else if (coex_dm->cur_ps_tdma == 10) { - halbtc8723b2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 15); - coex_dm->ps_tdma_du_adj_type = 15; - } else if (coex_dm->cur_ps_tdma == 11) { - halbtc8723b2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 15); - coex_dm->ps_tdma_du_adj_type = 15; - } else if (coex_dm->cur_ps_tdma == 12) { - halbtc8723b2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 16); - coex_dm->ps_tdma_du_adj_type = 16; - } - if (result == -1) { - if (coex_dm->cur_ps_tdma == 5) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 7); - coex_dm->ps_tdma_du_adj_type = - 7; - } else if (coex_dm->cur_ps_tdma == 6) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 7); - coex_dm->ps_tdma_du_adj_type = - 7; - } else if (coex_dm->cur_ps_tdma == 7) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 8); - coex_dm->ps_tdma_du_adj_type = - 8; - } else if (coex_dm->cur_ps_tdma == 13) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 15); - coex_dm->ps_tdma_du_adj_type = - 15; - } else if (coex_dm->cur_ps_tdma == 14) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 15); - coex_dm->ps_tdma_du_adj_type = - 15; - } else if (coex_dm->cur_ps_tdma == 15) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 16); - coex_dm->ps_tdma_du_adj_type = - 16; - } - } else if (result == 1) { - if (coex_dm->cur_ps_tdma == 8) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 7); - coex_dm->ps_tdma_du_adj_type = - 7; - } else if (coex_dm->cur_ps_tdma == 7) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 7); - coex_dm->ps_tdma_du_adj_type = - 7; - } else if (coex_dm->cur_ps_tdma == 6) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 7); - coex_dm->ps_tdma_du_adj_type = - 7; - } else if (coex_dm->cur_ps_tdma == 16) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 15); - coex_dm->ps_tdma_du_adj_type = - 15; - } else if (coex_dm->cur_ps_tdma == 15) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 15); - coex_dm->ps_tdma_du_adj_type = - 15; - } else if (coex_dm->cur_ps_tdma == 14) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 15); - coex_dm->ps_tdma_du_adj_type = - 15; - } - } - } else { - if (coex_dm->cur_ps_tdma == 5) { - halbtc8723b2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 3); - coex_dm->ps_tdma_du_adj_type = 3; - } else if (coex_dm->cur_ps_tdma == 6) { - halbtc8723b2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 3); - coex_dm->ps_tdma_du_adj_type = 3; - } else if (coex_dm->cur_ps_tdma == 7) { - halbtc8723b2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 3); - coex_dm->ps_tdma_du_adj_type = 3; - } else if (coex_dm->cur_ps_tdma == 8) { - halbtc8723b2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 4); - coex_dm->ps_tdma_du_adj_type = 4; - } - if (coex_dm->cur_ps_tdma == 13) { - halbtc8723b2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 11); - coex_dm->ps_tdma_du_adj_type = 11; - } else if (coex_dm->cur_ps_tdma == 14) { - halbtc8723b2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 11); - coex_dm->ps_tdma_du_adj_type = 11; - } else if (coex_dm->cur_ps_tdma == 15) { - halbtc8723b2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 11); - coex_dm->ps_tdma_du_adj_type = 11; - } else if (coex_dm->cur_ps_tdma == 16) { - halbtc8723b2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 12); - coex_dm->ps_tdma_du_adj_type = 12; - } - if (result == -1) { - if (coex_dm->cur_ps_tdma == 1) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 3); - coex_dm->ps_tdma_du_adj_type = - 3; - } else if (coex_dm->cur_ps_tdma == 2) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 3); - coex_dm->ps_tdma_du_adj_type = - 3; - } else if (coex_dm->cur_ps_tdma == 3) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 4); - coex_dm->ps_tdma_du_adj_type = - 4; - } else if (coex_dm->cur_ps_tdma == 9) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 11); - coex_dm->ps_tdma_du_adj_type = - 11; - } else if (coex_dm->cur_ps_tdma == 10) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 11); - coex_dm->ps_tdma_du_adj_type = - 11; - } else if (coex_dm->cur_ps_tdma == 11) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 12); - coex_dm->ps_tdma_du_adj_type = - 12; - } - } else if (result == 1) { - if (coex_dm->cur_ps_tdma == 4) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 3); - coex_dm->ps_tdma_du_adj_type = - 3; - } else if (coex_dm->cur_ps_tdma == 3) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 3); - coex_dm->ps_tdma_du_adj_type = - 3; - } else if (coex_dm->cur_ps_tdma == 2) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 3); - coex_dm->ps_tdma_du_adj_type = - 3; - } else if (coex_dm->cur_ps_tdma == 12) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 11); - coex_dm->ps_tdma_du_adj_type = - 11; - } else if (coex_dm->cur_ps_tdma == 11) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 11); - coex_dm->ps_tdma_du_adj_type = - 11; - } else if (coex_dm->cur_ps_tdma == 10) { - halbtc8723b2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 11); - coex_dm->ps_tdma_du_adj_type = - 11; - } - } - } - } - } - - /* if current PsTdma not match with the recorded one (when scan, dhcp...), */ - /* then we have to adjust it back to the previous record one. */ - if (coex_dm->cur_ps_tdma != coex_dm->ps_tdma_du_adj_type) { - boolean scan = false, link = false, roam = false; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], PsTdma type dismatch!!!, cur_ps_tdma=%d, recordPsTdma=%d\n", - coex_dm->cur_ps_tdma, coex_dm->ps_tdma_du_adj_type); - BTC_TRACE(trace_buf); - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam); - - if (!scan && !link && !roam) - halbtc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - coex_dm->ps_tdma_du_adj_type); - else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], roaming/link/scan is under progress, will adjust next time!!!\n"); - BTC_TRACE(trace_buf); - } - } -} - -/* SCO only or SCO+PAN(HS) */ -void halbtc8723b2ant_action_sco(IN struct btc_coexist *btcoexist) -{ - static u8 prewifi_rssi_state = BTC_RSSI_STATE_LOW; - static u8 pre_bt_rssi_state = BTC_RSSI_STATE_LOW; - u8 wifi_rssi_state, bt_rssi_state; - u32 wifi_bw; - - wifi_rssi_state = halbtc8723b2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state, 2, 15, 0); - bt_rssi_state = halbtc8723b2ant_bt_rssi_state(&pre_bt_rssi_state, 2, - BT_8723B_2ANT_BT_RSSI_COEXSWITCH_THRES - - coex_dm->switch_thres_offset, 0); - - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0); - - halbtc8723b2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8); - - halbtc8723b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 4); - - if (BTC_RSSI_HIGH(bt_rssi_state)) - halbtc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2); - else - halbtc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw); - - if (BTC_WIFI_BW_LEGACY == wifi_bw) /* for SCO quality at 11b/g mode */ - halbtc8723b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2); - else /* for SCO quality & wifi performance balance at 11n mode */ - halbtc8723b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 8); - - halbtc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, - 0); /* for voice quality */ - - /* sw mechanism */ - if (BTC_WIFI_BW_HT40 == wifi_bw) { - if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) || - (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) { - halbtc8723b2ant_sw_mechanism1(btcoexist, true, true, - false, false); - halbtc8723b2ant_sw_mechanism2(btcoexist, true, false, - true, 0x4); - } else { - halbtc8723b2ant_sw_mechanism1(btcoexist, true, true, - false, false); - halbtc8723b2ant_sw_mechanism2(btcoexist, false, false, - true, 0x4); - } - } else { - if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) || - (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) { - halbtc8723b2ant_sw_mechanism1(btcoexist, false, true, - false, false); - halbtc8723b2ant_sw_mechanism2(btcoexist, true, false, - true, 0x4); - } else { - halbtc8723b2ant_sw_mechanism1(btcoexist, false, true, - false, false); - halbtc8723b2ant_sw_mechanism2(btcoexist, false, false, - true, 0x4); - } - } -} - - -void halbtc8723b2ant_action_hid(IN struct btc_coexist *btcoexist) -{ - static u8 prewifi_rssi_state = BTC_RSSI_STATE_LOW; - static u8 pre_bt_rssi_state = BTC_RSSI_STATE_LOW; - u8 wifi_rssi_state, bt_rssi_state; - u32 wifi_bw; - - btcoexist->btc_phydm_modify_RA_PCR_threshold(btcoexist, 0, 25); - - wifi_rssi_state = halbtc8723b2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state, 2, 15, 0); - bt_rssi_state = halbtc8723b2ant_bt_rssi_state(&pre_bt_rssi_state, 2, - BT_8723B_2ANT_BT_RSSI_COEXSWITCH_THRES - - coex_dm->switch_thres_offset, 0); - - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0); - - halbtc8723b2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8); - - halbtc8723b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6); - - if (BTC_RSSI_HIGH(bt_rssi_state)) - halbtc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2); - else - halbtc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw); - - if (BTC_WIFI_BW_LEGACY == wifi_bw) /* for HID at 11b/g mode */ - halbtc8723b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7); - else /* for HID quality & wifi performance balance at 11n mode */ - halbtc8723b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 9); - - if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) || - (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) - halbtc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 9); - else - halbtc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 13); - - /* sw mechanism */ - if (BTC_WIFI_BW_HT40 == wifi_bw) { - if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) || - (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) { - halbtc8723b2ant_sw_mechanism1(btcoexist, true, true, - false, false); - halbtc8723b2ant_sw_mechanism2(btcoexist, true, false, - false, 0x18); - } else { - halbtc8723b2ant_sw_mechanism1(btcoexist, true, true, - false, false); - halbtc8723b2ant_sw_mechanism2(btcoexist, false, false, - false, 0x18); - } - } else { - if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) || - (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) { - halbtc8723b2ant_sw_mechanism1(btcoexist, false, true, - false, false); - halbtc8723b2ant_sw_mechanism2(btcoexist, true, false, - false, 0x18); - } else { - halbtc8723b2ant_sw_mechanism1(btcoexist, false, true, - false, false); - halbtc8723b2ant_sw_mechanism2(btcoexist, false, false, - false, 0x18); - } - } -} - -/* A2DP only / PAN(EDR) only/ A2DP+PAN(HS) */ -void halbtc8723b2ant_action_a2dp(IN struct btc_coexist *btcoexist) -{ - static u8 prewifi_rssi_state = BTC_RSSI_STATE_LOW, - prewifi_rssi_state1 = BTC_RSSI_STATE_LOW; - static u8 pre_bt_rssi_state = BTC_RSSI_STATE_LOW; - u8 wifi_rssi_state, wifi_rssi_state1, bt_rssi_state; - u32 wifi_bw; - u8 ap_num = 0; - - wifi_rssi_state = halbtc8723b2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state, 2, 15, 0); - wifi_rssi_state1 = halbtc8723b2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state1, 2, - BT_8723B_2ANT_WIFI_RSSI_COEXSWITCH_THRES - - coex_dm->switch_thres_offset, 0); - bt_rssi_state = halbtc8723b2ant_bt_rssi_state(&pre_bt_rssi_state, 2, - BT_8723B_2ANT_BT_RSSI_COEXSWITCH_THRES - - coex_dm->switch_thres_offset, 0); - - btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM, &ap_num); - - /* define the office environment */ - if ((ap_num >= 10) && BTC_RSSI_HIGH(wifi_rssi_state1) && - BTC_RSSI_HIGH(bt_rssi_state)) { - /* dbg_print(" AP#>10(%d)\n", ap_num); */ - - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, - 0x0); - halbtc8723b2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, - 0x8); - halbtc8723b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6); - halbtc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2); - - halbtc8723b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - - halbtc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1); - - /* sw mechanism */ - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw); - if (BTC_WIFI_BW_HT40 == wifi_bw) { - halbtc8723b2ant_sw_mechanism1(btcoexist, true, false, - false, false); - halbtc8723b2ant_sw_mechanism2(btcoexist, true, false, - true, 0x18); - } else { - halbtc8723b2ant_sw_mechanism1(btcoexist, false, false, - false, false); - halbtc8723b2ant_sw_mechanism2(btcoexist, true, false, - true, 0x18); - } - return; - - } - - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0); - halbtc8723b2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8); - - halbtc8723b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6); - - if (BTC_RSSI_HIGH(bt_rssi_state)) - halbtc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2); - else - halbtc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - - if (BTC_RSSI_HIGH(wifi_rssi_state1) && BTC_RSSI_HIGH(bt_rssi_state)) { - halbtc8723b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7); - - } else { - halbtc8723b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, - 13); - } - - - if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) || - (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) - halbtc8723b2ant_tdma_duration_adjust(btcoexist, false, false, - 1); - else - halbtc8723b2ant_tdma_duration_adjust(btcoexist, false, true, 1); - - /* sw mechanism */ - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw); - if (BTC_WIFI_BW_HT40 == wifi_bw) { - if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) || - (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) { - halbtc8723b2ant_sw_mechanism1(btcoexist, true, false, - false, false); - halbtc8723b2ant_sw_mechanism2(btcoexist, true, false, - false, 0x18); - } else { - halbtc8723b2ant_sw_mechanism1(btcoexist, true, false, - false, false); - halbtc8723b2ant_sw_mechanism2(btcoexist, false, false, - false, 0x18); - } - } else { - if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) || - (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) { - halbtc8723b2ant_sw_mechanism1(btcoexist, false, false, - false, false); - halbtc8723b2ant_sw_mechanism2(btcoexist, true, false, - false, 0x18); - } else { - halbtc8723b2ant_sw_mechanism1(btcoexist, false, false, - false, false); - halbtc8723b2ant_sw_mechanism2(btcoexist, false, false, - false, 0x18); - } - } -} - -void halbtc8723b2ant_action_a2dp_pan_hs(IN struct btc_coexist *btcoexist) -{ - static u8 prewifi_rssi_state = BTC_RSSI_STATE_LOW, - prewifi_rssi_state1 = BTC_RSSI_STATE_LOW; - static u8 pre_bt_rssi_state = BTC_RSSI_STATE_LOW; - u8 wifi_rssi_state, wifi_rssi_state1, bt_rssi_state; - u32 wifi_bw; - - wifi_rssi_state = halbtc8723b2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state, 2, 15, 0); - wifi_rssi_state1 = halbtc8723b2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state1, 2, - BT_8723B_2ANT_WIFI_RSSI_COEXSWITCH_THRES - - coex_dm->switch_thres_offset, 0); - bt_rssi_state = halbtc8723b2ant_bt_rssi_state(&pre_bt_rssi_state, 2, - BT_8723B_2ANT_BT_RSSI_COEXSWITCH_THRES - - coex_dm->switch_thres_offset, 0); - - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0); - - halbtc8723b2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8); - - halbtc8723b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6); - - if (BTC_RSSI_HIGH(bt_rssi_state)) - halbtc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2); - else - halbtc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - if (BTC_RSSI_HIGH(wifi_rssi_state1) && BTC_RSSI_HIGH(bt_rssi_state)) { - halbtc8723b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7); - - } else { - halbtc8723b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, - 13); - } - - halbtc8723b2ant_tdma_duration_adjust(btcoexist, false, true, 2); - - /* sw mechanism */ - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw); - if (BTC_WIFI_BW_HT40 == wifi_bw) { - if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) || - (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) { - halbtc8723b2ant_sw_mechanism1(btcoexist, true, false, - false, false); - halbtc8723b2ant_sw_mechanism2(btcoexist, true, false, - false, 0x18); - } else { - halbtc8723b2ant_sw_mechanism1(btcoexist, true, false, - false, false); - halbtc8723b2ant_sw_mechanism2(btcoexist, false, false, - false, 0x18); - } - } else { - if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) || - (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) { - halbtc8723b2ant_sw_mechanism1(btcoexist, false, false, - false, false); - halbtc8723b2ant_sw_mechanism2(btcoexist, true, false, - false, 0x18); - } else { - halbtc8723b2ant_sw_mechanism1(btcoexist, false, false, - false, false); - halbtc8723b2ant_sw_mechanism2(btcoexist, false, false, - false, 0x18); - } - } -} - -void halbtc8723b2ant_action_pan_edr(IN struct btc_coexist *btcoexist) -{ - static u8 prewifi_rssi_state = BTC_RSSI_STATE_LOW, - prewifi_rssi_state1 = BTC_RSSI_STATE_LOW; - static u8 pre_bt_rssi_state = BTC_RSSI_STATE_LOW; - u8 wifi_rssi_state, wifi_rssi_state1, bt_rssi_state; - u32 wifi_bw; - - wifi_rssi_state = halbtc8723b2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state, 2, 15, 0); - wifi_rssi_state1 = halbtc8723b2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state1, 2, - BT_8723B_2ANT_WIFI_RSSI_COEXSWITCH_THRES - - coex_dm->switch_thres_offset, 0); - bt_rssi_state = halbtc8723b2ant_bt_rssi_state(&pre_bt_rssi_state, 2, - BT_8723B_2ANT_BT_RSSI_COEXSWITCH_THRES - - coex_dm->switch_thres_offset, 0); - - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0); - - halbtc8723b2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8); - - halbtc8723b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6); - - if (BTC_RSSI_HIGH(bt_rssi_state)) - halbtc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2); - else - halbtc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - if (BTC_RSSI_HIGH(wifi_rssi_state1) && BTC_RSSI_HIGH(bt_rssi_state)) { - halbtc8723b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, - 10); - } else { - halbtc8723b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, - 13); - } - - if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) || - (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) - halbtc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 1); - else - halbtc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 5); - - /* sw mechanism */ - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw); - if (BTC_WIFI_BW_HT40 == wifi_bw) { - if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) || - (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) { - halbtc8723b2ant_sw_mechanism1(btcoexist, true, false, - false, false); - halbtc8723b2ant_sw_mechanism2(btcoexist, true, false, - false, 0x18); - } else { - halbtc8723b2ant_sw_mechanism1(btcoexist, true, false, - false, false); - halbtc8723b2ant_sw_mechanism2(btcoexist, false, false, - false, 0x18); - } - } else { - if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) || - (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) { - halbtc8723b2ant_sw_mechanism1(btcoexist, false, false, - false, false); - halbtc8723b2ant_sw_mechanism2(btcoexist, true, false, - false, 0x18); - } else { - halbtc8723b2ant_sw_mechanism1(btcoexist, false, false, - false, false); - halbtc8723b2ant_sw_mechanism2(btcoexist, false, false, - false, 0x18); - } - } -} - - -/* PAN(HS) only */ -void halbtc8723b2ant_action_pan_hs(IN struct btc_coexist *btcoexist) -{ - static u8 prewifi_rssi_state = BTC_RSSI_STATE_LOW, - prewifi_rssi_state1 = BTC_RSSI_STATE_LOW; - static u8 pre_bt_rssi_state = BTC_RSSI_STATE_LOW; - u8 wifi_rssi_state, wifi_rssi_state1, bt_rssi_state; - u32 wifi_bw; - - wifi_rssi_state = halbtc8723b2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state, 2, 15, 0); - wifi_rssi_state1 = halbtc8723b2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state1, 2, - BT_8723B_2ANT_WIFI_RSSI_COEXSWITCH_THRES - - coex_dm->switch_thres_offset, 0); - bt_rssi_state = halbtc8723b2ant_bt_rssi_state(&pre_bt_rssi_state, 2, - BT_8723B_2ANT_BT_RSSI_COEXSWITCH_THRES - - coex_dm->switch_thres_offset, 0); - - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0); - - halbtc8723b2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8); - - halbtc8723b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6); - - if (BTC_RSSI_HIGH(bt_rssi_state)) - halbtc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2); - else - halbtc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - halbtc8723b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7); - - halbtc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1); - - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw); - if (BTC_WIFI_BW_HT40 == wifi_bw) { - if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) || - (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) { - halbtc8723b2ant_sw_mechanism1(btcoexist, true, false, - false, false); - halbtc8723b2ant_sw_mechanism2(btcoexist, true, false, - false, 0x18); - } else { - halbtc8723b2ant_sw_mechanism1(btcoexist, true, false, - false, false); - halbtc8723b2ant_sw_mechanism2(btcoexist, false, false, - false, 0x18); - } - } else { - if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) || - (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) { - halbtc8723b2ant_sw_mechanism1(btcoexist, false, false, - false, false); - halbtc8723b2ant_sw_mechanism2(btcoexist, true, false, - false, 0x18); - } else { - halbtc8723b2ant_sw_mechanism1(btcoexist, false, false, - false, false); - halbtc8723b2ant_sw_mechanism2(btcoexist, false, false, - false, 0x18); - } - } -} - -/* PAN(EDR)+A2DP */ -void halbtc8723b2ant_action_pan_edr_a2dp(IN struct btc_coexist *btcoexist) -{ - static u8 prewifi_rssi_state = BTC_RSSI_STATE_LOW, - prewifi_rssi_state1 = BTC_RSSI_STATE_LOW; - static u8 pre_bt_rssi_state = BTC_RSSI_STATE_LOW; - u8 wifi_rssi_state, wifi_rssi_state1, bt_rssi_state; - u8 ap_num = 0; - u32 wifi_bw; - - wifi_rssi_state = halbtc8723b2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state, 2, 15, 0); - wifi_rssi_state1 = halbtc8723b2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state1, 2, - BT_8723B_2ANT_WIFI_RSSI_COEXSWITCH_THRES - - coex_dm->switch_thres_offset, 0); - bt_rssi_state = halbtc8723b2ant_bt_rssi_state(&pre_bt_rssi_state, 2, - BT_8723B_2ANT_BT_RSSI_COEXSWITCH_THRES - - coex_dm->switch_thres_offset, 0); - - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0); - - halbtc8723b2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8); - - halbtc8723b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6); - - if (BTC_RSSI_HIGH(bt_rssi_state)) - halbtc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2); - else - halbtc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw); - btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM, - &ap_num); - - if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) || - (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) { - halbtc8723b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, - 12); - - if (ap_num < 10) - halbtc8723b2ant_tdma_duration_adjust(btcoexist, true, - false, 1); - else - halbtc8723b2ant_tdma_duration_adjust(btcoexist, true, - false, 3); - - } else { - halbtc8723b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, - 13); - if (ap_num < 10) - halbtc8723b2ant_tdma_duration_adjust(btcoexist, true, - true, 1); - else - halbtc8723b2ant_tdma_duration_adjust(btcoexist, true, - true, 3); - } - - /* sw mechanism */ - if (BTC_WIFI_BW_HT40 == wifi_bw) { - if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) || - (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) { - halbtc8723b2ant_sw_mechanism1(btcoexist, true, false, - false, false); - halbtc8723b2ant_sw_mechanism2(btcoexist, true, false, - false, 0x18); - } else { - halbtc8723b2ant_sw_mechanism1(btcoexist, true, false, - false, false); - halbtc8723b2ant_sw_mechanism2(btcoexist, false, false, - false, 0x18); - } - } else { - if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) || - (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) { - halbtc8723b2ant_sw_mechanism1(btcoexist, false, false, - false, false); - halbtc8723b2ant_sw_mechanism2(btcoexist, true, false, - false, 0x18); - } else { - halbtc8723b2ant_sw_mechanism1(btcoexist, false, false, - false, false); - halbtc8723b2ant_sw_mechanism2(btcoexist, false, false, - false, 0x18); - } - } -} - -void halbtc8723b2ant_action_pan_edr_hid(IN struct btc_coexist *btcoexist) -{ - static u8 prewifi_rssi_state = BTC_RSSI_STATE_LOW, - prewifi_rssi_state1 = BTC_RSSI_STATE_LOW; - static u8 pre_bt_rssi_state = BTC_RSSI_STATE_LOW; - u8 wifi_rssi_state, wifi_rssi_state1, bt_rssi_state; - u32 wifi_bw; - - btcoexist->btc_phydm_modify_RA_PCR_threshold(btcoexist, 0, 25); - - wifi_rssi_state = halbtc8723b2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state, 2, 15, 0); - wifi_rssi_state1 = halbtc8723b2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state1, 2, - BT_8723B_2ANT_WIFI_RSSI_COEXSWITCH_THRES - - coex_dm->switch_thres_offset, 0); - bt_rssi_state = halbtc8723b2ant_bt_rssi_state(&pre_bt_rssi_state, 2, - BT_8723B_2ANT_BT_RSSI_COEXSWITCH_THRES - - coex_dm->switch_thres_offset, 0); - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw); - - halbtc8723b2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8); - - if (BTC_RSSI_HIGH(bt_rssi_state)) - halbtc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2); - else - halbtc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - if (BTC_RSSI_HIGH(wifi_rssi_state1) && BTC_RSSI_HIGH(bt_rssi_state)) { - halbtc8723b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7); - } else { - halbtc8723b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, - 14); - } - - if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) || - (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) { - if (BTC_WIFI_BW_HT40 == wifi_bw) { - halbtc8723b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, - 3); - /* halbtc8723b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 11); */ - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, - 0xfffff, 0x780); - } else { - halbtc8723b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, - 6); - /* halbtc8723b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7); */ - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, - 0xfffff, 0x0); - } - halbtc8723b2ant_tdma_duration_adjust(btcoexist, true, false, 2); - } else { - halbtc8723b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6); - /* halbtc8723b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 14); */ - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, - 0x0); - halbtc8723b2ant_tdma_duration_adjust(btcoexist, true, true, 2); - } - - /* sw mechanism */ - if (BTC_WIFI_BW_HT40 == wifi_bw) { - if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) || - (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) { - halbtc8723b2ant_sw_mechanism1(btcoexist, true, true, - false, false); - halbtc8723b2ant_sw_mechanism2(btcoexist, true, false, - false, 0x18); - } else { - halbtc8723b2ant_sw_mechanism1(btcoexist, true, true, - false, false); - halbtc8723b2ant_sw_mechanism2(btcoexist, false, false, - false, 0x18); - } - } else { - if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) || - (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) { - halbtc8723b2ant_sw_mechanism1(btcoexist, false, true, - false, false); - halbtc8723b2ant_sw_mechanism2(btcoexist, true, false, - false, 0x18); - } else { - halbtc8723b2ant_sw_mechanism1(btcoexist, false, true, - false, false); - halbtc8723b2ant_sw_mechanism2(btcoexist, false, false, - false, 0x18); - } - } -} - -/* HID+A2DP+PAN(EDR) */ -void halbtc8723b2ant_action_hid_a2dp_pan_edr(IN struct btc_coexist *btcoexist) -{ - static u8 prewifi_rssi_state = BTC_RSSI_STATE_LOW, - prewifi_rssi_state1 = BTC_RSSI_STATE_LOW; - static u8 pre_bt_rssi_state = BTC_RSSI_STATE_LOW; - u8 wifi_rssi_state, wifi_rssi_state1, bt_rssi_state; - u32 wifi_bw; - - btcoexist->btc_phydm_modify_RA_PCR_threshold(btcoexist, 0, 25); - - wifi_rssi_state = halbtc8723b2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state, 2, 15, 0); - wifi_rssi_state1 = halbtc8723b2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state1, 2, - BT_8723B_2ANT_WIFI_RSSI_COEXSWITCH_THRES - - coex_dm->switch_thres_offset, 0); - bt_rssi_state = halbtc8723b2ant_bt_rssi_state(&pre_bt_rssi_state, 2, - BT_8723B_2ANT_BT_RSSI_COEXSWITCH_THRES - - coex_dm->switch_thres_offset, 0); - - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0); - - halbtc8723b2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8); - - halbtc8723b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6); - - if (BTC_RSSI_HIGH(bt_rssi_state)) - halbtc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2); - else - halbtc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - if (BTC_RSSI_HIGH(wifi_rssi_state1) && BTC_RSSI_HIGH(bt_rssi_state)) { - halbtc8723b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7); - } else { - halbtc8723b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, - 14); - } - - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw); - - if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) || - (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) { - if (BTC_WIFI_BW_HT40 == wifi_bw) - halbtc8723b2ant_tdma_duration_adjust(btcoexist, true, - true, 3); - else - halbtc8723b2ant_tdma_duration_adjust(btcoexist, true, - false, 3); - } else - halbtc8723b2ant_tdma_duration_adjust(btcoexist, true, true, 3); - - /* sw mechanism */ - if (BTC_WIFI_BW_HT40 == wifi_bw) { - if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) || - (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) { - halbtc8723b2ant_sw_mechanism1(btcoexist, true, true, - false, false); - halbtc8723b2ant_sw_mechanism2(btcoexist, true, false, - false, 0x18); - } else { - halbtc8723b2ant_sw_mechanism1(btcoexist, true, true, - false, false); - halbtc8723b2ant_sw_mechanism2(btcoexist, false, false, - false, 0x18); - } - } else { - if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) || - (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) { - halbtc8723b2ant_sw_mechanism1(btcoexist, false, true, - false, false); - halbtc8723b2ant_sw_mechanism2(btcoexist, true, false, - false, 0x18); - } else { - halbtc8723b2ant_sw_mechanism1(btcoexist, false, true, - false, false); - halbtc8723b2ant_sw_mechanism2(btcoexist, false, false, - false, 0x18); - } - } -} - -void halbtc8723b2ant_action_hid_a2dp(IN struct btc_coexist *btcoexist) -{ - static u8 prewifi_rssi_state = BTC_RSSI_STATE_LOW, - prewifi_rssi_state1 = BTC_RSSI_STATE_LOW; - static u8 pre_bt_rssi_state = BTC_RSSI_STATE_LOW; - u8 wifi_rssi_state, wifi_rssi_state1, bt_rssi_state; - u32 wifi_bw; - u8 ap_num = 0; - - btcoexist->btc_phydm_modify_RA_PCR_threshold(btcoexist, 0, 35); - - - wifi_rssi_state = halbtc8723b2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state, 2, 15, 0); - /* bt_rssi_state = halbtc8723b2ant_bt_rssi_state(2, 29, 0); */ - wifi_rssi_state1 = halbtc8723b2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state1, 2, - BT_8723B_2ANT_WIFI_RSSI_COEXSWITCH_THRES - - coex_dm->switch_thres_offset, 0); - bt_rssi_state = halbtc8723b2ant_bt_rssi_state(&pre_bt_rssi_state, 3, - BT_8723B_2ANT_BT_RSSI_COEXSWITCH_THRES - - coex_dm->switch_thres_offset, 37); - - btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM, - &ap_num); - - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0); - - halbtc8723b2ant_limited_rx(btcoexist, NORMAL_EXEC, false, true, 0x5); - - halbtc8723b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6); - - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw); - if (BTC_WIFI_BW_LEGACY == wifi_bw) { - if (BTC_RSSI_HIGH(bt_rssi_state)) - halbtc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2); - else if (BTC_RSSI_MEDIUM(bt_rssi_state)) - halbtc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2); - else - halbtc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - } else { - /* only 802.11N mode we have to dec bt power to 4 degree */ - if (BTC_RSSI_HIGH(bt_rssi_state)) { - /* need to check ap Number of Not */ - if (ap_num < 10) - halbtc8723b2ant_dec_bt_pwr(btcoexist, - NORMAL_EXEC, 4); - else - halbtc8723b2ant_dec_bt_pwr(btcoexist, - NORMAL_EXEC, 2); - } else if (BTC_RSSI_MEDIUM(bt_rssi_state)) - halbtc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2); - else - halbtc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - } - - if (BTC_RSSI_HIGH(wifi_rssi_state1) && BTC_RSSI_HIGH(bt_rssi_state)) { - halbtc8723b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7); - } else { - halbtc8723b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, - 14); - } - - if (BTC_RSSI_HIGH(bt_rssi_state)) { - if (ap_num < 10) - halbtc8723b2ant_tdma_duration_adjust(btcoexist, true, - false, 2); - - else - halbtc8723b2ant_tdma_duration_adjust(btcoexist, true, - false, 3); - } else { - halbtc8723b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 18); - btcoexist->btc_write_1byte(btcoexist, 0x456, 0x38); - btcoexist->btc_write_2byte(btcoexist, 0x42a, 0x0808); - btcoexist->btc_write_4byte(btcoexist, 0x430, 0x0); - btcoexist->btc_write_4byte(btcoexist, 0x434, 0x01010000); - - if (ap_num < 10) - halbtc8723b2ant_tdma_duration_adjust(btcoexist, true, - true, 2); - - else - halbtc8723b2ant_tdma_duration_adjust(btcoexist, true, - true, 3); - } - - /* sw mechanism */ - if (BTC_WIFI_BW_HT40 == wifi_bw) { - if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) || - (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) { - halbtc8723b2ant_sw_mechanism1(btcoexist, true, true, - false, false); - halbtc8723b2ant_sw_mechanism2(btcoexist, true, false, - false, 0x18); - } else { - halbtc8723b2ant_sw_mechanism1(btcoexist, true, true, - false, false); - halbtc8723b2ant_sw_mechanism2(btcoexist, false, false, - false, 0x18); - } - } else { - if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) || - (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) { - halbtc8723b2ant_sw_mechanism1(btcoexist, false, true, - false, false); - halbtc8723b2ant_sw_mechanism2(btcoexist, true, false, - false, 0x18); - } else { - halbtc8723b2ant_sw_mechanism1(btcoexist, false, true, - false, false); - halbtc8723b2ant_sw_mechanism2(btcoexist, false, false, - false, 0x18); - } - } -} - -void halbtc8723b2ant_action_bt_whck_test(IN struct btc_coexist *btcoexist) -{ - halbtc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - /* sw all off */ - halbtc8723b2ant_sw_mechanism1(btcoexist, false, false, false, false); - halbtc8723b2ant_sw_mechanism2(btcoexist, false, false, false, 0x18); - - halbtc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1); - halbtc8723b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); -} - -void halbtc8723b2ant_action_wifi_multi_port(IN struct btc_coexist *btcoexist) -{ - halbtc8723b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6); - halbtc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - /* sw all off */ - halbtc8723b2ant_sw_mechanism1(btcoexist, false, false, false, false); - halbtc8723b2ant_sw_mechanism2(btcoexist, false, false, false, 0x18); - - /* hw all off */ - /* btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0); */ - halbtc8723b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - - halbtc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1); -} - -void halbtc8723b2ant_run_coexist_mechanism(IN struct btc_coexist *btcoexist) -{ - u8 algorithm = 0; - u32 num_of_wifi_link = 0; - u32 wifi_link_status = 0; - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - boolean miracast_plus_bt = false; - boolean scan = false, link = false, roam = false; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], RunCoexistMechanism()===>\n"); - BTC_TRACE(trace_buf); - - if (btcoexist->manual_control) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], RunCoexistMechanism(), return for Manual CTRL <===\n"); - BTC_TRACE(trace_buf); - return; - } - - if (coex_sta->under_ips) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], wifi is under IPS !!!\n"); - BTC_TRACE(trace_buf); - return; - } - - if (coex_sta->bt_whck_test) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT is under WHCK TEST!!!\n"); - BTC_TRACE(trace_buf); - halbtc8723b2ant_action_bt_whck_test(btcoexist); - return; - } - - algorithm = halbtc8723b2ant_action_algorithm(btcoexist); - if (coex_sta->c2h_bt_inquiry_page && - (BT_8723B_2ANT_COEX_ALGO_PANHS != algorithm)) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT is under inquiry/page scan !!\n"); - BTC_TRACE(trace_buf); - halbtc8723b2ant_action_bt_inquiry(btcoexist); - return; - } - - /* - if(coex_dm->need_recover0x948) - { - coex_dm->need_recover0x948 = false; - btcoexist->btc_write_4byte(btcoexist, 0x948, coex_dm->backup0x948); - } - */ - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam); - - if (scan || link || roam) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], WiFi is under Link Process !!\n"); - BTC_TRACE(trace_buf); - halbtc8723b2ant_action_wifi_link_process(btcoexist); - return; - } - - /* for P2P */ - - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS, - &wifi_link_status); - num_of_wifi_link = wifi_link_status >> 16; - - if ((num_of_wifi_link >= 2) || - (wifi_link_status & WIFI_P2P_GO_CONNECTED)) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "############# [BTCoex], Multi-Port num_of_wifi_link = %d, wifi_link_status = 0x%x\n", - num_of_wifi_link, wifi_link_status); - BTC_TRACE(trace_buf); - - if (bt_link_info->bt_link_exist) - miracast_plus_bt = true; - else - miracast_plus_bt = false; - - btcoexist->btc_set(btcoexist, BTC_SET_BL_MIRACAST_PLUS_BT, - &miracast_plus_bt); - halbtc8723b2ant_action_wifi_multi_port(btcoexist); - - return; - } - - miracast_plus_bt = false; - btcoexist->btc_set(btcoexist, BTC_SET_BL_MIRACAST_PLUS_BT, - &miracast_plus_bt); - - coex_dm->cur_algorithm = algorithm; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], Algorithm = %d\n", - coex_dm->cur_algorithm); - BTC_TRACE(trace_buf); - - if (halbtc8723b2ant_is_common_action(btcoexist)) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant common.\n"); - BTC_TRACE(trace_buf); - coex_dm->auto_tdma_adjust = false; - } else { - if (coex_dm->cur_algorithm != coex_dm->pre_algorithm) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], pre_algorithm=%d, cur_algorithm=%d\n", - coex_dm->pre_algorithm, coex_dm->cur_algorithm); - BTC_TRACE(trace_buf); - coex_dm->auto_tdma_adjust = false; - } - switch (coex_dm->cur_algorithm) { - case BT_8723B_2ANT_COEX_ALGO_SCO: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, algorithm = SCO.\n"); - BTC_TRACE(trace_buf); - halbtc8723b2ant_action_sco(btcoexist); - break; - case BT_8723B_2ANT_COEX_ALGO_HID: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, algorithm = HID.\n"); - BTC_TRACE(trace_buf); - halbtc8723b2ant_action_hid(btcoexist); - break; - case BT_8723B_2ANT_COEX_ALGO_A2DP: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, algorithm = A2DP.\n"); - BTC_TRACE(trace_buf); - halbtc8723b2ant_action_a2dp(btcoexist); - break; - case BT_8723B_2ANT_COEX_ALGO_A2DP_PANHS: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, algorithm = A2DP+PAN(HS).\n"); - BTC_TRACE(trace_buf); - halbtc8723b2ant_action_a2dp_pan_hs(btcoexist); - break; - case BT_8723B_2ANT_COEX_ALGO_PANEDR: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, algorithm = PAN(EDR).\n"); - BTC_TRACE(trace_buf); - halbtc8723b2ant_action_pan_edr(btcoexist); - break; - case BT_8723B_2ANT_COEX_ALGO_PANHS: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, algorithm = HS mode.\n"); - BTC_TRACE(trace_buf); - halbtc8723b2ant_action_pan_hs(btcoexist); - break; - case BT_8723B_2ANT_COEX_ALGO_PANEDR_A2DP: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, algorithm = PAN+A2DP.\n"); - BTC_TRACE(trace_buf); - halbtc8723b2ant_action_pan_edr_a2dp(btcoexist); - break; - case BT_8723B_2ANT_COEX_ALGO_PANEDR_HID: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, algorithm = PAN(EDR)+HID.\n"); - BTC_TRACE(trace_buf); - halbtc8723b2ant_action_pan_edr_hid(btcoexist); - break; - case BT_8723B_2ANT_COEX_ALGO_HID_A2DP_PANEDR: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, algorithm = HID+A2DP+PAN.\n"); - BTC_TRACE(trace_buf); - halbtc8723b2ant_action_hid_a2dp_pan_edr( - btcoexist); - break; - case BT_8723B_2ANT_COEX_ALGO_HID_A2DP: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, algorithm = HID+A2DP.\n"); - BTC_TRACE(trace_buf); - halbtc8723b2ant_action_hid_a2dp(btcoexist); - break; - default: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, algorithm = coexist All Off!!\n"); - BTC_TRACE(trace_buf); - halbtc8723b2ant_coex_all_off(btcoexist); - break; - } - coex_dm->pre_algorithm = coex_dm->cur_algorithm; - } -} - -void halbtc8723b2ant_wifi_off_hw_cfg(IN struct btc_coexist *btcoexist) -{ - boolean is_in_mp_mode = false; - u8 h2c_parameter[2] = {0}; - u32 fw_ver = 0; - - /* set wlan_act to low */ - btcoexist->btc_write_1byte(btcoexist, 0x76e, 0x4); - - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, - 0x780); /* WiFi goto standby while GNT_BT 0-->1 */ - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, &fw_ver); - if (fw_ver >= 0x180000) { - /* Use H2C to set GNT_BT to HIGH */ - h2c_parameter[0] = 1; - btcoexist->btc_fill_h2c(btcoexist, 0x6E, 1, h2c_parameter); - } else - btcoexist->btc_write_1byte(btcoexist, 0x765, 0x18); - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_IS_IN_MP_MODE, - &is_in_mp_mode); - if (!is_in_mp_mode) - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, 0x20, - 0x0); /* BT select s0/s1 is controlled by BT */ - else - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, 0x20, - 0x1); /* BT select s0/s1 is controlled by WiFi */ -} - -void halbtc8723b2ant_init_hw_config(IN struct btc_coexist *btcoexist, - IN boolean back_up) -{ - u8 u8tmp = 0; - u32 vendor; - - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], 2Ant Init HW Config!!\n"); - BTC_TRACE(trace_buf); - btcoexist->btc_get(btcoexist, BTC_GET_U4_VENDOR, &vendor); - if (vendor == BTC_VENDOR_LENOVO) - coex_dm->switch_thres_offset = 0; - else if (vendor == BTC_VENDOR_ASUS) - coex_dm->switch_thres_offset = 0; - else - coex_dm->switch_thres_offset = 20; - - /* 0xf0[15:12] --> Chip Cut information */ - coex_sta->cut_version = (btcoexist->btc_read_1byte(btcoexist, - 0xf1) & 0xf0) >> 4; - - /* backup rf 0x1e value */ - coex_dm->bt_rf_0x1e_backup = - btcoexist->btc_get_rf_reg(btcoexist, BTC_RF_A, 0x1e, 0xfffff); - - /* 0x790[5:0]=0x5 */ - u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x790); - u8tmp &= 0xc0; - u8tmp |= 0x5; - btcoexist->btc_write_1byte(btcoexist, 0x790, u8tmp); - - /* Antenna config */ - halbtc8723b2ant_set_ant_path(btcoexist, BTC_ANT_WIFI_AT_MAIN, true, - false); - coex_sta->dis_ver_info_cnt = 0; - - /* PTA parameter */ - halbtc8723b2ant_coex_table_with_type(btcoexist, FORCE_EXEC, 0); - - /* Enable counter statistics */ - btcoexist->btc_write_1byte(btcoexist, 0x76e, - 0x4); /* 0x76e[3] =1, WLAN_Act control by PTA */ - btcoexist->btc_write_1byte(btcoexist, 0x778, 0x3); - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x40, 0x20, 0x1); - - /* Give bt_coex_supported_version the default value */ - coex_sta->bt_coex_supported_version = 0; - -} - -/* ************************************************************ - * work around function start with wa_halbtc8723b2ant_ - * ************************************************************ - * ************************************************************ - * extern function start with ex_halbtc8723b2ant_ - * ************************************************************ */ -void ex_halbtc8723b2ant_power_on_setting(IN struct btc_coexist *btcoexist) -{ - struct btc_board_info *board_info = &btcoexist->board_info; - u16 u16tmp = 0x0; - u32 value = 0; - u32 u32tmp_1[4]; - - btcoexist->btc_write_1byte(btcoexist, 0x67, 0x20); - - /* enable BB, REG_SYS_FUNC_EN such that we can write 0x948 correctly. */ - u16tmp = btcoexist->btc_read_2byte(btcoexist, 0x2); - btcoexist->btc_write_2byte(btcoexist, 0x2, u16tmp | BIT(0) | BIT(1)); - - btcoexist->btc_write_4byte(btcoexist, 0x948, 0x0); - - if (btcoexist->chip_interface == BTC_INTF_USB) { - /* fixed at S0 for USB interface */ - board_info->btdm_ant_pos = BTC_ANTENNA_AT_AUX_PORT; - } else { - /* for PCIE and SDIO interface, we check efuse 0xc3[6] */ - if (board_info->single_ant_path == 0) { - /* set to S1 */ - board_info->btdm_ant_pos = BTC_ANTENNA_AT_MAIN_PORT; - } else if (board_info->single_ant_path == 1) { - /* set to S0 */ - board_info->btdm_ant_pos = BTC_ANTENNA_AT_AUX_PORT; - } - btcoexist->btc_set(btcoexist, BTC_SET_ACT_ANTPOSREGRISTRY_CTRL, - &value); - } -} - -void ex_halbtc8723b2ant_pre_load_firmware(IN struct btc_coexist *btcoexist) -{ - struct btc_board_info *board_info = &btcoexist->board_info; - u8 u8tmp = 0x4; /* Set BIT2 by default since it's 2ant case */ - - /* */ - /* S0 or S1 setting and Local register setting(By the setting fw can get ant number, S0/S1, ... info) */ - /* Local setting bit define */ - /* BIT0: "0" for no antenna inverse; "1" for antenna inverse */ - /* BIT1: "0" for internal switch; "1" for external switch */ - /* BIT2: "0" for one antenna; "1" for two antenna */ - /* NOTE: here default all internal switch and 1-antenna ==> BIT1=0 and BIT2=0 */ - if (btcoexist->chip_interface == BTC_INTF_USB) { - /* fixed at S0 for USB interface */ - u8tmp |= 0x1; /* antenna inverse */ - btcoexist->btc_write_local_reg_1byte(btcoexist, 0xfe08, u8tmp); - } else { - if (board_info->single_ant_path == 1) { - /* set to S0 */ - u8tmp |= 0x1; /* antenna inverse */ - } - - if (btcoexist->chip_interface == BTC_INTF_PCI) - btcoexist->btc_write_local_reg_1byte(btcoexist, 0x384, - u8tmp); - else if (btcoexist->chip_interface == BTC_INTF_SDIO) - btcoexist->btc_write_local_reg_1byte(btcoexist, 0x60, - u8tmp); - } -} - -void ex_halbtc8723b2ant_init_hw_config(IN struct btc_coexist *btcoexist, - IN boolean wifi_only) -{ - halbtc8723b2ant_init_hw_config(btcoexist, true); -} - -void ex_halbtc8723b2ant_init_coex_dm(IN struct btc_coexist *btcoexist) -{ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Coex Mechanism Init!!\n"); - BTC_TRACE(trace_buf); - - halbtc8723b2ant_init_coex_dm(btcoexist); -} - -void ex_halbtc8723b2ant_display_coex_info(IN struct btc_coexist *btcoexist) -{ - struct btc_board_info *board_info = &btcoexist->board_info; - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - u8 *cli_buf = btcoexist->cli_buf; - u8 u8tmp[4], i, bt_info_ext, ps_tdma_case = 0; - u32 u32tmp[4]; - u32 fa_ofdm, fa_cck, cca_ofdm, cca_cck; - u32 fw_ver = 0, bt_patch_ver = 0; - u32 bt_coex_ver = 0; - static u8 pop_report_in_10s = 0; - u32 phyver = 0; - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n ============[BT Coexist info]============"); - CL_PRINTF(cli_buf); - - if (btcoexist->manual_control) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n ============[Under Manual Control]============"); - CL_PRINTF(cli_buf); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n =========================================="); - CL_PRINTF(cli_buf); - } - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d ", - "Ant PG number/ Ant mechanism:", - board_info->pg_ant_num, board_info->btdm_ant_num); - CL_PRINTF(cli_buf); - - /* btcoexist->btc_get(btcoexist, BTC_GET_U4_BT_PATCH_VER, &bt_patch_ver); */ - bt_patch_ver = btcoexist->bt_info.bt_get_fw_ver; - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, &fw_ver); - phyver = btcoexist->btc_get_bt_phydm_version(btcoexist); - bt_coex_ver = coex_sta->bt_coex_supported_version & 0xff; - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %d_%02x/ 0x%02x/ 0x%02x (%s)", - "CoexVer WL/ BT_Desired/ BT_Report", - glcoex_ver_date_8723b_2ant, glcoex_ver_8723b_2ant, - glcoex_ver_btdesired_8723b_2ant, - bt_coex_ver, - (bt_coex_ver == 0xff ? "Unknown" : - (bt_coex_ver >= glcoex_ver_btdesired_8723b_2ant ? - "Match" : "Mis-Match"))); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = 0x%x/ 0x%x/ v%d/ %c", - "W_FW/ B_FW/ Phy/ Kt", - fw_ver, bt_patch_ver, phyver, - coex_sta->cut_version + 65); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x ", - "Wifi channel informed to BT", - coex_dm->wifi_chnl_info[0], coex_dm->wifi_chnl_info[1], - coex_dm->wifi_chnl_info[2]); - CL_PRINTF(cli_buf); - - /* wifi status */ - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s", - "============[Wifi Status]============"); - CL_PRINTF(cli_buf); - btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_WIFI_STATUS); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s", - "============[BT Status]============"); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s", - "BT Abnormal scan", - (coex_sta->bt_abnormal_scan) ? "Yes" : "No"); - CL_PRINTF(cli_buf); - - pop_report_in_10s++; - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = [%s/ %d/ %d/ %d] ", - "BT [status/ rssi/ retryCnt/ popCnt]", - ((coex_sta->bt_disabled) ? ("disabled") : (( - coex_sta->c2h_bt_inquiry_page) ? ("inquiry/page scan") - : ((BT_8723B_1ANT_BT_STATUS_NON_CONNECTED_IDLE == - coex_dm->bt_status) ? "non-connected idle" : - ((BT_8723B_2ANT_BT_STATUS_CONNECTED_IDLE == coex_dm->bt_status) - ? "connected-idle" : "busy")))), - coex_sta->bt_rssi - 100, coex_sta->bt_retry_cnt, - coex_sta->pop_event_cnt); - CL_PRINTF(cli_buf); - - if (pop_report_in_10s >= 5) { - coex_sta->pop_event_cnt = 0; - pop_report_in_10s = 0; - } - - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %d / %d / %d / %d / %d / %d", - "SCO/HID/PAN/A2DP/NameReq/WHQL", - bt_link_info->sco_exist, bt_link_info->hid_exist, - bt_link_info->pan_exist, bt_link_info->a2dp_exist, - coex_sta->c2h_bt_remote_name_req, - coex_sta->bt_whck_test); - CL_PRINTF(cli_buf); - - { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s", - "BT Role", - (bt_link_info->slave_role) ? "Slave" : "Master"); - CL_PRINTF(cli_buf); - } - - bt_info_ext = coex_sta->bt_info_ext; - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s / %d", - "A2DP Rate/Bitpool", - (bt_info_ext & BIT(0)) ? "BR" : "EDR", coex_sta->a2dp_bit_pool); - CL_PRINTF(cli_buf); - - for (i = 0; i < BT_INFO_SRC_8723B_2ANT_MAX; i++) { - if (coex_sta->bt_info_c2h_cnt[i]) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %02x %02x %02x %02x %02x %02x %02x(%d)", - glbt_info_src_8723b_2ant[i], - coex_sta->bt_info_c2h[i][0], - coex_sta->bt_info_c2h[i][1], - coex_sta->bt_info_c2h[i][2], - coex_sta->bt_info_c2h[i][3], - coex_sta->bt_info_c2h[i][4], - coex_sta->bt_info_c2h[i][5], - coex_sta->bt_info_c2h[i][6], - coex_sta->bt_info_c2h_cnt[i]); - CL_PRINTF(cli_buf); - } - } - - /* Sw mechanism */ - if (btcoexist->manual_control) - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s", - "============[Sw mechanism] (before Manual)============"); - else - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s", - "============[Sw mechanism]============"); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d ", - "SM1[ShRf/ LpRA/ LimDig]", - coex_dm->cur_rf_rx_lpf_shrink, coex_dm->cur_low_penalty_ra, - coex_dm->limited_dig); - CL_PRINTF(cli_buf); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d(0x%x) ", - "SM2[AgcT/ AdcB/ SwDacSwing(lvl)]", - coex_dm->cur_agc_table_en, coex_dm->cur_adc_back_off, - coex_dm->cur_dac_swing_on, coex_dm->cur_dac_swing_lvl); - CL_PRINTF(cli_buf); - - /* Fw mechanism */ - if (btcoexist->manual_control) - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s", - "============[Fw mechanism] (before Manual) ============"); - else - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s", - "============[Fw mechanism]============"); - - ps_tdma_case = coex_dm->cur_ps_tdma; - - if (coex_dm->is_switch_to_1dot5_ant) - ps_tdma_case = ps_tdma_case + 100; - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %02x %02x %02x %02x %02x case-%d (%s,%s)", - "PS TDMA", - coex_dm->ps_tdma_para[0], coex_dm->ps_tdma_para[1], - coex_dm->ps_tdma_para[2], coex_dm->ps_tdma_para[3], - coex_dm->ps_tdma_para[4], ps_tdma_case, - (coex_dm->cur_ps_tdma_on ? "On" : "Off"), - (coex_dm->auto_tdma_adjust ? "Adj" : "Fix")); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d", - "Coex Table Type", - coex_sta->coex_table_type); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d ", - "DecBtPwr/ IgnWlanAct", - coex_dm->cur_bt_dec_pwr_lvl, coex_dm->cur_ignore_wlan_act); - CL_PRINTF(cli_buf); - - /* Hw setting */ - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s", - "============[Hw setting]============"); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", - "RF-A, 0x1e initVal", - coex_dm->bt_rf_0x1e_backup); - CL_PRINTF(cli_buf); - - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x778); - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x880); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", - "0x778/0x880[29:25]", - u8tmp[0], (u32tmp[0] & 0x3e000000) >> 25); - CL_PRINTF(cli_buf); - - - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x948); - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x67); - u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0x765); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", - "0x948/ 0x67[5] / 0x765", - u32tmp[0], ((u8tmp[0] & 0x20) >> 5), u8tmp[1]); - CL_PRINTF(cli_buf); - - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x92c); - u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x930); - u32tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0x944); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", - "0x92c[1:0]/ 0x930[7:0]/0x944[1:0]", - u32tmp[0] & 0x3, u32tmp[1] & 0xff, u32tmp[2] & 0x3); - CL_PRINTF(cli_buf); - - - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x39); - u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0x40); - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x4c); - u8tmp[2] = btcoexist->btc_read_1byte(btcoexist, 0x64); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", - "0x38[11]/0x40/0x4c[24:23]/0x64[0]", - ((u8tmp[0] & 0x8) >> 3), u8tmp[1], - ((u32tmp[0] & 0x01800000) >> 23), u8tmp[2] & 0x1); - CL_PRINTF(cli_buf); - - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x550); - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x522); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", - "0x550(bcn ctrl)/0x522", - u32tmp[0], u8tmp[0]); - CL_PRINTF(cli_buf); - - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xc50); - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x49c); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", - "0xc50(dig)/0x49c(null-drop)", - u32tmp[0] & 0xff, u8tmp[0]); - CL_PRINTF(cli_buf); - - fa_ofdm = btcoexist->btc_phydm_query_PHY_counter(btcoexist, - PHYDM_INFO_FA_OFDM); - fa_cck = btcoexist->btc_phydm_query_PHY_counter(btcoexist, - PHYDM_INFO_FA_CCK); - cca_ofdm = btcoexist->btc_phydm_query_PHY_counter(btcoexist, - PHYDM_INFO_CCA_OFDM); - cca_cck = btcoexist->btc_phydm_query_PHY_counter(btcoexist, - PHYDM_INFO_CCA_CCK); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", - "CCK-CCA/CCK-FA/OFDM-CCA/OFDM-FA", - cca_cck, fa_cck, cca_ofdm, fa_ofdm); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d", - "CRC_OK CCK/11g/11n/11n-agg", - coex_sta->crc_ok_cck, coex_sta->crc_ok_11g, - coex_sta->crc_ok_11n, coex_sta->crc_ok_11n_vht); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d", - "CRC_Err CCK/11g/11n/11n-agg", - coex_sta->crc_err_cck, coex_sta->crc_err_11g, - coex_sta->crc_err_11n, coex_sta->crc_err_11n_vht); - CL_PRINTF(cli_buf); - - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x6c0); - u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x6c4); - u32tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0x6c8); - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x6cc); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", - "0x6c0/0x6c4/0x6c8/0x6cc(coexTable)", - u32tmp[0], u32tmp[1], u32tmp[2], u8tmp[0]); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", - "0x770(high-pri rx/tx)", - coex_sta->high_priority_rx, coex_sta->high_priority_tx); - CL_PRINTF(cli_buf); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", - "0x774(low-pri rx/tx)", - coex_sta->low_priority_rx, coex_sta->low_priority_tx); - CL_PRINTF(cli_buf); -#if (BT_AUTO_REPORT_ONLY_8723B_2ANT == 1) - /* halbtc8723b2ant_monitor_bt_ctr(btcoexist); */ -#endif - btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_COEX_STATISTICS); -} - - -void ex_halbtc8723b2ant_ips_notify(IN struct btc_coexist *btcoexist, IN u8 type) -{ - if (BTC_IPS_ENTER == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], IPS ENTER notify\n"); - BTC_TRACE(trace_buf); - coex_sta->under_ips = true; - halbtc8723b2ant_wifi_off_hw_cfg(btcoexist); - halbtc8723b2ant_ignore_wlan_act(btcoexist, FORCE_EXEC, true); - halbtc8723b2ant_coex_all_off(btcoexist); - } else if (BTC_IPS_LEAVE == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], IPS LEAVE notify\n"); - BTC_TRACE(trace_buf); - coex_sta->under_ips = false; - halbtc8723b2ant_init_hw_config(btcoexist, false); - halbtc8723b2ant_init_coex_dm(btcoexist); - halbtc8723b2ant_query_bt_info(btcoexist); - } -} - -void ex_halbtc8723b2ant_lps_notify(IN struct btc_coexist *btcoexist, IN u8 type) -{ - if (BTC_LPS_ENABLE == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], LPS ENABLE notify\n"); - BTC_TRACE(trace_buf); - coex_sta->under_lps = true; - } else if (BTC_LPS_DISABLE == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], LPS DISABLE notify\n"); - BTC_TRACE(trace_buf); - coex_sta->under_lps = false; - } -} - -void ex_halbtc8723b2ant_scan_notify(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - u32 u32tmp; - u8 u8tmpa, u8tmpb; - - - - u32tmp = btcoexist->btc_read_4byte(btcoexist, 0x948); - u8tmpa = btcoexist->btc_read_1byte(btcoexist, 0x765); - u8tmpb = btcoexist->btc_read_1byte(btcoexist, 0x76e); - - if (BTC_SCAN_START == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCAN START notify\n"); - BTC_TRACE(trace_buf); - halbtc8723b2ant_set_ant_path(btcoexist, BTC_ANT_WIFI_AT_MAIN, - false, false); - } else if (BTC_SCAN_FINISH == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCAN FINISH notify\n"); - BTC_TRACE(trace_buf); - btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM, - &coex_sta->scan_ap_num); - } - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "############# [BTCoex], 0x948=0x%x, 0x765=0x%x, 0x76e=0x%x\n", - u32tmp, u8tmpa, u8tmpb); - BTC_TRACE(trace_buf); -} - -void ex_halbtc8723b2ant_connect_notify(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - if (BTC_ASSOCIATE_START == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], CONNECT START notify\n"); - BTC_TRACE(trace_buf); - halbtc8723b2ant_set_ant_path(btcoexist, BTC_ANT_WIFI_AT_MAIN, - false, false); - } else if (BTC_ASSOCIATE_FINISH == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], CONNECT FINISH notify\n"); - BTC_TRACE(trace_buf); - } -} - -void ex_halbtc8723b2ant_media_status_notify(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - u8 h2c_parameter[3] = {0}; - u32 wifi_bw; - u8 wifi_central_chnl; - u8 ap_num = 0; - - if (BTC_MEDIA_CONNECT == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], MEDIA connect notify\n"); - BTC_TRACE(trace_buf); - halbtc8723b2ant_set_ant_path(btcoexist, BTC_ANT_WIFI_AT_MAIN, - false, false); - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], MEDIA disconnect notify\n"); - BTC_TRACE(trace_buf); - } - - /* only 2.4G we need to inform bt the chnl mask */ - btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_CENTRAL_CHNL, - &wifi_central_chnl); - if ((BTC_MEDIA_CONNECT == type) && - (wifi_central_chnl <= 14)) { - h2c_parameter[0] = 0x1; - h2c_parameter[1] = wifi_central_chnl; - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw); - if (BTC_WIFI_BW_HT40 == wifi_bw) - h2c_parameter[2] = 0x30; - else { - btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM, - &ap_num); - if (ap_num < 10) - h2c_parameter[2] = 0x30; - else - h2c_parameter[2] = 0x20; - } - } - - coex_dm->wifi_chnl_info[0] = h2c_parameter[0]; - coex_dm->wifi_chnl_info[1] = h2c_parameter[1]; - coex_dm->wifi_chnl_info[2] = h2c_parameter[2]; - - btcoexist->btc_fill_h2c(btcoexist, 0x66, 3, h2c_parameter); -} - -void ex_halbtc8723b2ant_specific_packet_notify(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - if (type == BTC_PACKET_DHCP) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], DHCP Packet notify\n"); - BTC_TRACE(trace_buf); - } -} - -void ex_halbtc8723b2ant_bt_info_notify(IN struct btc_coexist *btcoexist, - IN u8 *tmp_buf, IN u8 length) -{ - u8 bt_info = 0; - u8 i, rsp_source = 0; - boolean bt_busy = false, limited_dig = false; - boolean wifi_connected = false; - - coex_sta->c2h_bt_info_req_sent = false; - - rsp_source = tmp_buf[0] & 0xf; - if (rsp_source >= BT_INFO_SRC_8723B_2ANT_MAX) - rsp_source = BT_INFO_SRC_8723B_2ANT_WIFI_FW; - coex_sta->bt_info_c2h_cnt[rsp_source]++; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Bt info[%d], length=%d, hex data=[", rsp_source, - length); - BTC_TRACE(trace_buf); - for (i = 0; i < length; i++) { - coex_sta->bt_info_c2h[rsp_source][i] = tmp_buf[i]; - if (i == 1) - bt_info = tmp_buf[i]; - if (i == length - 1) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "0x%02x]\n", - tmp_buf[i]); - BTC_TRACE(trace_buf); - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "0x%02x, ", - tmp_buf[i]); - BTC_TRACE(trace_buf); - } - } - - if (btcoexist->manual_control) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), return for Manual CTRL<===\n"); - BTC_TRACE(trace_buf); - return; - } - - /* if 0xff, it means BT is under WHCK test */ - if (bt_info == 0xff) - coex_sta->bt_whck_test = true; - else - coex_sta->bt_whck_test = false; - - if (BT_INFO_SRC_8723B_2ANT_WIFI_FW != rsp_source) { - coex_sta->bt_retry_cnt = /* [3:0] */ - coex_sta->bt_info_c2h[rsp_source][2] & 0xf; - - if (coex_sta->bt_retry_cnt >= 1) - coex_sta->pop_event_cnt++; - - coex_sta->bt_rssi = - coex_sta->bt_info_c2h[rsp_source][3] * 2 + 10; - - coex_sta->bt_info_ext = - coex_sta->bt_info_c2h[rsp_source][4]; - - if (coex_sta->bt_info_c2h[rsp_source][2] & 0x20) - coex_sta->c2h_bt_remote_name_req = true; - else - coex_sta->c2h_bt_remote_name_req = false; - - if (coex_sta->bt_info_c2h[rsp_source][1] == 0x49) { - coex_sta->a2dp_bit_pool = - coex_sta->bt_info_c2h[rsp_source][6]; - } else - coex_sta->a2dp_bit_pool = 0; - - coex_sta->bt_tx_rx_mask = (coex_sta->bt_info_c2h[rsp_source][2] - & 0x40); - btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TX_RX_MASK, - &coex_sta->bt_tx_rx_mask); - if (coex_sta->bt_tx_rx_mask) { - /* BT into is responded by BT FW and BT RF REG 0x3C != 0x01 => Need to switch BT TRx Mask */ - /* BT TRx mask off */ - btcoexist->btc_set_bt_trx_mask(btcoexist, 0); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "############# [BTCoex], BT TRx Mask off for BT Info Notify\n"); - BTC_TRACE(trace_buf); -#if 0 - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Switch BT TRx Mask since BT RF REG 0x3C != 0x01\n"); - BTC_TRACE(trace_buf); - btcoexist->btc_set_bt_reg(btcoexist, BTC_BT_REG_RF, - 0x3c, 0x01); -#endif - } - - /* Here we need to resend some wifi info to BT */ - /* because bt is reset and loss of the info. */ - if ((coex_sta->bt_info_ext & BIT(1))) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT ext info bit1 check, send wifi BW&Chnl to BT!!\n"); - BTC_TRACE(trace_buf); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - if (wifi_connected) - ex_halbtc8723b2ant_media_status_notify( - btcoexist, BTC_MEDIA_CONNECT); - else - ex_halbtc8723b2ant_media_status_notify( - btcoexist, BTC_MEDIA_DISCONNECT); - } - - if ((coex_sta->bt_info_ext & BIT(3))) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT ext info bit3 check, set BT NOT to ignore Wlan active!!\n"); - BTC_TRACE(trace_buf); - halbtc8723b2ant_ignore_wlan_act(btcoexist, FORCE_EXEC, - false); - } else { - /* BT already NOT ignore Wlan active, do nothing here. */ - } -#if (BT_AUTO_REPORT_ONLY_8723B_2ANT == 0) - if ((coex_sta->bt_info_ext & BIT(4))) { - /* BT auto report already enabled, do nothing */ - } else - halbtc8723b2ant_bt_auto_report(btcoexist, FORCE_EXEC, - true); -#endif - } - - /* check BIT2 first ==> check if bt is under inquiry or page scan */ - if (bt_info & BT_INFO_8723B_2ANT_B_INQ_PAGE) - coex_sta->c2h_bt_inquiry_page = true; - else - coex_sta->c2h_bt_inquiry_page = false; - - /* set link exist status */ - if (!(bt_info & BT_INFO_8723B_2ANT_B_CONNECTION)) { - coex_sta->bt_link_exist = false; - coex_sta->pan_exist = false; - coex_sta->a2dp_exist = false; - coex_sta->hid_exist = false; - coex_sta->sco_exist = false; - } else { /* connection exists */ - coex_sta->bt_link_exist = true; - if (bt_info & BT_INFO_8723B_2ANT_B_FTP) - coex_sta->pan_exist = true; - else - coex_sta->pan_exist = false; - if (bt_info & BT_INFO_8723B_2ANT_B_A2DP) - coex_sta->a2dp_exist = true; - else - coex_sta->a2dp_exist = false; - if (bt_info & BT_INFO_8723B_2ANT_B_HID) - coex_sta->hid_exist = true; - else - coex_sta->hid_exist = false; - if (bt_info & BT_INFO_8723B_2ANT_B_SCO_ESCO) - coex_sta->sco_exist = true; - else - coex_sta->sco_exist = false; - - if ((coex_sta->hid_exist == false) && - (coex_sta->c2h_bt_inquiry_page == false) && - (coex_sta->sco_exist == false)) { - if (coex_sta->high_priority_tx + - coex_sta->high_priority_rx >= 160) { - coex_sta->hid_exist = true; - bt_info = bt_info | 0x28; - } - } - } - - halbtc8723b2ant_update_bt_link_info(btcoexist); - - if (!(bt_info & BT_INFO_8723B_2ANT_B_CONNECTION)) { - coex_dm->bt_status = BT_8723B_2ANT_BT_STATUS_NON_CONNECTED_IDLE; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), BT Non-Connected idle!!!\n"); - BTC_TRACE(trace_buf); - } else if (bt_info == - BT_INFO_8723B_2ANT_B_CONNECTION) { /* connection exists but no busy */ - coex_dm->bt_status = BT_8723B_2ANT_BT_STATUS_CONNECTED_IDLE; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), BT Connected-idle!!!\n"); - BTC_TRACE(trace_buf); - } else if ((bt_info & BT_INFO_8723B_2ANT_B_SCO_ESCO) || - (bt_info & BT_INFO_8723B_2ANT_B_SCO_BUSY)) { - coex_dm->bt_status = BT_8723B_2ANT_BT_STATUS_SCO_BUSY; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), BT SCO busy!!!\n"); - BTC_TRACE(trace_buf); - } else if (bt_info & BT_INFO_8723B_2ANT_B_ACL_BUSY) { - coex_dm->bt_status = BT_8723B_2ANT_BT_STATUS_ACL_BUSY; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), BT ACL busy!!!\n"); - BTC_TRACE(trace_buf); - } else { - coex_dm->bt_status = BT_8723B_2ANT_BT_STATUS_MAX; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), BT Non-Defined state!!!\n"); - BTC_TRACE(trace_buf); - } - - if ((BT_8723B_2ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) || - (BT_8723B_2ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) || - (BT_8723B_2ANT_BT_STATUS_ACL_SCO_BUSY == coex_dm->bt_status)) { - bt_busy = true; - limited_dig = true; - } else { - bt_busy = false; - limited_dig = false; - } - - btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bt_busy); - - coex_dm->limited_dig = limited_dig; - btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_LIMITED_DIG, &limited_dig); - - halbtc8723b2ant_run_coexist_mechanism(btcoexist); -} - -void ex_halbtc8723b2ant_halt_notify(IN struct btc_coexist *btcoexist) -{ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], Halt notify\n"); - BTC_TRACE(trace_buf); - - halbtc8723b2ant_wifi_off_hw_cfg(btcoexist); - /* remove due to interrupt is disabled that polling c2h will fail and delay 100ms. */ - /* btcoexist->btc_set_bt_reg(btcoexist, BTC_BT_REG_RF, 0x3c, 0x15); */ /*BT goto standby while GNT_BT 1-->0 */ - halbtc8723b2ant_ignore_wlan_act(btcoexist, FORCE_EXEC, true); - - ex_halbtc8723b2ant_media_status_notify(btcoexist, BTC_MEDIA_DISCONNECT); -} - -void ex_halbtc8723b2ant_pnp_notify(IN struct btc_coexist *btcoexist, - IN u8 pnp_state) -{ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], Pnp notify\n"); - BTC_TRACE(trace_buf); - - if (BTC_WIFI_PNP_SLEEP == pnp_state) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Pnp notify to SLEEP\n"); - BTC_TRACE(trace_buf); - - /* Sinda 20150819, workaround for driver skip leave IPS/LPS to speed up sleep time. */ - /* Driver do not leave IPS/LPS when driver is going to sleep, so BTCoexistence think wifi is still under IPS/LPS */ - /* BT should clear UnderIPS/UnderLPS state to avoid mismatch state after wakeup. */ - coex_sta->under_ips = false; - coex_sta->under_lps = false; - } else if (BTC_WIFI_PNP_WAKE_UP == pnp_state) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Pnp notify to WAKE UP\n"); - BTC_TRACE(trace_buf); - halbtc8723b2ant_init_hw_config(btcoexist, false); - halbtc8723b2ant_init_coex_dm(btcoexist); - halbtc8723b2ant_query_bt_info(btcoexist); - } -} - -void ex_halbtc8723b2ant_periodical(IN struct btc_coexist *btcoexist) -{ - u32 bt_patch_ver; - - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ==========================Periodical===========================\n"); - BTC_TRACE(trace_buf); - if (coex_sta->dis_ver_info_cnt <= 5) { - coex_sta->dis_ver_info_cnt += 1; - if (coex_sta->dis_ver_info_cnt == 3) { - /* Antenna config to set 0x765 = 0x0 (GNT_BT control by PTA) after initial */ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Set GNT_BT control by PTA\n"); - BTC_TRACE(trace_buf); - halbtc8723b2ant_set_ant_path(btcoexist, - BTC_ANT_WIFI_AT_MAIN, false, false); - } - } - - if (((coex_sta->bt_coex_supported_version == 0) || - (coex_sta->bt_coex_supported_version == 0xffff)) && (!coex_sta->bt_disabled)) - btcoexist->btc_get(btcoexist, BTC_GET_U4_SUPPORTED_VERSION, &coex_sta->bt_coex_supported_version); - - - btcoexist->btc_get(btcoexist, BTC_GET_U4_BT_PATCH_VER, &bt_patch_ver); - btcoexist->bt_info.bt_get_fw_ver = bt_patch_ver; - -#if (BT_AUTO_REPORT_ONLY_8723B_2ANT == 0) - halbtc8723b2ant_query_bt_info(btcoexist); - halbtc8723b2ant_monitor_bt_enable_disable(btcoexist); -#else - halbtc8723b2ant_monitor_bt_ctr(btcoexist); - halbtc8723b2ant_monitor_wifi_ctr(btcoexist); - - /* for some BT speaker that Hi-Pri pkt appear begore start play, this will cause HID exist */ - if ((coex_sta->high_priority_tx + coex_sta->high_priority_rx < 50) && - (bt_link_info->hid_exist == true)) - bt_link_info->hid_exist = false; - - if (halbtc8723b2ant_is_wifi_status_changed(btcoexist) || - coex_dm->auto_tdma_adjust) - halbtc8723b2ant_run_coexist_mechanism(btcoexist); -#endif -} - -#endif - -#endif /* #if (BT_SUPPORT == 1 && COEX_SUPPORT == 1) */ - - diff --git a/hal/btc/halbtc8723b2ant.h b/hal/btc/halbtc8723b2ant.h deleted file mode 100644 index b44959c..0000000 --- a/hal/btc/halbtc8723b2ant.h +++ /dev/null @@ -1,217 +0,0 @@ - -#if (BT_SUPPORT == 1 && COEX_SUPPORT == 1) - -#if (RTL8723B_SUPPORT == 1) -/* ******************************************* - * The following is for 8723B 2Ant BT Co-exist definition - * ******************************************* */ -#define BT_AUTO_REPORT_ONLY_8723B_2ANT 1 - - -#define BT_INFO_8723B_2ANT_B_FTP BIT(7) -#define BT_INFO_8723B_2ANT_B_A2DP BIT(6) -#define BT_INFO_8723B_2ANT_B_HID BIT(5) -#define BT_INFO_8723B_2ANT_B_SCO_BUSY BIT(4) -#define BT_INFO_8723B_2ANT_B_ACL_BUSY BIT(3) -#define BT_INFO_8723B_2ANT_B_INQ_PAGE BIT(2) -#define BT_INFO_8723B_2ANT_B_SCO_ESCO BIT(1) -#define BT_INFO_8723B_2ANT_B_CONNECTION BIT(0) - -#define BTC_RSSI_COEX_THRESH_TOL_8723B_2ANT 2 - - -#define BT_8723B_2ANT_WIFI_RSSI_COEXSWITCH_THRES 42 /* WiFi RSSI Threshold for 2-Ant TDMA/1-Ant PS-TDMA translation */ -#define BT_8723B_2ANT_BT_RSSI_COEXSWITCH_THRES 46 /* BT RSSI Threshold for 2-Ant TDMA/1-Ant PS-TDMA translation */ - -enum bt_info_src_8723b_2ant { - BT_INFO_SRC_8723B_2ANT_WIFI_FW = 0x0, - BT_INFO_SRC_8723B_2ANT_BT_RSP = 0x1, - BT_INFO_SRC_8723B_2ANT_BT_ACTIVE_SEND = 0x2, - BT_INFO_SRC_8723B_2ANT_MAX -}; - -enum bt_8723b_2ant_bt_status { - BT_8723B_2ANT_BT_STATUS_NON_CONNECTED_IDLE = 0x0, - BT_8723B_2ANT_BT_STATUS_CONNECTED_IDLE = 0x1, - BT_8723B_2ANT_BT_STATUS_INQ_PAGE = 0x2, - BT_8723B_2ANT_BT_STATUS_ACL_BUSY = 0x3, - BT_8723B_2ANT_BT_STATUS_SCO_BUSY = 0x4, - BT_8723B_2ANT_BT_STATUS_ACL_SCO_BUSY = 0x5, - BT_8723B_2ANT_BT_STATUS_MAX -}; - -enum bt_8723b_2ant_coex_algo { - BT_8723B_2ANT_COEX_ALGO_UNDEFINED = 0x0, - BT_8723B_2ANT_COEX_ALGO_SCO = 0x1, - BT_8723B_2ANT_COEX_ALGO_HID = 0x2, - BT_8723B_2ANT_COEX_ALGO_A2DP = 0x3, - BT_8723B_2ANT_COEX_ALGO_A2DP_PANHS = 0x4, - BT_8723B_2ANT_COEX_ALGO_PANEDR = 0x5, - BT_8723B_2ANT_COEX_ALGO_PANHS = 0x6, - BT_8723B_2ANT_COEX_ALGO_PANEDR_A2DP = 0x7, - BT_8723B_2ANT_COEX_ALGO_PANEDR_HID = 0x8, - BT_8723B_2ANT_COEX_ALGO_HID_A2DP_PANEDR = 0x9, - BT_8723B_2ANT_COEX_ALGO_HID_A2DP = 0xa, - BT_8723B_2ANT_COEX_ALGO_MAX = 0xb, -}; - -struct coex_dm_8723b_2ant { - /* fw mechanism */ - u8 pre_bt_dec_pwr_lvl; - u8 cur_bt_dec_pwr_lvl; - u8 pre_fw_dac_swing_lvl; - u8 cur_fw_dac_swing_lvl; - boolean cur_ignore_wlan_act; - boolean pre_ignore_wlan_act; - u8 pre_ps_tdma; - u8 cur_ps_tdma; - u8 ps_tdma_para[5]; - u8 ps_tdma_du_adj_type; - boolean reset_tdma_adjust; - boolean auto_tdma_adjust; - boolean pre_ps_tdma_on; - boolean cur_ps_tdma_on; - boolean pre_bt_auto_report; - boolean cur_bt_auto_report; - - /* sw mechanism */ - boolean pre_rf_rx_lpf_shrink; - boolean cur_rf_rx_lpf_shrink; - u32 bt_rf_0x1e_backup; - boolean pre_low_penalty_ra; - boolean cur_low_penalty_ra; - boolean pre_dac_swing_on; - u32 pre_dac_swing_lvl; - boolean cur_dac_swing_on; - u32 cur_dac_swing_lvl; - boolean pre_adc_back_off; - boolean cur_adc_back_off; - boolean pre_agc_table_en; - boolean cur_agc_table_en; - u32 pre_val0x6c0; - u32 cur_val0x6c0; - u32 pre_val0x6c4; - u32 cur_val0x6c4; - u32 pre_val0x6c8; - u32 cur_val0x6c8; - u8 pre_val0x6cc; - u8 cur_val0x6cc; - boolean limited_dig; - - /* algorithm related */ - u8 pre_algorithm; - u8 cur_algorithm; - u8 bt_status; - u8 wifi_chnl_info[3]; - - boolean need_recover0x948; - u32 backup0x948; - - u8 pre_lps; - u8 cur_lps; - u8 pre_rpwm; - u8 cur_rpwm; - - boolean is_switch_to_1dot5_ant; - u8 switch_thres_offset; -}; - -struct coex_sta_8723b_2ant { - boolean bt_disabled; - boolean bt_link_exist; - boolean sco_exist; - boolean a2dp_exist; - boolean hid_exist; - boolean pan_exist; - boolean bt_abnormal_scan; - boolean under_lps; - boolean under_ips; - u32 high_priority_tx; - u32 high_priority_rx; - u32 low_priority_tx; - u32 low_priority_rx; - u8 bt_rssi; - boolean bt_tx_rx_mask; - u8 pre_bt_rssi_state; - u8 pre_wifi_rssi_state[4]; - boolean c2h_bt_info_req_sent; - u8 bt_info_c2h[BT_INFO_SRC_8723B_2ANT_MAX][10]; - u32 bt_info_c2h_cnt[BT_INFO_SRC_8723B_2ANT_MAX]; - boolean bt_whck_test; - boolean c2h_bt_inquiry_page; - boolean c2h_bt_remote_name_req; - u8 bt_retry_cnt; - u8 bt_info_ext; - u32 pop_event_cnt; - u8 scan_ap_num; - - u32 crc_ok_cck; - u32 crc_ok_11g; - u32 crc_ok_11n; - u32 crc_ok_11n_vht; - - u32 crc_err_cck; - u32 crc_err_11g; - u32 crc_err_11n; - u32 crc_err_11n_vht; - - u32 bt_coex_supported_version; - - u8 coex_table_type; - boolean force_lps_on; - - u8 dis_ver_info_cnt; - - u8 a2dp_bit_pool; - u8 cut_version; -}; - -/* ******************************************* - * The following is interface which will notify coex module. - * ******************************************* */ -void ex_halbtc8723b2ant_power_on_setting(IN struct btc_coexist *btcoexist); -void ex_halbtc8723b2ant_pre_load_firmware(IN struct btc_coexist *btcoexist); -void ex_halbtc8723b2ant_init_hw_config(IN struct btc_coexist *btcoexist, - IN boolean wifi_only); -void ex_halbtc8723b2ant_init_coex_dm(IN struct btc_coexist *btcoexist); -void ex_halbtc8723b2ant_ips_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8723b2ant_lps_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8723b2ant_scan_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8723b2ant_connect_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8723b2ant_media_status_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8723b2ant_specific_packet_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8723b2ant_bt_info_notify(IN struct btc_coexist *btcoexist, - IN u8 *tmp_buf, IN u8 length); -void ex_halbtc8723b2ant_halt_notify(IN struct btc_coexist *btcoexist); -void ex_halbtc8723b2ant_pnp_notify(IN struct btc_coexist *btcoexist, - IN u8 pnp_state); -void ex_halbtc8723b2ant_periodical(IN struct btc_coexist *btcoexist); -void ex_halbtc8723b2ant_display_coex_info(IN struct btc_coexist *btcoexist); - -#else -#define ex_halbtc8723b2ant_power_on_setting(btcoexist) -#define ex_halbtc8723b2ant_pre_load_firmware(btcoexist) -#define ex_halbtc8723b2ant_init_hw_config(btcoexist, wifi_only) -#define ex_halbtc8723b2ant_init_coex_dm(btcoexist) -#define ex_halbtc8723b2ant_ips_notify(btcoexist, type) -#define ex_halbtc8723b2ant_lps_notify(btcoexist, type) -#define ex_halbtc8723b2ant_scan_notify(btcoexist, type) -#define ex_halbtc8723b2ant_connect_notify(btcoexist, type) -#define ex_halbtc8723b2ant_media_status_notify(btcoexist, type) -#define ex_halbtc8723b2ant_specific_packet_notify(btcoexist, type) -#define ex_halbtc8723b2ant_bt_info_notify(btcoexist, tmp_buf, length) -#define ex_halbtc8723b2ant_halt_notify(btcoexist) -#define ex_halbtc8723b2ant_pnp_notify(btcoexist, pnp_state) -#define ex_halbtc8723b2ant_periodical(btcoexist) -#define ex_halbtc8723b2ant_display_coex_info(btcoexist) - -#endif - -#endif - diff --git a/hal/btc/halbtc8723bwifionly.c b/hal/btc/halbtc8723bwifionly.c deleted file mode 100644 index 9be8d62..0000000 --- a/hal/btc/halbtc8723bwifionly.c +++ /dev/null @@ -1,68 +0,0 @@ -#include "mp_precomp.h" - - -VOID -ex_hal8723b_wifi_only_hw_config( - IN struct wifi_only_cfg *pwifionlycfg - ) -{ - struct wifi_only_haldata *pwifionly_haldata = &pwifionlycfg->haldata_info; - - - halwifionly_write1byte(pwifionlycfg, 0x778, 0x3); /* Set pta for wifi first priority, 0x1 need to reference pta table to determine wifi and bt priority */ - halwifionly_bitmaskwrite1byte(pwifionlycfg, 0x40, 0x20, 0x1); - - /* Set Antenna path to Wifi */ - halwifionly_write2byte(pwifionlycfg, 0x0765, 0x8); /* Set pta for wifi first priority, 0x0 need to reference pta table to determine wifi and bt priority */ - halwifionly_write2byte(pwifionlycfg, 0x076e, 0xc); - - halwifionly_write4byte(pwifionlycfg, 0x000006c0, 0xaaaaaaaa); /* pta table, 0xaaaaaaaa means wifi is higher priority than bt */ - halwifionly_write4byte(pwifionlycfg, 0x000006c4, 0xaaaaaaaa); - - halwifionly_bitmaskwrite1byte(pwifionlycfg, 0x67, 0x20, 0x1); /* BT select s0/s1 is controlled by WiFi */ - - /* 0x948 setting */ - if (pwifionlycfg->chip_interface == WIFIONLY_INTF_PCI) { - /* HP Foxconn NGFF at S0 - not sure HP pg correct or not(EEPROMBluetoothSingleAntPath), so here we just write - 0x948=0x280 for HP HW id NIC. */ - if (pwifionly_haldata->customer_id == CUSTOMER_HP_1) { - halwifionly_write4byte(pwifionlycfg, 0x948, 0x280); - halwifionly_phy_set_rf_reg(pwifionlycfg, 0, 0x1, 0xfffff, 0x0); /* WiFi TRx Mask off */ - return; - } - } - - if (pwifionly_haldata->efuse_pg_antnum == 2) { - halwifionly_write4byte(pwifionlycfg, 0x948, 0x0); - } else { - /* 3Attention !!! For 8723BU !!!! - For 8723BU single ant case: jira [USB-1237] - Because of 8723BU S1 has HW problem, we only can use S0 instead. - Whether Efuse 0xc3 [6] is 0 or 1, we should always use S0 and write 0x948 to 80/280 - - -------------------------------------------------- - BT Team : - When in Single Ant case, Reg[0x948] has two case : 0x80 or 0x200 - When in Two Ant case, Reg[0x948] has two case : 0x280 or 0x0 - Efuse 0xc3 [6] Antenna Path - 0xc3 [6] = 0 ==> S1 ==> 0x948 = 0/40/200 - 0xc3 [6] = 1 ==> S0 ==> 0x948 = 80/240/280 */ - - if (pwifionlycfg->chip_interface == WIFIONLY_INTF_USB) - halwifionly_write4byte(pwifionlycfg, 0x948, 0x80); - else { - if (pwifionly_haldata->efuse_pg_antpath == 0) - halwifionly_write4byte(pwifionlycfg, 0x948, 0x0); - else - halwifionly_write4byte(pwifionlycfg, 0x948, 0x280); - } - - } - - - /* after 8723B F-cut, TRx Mask should be set when 0x948=0x0 or 0x280 - PHY_SetRFReg(Adapter, 0, 0x1, 0xfffff, 0x780); WiFi TRx Mask on */ - halwifionly_phy_set_rf_reg(pwifionlycfg, 0, 0x1, 0xfffff, 0x0); /*WiFi TRx Mask off */ - -} diff --git a/hal/btc/halbtc8723bwifionly.h b/hal/btc/halbtc8723bwifionly.h deleted file mode 100644 index 0265ab3..0000000 --- a/hal/btc/halbtc8723bwifionly.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef __INC_HAL8723BWIFIONLYHWCFG_H -#define __INC_HAL8723BWIFIONLYHWCFG_H - -VOID -ex_hal8723b_wifi_only_hw_config( - IN struct wifi_only_cfg *pwifionlycfg - ); -#endif diff --git a/hal/btc/halbtc8723d1ant.c b/hal/btc/halbtc8723d1ant.c deleted file mode 100644 index 4693795..0000000 --- a/hal/btc/halbtc8723d1ant.c +++ /dev/null @@ -1,6080 +0,0 @@ -/* ************************************************************ - * Description: - * - * This file is for RTL8723D Co-exist mechanism - * - * History - * 2012/11/15 Cosa first check in. - * - * ************************************************************ */ - -/* ************************************************************ - * include files - * ************************************************************ */ -#include "mp_precomp.h" - -#if (BT_SUPPORT == 1 && COEX_SUPPORT == 1) - -#if (RTL8723D_SUPPORT == 1) -/* ************************************************************ - * Global variables, these are static variables - * ************************************************************ */ -static u8 *trace_buf = &gl_btc_trace_buf[0]; -static struct coex_dm_8723d_1ant glcoex_dm_8723d_1ant; -static struct coex_dm_8723d_1ant *coex_dm = &glcoex_dm_8723d_1ant; -static struct coex_sta_8723d_1ant glcoex_sta_8723d_1ant; -static struct coex_sta_8723d_1ant *coex_sta = &glcoex_sta_8723d_1ant; -static struct psdscan_sta_8723d_1ant gl_psd_scan_8723d_1ant; -static struct psdscan_sta_8723d_1ant *psd_scan = &gl_psd_scan_8723d_1ant; - -const char *const glbt_info_src_8723d_1ant[] = { - "BT Info[wifi fw]", - "BT Info[bt rsp]", - "BT Info[bt auto report]", -}; -/* ************************************************************ - * BtCoex Version Format: - * 1. date : glcoex_ver_date_XXXXX_1ant - * 2. WifiCoexVersion : glcoex_ver_XXXX_1ant - * 3. BtCoexVersion : glcoex_ver_btdesired_XXXXX_1ant - * 4. others : glcoex_ver_XXXXXX_XXXXX_1ant - * - * Variable should be indicated IC and Antenna numbers !!! - * Please strictly follow this order and naming style !!! - * - * ************************************************************ */ -u32 glcoex_ver_date_8723d_1ant = 20161027; -u32 glcoex_ver_8723d_1ant = 0x0f; -u32 glcoex_ver_btdesired_8723d_1ant = 0x0d; - -/* ************************************************************ - * local function proto type if needed - * ************************************************************ - * ************************************************************ - * local function start with halbtc8723d1ant_ - * ************************************************************ */ -u8 halbtc8723d1ant_bt_rssi_state(u8 level_num, u8 rssi_thresh, u8 rssi_thresh1) -{ - s32 bt_rssi = 0; - u8 bt_rssi_state = coex_sta->pre_bt_rssi_state; - - bt_rssi = coex_sta->bt_rssi; - - if (level_num == 2) { - if ((coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_LOW) || - (coex_sta->pre_bt_rssi_state == - BTC_RSSI_STATE_STAY_LOW)) { - if (bt_rssi >= (rssi_thresh + - BTC_RSSI_COEX_THRESH_TOL_8723D_1ANT)) - bt_rssi_state = BTC_RSSI_STATE_HIGH; - else - bt_rssi_state = BTC_RSSI_STATE_STAY_LOW; - } else { - if (bt_rssi < rssi_thresh) - bt_rssi_state = BTC_RSSI_STATE_LOW; - else - bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH; - } - } else if (level_num == 3) { - if (rssi_thresh > rssi_thresh1) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Rssi thresh error!!\n"); - BTC_TRACE(trace_buf); - return coex_sta->pre_bt_rssi_state; - } - - if ((coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_LOW) || - (coex_sta->pre_bt_rssi_state == - BTC_RSSI_STATE_STAY_LOW)) { - if (bt_rssi >= (rssi_thresh + - BTC_RSSI_COEX_THRESH_TOL_8723D_1ANT)) - bt_rssi_state = BTC_RSSI_STATE_MEDIUM; - else - bt_rssi_state = BTC_RSSI_STATE_STAY_LOW; - } else if ((coex_sta->pre_bt_rssi_state == - BTC_RSSI_STATE_MEDIUM) || - (coex_sta->pre_bt_rssi_state == - BTC_RSSI_STATE_STAY_MEDIUM)) { - if (bt_rssi >= (rssi_thresh1 + - BTC_RSSI_COEX_THRESH_TOL_8723D_1ANT)) - bt_rssi_state = BTC_RSSI_STATE_HIGH; - else if (bt_rssi < rssi_thresh) - bt_rssi_state = BTC_RSSI_STATE_LOW; - else - bt_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM; - } else { - if (bt_rssi < rssi_thresh1) - bt_rssi_state = BTC_RSSI_STATE_MEDIUM; - else - bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH; - } - } - - coex_sta->pre_bt_rssi_state = bt_rssi_state; - - return bt_rssi_state; -} - -u8 halbtc8723d1ant_wifi_rssi_state(IN struct btc_coexist *btcoexist, - IN u8 index, IN u8 level_num, IN u8 rssi_thresh, IN u8 rssi_thresh1) -{ - s32 wifi_rssi = 0; - u8 wifi_rssi_state = coex_sta->pre_wifi_rssi_state[index]; - - btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi); - - if (level_num == 2) { - if ((coex_sta->pre_wifi_rssi_state[index] == BTC_RSSI_STATE_LOW) - || - (coex_sta->pre_wifi_rssi_state[index] == - BTC_RSSI_STATE_STAY_LOW)) { - if (wifi_rssi >= (rssi_thresh + - BTC_RSSI_COEX_THRESH_TOL_8723D_1ANT)) - wifi_rssi_state = BTC_RSSI_STATE_HIGH; - else - wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW; - } else { - if (wifi_rssi < rssi_thresh) - wifi_rssi_state = BTC_RSSI_STATE_LOW; - else - wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH; - } - } else if (level_num == 3) { - if (rssi_thresh > rssi_thresh1) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], wifi RSSI thresh error!!\n"); - BTC_TRACE(trace_buf); - return coex_sta->pre_wifi_rssi_state[index]; - } - - if ((coex_sta->pre_wifi_rssi_state[index] == BTC_RSSI_STATE_LOW) - || - (coex_sta->pre_wifi_rssi_state[index] == - BTC_RSSI_STATE_STAY_LOW)) { - if (wifi_rssi >= (rssi_thresh + - BTC_RSSI_COEX_THRESH_TOL_8723D_1ANT)) - wifi_rssi_state = BTC_RSSI_STATE_MEDIUM; - else - wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW; - } else if ((coex_sta->pre_wifi_rssi_state[index] == - BTC_RSSI_STATE_MEDIUM) || - (coex_sta->pre_wifi_rssi_state[index] == - BTC_RSSI_STATE_STAY_MEDIUM)) { - if (wifi_rssi >= (rssi_thresh1 + - BTC_RSSI_COEX_THRESH_TOL_8723D_1ANT)) - wifi_rssi_state = BTC_RSSI_STATE_HIGH; - else if (wifi_rssi < rssi_thresh) - wifi_rssi_state = BTC_RSSI_STATE_LOW; - else - wifi_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM; - } else { - if (wifi_rssi < rssi_thresh1) - wifi_rssi_state = BTC_RSSI_STATE_MEDIUM; - else - wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH; - } - } - - coex_sta->pre_wifi_rssi_state[index] = wifi_rssi_state; - - return wifi_rssi_state; -} - -void halbtc8723d1ant_update_ra_mask(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u32 dis_rate_mask) -{ - coex_dm->cur_ra_mask = dis_rate_mask; - - if (force_exec || (coex_dm->pre_ra_mask != coex_dm->cur_ra_mask)) - btcoexist->btc_set(btcoexist, BTC_SET_ACT_UPDATE_RAMASK, - &coex_dm->cur_ra_mask); - coex_dm->pre_ra_mask = coex_dm->cur_ra_mask; -} - -void halbtc8723d1ant_auto_rate_fallback_retry(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 type) -{ - boolean wifi_under_b_mode = false; - - coex_dm->cur_arfr_type = type; - - if (force_exec || (coex_dm->pre_arfr_type != coex_dm->cur_arfr_type)) { - switch (coex_dm->cur_arfr_type) { - case 0: /* normal mode */ - btcoexist->btc_write_4byte(btcoexist, 0x430, - coex_dm->backup_arfr_cnt1); - btcoexist->btc_write_4byte(btcoexist, 0x434, - coex_dm->backup_arfr_cnt2); - break; - case 1: - btcoexist->btc_get(btcoexist, - BTC_GET_BL_WIFI_UNDER_B_MODE, - &wifi_under_b_mode); - if (wifi_under_b_mode) { - btcoexist->btc_write_4byte(btcoexist, - 0x430, 0x0); - btcoexist->btc_write_4byte(btcoexist, - 0x434, 0x01010101); - } else { - btcoexist->btc_write_4byte(btcoexist, - 0x430, 0x0); - btcoexist->btc_write_4byte(btcoexist, - 0x434, 0x04030201); - } - break; - default: - break; - } - } - - coex_dm->pre_arfr_type = coex_dm->cur_arfr_type; -} - -void halbtc8723d1ant_retry_limit(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 type) -{ - coex_dm->cur_retry_limit_type = type; - - if (force_exec || - (coex_dm->pre_retry_limit_type != - coex_dm->cur_retry_limit_type)) { - switch (coex_dm->cur_retry_limit_type) { - case 0: /* normal mode */ - btcoexist->btc_write_2byte(btcoexist, 0x42a, - coex_dm->backup_retry_limit); - break; - case 1: /* retry limit=8 */ - btcoexist->btc_write_2byte(btcoexist, 0x42a, - 0x0808); - break; - default: - break; - } - } - - coex_dm->pre_retry_limit_type = coex_dm->cur_retry_limit_type; -} - -void halbtc8723d1ant_ampdu_max_time(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 type) -{ - coex_dm->cur_ampdu_time_type = type; - - if (force_exec || - (coex_dm->pre_ampdu_time_type != coex_dm->cur_ampdu_time_type)) { - switch (coex_dm->cur_ampdu_time_type) { - case 0: /* normal mode */ - btcoexist->btc_write_1byte(btcoexist, 0x456, - coex_dm->backup_ampdu_max_time); - break; - case 1: /* AMPDU timw = 0x38 * 32us */ - btcoexist->btc_write_1byte(btcoexist, 0x456, - 0x38); - break; - default: - break; - } - } - - coex_dm->pre_ampdu_time_type = coex_dm->cur_ampdu_time_type; -} - -void halbtc8723d1ant_limited_tx(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 ra_mask_type, IN u8 arfr_type, - IN u8 retry_limit_type, IN u8 ampdu_time_type) -{ - switch (ra_mask_type) { - case 0: /* normal mode */ - halbtc8723d1ant_update_ra_mask(btcoexist, force_exec, - 0x0); - break; - case 1: /* disable cck 1/2 */ - halbtc8723d1ant_update_ra_mask(btcoexist, force_exec, - 0x00000003); - break; - case 2: /* disable cck 1/2/5.5, ofdm 6/9/12/18/24, mcs 0/1/2/3/4 */ - halbtc8723d1ant_update_ra_mask(btcoexist, force_exec, - 0x0001f1f7); - break; - default: - break; - } - - halbtc8723d1ant_auto_rate_fallback_retry(btcoexist, force_exec, - arfr_type); - halbtc8723d1ant_retry_limit(btcoexist, force_exec, retry_limit_type); - halbtc8723d1ant_ampdu_max_time(btcoexist, force_exec, ampdu_time_type); -} - -void halbtc8723d1ant_limited_rx(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean rej_ap_agg_pkt, - IN boolean bt_ctrl_agg_buf_size, IN u8 agg_buf_size) -{ - boolean reject_rx_agg = rej_ap_agg_pkt; - boolean bt_ctrl_rx_agg_size = bt_ctrl_agg_buf_size; - u8 rx_agg_size = agg_buf_size; - - /* ============================================ */ - /* Rx Aggregation related setting */ - /* ============================================ */ - btcoexist->btc_set(btcoexist, BTC_SET_BL_TO_REJ_AP_AGG_PKT, - &reject_rx_agg); - /* decide BT control aggregation buf size or not */ - btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_CTRL_AGG_SIZE, - &bt_ctrl_rx_agg_size); - /* aggregation buf size, only work when BT control Rx aggregation size. */ - btcoexist->btc_set(btcoexist, BTC_SET_U1_AGG_BUF_SIZE, &rx_agg_size); - /* real update aggregation setting */ - btcoexist->btc_set(btcoexist, BTC_SET_ACT_AGGREGATE_CTRL, NULL); - -} - -void halbtc8723d1ant_query_bt_info(IN struct btc_coexist *btcoexist) -{ - u8 h2c_parameter[1] = {0}; - - h2c_parameter[0] |= BIT(0); /* trigger */ - - btcoexist->btc_fill_h2c(btcoexist, 0x61, 1, h2c_parameter); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], WL query BT info!!\n"); - BTC_TRACE(trace_buf); -} - -void halbtc8723d1ant_monitor_bt_ctr(IN struct btc_coexist *btcoexist) -{ - u32 reg_hp_txrx, reg_lp_txrx, u32tmp; - u32 reg_hp_tx = 0, reg_hp_rx = 0, reg_lp_tx = 0, reg_lp_rx = 0; - static u8 num_of_bt_counter_chk = 0, cnt_slave = 0, cnt_overhead = 0, - cnt_autoslot_hang = 0; - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - - /* to avoid 0x76e[3] = 1 (WLAN_Act control by PTA) during IPS */ - /* if (! (btcoexist->btc_read_1byte(btcoexist, 0x76e) & 0x8) ) */ - - reg_hp_txrx = 0x770; - reg_lp_txrx = 0x774; - - u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_hp_txrx); - reg_hp_tx = u32tmp & MASKLWORD; - reg_hp_rx = (u32tmp & MASKHWORD) >> 16; - - u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_lp_txrx); - reg_lp_tx = u32tmp & MASKLWORD; - reg_lp_rx = (u32tmp & MASKHWORD) >> 16; - - coex_sta->high_priority_tx = reg_hp_tx; - coex_sta->high_priority_rx = reg_hp_rx; - coex_sta->low_priority_tx = reg_lp_tx; - coex_sta->low_priority_rx = reg_lp_rx; - - if (BT_8723D_1ANT_BT_STATUS_NON_CONNECTED_IDLE == - coex_dm->bt_status) { - - if (coex_sta->high_priority_rx >= 15) { - if (cnt_overhead < 3) - cnt_overhead++; - - if (cnt_overhead == 3) - coex_sta->is_hiPri_rx_overhead = true; - } else { - if (cnt_overhead > 0) - cnt_overhead--; - - if (cnt_overhead == 0) - coex_sta->is_hiPri_rx_overhead = false; - } - } - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Hi-Pri Rx/Tx: %d/%d, Lo-Pri Rx/Tx: %d/%d\n", - reg_hp_rx, reg_hp_tx, reg_lp_rx, reg_lp_tx); - - BTC_TRACE(trace_buf); - - /* reset counter */ - btcoexist->btc_write_1byte(btcoexist, 0x76e, 0xc); - - if ((coex_sta->low_priority_tx > 1150) && - (!coex_sta->c2h_bt_inquiry_page)) - coex_sta->pop_event_cnt++; - - if ((coex_sta->low_priority_rx >= 1150) && - (coex_sta->low_priority_rx >= coex_sta->low_priority_tx) - && (!coex_sta->under_ips) && (!coex_sta->c2h_bt_inquiry_page) && - (coex_sta->bt_link_exist)) { - if (cnt_slave >= 2) { - bt_link_info->slave_role = true; - cnt_slave = 2; - } else - cnt_slave++; - } else { - if (cnt_slave == 0) { - bt_link_info->slave_role = false; - cnt_slave = 0; - } else - cnt_slave--; - - } - - if (coex_sta->is_tdma_btautoslot) { - if ((coex_sta->low_priority_tx >= 1300) && - (coex_sta->low_priority_rx <= 150)) { - if (cnt_autoslot_hang >= 2) { - coex_sta->is_tdma_btautoslot_hang = true; - cnt_autoslot_hang = 2; - } else - cnt_autoslot_hang++; - } else { - if (cnt_autoslot_hang == 0) { - coex_sta->is_tdma_btautoslot_hang = false; - cnt_autoslot_hang = 0; - } else - cnt_autoslot_hang--; - } - } - - if (!coex_sta->bt_disabled) { - - if ((coex_sta->high_priority_tx == 0) && - (coex_sta->high_priority_rx == 0) && - (coex_sta->low_priority_tx == 0) && - (coex_sta->low_priority_rx == 0)) { - num_of_bt_counter_chk++; - if (num_of_bt_counter_chk >= 3) { - halbtc8723d1ant_query_bt_info(btcoexist); - num_of_bt_counter_chk = 0; - } - } - } - -} - -void halbtc8723d1ant_monitor_wifi_ctr(IN struct btc_coexist *btcoexist) -{ -#if 1 - s32 wifi_rssi = 0; - boolean wifi_busy = false, wifi_under_b_mode = false, - wifi_scan = false; - boolean bt_idle = false, wl_idle = false; - static u8 cck_lock_counter = 0, wl_noisy_count0 = 0, - wl_noisy_count1 = 3, wl_noisy_count2 = 0; - u32 total_cnt, reg_val1, reg_val2, cck_cnt; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_B_MODE, - &wifi_under_b_mode); - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &wifi_scan); - - coex_sta->crc_ok_cck = btcoexist->btc_phydm_query_PHY_counter( - btcoexist, PHYDM_INFO_CRC32_OK_CCK); - coex_sta->crc_ok_11g = btcoexist->btc_phydm_query_PHY_counter( - btcoexist, PHYDM_INFO_CRC32_OK_LEGACY); - coex_sta->crc_ok_11n = btcoexist->btc_phydm_query_PHY_counter( - btcoexist, PHYDM_INFO_CRC32_OK_HT); - coex_sta->crc_ok_11n_vht = btcoexist->btc_phydm_query_PHY_counter( - btcoexist, PHYDM_INFO_CRC32_OK_VHT); - - coex_sta->crc_err_cck = btcoexist->btc_phydm_query_PHY_counter( - btcoexist, PHYDM_INFO_CRC32_ERROR_CCK); - coex_sta->crc_err_11g = btcoexist->btc_phydm_query_PHY_counter( - btcoexist, PHYDM_INFO_CRC32_ERROR_LEGACY); - coex_sta->crc_err_11n = btcoexist->btc_phydm_query_PHY_counter( - btcoexist, PHYDM_INFO_CRC32_ERROR_HT); - coex_sta->crc_err_11n_vht = btcoexist->btc_phydm_query_PHY_counter( - btcoexist, PHYDM_INFO_CRC32_ERROR_VHT); - - cck_cnt = coex_sta->crc_ok_cck + coex_sta->crc_err_cck; - - if (cck_cnt > 250) { - if (wl_noisy_count2 < 3) - wl_noisy_count2++; - - if (wl_noisy_count2 == 3) { - wl_noisy_count0 = 0; - wl_noisy_count1 = 0; - } - } else if (cck_cnt < 50) { - if (wl_noisy_count0 < 3) - wl_noisy_count0++; - - if (wl_noisy_count0 == 3) { - wl_noisy_count1 = 0; - wl_noisy_count2 = 0; - } - } else { - if (wl_noisy_count1 < 3) - wl_noisy_count1++; - - if (wl_noisy_count1 == 3) { - wl_noisy_count0 = 0; - wl_noisy_count2 = 0; - } - } - - if (wl_noisy_count2 == 3) - coex_sta->wl_noisy_level = 2; - else if (wl_noisy_count1 == 3) - coex_sta->wl_noisy_level = 1; - else - coex_sta->wl_noisy_level = 0; - - if ((wifi_busy) && (wifi_rssi >= 30) && (!wifi_under_b_mode)) { - total_cnt = coex_sta->crc_ok_cck + coex_sta->crc_ok_11g + - coex_sta->crc_ok_11n + coex_sta->crc_ok_11n_vht; - - if ((coex_dm->bt_status == BT_8723D_1ANT_BT_STATUS_ACL_BUSY) || - (coex_dm->bt_status == BT_8723D_1ANT_BT_STATUS_ACL_SCO_BUSY) || - (coex_dm->bt_status == BT_8723D_1ANT_BT_STATUS_SCO_BUSY)) { - if (coex_sta->crc_ok_cck > (total_cnt - - coex_sta->crc_ok_cck)) { - if (cck_lock_counter < 3) - cck_lock_counter++; - } else { - if (cck_lock_counter > 0) - cck_lock_counter--; - } - - } else { - if (cck_lock_counter > 0) - cck_lock_counter--; - } - } else { - if (cck_lock_counter > 0) - cck_lock_counter--; - } - - if (!coex_sta->pre_ccklock) { - - if (cck_lock_counter >= 3) - coex_sta->cck_lock = true; - else - coex_sta->cck_lock = false; - } else { - if (cck_lock_counter == 0) - coex_sta->cck_lock = false; - else - coex_sta->cck_lock = true; - } - - if (coex_sta->cck_lock) - coex_sta->cck_ever_lock = true; - - coex_sta->pre_ccklock = coex_sta->cck_lock; - -#endif -} - -boolean halbtc8723d1ant_is_wifibt_status_changed(IN struct btc_coexist - *btcoexist) -{ - static boolean pre_wifi_busy = false, pre_under_4way = false, - pre_bt_hs_on = false, pre_bt_off = false, pre_bt_slave = false; - static u8 pre_hid_busy_num = 0, pre_wl_noisy_level = 0; - boolean wifi_busy = false, under_4way = false, bt_hs_on = false; - boolean wifi_connected = false; - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS, - &under_4way); - - if (coex_sta->bt_disabled != pre_bt_off) { - pre_bt_off = coex_sta->bt_disabled; - - if (coex_sta->bt_disabled) - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT is disabled !!\n"); - else - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT is enabled !!\n"); - - BTC_TRACE(trace_buf); - - coex_sta->bt_coex_supported_feature = 0; - coex_sta->bt_coex_supported_version = 0; - coex_sta->bt_ble_scan_type = 0; - coex_sta->bt_ble_scan_para[0] = 0; - coex_sta->bt_ble_scan_para[1] = 0; - coex_sta->bt_ble_scan_para[2] = 0; - coex_sta->bt_reg_vendor_ac = 0xffff; - coex_sta->bt_reg_vendor_ae = 0xffff; - return true; - } - - if (wifi_connected) { - if (wifi_busy != pre_wifi_busy) { - pre_wifi_busy = wifi_busy; - return true; - } - if (under_4way != pre_under_4way) { - pre_under_4way = under_4way; - return true; - } - if (bt_hs_on != pre_bt_hs_on) { - pre_bt_hs_on = bt_hs_on; - return true; - } - if (coex_sta->wl_noisy_level != pre_wl_noisy_level) { - pre_wl_noisy_level = coex_sta->wl_noisy_level; - return true; - } - } - - if (!coex_sta->bt_disabled) { - if (coex_sta->hid_busy_num != pre_hid_busy_num) { - pre_hid_busy_num = coex_sta->hid_busy_num; - return true; - } - } - - if (bt_link_info->slave_role != pre_bt_slave) { - pre_bt_slave = bt_link_info->slave_role; - return true; - } - - return false; -} - -void halbtc8723d1ant_update_bt_link_info(IN struct btc_coexist *btcoexist) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - boolean bt_hs_on = false; - boolean bt_busy = false; - - coex_sta->num_of_profile = 0; - - /* set link exist status */ - if (!(coex_sta->bt_info & BT_INFO_8723D_1ANT_B_CONNECTION)) { - coex_sta->bt_link_exist = false; - coex_sta->pan_exist = false; - coex_sta->a2dp_exist = false; - coex_sta->hid_exist = false; - coex_sta->sco_exist = false; - } else { /* connection exists */ - coex_sta->bt_link_exist = true; - if (coex_sta->bt_info & BT_INFO_8723D_1ANT_B_FTP) { - coex_sta->pan_exist = true; - coex_sta->num_of_profile++; - } else - coex_sta->pan_exist = false; - - if (coex_sta->bt_info & BT_INFO_8723D_1ANT_B_A2DP) { - coex_sta->a2dp_exist = true; - coex_sta->num_of_profile++; - } else - coex_sta->a2dp_exist = false; - - if (coex_sta->bt_info & BT_INFO_8723D_1ANT_B_HID) { - coex_sta->hid_exist = true; - coex_sta->num_of_profile++; - } else - coex_sta->hid_exist = false; - - if (coex_sta->bt_info & BT_INFO_8723D_1ANT_B_SCO_ESCO) { - coex_sta->sco_exist = true; - coex_sta->num_of_profile++; - } else - coex_sta->sco_exist = false; - - } - - btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); - - bt_link_info->bt_link_exist = coex_sta->bt_link_exist; - bt_link_info->sco_exist = coex_sta->sco_exist; - bt_link_info->a2dp_exist = coex_sta->a2dp_exist; - bt_link_info->pan_exist = coex_sta->pan_exist; - bt_link_info->hid_exist = coex_sta->hid_exist; - bt_link_info->acl_busy = coex_sta->acl_busy; - - /* work around for HS mode. */ - if (bt_hs_on) { - bt_link_info->pan_exist = true; - bt_link_info->bt_link_exist = true; - } - - /* check if Sco only */ - if (bt_link_info->sco_exist && - !bt_link_info->a2dp_exist && - !bt_link_info->pan_exist && - !bt_link_info->hid_exist) - bt_link_info->sco_only = true; - else - bt_link_info->sco_only = false; - - /* check if A2dp only */ - if (!bt_link_info->sco_exist && - bt_link_info->a2dp_exist && - !bt_link_info->pan_exist && - !bt_link_info->hid_exist) - bt_link_info->a2dp_only = true; - else - bt_link_info->a2dp_only = false; - - /* check if Pan only */ - if (!bt_link_info->sco_exist && - !bt_link_info->a2dp_exist && - bt_link_info->pan_exist && - !bt_link_info->hid_exist) - bt_link_info->pan_only = true; - else - bt_link_info->pan_only = false; - - /* check if Hid only */ - if (!bt_link_info->sco_exist && - !bt_link_info->a2dp_exist && - !bt_link_info->pan_exist && - bt_link_info->hid_exist) - bt_link_info->hid_only = true; - else - bt_link_info->hid_only = false; - - if (coex_sta->bt_info & BT_INFO_8723D_1ANT_B_INQ_PAGE) { - coex_dm->bt_status = BT_8723D_1ANT_BT_STATUS_INQ_PAGE; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), BT Inq/page!!!\n"); - } else if (!(coex_sta->bt_info & BT_INFO_8723D_1ANT_B_CONNECTION)) { - coex_dm->bt_status = BT_8723D_1ANT_BT_STATUS_NON_CONNECTED_IDLE; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), BT Non-Connected idle!!!\n"); - } else if (coex_sta->bt_info == BT_INFO_8723D_1ANT_B_CONNECTION) { - /* connection exists but no busy */ - coex_dm->bt_status = BT_8723D_1ANT_BT_STATUS_CONNECTED_IDLE; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), BT Connected-idle!!!\n"); - } else if (((coex_sta->bt_info & BT_INFO_8723D_1ANT_B_SCO_ESCO) || - (coex_sta->bt_info & BT_INFO_8723D_1ANT_B_SCO_BUSY)) && - (coex_sta->bt_info & BT_INFO_8723D_1ANT_B_ACL_BUSY)) { - coex_dm->bt_status = BT_8723D_1ANT_BT_STATUS_ACL_SCO_BUSY; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), BT ACL SCO busy!!!\n"); - } else if ((coex_sta->bt_info & BT_INFO_8723D_1ANT_B_SCO_ESCO) || - (coex_sta->bt_info & BT_INFO_8723D_1ANT_B_SCO_BUSY)) { - coex_dm->bt_status = BT_8723D_1ANT_BT_STATUS_SCO_BUSY; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), BT SCO busy!!!\n"); - } else if (coex_sta->bt_info & BT_INFO_8723D_1ANT_B_ACL_BUSY) { - coex_dm->bt_status = BT_8723D_1ANT_BT_STATUS_ACL_BUSY; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), BT ACL busy!!!\n"); - } else { - coex_dm->bt_status = BT_8723D_1ANT_BT_STATUS_MAX; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), BT Non-Defined state!!!\n"); - } - - BTC_TRACE(trace_buf); - - if ((BT_8723D_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) || - (BT_8723D_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) || - (BT_8723D_1ANT_BT_STATUS_ACL_SCO_BUSY == coex_dm->bt_status)) - bt_busy = true; - else - bt_busy = false; - - btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bt_busy); -} - -void halbtc8723d1ant_update_wifi_channel_info(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - u8 h2c_parameter[3] = {0}; - u32 wifi_bw; - u8 wifi_central_chnl; - - /* only 2.4G we need to inform bt the chnl mask */ - btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_CENTRAL_CHNL, - &wifi_central_chnl); - if ((BTC_MEDIA_CONNECT == type) && - (wifi_central_chnl <= 14)) { - h2c_parameter[0] = - 0x1; /* enable BT AFH skip WL channel for 8723d because BT Rx LO interference */ - /* h2c_parameter[0] = 0x0; */ - h2c_parameter[1] = wifi_central_chnl; - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw); - if (BTC_WIFI_BW_HT40 == wifi_bw) - h2c_parameter[2] = 0x30; - else - h2c_parameter[2] = 0x20; - } - - coex_dm->wifi_chnl_info[0] = h2c_parameter[0]; - coex_dm->wifi_chnl_info[1] = h2c_parameter[1]; - coex_dm->wifi_chnl_info[2] = h2c_parameter[2]; - - btcoexist->btc_fill_h2c(btcoexist, 0x66, 3, h2c_parameter); - -} - -u8 halbtc8723d1ant_action_algorithm(IN struct btc_coexist *btcoexist) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - boolean bt_hs_on = false; - u8 algorithm = BT_8723D_1ANT_COEX_ALGO_UNDEFINED; - u8 num_of_diff_profile = 0; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); - - if (!bt_link_info->bt_link_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], No BT link exists!!!\n"); - BTC_TRACE(trace_buf); - return algorithm; - } - - if (bt_link_info->sco_exist) - num_of_diff_profile++; - if (bt_link_info->hid_exist) - num_of_diff_profile++; - if (bt_link_info->pan_exist) - num_of_diff_profile++; - if (bt_link_info->a2dp_exist) - num_of_diff_profile++; - - if (num_of_diff_profile == 1) { - if (bt_link_info->sco_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = SCO only\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8723D_1ANT_COEX_ALGO_SCO; - } else { - if (bt_link_info->hid_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = HID only\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8723D_1ANT_COEX_ALGO_HID; - } else if (bt_link_info->a2dp_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = A2DP only\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8723D_1ANT_COEX_ALGO_A2DP; - } else if (bt_link_info->pan_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = PAN(HS) only\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8723D_1ANT_COEX_ALGO_PANHS; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = PAN(EDR) only\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8723D_1ANT_COEX_ALGO_PANEDR; - } - } - } - } else if (num_of_diff_profile == 2) { - if (bt_link_info->sco_exist) { - if (bt_link_info->hid_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = SCO + HID\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8723D_1ANT_COEX_ALGO_HID; - } else if (bt_link_info->a2dp_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = SCO + A2DP ==> SCO\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8723D_1ANT_COEX_ALGO_SCO; - } else if (bt_link_info->pan_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = SCO + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8723D_1ANT_COEX_ALGO_SCO; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = SCO + PAN(EDR)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8723D_1ANT_COEX_ALGO_PANEDR_HID; - } - } - } else { - if (bt_link_info->hid_exist && - bt_link_info->a2dp_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = HID + A2DP\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8723D_1ANT_COEX_ALGO_HID_A2DP; - } else if (bt_link_info->hid_exist && - bt_link_info->pan_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = HID + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8723D_1ANT_COEX_ALGO_HID_A2DP; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = HID + PAN(EDR)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8723D_1ANT_COEX_ALGO_PANEDR_HID; - } - } else if (bt_link_info->pan_exist && - bt_link_info->a2dp_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = A2DP + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8723D_1ANT_COEX_ALGO_A2DP_PANHS; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = A2DP + PAN(EDR)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8723D_1ANT_COEX_ALGO_PANEDR_A2DP; - } - } - } - } else if (num_of_diff_profile == 3) { - if (bt_link_info->sco_exist) { - if (bt_link_info->hid_exist && - bt_link_info->a2dp_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = SCO + HID + A2DP ==> HID\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8723D_1ANT_COEX_ALGO_HID; - } else if (bt_link_info->hid_exist && - bt_link_info->pan_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = SCO + HID + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8723D_1ANT_COEX_ALGO_HID_A2DP; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = SCO + HID + PAN(EDR)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8723D_1ANT_COEX_ALGO_PANEDR_HID; - } - } else if (bt_link_info->pan_exist && - bt_link_info->a2dp_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = SCO + A2DP + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8723D_1ANT_COEX_ALGO_SCO; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = SCO + A2DP + PAN(EDR) ==> HID\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8723D_1ANT_COEX_ALGO_PANEDR_HID; - } - } - } else { - if (bt_link_info->hid_exist && - bt_link_info->pan_exist && - bt_link_info->a2dp_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = HID + A2DP + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8723D_1ANT_COEX_ALGO_HID_A2DP; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = HID + A2DP + PAN(EDR)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8723D_1ANT_COEX_ALGO_HID_A2DP_PANEDR; - } - } - } - } else if (num_of_diff_profile >= 3) { - if (bt_link_info->sco_exist) { - if (bt_link_info->hid_exist && - bt_link_info->pan_exist && - bt_link_info->a2dp_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Error!!! BT Profile = SCO + HID + A2DP + PAN(HS)\n"); - BTC_TRACE(trace_buf); - - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = SCO + HID + A2DP + PAN(EDR)==>PAN(EDR)+HID\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8723D_1ANT_COEX_ALGO_PANEDR_HID; - } - } - } - } - - return algorithm; -} - -void halbtc8723d1ant_set_bt_auto_report(IN struct btc_coexist *btcoexist, - IN boolean enable_auto_report) -{ - u8 h2c_parameter[1] = {0}; - - h2c_parameter[0] = 0; - - if (enable_auto_report) - h2c_parameter[0] |= BIT(0); - - btcoexist->btc_fill_h2c(btcoexist, 0x68, 1, h2c_parameter); -} - -void halbtc8723d1ant_bt_auto_report(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean enable_auto_report) -{ - coex_dm->cur_bt_auto_report = enable_auto_report; - - if (!force_exec) { - if (coex_dm->pre_bt_auto_report == coex_dm->cur_bt_auto_report) - return; - } - halbtc8723d1ant_set_bt_auto_report(btcoexist, - coex_dm->cur_bt_auto_report); - - coex_dm->pre_bt_auto_report = coex_dm->cur_bt_auto_report; -} - -void halbtc8723d1ant_set_fw_low_penalty_ra(IN struct btc_coexist - *btcoexist, IN boolean low_penalty_ra) -{ -#if 1 - u8 h2c_parameter[6] = {0}; - - h2c_parameter[0] = 0x6; /* op_code, 0x6= Retry_Penalty */ - - if (low_penalty_ra) { - h2c_parameter[1] |= BIT(0); - h2c_parameter[2] = - 0x00; /* normal rate except MCS7/6/5, OFDM54/48/36 */ - h2c_parameter[3] = 0xf7; /* MCS7 or OFDM54 */ - h2c_parameter[4] = 0xf8; /* MCS6 or OFDM48 */ - h2c_parameter[5] = 0xf9; /* MCS5 or OFDM36 */ - } - - btcoexist->btc_fill_h2c(btcoexist, 0x69, 6, h2c_parameter); -#endif -} - -void halbtc8723d1ant_low_penalty_ra(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean low_penalty_ra) -{ -#if 1 - coex_dm->cur_low_penalty_ra = low_penalty_ra; - - if (!force_exec) { - if (coex_dm->pre_low_penalty_ra == coex_dm->cur_low_penalty_ra) - return; - } - - halbtc8723d1ant_set_fw_low_penalty_ra(btcoexist, - coex_dm->cur_low_penalty_ra); - - coex_dm->pre_low_penalty_ra = coex_dm->cur_low_penalty_ra; -} - -void halbtc8723d1ant_write_score_board( - IN struct btc_coexist *btcoexist, - IN u16 bitpos, - IN boolean state -) -{ - - static u16 originalval = 0x8002; - - if (state) - originalval = originalval | bitpos; - else - originalval = originalval & (~bitpos); - - btcoexist->btc_write_2byte(btcoexist, 0xaa, originalval); - -} - -void halbtc8723d1ant_read_score_board( - IN struct btc_coexist *btcoexist, - IN u16 *score_board_val -) -{ - - *score_board_val = (btcoexist->btc_read_2byte(btcoexist, - 0xaa)) & 0x7fff; -} - -void halbtc8723d1ant_post_state_to_bt( - IN struct btc_coexist *btcoexist, - IN u16 type, - IN boolean state -) -{ - halbtc8723d1ant_write_score_board(btcoexist, (u16) type, state); -} - -void halbtc8723d1ant_monitor_bt_enable_disable(IN struct btc_coexist *btcoexist) -{ - static u32 bt_disable_cnt = 0; - boolean bt_active = true, bt_disabled = false; - u16 u16tmp; - - /* This function check if bt is disabled */ - /* Read BT on/off status from scoreboard[1], enable this only if BT patch support this feature */ - halbtc8723d1ant_read_score_board(btcoexist, &u16tmp); - - bt_active = u16tmp & BIT(1); - - if (bt_active) { - bt_disable_cnt = 0; - bt_disabled = false; - btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_DISABLE, - &bt_disabled); - } else { - - bt_disable_cnt++; - if (bt_disable_cnt >= 2) { - bt_disabled = true; - bt_disable_cnt = 2; - } - - btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_DISABLE, - &bt_disabled); - } - - if (bt_disabled) - halbtc8723d1ant_low_penalty_ra(btcoexist, NORMAL_EXEC, false); - else - halbtc8723d1ant_low_penalty_ra(btcoexist, NORMAL_EXEC, true); - - if (coex_sta->bt_disabled != bt_disabled) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT is from %s to %s!!\n", - (coex_sta->bt_disabled ? "disabled" : "enabled"), - (bt_disabled ? "disabled" : "enabled")); - BTC_TRACE(trace_buf); - coex_sta->bt_disabled = bt_disabled; - } - -} - -void halbtc8723d1ant_enable_gnt_to_gpio(IN struct btc_coexist *btcoexist, - boolean isenable) -{ -#if BT_8723D_1ANT_COEX_DBG - if (isenable) { - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x73, 0x8, 0x1); - - /* enable GNT_BT to GPIO debug */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4e, 0x40, 0x0); - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, 0x1, 0x0); - - /* 0x48[20] = 0 for GPIO14 = GNT_WL*/ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4a, 0x10, 0x0); - /* 0x40[17] = 0 for GPIO14 = GNT_WL*/ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x42, 0x02, 0x0); - - /* 0x66[9] = 0 for GPIO15 = GNT_B T*/ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, 0x02, 0x0); - /* 0x66[7] = 0 - for GPIO15 = GNT_BT*/ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x66, 0x80, 0x0); - /* 0x8[8] = 0 for GPIO15 = GNT_BT*/ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x9, 0x1, 0x0); - - /* BT Vendor Reg 0x76[0] = 0 for GPIO15 = GNT_BT, this is not set here*/ - } else { - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x73, 0x8, 0x0); - - /* Disable GNT_BT debug to GPIO, and enable chip_wakeup_host */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4e, 0x40, 0x1); - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, 0x1, 0x1); - - /* 0x48[20] = 0 for GPIO14 = GNT_WL*/ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4a, 0x10, 0x1); - } - -#endif -} - -u32 halbtc8723d1ant_ltecoex_indirect_read_reg(IN struct btc_coexist *btcoexist, - IN u16 reg_addr) -{ - u32 j = 0; - - /* wait for ready bit before access 0x7c0 */ - btcoexist->btc_write_4byte(btcoexist, 0x7c0, 0x800F0000 | reg_addr); - - do { - j++; - } while (((btcoexist->btc_read_1byte(btcoexist, - 0x7c3)&BIT(5)) == 0) && - (j < BT_8723D_1ANT_LTECOEX_INDIRECTREG_ACCESS_TIMEOUT)); - - return btcoexist->btc_read_4byte(btcoexist, - 0x7c8); /* get read data */ - -} - -void halbtc8723d1ant_ltecoex_indirect_write_reg(IN struct btc_coexist - *btcoexist, - IN u16 reg_addr, IN u32 bit_mask, IN u32 reg_value) -{ - u32 val, i = 0, j = 0, bitpos = 0; - - if (bit_mask == 0x0) - return; - if (bit_mask == 0xffffffff) { - btcoexist->btc_write_4byte(btcoexist, 0x7c4, - reg_value); /* put write data */ - - /* wait for ready bit before access 0x7c0 */ - do { - j++; - } while (((btcoexist->btc_read_1byte(btcoexist, - 0x7c3)&BIT(5)) == 0) && - (j < BT_8723D_1ANT_LTECOEX_INDIRECTREG_ACCESS_TIMEOUT)); - - btcoexist->btc_write_4byte(btcoexist, 0x7c0, - 0xc00F0000 | reg_addr); - } else { - for (i = 0; i <= 31; i++) { - if (((bit_mask >> i) & 0x1) == 0x1) { - bitpos = i; - break; - } - } - - /* read back register value before write */ - val = halbtc8723d1ant_ltecoex_indirect_read_reg(btcoexist, - reg_addr); - val = (val & (~bit_mask)) | (reg_value << bitpos); - - btcoexist->btc_write_4byte(btcoexist, 0x7c4, - val); /* put write data */ - - /* wait for ready bit before access 0x7c0 */ - do { - j++; - } while (((btcoexist->btc_read_1byte(btcoexist, - 0x7c3)&BIT(5)) == 0) && - (j < BT_8723D_1ANT_LTECOEX_INDIRECTREG_ACCESS_TIMEOUT)); - - btcoexist->btc_write_4byte(btcoexist, 0x7c0, - 0xc00F0000 | reg_addr); - - } - -} - -void halbtc8723d1ant_ltecoex_enable(IN struct btc_coexist *btcoexist, - IN boolean enable) -{ - u8 val; - - val = (enable) ? 1 : 0; - halbtc8723d1ant_ltecoex_indirect_write_reg(btcoexist, 0x38, 0x80, - val); /* 0x38[7] */ - -} - -void halbtc8723d1ant_ltecoex_pathcontrol_owner(IN struct btc_coexist *btcoexist, - IN boolean wifi_control) -{ - u8 val; - - val = (wifi_control) ? 1 : 0; - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x73, 0x4, - val); /* 0x70[26] */ - -} - -void halbtc8723d1ant_ltecoex_set_gnt_bt(IN struct btc_coexist *btcoexist, - IN u8 control_block, IN boolean sw_control, IN u8 state) -{ - u32 val = 0, val_orig = 0; - - if (!sw_control) - val = 0x0; - else if (state & 0x1) - val = 0x3; - else - val = 0x1; - - val_orig = halbtc8723d1ant_ltecoex_indirect_read_reg(btcoexist, - 0x38); - - switch (control_block) { - case BT_8723D_1ANT_GNT_BLOCK_RFC_BB: - default: - val = ((val << 14) | (val << 10)) | (val_orig & 0xffff33ff); - break; - case BT_8723D_1ANT_GNT_BLOCK_RFC: - val = (val << 14) | (val_orig & 0xffff3fff); - break; - case BT_8723D_1ANT_GNT_BLOCK_BB: - val = (val << 10) | (val_orig & 0xfffff3ff); - break; - } - - halbtc8723d1ant_ltecoex_indirect_write_reg(btcoexist, - 0x38, 0xffffffff, val); -} - -void halbtc8723d1ant_ltecoex_set_gnt_wl(IN struct btc_coexist *btcoexist, - IN u8 control_block, IN boolean sw_control, IN u8 state) -{ - u32 val = 0, val_orig = 0; - - if (!sw_control) - val = 0x0; - else if (state & 0x1) - val = 0x3; - else - val = 0x1; - - val_orig = halbtc8723d1ant_ltecoex_indirect_read_reg(btcoexist, - 0x38); - - switch (control_block) { - case BT_8723D_1ANT_GNT_BLOCK_RFC_BB: - default: - val = ((val << 12) | (val << 8)) | (val_orig & 0xffffccff); - break; - case BT_8723D_1ANT_GNT_BLOCK_RFC: - val = (val << 12) | (val_orig & 0xffffcfff); - break; - case BT_8723D_1ANT_GNT_BLOCK_BB: - val = (val << 8) | (val_orig & 0xfffffcff); - break; - } - - halbtc8723d1ant_ltecoex_indirect_write_reg(btcoexist, 0x38, - 0xffffffff, val); -} - -void halbtc8723d1ant_ltecoex_set_coex_table(IN struct btc_coexist *btcoexist, - IN u8 table_type, IN u16 table_content) -{ - u16 reg_addr = 0x0000; - - switch (table_type) { - case BT_8723D_1ANT_CTT_WL_VS_LTE: - reg_addr = 0xa0; - break; - case BT_8723D_1ANT_CTT_BT_VS_LTE: - reg_addr = 0xa4; - break; - } - - if (reg_addr != 0x0000) - halbtc8723d1ant_ltecoex_indirect_write_reg(btcoexist, reg_addr, - 0xffff, table_content); /* 0xa0[15:0] or 0xa4[15:0] */ - -} - -void halbtc8723d1ant_ltecoex_set_break_table(IN struct btc_coexist *btcoexist, - IN u8 table_type, IN u8 table_content) -{ - u16 reg_addr = 0x0000; - - switch (table_type) { - case BT_8723D_1ANT_LBTT_WL_BREAK_LTE: - reg_addr = 0xa8; - break; - case BT_8723D_1ANT_LBTT_BT_BREAK_LTE: - reg_addr = 0xac; - break; - case BT_8723D_1ANT_LBTT_LTE_BREAK_WL: - reg_addr = 0xb0; - break; - case BT_8723D_1ANT_LBTT_LTE_BREAK_BT: - reg_addr = 0xb4; - break; - } - - if (reg_addr != 0x0000) - halbtc8723d1ant_ltecoex_indirect_write_reg(btcoexist, reg_addr, - 0xff, table_content); /* 0xa8[15:0] or 0xb4[15:0] */ - -} - -void halbtc8723d1ant_set_wltoggle_coex_table(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 interval, - IN u8 val0x6c4_b0, IN u8 val0x6c4_b1, IN u8 val0x6c4_b2, - IN u8 val0x6c4_b3) -{ - static u8 pre_h2c_parameter[6] = {0}; - u8 cur_h2c_parameter[6] = {0}; - u8 i, match_cnt = 0; - - cur_h2c_parameter[0] = 0x7; /* op_code, 0x7= wlan toggle slot*/ - - cur_h2c_parameter[1] = interval; - cur_h2c_parameter[2] = val0x6c4_b0; - cur_h2c_parameter[3] = val0x6c4_b1; - cur_h2c_parameter[4] = val0x6c4_b2; - cur_h2c_parameter[5] = val0x6c4_b3; - - if (!force_exec) { - for (i = 1; i <= 5; i++) { - if (cur_h2c_parameter[i] != pre_h2c_parameter[i]) - break; - - match_cnt++; - } - - if (match_cnt == 5) - return; - } - - for (i = 1; i <= 5; i++) - pre_h2c_parameter[i] = cur_h2c_parameter[i]; - - btcoexist->btc_fill_h2c(btcoexist, 0x69, 6, cur_h2c_parameter); -} - -void halbtc8723d1ant_set_coex_table(IN struct btc_coexist *btcoexist, - IN u32 val0x6c0, IN u32 val0x6c4, IN u32 val0x6c8, IN u8 val0x6cc) -{ - btcoexist->btc_write_4byte(btcoexist, 0x6c0, val0x6c0); - - btcoexist->btc_write_4byte(btcoexist, 0x6c4, val0x6c4); - - btcoexist->btc_write_4byte(btcoexist, 0x6c8, val0x6c8); - - btcoexist->btc_write_1byte(btcoexist, 0x6cc, val0x6cc); -} - -void halbtc8723d1ant_coex_table(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u32 val0x6c0, IN u32 val0x6c4, - IN u32 val0x6c8, IN u8 val0x6cc) -{ - coex_dm->cur_val0x6c0 = val0x6c0; - coex_dm->cur_val0x6c4 = val0x6c4; - coex_dm->cur_val0x6c8 = val0x6c8; - coex_dm->cur_val0x6cc = val0x6cc; - - if (!force_exec) { - if ((coex_dm->pre_val0x6c0 == coex_dm->cur_val0x6c0) && - (coex_dm->pre_val0x6c4 == coex_dm->cur_val0x6c4) && - (coex_dm->pre_val0x6c8 == coex_dm->cur_val0x6c8) && - (coex_dm->pre_val0x6cc == coex_dm->cur_val0x6cc)) - return; - } - - halbtc8723d1ant_set_coex_table(btcoexist, val0x6c0, val0x6c4, val0x6c8, - val0x6cc); - - coex_dm->pre_val0x6c0 = coex_dm->cur_val0x6c0; - coex_dm->pre_val0x6c4 = coex_dm->cur_val0x6c4; - coex_dm->pre_val0x6c8 = coex_dm->cur_val0x6c8; - coex_dm->pre_val0x6cc = coex_dm->cur_val0x6cc; -} - -void halbtc8723d1ant_coex_table_with_type(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 type) -{ - u32 break_table; - u8 select_table; - - coex_sta->coex_table_type = type; - - if (coex_sta->concurrent_rx_mode_on == true) { - break_table = 0xf0ffffff; /* set WL hi-pri can break BT */ - select_table = - 0xb; /* set Tx response = Hi-Pri (ex: Transmitting ACK,BA,CTS) */ - } else { - break_table = 0xffffff; - select_table = 0x3; - } - - switch (type) { - case 0: - halbtc8723d1ant_coex_table(btcoexist, force_exec, - 0x55555555, 0x55555555, break_table, - select_table); - break; - case 1: - halbtc8723d1ant_coex_table(btcoexist, force_exec, - 0x55555555, 0x5a5a5a5a, break_table, - select_table); - break; - case 2: - halbtc8723d1ant_coex_table(btcoexist, force_exec, - 0xaa5a5a5a, 0xaa5a5a5a, break_table, - select_table); - break; - case 3: - halbtc8723d1ant_coex_table(btcoexist, force_exec, - 0xaa555555, 0xaa5a5a5a, break_table, - select_table); - break; - case 4: - halbtc8723d1ant_coex_table(btcoexist, force_exec, - 0xa5555555, 0x5a5a5a5a, break_table, - select_table); - break; - case 5: - halbtc8723d1ant_coex_table(btcoexist, force_exec, - 0x5a5a5a5a, 0x5a5a5a5a, break_table, - select_table); - break; - case 6: - halbtc8723d1ant_coex_table(btcoexist, force_exec, - 0xa5555555, 0x5a5a5a5a, break_table, - select_table); - break; - case 7: - halbtc8723d1ant_coex_table(btcoexist, force_exec, - 0xaaaaaaaa, 0xaaaaaaaa, break_table, - select_table); - break; - case 8: - halbtc8723d1ant_coex_table(btcoexist, force_exec, - 0xa5555555, 0xaaaaaaaa, break_table, - select_table); - break; - case 9: - halbtc8723d1ant_coex_table(btcoexist, force_exec, - 0x5a5a5a5a, 0xaaaa5aaa, break_table, - select_table); - break; - default: - break; - } -} - -void halbtc8723d1ant_set_fw_ignore_wlan_act(IN struct btc_coexist *btcoexist, - IN boolean enable) -{ - u8 h2c_parameter[1] = {0}; - - if (enable) { - h2c_parameter[0] |= BIT(0); /* function enable */ - } - - btcoexist->btc_fill_h2c(btcoexist, 0x63, 1, h2c_parameter); -} - -void halbtc8723d1ant_ignore_wlan_act(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean enable) -{ - coex_dm->cur_ignore_wlan_act = enable; - - if (!force_exec) { - if (coex_dm->pre_ignore_wlan_act == - coex_dm->cur_ignore_wlan_act) - return; - } - halbtc8723d1ant_set_fw_ignore_wlan_act(btcoexist, enable); - - coex_dm->pre_ignore_wlan_act = coex_dm->cur_ignore_wlan_act; -} - -void halbtc8723d1ant_set_lps_rpwm(IN struct btc_coexist *btcoexist, - IN u8 lps_val, IN u8 rpwm_val) -{ - u8 lps = lps_val; - u8 rpwm = rpwm_val; - - btcoexist->btc_set(btcoexist, BTC_SET_U1_LPS_VAL, &lps); - btcoexist->btc_set(btcoexist, BTC_SET_U1_RPWM_VAL, &rpwm); -} - -void halbtc8723d1ant_lps_rpwm(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 lps_val, IN u8 rpwm_val) -{ - coex_dm->cur_lps = lps_val; - coex_dm->cur_rpwm = rpwm_val; - - if (!force_exec) { - if ((coex_dm->pre_lps == coex_dm->cur_lps) && - (coex_dm->pre_rpwm == coex_dm->cur_rpwm)) - return; - } - halbtc8723d1ant_set_lps_rpwm(btcoexist, lps_val, rpwm_val); - - coex_dm->pre_lps = coex_dm->cur_lps; - coex_dm->pre_rpwm = coex_dm->cur_rpwm; -} - -void halbtc8723d1ant_ps_tdma_check_for_power_save_state( - IN struct btc_coexist *btcoexist, IN boolean new_ps_state) -{ - u8 lps_mode = 0x0; - u8 h2c_parameter[5] = {0x8, 0, 0, 0, 0}; - - btcoexist->btc_get(btcoexist, BTC_GET_U1_LPS_MODE, &lps_mode); - - if (lps_mode) { /* already under LPS state */ - if (new_ps_state) { - /* keep state under LPS, do nothing. */ - } else { - /* will leave LPS state, turn off psTdma first */ - /*halbtc8723d1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, - 8); */ - btcoexist->btc_fill_h2c(btcoexist, 0x60, 5, - h2c_parameter); - } - } else { /* NO PS state */ - if (new_ps_state) { - /* will enter LPS state, turn off psTdma first */ - /*halbtc8723d1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, - 8);*/ - btcoexist->btc_fill_h2c(btcoexist, 0x60, 5, - h2c_parameter); - } else { - /* keep state under NO PS state, do nothing. */ - } - } -} - -void halbtc8723d1ant_power_save_state(IN struct btc_coexist *btcoexist, - IN u8 ps_type, IN u8 lps_val, IN u8 rpwm_val) -{ - boolean low_pwr_disable = false; - - switch (ps_type) { - case BTC_PS_WIFI_NATIVE: - /* recover to original 32k low power setting */ - coex_sta->force_lps_on = false; - low_pwr_disable = false; - btcoexist->btc_set(btcoexist, - BTC_SET_ACT_DISABLE_LOW_POWER, - &low_pwr_disable); - btcoexist->btc_set(btcoexist, BTC_SET_ACT_NORMAL_LPS, - NULL); - - break; - case BTC_PS_LPS_ON: - coex_sta->force_lps_on = true; - halbtc8723d1ant_ps_tdma_check_for_power_save_state( - btcoexist, true); - halbtc8723d1ant_lps_rpwm(btcoexist, NORMAL_EXEC, - lps_val, rpwm_val); - /* when coex force to enter LPS, do not enter 32k low power. */ - low_pwr_disable = true; - btcoexist->btc_set(btcoexist, - BTC_SET_ACT_DISABLE_LOW_POWER, - &low_pwr_disable); - /* power save must executed before psTdma. */ - btcoexist->btc_set(btcoexist, BTC_SET_ACT_ENTER_LPS, - NULL); - - break; - case BTC_PS_LPS_OFF: - coex_sta->force_lps_on = false; - halbtc8723d1ant_ps_tdma_check_for_power_save_state( - btcoexist, false); - btcoexist->btc_set(btcoexist, BTC_SET_ACT_LEAVE_LPS, - NULL); - - break; - default: - break; - } -} - -void halbtc8723d1ant_set_fw_pstdma(IN struct btc_coexist *btcoexist, - IN u8 byte1, IN u8 byte2, IN u8 byte3, IN u8 byte4, IN u8 byte5) -{ - u8 h2c_parameter[5] = {0}; - u8 real_byte1 = byte1, real_byte5 = byte5; - boolean ap_enable = false; - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - - if (byte5 & BIT(2)) - coex_sta->is_tdma_btautoslot = true; - else - coex_sta->is_tdma_btautoslot = false; - - /* release bt-auto slot for auto-slot hang is detected!! */ - if (coex_sta->is_tdma_btautoslot) - if ((coex_sta->is_tdma_btautoslot_hang) || - (bt_link_info->slave_role)) - byte5 = byte5 & 0xfb; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, - &ap_enable); - - if (ap_enable) { - if (byte1 & BIT(4) && !(byte1 & BIT(5))) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], FW for AP mode\n"); - BTC_TRACE(trace_buf); - real_byte1 &= ~BIT(4); - real_byte1 |= BIT(5); - - real_byte5 |= BIT(5); - real_byte5 &= ~BIT(6); - - halbtc8723d1ant_power_save_state(btcoexist, - BTC_PS_WIFI_NATIVE, 0x0, - 0x0); - } - } else if (byte1 & BIT(4) && !(byte1 & BIT(5))) { - - halbtc8723d1ant_power_save_state( - btcoexist, BTC_PS_LPS_ON, 0x50, - 0x4); - } else { - halbtc8723d1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, - 0x0, - 0x0); - } - - h2c_parameter[0] = real_byte1; - h2c_parameter[1] = byte2; - h2c_parameter[2] = byte3; - h2c_parameter[3] = byte4; - h2c_parameter[4] = real_byte5; - - coex_dm->ps_tdma_para[0] = real_byte1; - coex_dm->ps_tdma_para[1] = byte2; - coex_dm->ps_tdma_para[2] = byte3; - coex_dm->ps_tdma_para[3] = byte4; - coex_dm->ps_tdma_para[4] = real_byte5; - - btcoexist->btc_fill_h2c(btcoexist, 0x60, 5, h2c_parameter); -} - -void halbtc8723d1ant_ps_tdma(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean turn_on, IN u8 type) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - struct btc_board_info *board_info = &btcoexist->board_info; - boolean wifi_busy = false; - static u8 psTdmaByte4Modify = 0x0, pre_psTdmaByte4Modify = 0x0; - static boolean pre_wifi_busy = false; - -#if BT_8723D_1ANT_ANTDET_ENABLE - - if (board_info->btdm_ant_num_by_ant_det == 2) { - } - -#endif - - coex_dm->cur_ps_tdma_on = turn_on; - coex_dm->cur_ps_tdma = type; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - - if (wifi_busy != pre_wifi_busy) { - force_exec = true; - pre_wifi_busy = wifi_busy; - } - - /* 0x778 = 0x1 at wifi slot (no blocking BT Low-Pri pkts) */ - if ((bt_link_info->slave_role) && (bt_link_info->a2dp_exist)) - psTdmaByte4Modify = 0x1; - else - psTdmaByte4Modify = 0x0; - - if (pre_psTdmaByte4Modify != psTdmaByte4Modify) { - - force_exec = true; - pre_psTdmaByte4Modify = psTdmaByte4Modify; - } - - if (!force_exec) { - if ((coex_dm->pre_ps_tdma_on == coex_dm->cur_ps_tdma_on) && - (coex_dm->pre_ps_tdma == coex_dm->cur_ps_tdma)) - return; - } - - if (coex_dm->cur_ps_tdma_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** TDMA(on, %d) **********\n", - coex_dm->cur_ps_tdma); - BTC_TRACE(trace_buf); - - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x550, 0x8, - 0x1); /* enable TBTT nterrupt */ - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** TDMA(off, %d) **********\n", - coex_dm->cur_ps_tdma); - BTC_TRACE(trace_buf); - } - - if (turn_on) { - switch (type) { - default: - halbtc8723d1ant_set_fw_pstdma(btcoexist, - 0x61, 0x35, 0x03, 0x11, 0x11); - break; - case 3: - halbtc8723d1ant_set_fw_pstdma(btcoexist, - 0x51, 0x3a, 0x03, 0x10, 0x50); - break; - case 4: - halbtc8723d1ant_set_fw_pstdma(btcoexist, - 0x51, 0x21, 0x03, 0x10, 0x50); - break; - case 5: - halbtc8723d1ant_set_fw_pstdma(btcoexist, - 0x61, 0x15, 0x03, 0x11, 0x11); - break; - case 6: - halbtc8723d1ant_set_fw_pstdma(btcoexist, - 0x61, 0x20, 0x03, 0x11, 0x11); - break; - case 7: - halbtc8723d1ant_set_fw_pstdma(btcoexist, - 0x51, 0x10, 0x03, 0x10, 0x54 | - psTdmaByte4Modify); - break; - case 8: - halbtc8723d1ant_set_fw_pstdma(btcoexist, - 0x51, 0x10, 0x03, 0x10, 0x54 | - psTdmaByte4Modify); - break; - case 9: - halbtc8723d1ant_set_fw_pstdma(btcoexist, - 0x55, 0x10, 0x03, 0x10, 0x54 | - psTdmaByte4Modify); - break; - case 10: - halbtc8723d1ant_set_fw_pstdma(btcoexist, - 0x61, 0x30, 0x03, 0x11, 0x10); - break; - case 11: - halbtc8723d1ant_set_fw_pstdma(btcoexist, - 0x65, 0x25, 0x03, 0x11, 0x11 | - psTdmaByte4Modify); - break; - case 12: - halbtc8723d1ant_set_fw_pstdma(btcoexist, - 0x55, 0x30, 0x03, 0x10, 0x50 | - psTdmaByte4Modify); - break; - case 13: - halbtc8723d1ant_set_fw_pstdma(btcoexist, - 0x51, 0x25, 0x03, 0x10, 0x50 | - psTdmaByte4Modify); - break; - case 14: - halbtc8723d1ant_set_fw_pstdma(btcoexist, - 0x51, 0x15, 0x03, 0x10, 0x50 | - psTdmaByte4Modify); - break; - case 15: - halbtc8723d1ant_set_fw_pstdma(btcoexist, - 0x51, 0x20, 0x03, 0x10, 0x50 | - psTdmaByte4Modify); - break; - case 16: - halbtc8723d1ant_set_fw_pstdma(btcoexist, - 0x61, 0x10, 0x03, 0x11, 0x15 | - psTdmaByte4Modify); - break; - case 17: - halbtc8723d1ant_set_fw_pstdma(btcoexist, - 0x61, 0x10, 0x03, 0x11, 0x14); - break; - case 18: - halbtc8723d1ant_set_fw_pstdma(btcoexist, - 0x51, 0x30, 0x03, 0x10, 0x50 | - psTdmaByte4Modify); - break; - case 19: - halbtc8723d1ant_set_fw_pstdma(btcoexist, - 0x61, 0x15, 0x03, 0x11, 0x10); - break; - case 20: - halbtc8723d1ant_set_fw_pstdma(btcoexist, - 0x61, 0x30, 0x03, 0x11, 0x10); - break; - case 21: - halbtc8723d1ant_set_fw_pstdma(btcoexist, - 0x61, 0x30, 0x03, 0x11, 0x10); - break; - case 22: - halbtc8723d1ant_set_fw_pstdma(btcoexist, - 0x61, 0x25, 0x03, 0x11, 0x10); - break; - case 23: - halbtc8723d1ant_set_fw_pstdma(btcoexist, - 0x61, 0x10, 0x03, 0x11, 0x10); - break; - case 32: - halbtc8723d1ant_set_fw_pstdma(btcoexist, - 0x61, 0x35, 0x03, 0x11, 0x11); - break; - case 33: - halbtc8723d1ant_set_fw_pstdma(btcoexist, - 0x61, 0x35, 0x03, 0x11, 0x10); - break; - case 57: - halbtc8723d1ant_set_fw_pstdma(btcoexist, - 0x51, 0x10, 0x03, 0x10, 0x50 | - psTdmaByte4Modify); - break; - case 58: - halbtc8723d1ant_set_fw_pstdma(btcoexist, - 0x51, 0x10, 0x03, 0x10, 0x50 | - psTdmaByte4Modify); - break; - case 67: - halbtc8723d1ant_set_fw_pstdma(btcoexist, - 0x61, 0x10, 0x03, 0x11, 0x10 | - psTdmaByte4Modify); - break; - /* 1-Ant to 2-Ant TDMA case */ - case 103: - halbtc8723d1ant_set_fw_pstdma(btcoexist, - 0xd3, 0x3a, 0x03, 0x70, 0x10); - break; - case 104: - halbtc8723d1ant_set_fw_pstdma(btcoexist, - 0xd3, 0x21, 0x03, 0x70, 0x10); - break; - case 105: - halbtc8723d1ant_set_fw_pstdma(btcoexist, - 0xe3, 0x15, 0x03, 0x71, 0x11); - break; - case 106: - halbtc8723d1ant_set_fw_pstdma(btcoexist, - 0xe3, 0x20, 0x03, 0x71, 0x11); - break; - case 107: - halbtc8723d1ant_set_fw_pstdma(btcoexist, - 0xd3, 0x10, 0x03, 0x70, 0x14 | - psTdmaByte4Modify); - break; - case 108: - halbtc8723d1ant_set_fw_pstdma(btcoexist, - 0xd3, 0x10, 0x03, 0x70, 0x14 | - psTdmaByte4Modify); - break; - case 113: - halbtc8723d1ant_set_fw_pstdma(btcoexist, - 0xd3, 0x25, 0x03, 0x70, 0x10 | - psTdmaByte4Modify); - break; - case 114: - halbtc8723d1ant_set_fw_pstdma(btcoexist, - 0xd3, 0x15, 0x03, 0x70, 0x10 | - psTdmaByte4Modify); - break; - case 115: - halbtc8723d1ant_set_fw_pstdma(btcoexist, - 0xd3, 0x20, 0x03, 0x70, 0x10 | - psTdmaByte4Modify); - break; - case 117: - halbtc8723d1ant_set_fw_pstdma(btcoexist, - 0xe3, 0x10, 0x03, 0x71, 0x14 | - psTdmaByte4Modify); - break; - case 119: - halbtc8723d1ant_set_fw_pstdma(btcoexist, - 0xe3, 0x15, 0x03, 0x71, 0x10); - break; - case 120: - halbtc8723d1ant_set_fw_pstdma(btcoexist, - 0xe3, 0x30, 0x03, 0x71, 0x10); - break; - case 121: - halbtc8723d1ant_set_fw_pstdma(btcoexist, - 0xe3, 0x30, 0x03, 0x71, 0x10); - break; - case 122: - halbtc8723d1ant_set_fw_pstdma(btcoexist, - 0xe3, 0x25, 0x03, 0x71, 0x10); - break; - case 132: - halbtc8723d1ant_set_fw_pstdma(btcoexist, - 0xe3, 0x35, 0x03, 0x71, 0x11); - break; - case 133: - halbtc8723d1ant_set_fw_pstdma(btcoexist, - 0xe3, 0x35, 0x03, 0x71, 0x10); - break; - } - } else { - - /* disable PS tdma */ - switch (type) { - case 8: /* PTA Control */ - halbtc8723d1ant_set_fw_pstdma(btcoexist, 0x8, - 0x0, 0x0, 0x0, 0x0); - break; - case 0: - default: /* Software control, Antenna at BT side */ - halbtc8723d1ant_set_fw_pstdma(btcoexist, 0x0, - 0x0, 0x0, 0x0, 0x0); - break; - case 1: /* 2-Ant, 0x778=3, antenna control by antenna diversity */ - halbtc8723d1ant_set_fw_pstdma(btcoexist, 0x0, - 0x0, 0x0, 0x48, 0x0); - break; - } - } - - /* update pre state */ - coex_dm->pre_ps_tdma_on = coex_dm->cur_ps_tdma_on; - coex_dm->pre_ps_tdma = coex_dm->cur_ps_tdma; -} - -void halbtc8723d1ant_set_ant_path(IN struct btc_coexist *btcoexist, - IN u8 ant_pos_type, IN boolean force_exec, - IN u8 phase) -{ - struct btc_board_info *board_info = &btcoexist->board_info; - u32 cnt_bt_cal_chk = 0; - boolean is_in_mp_mode = false, is_hw_ant_div_on = false; - u8 u8tmp0 = 0, u8tmp1 = 0; - u32 u32tmp1 = 0, u32tmp2 = 0, u32tmp3 = 0; - u16 u16tmp0, u16tmp1 = 0; - -#if BT_8723D_1ANT_ANTDET_ENABLE - - if (ant_pos_type == BTC_ANT_PATH_PTA) { - if ((board_info->btdm_ant_det_finish) && - (board_info->btdm_ant_num_by_ant_det == 2)) { - if (board_info->btdm_ant_pos == - BTC_ANTENNA_AT_MAIN_PORT) - ant_pos_type = BTC_ANT_PATH_WIFI; - else - ant_pos_type = BTC_ANT_PATH_BT; - } - } - -#endif - - u32tmp1 = halbtc8723d1ant_ltecoex_indirect_read_reg(btcoexist, - 0x38); - - /* To avoid indirect access fail */ - if (((u32tmp1 & 0xf000) >> 12) != ((u32tmp1 & 0x0f00) >> 8)) { - force_exec = true; - coex_sta->gnt_error_cnt++; - } - -#if BT_8723D_1ANT_COEX_DBG - u32tmp2 = halbtc8723d1ant_ltecoex_indirect_read_reg(btcoexist, 0x54); - u16tmp0 = btcoexist->btc_read_2byte(btcoexist, 0xaa); - u16tmp1 = btcoexist->btc_read_2byte(btcoexist, 0x948); - u8tmp1 = btcoexist->btc_read_1byte(btcoexist, 0x73); - u8tmp0 = btcoexist->btc_read_1byte(btcoexist, 0x67); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** 0x67 = 0x%x, 0x948 = 0x%x, 0x73 = 0x%x(Before Set Ant Pat)\n", - u8tmp0, u16tmp1, u8tmp1); - BTC_TRACE(trace_buf); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], **********0x38= 0x%x, 0x54= 0x%x, 0xaa = 0x%x(Before Set Ant Path)\n", - u32tmp1, u32tmp2, u16tmp0); - BTC_TRACE(trace_buf); -#endif - - coex_dm->cur_ant_pos_type = ant_pos_type; - - if (!force_exec) { - if (coex_dm->cur_ant_pos_type == coex_dm->pre_ant_pos_type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** Skip Antenna Path Setup because no change!!**********\n"); - BTC_TRACE(trace_buf); - return; - } - } - - coex_dm->pre_ant_pos_type = coex_dm->cur_ant_pos_type; - - switch (phase) { - case BT_8723D_1ANT_PHASE_COEX_POWERON: - /* Set Path control to WL */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, - 0x80, 0x0); - - /* set Path control owner to WL at initial step */ - halbtc8723d1ant_ltecoex_pathcontrol_owner(btcoexist, - BT_8723D_1ANT_PCO_BTSIDE); - - /* set GNT_BT to SW high */ - halbtc8723d1ant_ltecoex_set_gnt_bt(btcoexist, - BT_8723D_1ANT_GNT_BLOCK_RFC_BB, - BT_8723D_1ANT_GNT_TYPE_CTRL_BY_SW, - BT_8723D_1ANT_SIG_STA_SET_TO_HIGH); - /* Set GNT_WL to SW low */ - halbtc8723d1ant_ltecoex_set_gnt_wl(btcoexist, - BT_8723D_1ANT_GNT_BLOCK_RFC_BB, - BT_8723D_1ANT_GNT_TYPE_CTRL_BY_SW, - BT_8723D_1ANT_SIG_STA_SET_TO_HIGH); - - if (BTC_ANT_PATH_AUTO == ant_pos_type) - ant_pos_type = BTC_ANT_PATH_BT; - - coex_sta->run_time_state = false; - - break; - case BT_8723D_1ANT_PHASE_COEX_INIT: - /* Disable LTE Coex Function in WiFi side (this should be on if LTE coex is required) */ - halbtc8723d1ant_ltecoex_enable(btcoexist, 0x0); - - /* GNT_WL_LTE always = 1 (this should be config if LTE coex is required) */ - halbtc8723d1ant_ltecoex_set_coex_table(btcoexist, - BT_8723D_1ANT_CTT_WL_VS_LTE, 0xffff); - - /* GNT_BT_LTE always = 1 (this should be config if LTE coex is required) */ - halbtc8723d1ant_ltecoex_set_coex_table(btcoexist, - BT_8723D_1ANT_CTT_BT_VS_LTE, 0xffff); - - /* Wait If BT IQK running, because Path control owner is at BT during BT IQK (setup by WiFi firmware) */ - while (cnt_bt_cal_chk <= 20) { - u8tmp0 = btcoexist->btc_read_1byte(btcoexist, - 0x49d); - cnt_bt_cal_chk++; - if (u8tmp0 & BIT(0)) { - BTC_SPRINTF(trace_buf, - BT_TMP_BUF_SIZE, - "[BTCoex], ########### BT is calibrating (wait cnt=%d) ###########\n", - cnt_bt_cal_chk); - BTC_TRACE(trace_buf); - delay_ms(50); - } else { - BTC_SPRINTF(trace_buf, - BT_TMP_BUF_SIZE, - "[BTCoex], ********** WL is NOT calibrating (wait cnt=%d)**********\n", - cnt_bt_cal_chk); - BTC_TRACE(trace_buf); - break; - } - } - - /* Set Path control to WL */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, - 0x80, 0x1); - - /* set Path control owner to WL at initial step */ - halbtc8723d1ant_ltecoex_pathcontrol_owner(btcoexist, - BT_8723D_1ANT_PCO_WLSIDE); - - /* set GNT_BT to SW high */ - halbtc8723d1ant_ltecoex_set_gnt_bt(btcoexist, - BT_8723D_1ANT_GNT_BLOCK_RFC_BB, - BT_8723D_1ANT_GNT_TYPE_CTRL_BY_SW, - BT_8723D_1ANT_SIG_STA_SET_TO_HIGH); - /* Set GNT_WL to SW low */ - halbtc8723d1ant_ltecoex_set_gnt_wl(btcoexist, - BT_8723D_1ANT_GNT_BLOCK_RFC_BB, - BT_8723D_1ANT_GNT_TYPE_CTRL_BY_SW, - BT_8723D_1ANT_SIG_STA_SET_TO_HIGH); - - if (BTC_ANT_PATH_AUTO == ant_pos_type) - ant_pos_type = BTC_ANT_PATH_BT; - - coex_sta->run_time_state = false; - break; - case BT_8723D_1ANT_PHASE_WLANONLY_INIT: - /* Disable LTE Coex Function in WiFi side (this should be on if LTE coex is required) */ - halbtc8723d1ant_ltecoex_enable(btcoexist, 0x0); - - /* GNT_WL_LTE always = 1 (this should be config if LTE coex is required) */ - halbtc8723d1ant_ltecoex_set_coex_table(btcoexist, - BT_8723D_1ANT_CTT_WL_VS_LTE, 0xffff); - - /* GNT_BT_LTE always = 1 (this should be config if LTE coex is required) */ - halbtc8723d1ant_ltecoex_set_coex_table(btcoexist, - BT_8723D_1ANT_CTT_BT_VS_LTE, 0xffff); - - /* Set Path control to WL */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, - 0x80, 0x1); - - /* set Path control owner to WL at initial step */ - halbtc8723d1ant_ltecoex_pathcontrol_owner(btcoexist, - BT_8723D_1ANT_PCO_WLSIDE); - - /* set GNT_BT to SW low */ - halbtc8723d1ant_ltecoex_set_gnt_bt(btcoexist, - BT_8723D_1ANT_GNT_BLOCK_RFC_BB, - BT_8723D_1ANT_GNT_TYPE_CTRL_BY_SW, - BT_8723D_1ANT_SIG_STA_SET_TO_LOW); - /* Set GNT_WL to SW high */ - halbtc8723d1ant_ltecoex_set_gnt_wl(btcoexist, - BT_8723D_1ANT_GNT_BLOCK_RFC_BB, - BT_8723D_1ANT_GNT_TYPE_CTRL_BY_SW, - BT_8723D_1ANT_SIG_STA_SET_TO_HIGH); - - if (BTC_ANT_PATH_AUTO == ant_pos_type) - ant_pos_type = BTC_ANT_PATH_WIFI; - - coex_sta->run_time_state = false; - break; - case BT_8723D_1ANT_PHASE_WLAN_OFF: - /* Disable LTE Coex Function in WiFi side */ - halbtc8723d1ant_ltecoex_enable(btcoexist, 0x0); - - /* Set Path control to BT */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, - 0x80, 0x0); - - /* set Path control owner to BT */ - halbtc8723d1ant_ltecoex_pathcontrol_owner(btcoexist, - BT_8723D_1ANT_PCO_BTSIDE); - - if (BTC_ANT_PATH_AUTO == ant_pos_type) - ant_pos_type = BTC_ANT_PATH_BT; - - coex_sta->run_time_state = false; - break; - case BT_8723D_1ANT_PHASE_2G_RUNTIME: - - /* wait for WL/BT IQK finish, keep 0x38 = 0xff00 for WL IQK */ - while (cnt_bt_cal_chk <= 20) { - u8tmp0 = btcoexist->btc_read_1byte(btcoexist, - 0x1e6); - - u8tmp1 = btcoexist->btc_read_1byte(btcoexist, - 0x49d); - - cnt_bt_cal_chk++; - if ((u8tmp0 & BIT(0)) || (u8tmp1 & BIT(0))) { - BTC_SPRINTF(trace_buf, - BT_TMP_BUF_SIZE, - "[BTCoex], ########### WL or BT is IQK (wait cnt=%d)\n", - cnt_bt_cal_chk); - BTC_TRACE(trace_buf); - delay_ms(50); - } else { - BTC_SPRINTF(trace_buf, - BT_TMP_BUF_SIZE, - "[BTCoex], ********** WL and BT is NOT IQK (wait cnt=%d)\n", - cnt_bt_cal_chk); - BTC_TRACE(trace_buf); - break; - } - } - - /* Set Path control to WL */ - /* btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, 0x80, 0x1); */ - - halbtc8723d1ant_ltecoex_pathcontrol_owner(btcoexist, - BT_8723D_1ANT_PCO_WLSIDE); - - /* set GNT_BT to PTA */ - halbtc8723d1ant_ltecoex_set_gnt_bt(btcoexist, - BT_8723D_1ANT_GNT_BLOCK_RFC_BB, - BT_8723D_1ANT_GNT_TYPE_CTRL_BY_PTA, - BT_8723D_1ANT_SIG_STA_SET_BY_HW); - /* Set GNT_WL to PTA */ - halbtc8723d1ant_ltecoex_set_gnt_wl(btcoexist, - BT_8723D_1ANT_GNT_BLOCK_RFC_BB, - BT_8723D_1ANT_GNT_TYPE_CTRL_BY_PTA, - BT_8723D_1ANT_SIG_STA_SET_BY_HW); - - if (BTC_ANT_PATH_AUTO == ant_pos_type) - ant_pos_type = BTC_ANT_PATH_PTA; - - coex_sta->run_time_state = true; - break; - case BT_8723D_1ANT_PHASE_BTMPMODE: - halbtc8723d1ant_ltecoex_pathcontrol_owner(btcoexist, - BT_8723D_1ANT_PCO_WLSIDE); - - /* Set Path control to WL */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, - 0x80, 0x1); - - /* set GNT_BT to high */ - halbtc8723d1ant_ltecoex_set_gnt_bt(btcoexist, - BT_8723D_1ANT_GNT_BLOCK_RFC_BB, - BT_8723D_1ANT_GNT_TYPE_CTRL_BY_SW, - BT_8723D_1ANT_SIG_STA_SET_TO_HIGH); - /* Set GNT_WL to low */ - halbtc8723d1ant_ltecoex_set_gnt_wl(btcoexist, - BT_8723D_1ANT_GNT_BLOCK_RFC_BB, - BT_8723D_1ANT_GNT_TYPE_CTRL_BY_SW, - BT_8723D_1ANT_SIG_STA_SET_TO_LOW); - - if (BTC_ANT_PATH_AUTO == ant_pos_type) - ant_pos_type = BTC_ANT_PATH_BT; - - coex_sta->run_time_state = false; - break; - case BT_8723D_1ANT_PHASE_ANTENNA_DET: - halbtc8723d1ant_ltecoex_pathcontrol_owner(btcoexist, - BT_8723D_1ANT_PCO_WLSIDE); - - /* Set Path control to WL */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, - 0x80, 0x1); - - /* set GNT_BT to high */ - halbtc8723d1ant_ltecoex_set_gnt_bt(btcoexist, - BT_8723D_1ANT_GNT_BLOCK_RFC_BB, - BT_8723D_1ANT_GNT_TYPE_CTRL_BY_SW, - BT_8723D_1ANT_SIG_STA_SET_TO_HIGH); - /* Set GNT_WL to high */ - halbtc8723d1ant_ltecoex_set_gnt_wl(btcoexist, - BT_8723D_1ANT_GNT_BLOCK_RFC_BB, - BT_8723D_1ANT_GNT_TYPE_CTRL_BY_SW, - BT_8723D_1ANT_SIG_STA_SET_TO_HIGH); - - if (BTC_ANT_PATH_AUTO == ant_pos_type) - ant_pos_type = BTC_ANT_PATH_BT; - - coex_sta->run_time_state = false; - - break; - } - - is_hw_ant_div_on = board_info->ant_div_cfg; - - if ((is_hw_ant_div_on) && (phase != BT_8723D_1ANT_PHASE_ANTENNA_DET)) - - if (board_info->btdm_ant_pos == BTC_ANTENNA_AT_MAIN_PORT) - /* 0x948 = 0x200, 0x0 while antenna diversity */ - btcoexist->btc_write_2byte(btcoexist, 0x948, 0x100); - else /* 0x948 = 0x80, 0x0 while antenna diversity */ - btcoexist->btc_write_2byte(btcoexist, 0x948, 0x40); - - else if ((is_hw_ant_div_on == false) && - (phase != BT_8723D_1ANT_PHASE_WLAN_OFF)) { /* internal switch setting */ - - switch (ant_pos_type) { - - case BTC_ANT_PATH_WIFI: - if (board_info->btdm_ant_pos == - BTC_ANTENNA_AT_MAIN_PORT) - - btcoexist->btc_write_2byte( - btcoexist, 0x948, 0x0); - else - btcoexist->btc_write_2byte( - btcoexist, 0x948, 0x280); - - break; - case BTC_ANT_PATH_BT: - if (board_info->btdm_ant_pos == - BTC_ANTENNA_AT_MAIN_PORT) - - btcoexist->btc_write_2byte( - btcoexist, 0x948, 0x280); - else - btcoexist->btc_write_2byte( - btcoexist, 0x948, 0x0); - - break; - default: - case BTC_ANT_PATH_PTA: - if (board_info->btdm_ant_pos == - BTC_ANTENNA_AT_MAIN_PORT) - btcoexist->btc_write_2byte( - btcoexist, 0x948, - 0x200); - else - btcoexist->btc_write_2byte( - btcoexist, 0x948, 0x80); - break; - } - } - -#if BT_8723D_1ANT_COEX_DBG - u32tmp1 = halbtc8723d1ant_ltecoex_indirect_read_reg(btcoexist, 0x38); - u32tmp2 = halbtc8723d1ant_ltecoex_indirect_read_reg(btcoexist, 0x54); - u16tmp0 = btcoexist->btc_read_2byte(btcoexist, 0xaa); - u16tmp1 = btcoexist->btc_read_2byte(btcoexist, 0x948); - u8tmp1 = btcoexist->btc_read_1byte(btcoexist, 0x73); - u8tmp0 = btcoexist->btc_read_1byte(btcoexist, 0x67); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** 0x67 = 0x%x, 0x948 = 0x%x, 0x73 = 0x%x(After Set Ant Pat)\n", - u8tmp0, u16tmp1, u8tmp1); - BTC_TRACE(trace_buf); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], **********0x38= 0x%x, 0x54= 0x%x, 0xaa = 0x%x(After Set Ant Path)\n", - u32tmp1, u32tmp2, u16tmp0); - BTC_TRACE(trace_buf); -#endif - -} - -boolean halbtc8723d1ant_is_common_action(IN struct btc_coexist *btcoexist) -{ - boolean common = false, wifi_connected = false, wifi_busy = false; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - - if (!wifi_connected && - BT_8723D_1ANT_BT_STATUS_NON_CONNECTED_IDLE == - coex_dm->bt_status) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi non connected-idle + BT non connected-idle!!\n"); - BTC_TRACE(trace_buf); - common = true; - } else if (wifi_connected && - (BT_8723D_1ANT_BT_STATUS_NON_CONNECTED_IDLE == - coex_dm->bt_status)) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi connected + BT non connected-idle!!\n"); - BTC_TRACE(trace_buf); - common = true; - } else if (!wifi_connected && - (BT_8723D_1ANT_BT_STATUS_CONNECTED_IDLE == - coex_dm->bt_status)) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi non connected-idle + BT connected-idle!!\n"); - BTC_TRACE(trace_buf); - common = true; - } else if (wifi_connected && - (BT_8723D_1ANT_BT_STATUS_CONNECTED_IDLE == - coex_dm->bt_status)) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi connected + BT connected-idle!!\n"); - BTC_TRACE(trace_buf); - common = true; - } else if (!wifi_connected && - (BT_8723D_1ANT_BT_STATUS_CONNECTED_IDLE != - coex_dm->bt_status)) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi non connected-idle + BT Busy!!\n"); - BTC_TRACE(trace_buf); - common = true; - } else { - if (wifi_busy) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi Connected-Busy + BT Busy!!\n"); - BTC_TRACE(trace_buf); - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi Connected-Idle + BT Busy!!\n"); - BTC_TRACE(trace_buf); - } - - common = false; - } - - return common; -} - -/* ********************************************* - * - * Non-Software Coex Mechanism start - * - * ********************************************* */ -void halbtc8723d1ant_action_bt_whql_test(IN struct btc_coexist *btcoexist) -{ - halbtc8723d1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8); - halbtc8723d1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, NORMAL_EXEC, - BT_8723D_1ANT_PHASE_2G_RUNTIME); - halbtc8723d1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); -} - -void halbtc8723d1ant_action_bt_hs(IN struct btc_coexist *btcoexist) -{ - halbtc8723d1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 5); - halbtc8723d1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2); -} - -void halbtc8723d1ant_action_bt_relink(IN struct btc_coexist *btcoexist) -{ - halbtc8723d1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 5); - halbtc8723d1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1); - coex_sta->bt_relink_downcount = 2; -} - -void halbtc8723d1ant_action_bt_idle(IN struct btc_coexist *btcoexist) -{ - boolean wifi_busy = false; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - - if (!wifi_busy) { - halbtc8723d1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8); - halbtc8723d1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2); - } else { - /* if wl busy */ - if (BT_8723D_1ANT_BT_STATUS_NON_CONNECTED_IDLE == - coex_dm->bt_status) { - halbtc8723d1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 8); - - halbtc8723d1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 33); - } else { - halbtc8723d1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 8); - halbtc8723d1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32); - } -} - -} - -void halbtc8723d1ant_action_bt_inquiry(IN struct btc_coexist *btcoexist) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - boolean wifi_connected = false, wifi_busy = false, bt_busy = false; - boolean wifi_scan = false, wifi_link = false, wifi_roam = false; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bt_busy); - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &wifi_scan); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &wifi_link); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &wifi_roam); - - if ((coex_sta->bt_create_connection) && ((wifi_link) || (wifi_roam) - || (wifi_scan) || (wifi_busy) || (coex_sta->wifi_is_high_pri_task))) { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi link/roam/Scan/busy/hi-pri-task + BT Inq/Page!!\n"); - BTC_TRACE(trace_buf); - - halbtc8723d1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1); - - if ((bt_link_info->a2dp_exist) && (!bt_link_info->pan_exist)) - halbtc8723d1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 17); - else - halbtc8723d1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 33); - } else if ((!wifi_connected) && (!wifi_scan)) { - - halbtc8723d1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8); - - halbtc8723d1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - } else if (bt_link_info->pan_exist) { - - halbtc8723d1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 22); - - halbtc8723d1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); - - } else if (bt_link_info->a2dp_exist) { - - halbtc8723d1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 16); - - halbtc8723d1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); - } else { - - if ((wifi_link) || (wifi_roam) || (wifi_scan) || (wifi_busy) - || (coex_sta->wifi_is_high_pri_task)) - halbtc8723d1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 21); - else - halbtc8723d1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 23); - - halbtc8723d1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); - } -} - -void halbtc8723d1ant_action_bt_sco_hid_only_busy(IN struct btc_coexist - *btcoexist) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - boolean wifi_connected = false, wifi_busy = false; - u32 wifi_bw = 1; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, - &wifi_bw); - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - - if (bt_link_info->sco_exist) { - halbtc8723d1ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 5); - halbtc8723d1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 5); - } else if (coex_sta->hid_busy_num >= 2) { - /*for 4/18 hid */ - /* if 11bg mode */ - if (wifi_bw == 0) { - - halbtc8723d1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 6); - halbtc8723d1ant_set_wltoggle_coex_table(btcoexist, - NORMAL_EXEC, - 0x1, 0xaa, - 0x5a, 0xaa, - 0xaa); - halbtc8723d1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 11); - } else { - - if (wifi_busy) { - - halbtc8723d1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 6); - halbtc8723d1ant_set_wltoggle_coex_table(btcoexist, - NORMAL_EXEC, - 0x2, 0xaa, - 0x5a, 0xaa, - 0xaa); - halbtc8723d1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 11); - } else { - - halbtc8723d1ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 6); - halbtc8723d1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 3); - - } - } - } else { - halbtc8723d1ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 6); - halbtc8723d1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 3); - } -} - -void halbtc8723d1ant_action_wifi_only(IN struct btc_coexist *btcoexist) -{ - halbtc8723d1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 8); - halbtc8723d1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, FORCE_EXEC, - BT_8723D_1ANT_PHASE_2G_RUNTIME); - halbtc8723d1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 0); -} - -void halbtc8723d1ant_action_wifi_multi_port(IN struct btc_coexist *btcoexist) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - - halbtc8723d1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8); - halbtc8723d1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, NORMAL_EXEC, - BT_8723D_1ANT_PHASE_2G_RUNTIME); - - if (!bt_link_info->pan_exist) - halbtc8723d1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - else - halbtc8723d1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2); -} - -void halbtc8723d1ant_action_wifi_linkscan_process(IN struct btc_coexist - *btcoexist) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - - if (bt_link_info->pan_exist) { - - halbtc8723d1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 22); - - halbtc8723d1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); - - } else if (bt_link_info->a2dp_exist) { - - halbtc8723d1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 17); - - halbtc8723d1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); - } else { - - halbtc8723d1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 21); - - halbtc8723d1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); - } -} - -void halbtc8723d1ant_action_wifi_connected_bt_acl_busy(IN struct btc_coexist - *btcoexist) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - boolean wifi_busy = false, wifi_turbo = false; - u32 wifi_bw = 1; - - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM, &coex_sta->scan_ap_num); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "############# [BTCoex], scan_ap_num = %d, wl_noisy_level = %d\n", - coex_sta->scan_ap_num, coex_sta->wl_noisy_level); - BTC_TRACE(trace_buf); - -#if 1 - if ((wifi_busy) && (coex_sta->wl_noisy_level == 0)) - wifi_turbo = true; -#endif - - if ((coex_sta->bt_relink_downcount != 0) - && (!bt_link_info->pan_exist) && (wifi_busy)) { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "############# [BTCoex], BT Re-Link + A2DP + WL busy\n"); - BTC_TRACE(trace_buf); - - /*halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32);*/ - halbtc8723d1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8); - halbtc8723d1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - - } else if (bt_link_info->a2dp_only) { /* A2DP */ - if (!wifi_busy) { - halbtc8723d1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 32); - halbtc8723d1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 4); - } else { - - if (coex_sta->wl_noisy_level == 2) - halbtc8723d1ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 17); - else - halbtc8723d1ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 7); - - if (wifi_turbo) - halbtc8723d1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 8); - else - halbtc8723d1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 4); - } - } else if (((bt_link_info->a2dp_exist) && - (bt_link_info->pan_exist)) || - (bt_link_info->hid_exist && bt_link_info->a2dp_exist && - bt_link_info->pan_exist)) { /* A2DP+PAN(OPP,FTP), HID+A2DP+PAN(OPP,FTP) */ - - if ((bt_link_info->hid_exist) && (coex_sta->hid_busy_num >= 2)) { - halbtc8723d1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 6); - if (wifi_bw == 0) /* 11bg mode */ - halbtc8723d1ant_set_wltoggle_coex_table(btcoexist, - NORMAL_EXEC, - 0x1, 0xaa, - 0x5a, 0xaa, - 0xaa); - else - halbtc8723d1ant_set_wltoggle_coex_table(btcoexist, - NORMAL_EXEC, - 0x2, 0xaa, - 0x5a, 0xaa, - 0xaa); - halbtc8723d1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 12); - } else if (wifi_busy) { - if (((coex_sta->a2dp_bit_pool > 40) && - (coex_sta->a2dp_bit_pool < 255)) || - (!coex_sta->is_A2DP_3M)) - halbtc8723d1ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 15); - else if (wifi_turbo) - halbtc8723d1ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 18); - else - halbtc8723d1ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 13); - } else - halbtc8723d1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 14); - - if (bt_link_info->hid_exist) - halbtc8723d1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1); - else if (wifi_turbo) - halbtc8723d1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 8); - else - halbtc8723d1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 4); - } else if (bt_link_info->hid_exist && - bt_link_info->a2dp_exist) { /* HID+A2DP */ - - if ((wifi_busy) && (coex_sta->hid_busy_num >= 2)) { /*for 4/18 hid */ - halbtc8723d1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 6); - if (wifi_bw == 0) /* 11bg mode */ - halbtc8723d1ant_set_wltoggle_coex_table(btcoexist, - NORMAL_EXEC, - 0x1, 0xaa, - 0x5a, 0xaa, - 0xaa); - else - halbtc8723d1ant_set_wltoggle_coex_table(btcoexist, - NORMAL_EXEC, - 0x2, 0xaa, - 0x5a, 0xaa, - 0xaa); - halbtc8723d1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 9); - } else { - halbtc8723d1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 8); - halbtc8723d1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 1); - } - - } else if ((bt_link_info->pan_only) - || (bt_link_info->hid_exist && bt_link_info->pan_exist)) { - /* PAN(OPP,FTP), HID+PAN(OPP,FTP) */ - - if ((bt_link_info->hid_exist) && (bt_link_info->pan_exist) && - (coex_sta->hid_busy_num >= 2)) { - - halbtc8723d1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 6); - if (wifi_bw == 0) /* 11bg mode */ - halbtc8723d1ant_set_wltoggle_coex_table(btcoexist, - NORMAL_EXEC, - 0x1, 0xaa, - 0x5a, 0xaa, - 0xaa); - else - halbtc8723d1ant_set_wltoggle_coex_table(btcoexist, - NORMAL_EXEC, - 0x2, 0xaa, - 0x5a, 0xaa, - 0xaa); - halbtc8723d1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 12); - } else { - if (!wifi_busy) - halbtc8723d1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 4); - else - halbtc8723d1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 3); - - if (bt_link_info->hid_exist) - halbtc8723d1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1); - else if (wifi_turbo) - halbtc8723d1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 8); - else - halbtc8723d1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 4); - } - } else { - /* BT no-profile busy (0x9) */ - halbtc8723d1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 33); - halbtc8723d1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); - } -} - -void halbtc8723d1ant_action_wifi_not_connected(IN struct btc_coexist *btcoexist) -{ - /* tdma and coex table */ - halbtc8723d1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 8); - halbtc8723d1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, NORMAL_EXEC, - BT_8723D_1ANT_PHASE_2G_RUNTIME); - halbtc8723d1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); -} - -void halbtc8723d1ant_action_wifi_connected(IN struct btc_coexist *btcoexist) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - boolean wifi_busy = false; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], CoexForWifiConnect()===>\n"); - BTC_TRACE(trace_buf); - - halbtc8723d1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, - NORMAL_EXEC, - BT_8723D_1ANT_PHASE_2G_RUNTIME); - - if (BT_8723D_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) { - - if (bt_link_info->hid_only) /* HID only */ - halbtc8723d1ant_action_bt_sco_hid_only_busy(btcoexist); - else - halbtc8723d1ant_action_wifi_connected_bt_acl_busy(btcoexist); - - } else if ((BT_8723D_1ANT_BT_STATUS_SCO_BUSY == - coex_dm->bt_status) || - (BT_8723D_1ANT_BT_STATUS_ACL_SCO_BUSY == - coex_dm->bt_status)) { - halbtc8723d1ant_action_bt_sco_hid_only_busy(btcoexist); - } else - halbtc8723d1ant_action_bt_idle(btcoexist); -} - -void halbtc8723d1ant_run_sw_coexist_mechanism(IN struct btc_coexist *btcoexist) -{ - u8 algorithm = 0; - - algorithm = halbtc8723d1ant_action_algorithm(btcoexist); - coex_dm->cur_algorithm = algorithm; - - if (halbtc8723d1ant_is_common_action(btcoexist)) { - - } else { - switch (coex_dm->cur_algorithm) { - case BT_8723D_1ANT_COEX_ALGO_SCO: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action algorithm = SCO.\n"); - BTC_TRACE(trace_buf); - break; - case BT_8723D_1ANT_COEX_ALGO_HID: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action algorithm = HID.\n"); - BTC_TRACE(trace_buf); - break; - case BT_8723D_1ANT_COEX_ALGO_A2DP: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action algorithm = A2DP.\n"); - BTC_TRACE(trace_buf); - break; - case BT_8723D_1ANT_COEX_ALGO_A2DP_PANHS: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action algorithm = A2DP+PAN(HS).\n"); - BTC_TRACE(trace_buf); - break; - case BT_8723D_1ANT_COEX_ALGO_PANEDR: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action algorithm = PAN(EDR).\n"); - BTC_TRACE(trace_buf); - break; - case BT_8723D_1ANT_COEX_ALGO_PANHS: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action algorithm = HS mode.\n"); - BTC_TRACE(trace_buf); - break; - case BT_8723D_1ANT_COEX_ALGO_PANEDR_A2DP: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action algorithm = PAN+A2DP.\n"); - BTC_TRACE(trace_buf); - break; - case BT_8723D_1ANT_COEX_ALGO_PANEDR_HID: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action algorithm = PAN(EDR)+HID.\n"); - BTC_TRACE(trace_buf); - break; - case BT_8723D_1ANT_COEX_ALGO_HID_A2DP_PANEDR: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action algorithm = HID+A2DP+PAN.\n"); - BTC_TRACE(trace_buf); - break; - case BT_8723D_1ANT_COEX_ALGO_HID_A2DP: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action algorithm = HID+A2DP.\n"); - BTC_TRACE(trace_buf); - break; - default: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action algorithm = coexist All Off!!\n"); - BTC_TRACE(trace_buf); - break; - } - coex_dm->pre_algorithm = coex_dm->cur_algorithm; - } -} - -void halbtc8723d1ant_run_coexist_mechanism(IN struct btc_coexist *btcoexist) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - boolean wifi_connected = false, bt_hs_on = false; - boolean increase_scan_dev_num = false; - boolean bt_ctrl_agg_buf_size = false; - boolean miracast_plus_bt = false, wifi_under_5g = false; - u8 agg_buf_size = 5; - u32 wifi_link_status = 0; - u32 num_of_wifi_link = 0, wifi_bw; - u8 iot_peer = BTC_IOT_PEER_UNKNOWN; - boolean scan = false, link = false, roam = false, under_4way = false; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS, - &under_4way); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], RunCoexistMechanism()===>\n"); - BTC_TRACE(trace_buf); - - if (btcoexist->manual_control) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], RunCoexistMechanism(), return for Manual CTRL <===\n"); - BTC_TRACE(trace_buf); - return; - } - - if (btcoexist->stop_coex_dm) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], RunCoexistMechanism(), return for Stop Coex DM <===\n"); - BTC_TRACE(trace_buf); - return; - } - - if (coex_sta->under_ips) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], wifi is under IPS !!!\n"); - BTC_TRACE(trace_buf); - return; - } - - if (!coex_sta->run_time_state) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], return for run_time_state = false !!!\n"); - BTC_TRACE(trace_buf); - return; - } - - if (coex_sta->freeze_coexrun_by_btinfo) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), return for freeze_coexrun_by_btinfo\n"); - BTC_TRACE(trace_buf); - return; - } - - if (coex_sta->bt_whck_test) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT is under WHCK TEST!!!\n"); - BTC_TRACE(trace_buf); - halbtc8723d1ant_action_bt_whql_test(btcoexist); - return; - } - - if (coex_sta->bt_disabled) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT is disabled !!!\n"); - halbtc8723d1ant_action_wifi_only(btcoexist); - return; - } - - if (coex_sta->c2h_bt_inquiry_page) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT is under inquiry/page scan !!\n"); - BTC_TRACE(trace_buf); - halbtc8723d1ant_action_bt_inquiry(btcoexist); - return; - } - - if (coex_sta->is_setupLink) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT is re-link !!!\n"); - halbtc8723d1ant_action_bt_relink(btcoexist); - return; - } - - if ((BT_8723D_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) || - (BT_8723D_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) || - (BT_8723D_1ANT_BT_STATUS_ACL_SCO_BUSY == coex_dm->bt_status)) - increase_scan_dev_num = true; - - btcoexist->btc_set(btcoexist, BTC_SET_BL_INC_SCAN_DEV_NUM, - &increase_scan_dev_num); - - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS, - &wifi_link_status); - - num_of_wifi_link = wifi_link_status >> 16; - - if ((num_of_wifi_link >= 2) || - (wifi_link_status & WIFI_P2P_GO_CONNECTED)) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "############# [BTCoex], Multi-Port num_of_wifi_link = %d, wifi_link_status = 0x%x\n", - num_of_wifi_link, wifi_link_status); - BTC_TRACE(trace_buf); - - if (bt_link_info->bt_link_exist) - miracast_plus_bt = true; - else - miracast_plus_bt = false; - - btcoexist->btc_set(btcoexist, BTC_SET_BL_MIRACAST_PLUS_BT, - &miracast_plus_bt); - - halbtc8723d1ant_limited_rx(btcoexist, NORMAL_EXEC, false, - false, 0x5); - - if (scan || link || roam || under_4way) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], scan = %d, link = %d, roam = %d 4way = %d!!!\n", - scan, link, roam, under_4way); - BTC_TRACE(trace_buf); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], wifi is under linkscan process + Multi-Port !!\n"); - BTC_TRACE(trace_buf); - - halbtc8723d1ant_action_wifi_linkscan_process(btcoexist); - } else - halbtc8723d1ant_action_wifi_multi_port(btcoexist); - - return; - } else { - - miracast_plus_bt = false; - btcoexist->btc_set(btcoexist, BTC_SET_BL_MIRACAST_PLUS_BT, - &miracast_plus_bt); - } - - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - - if ((bt_link_info->bt_link_exist) && (wifi_connected)) { - - btcoexist->btc_get(btcoexist, BTC_GET_U1_IOT_PEER, &iot_peer); - - if (BTC_IOT_PEER_CISCO == iot_peer) { - - if (BTC_WIFI_BW_HT40 == wifi_bw) - halbtc8723d1ant_limited_rx(btcoexist, - NORMAL_EXEC, false, true, 0x10); - else - halbtc8723d1ant_limited_rx(btcoexist, - NORMAL_EXEC, false, true, 0x8); - } else - halbtc8723d1ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, - 0x5); - } - - halbtc8723d1ant_run_sw_coexist_mechanism( - btcoexist); /* just print debug message */ - - btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); - - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "############# [BTCoex], BT Is hs\n"); - BTC_TRACE(trace_buf); - halbtc8723d1ant_action_bt_hs(btcoexist); - return; - } - - if ((BT_8723D_1ANT_BT_STATUS_NON_CONNECTED_IDLE == - coex_dm->bt_status) || - (BT_8723D_1ANT_BT_STATUS_CONNECTED_IDLE == - coex_dm->bt_status)) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "############# [BTCoex], BT Is idle\n"); - BTC_TRACE(trace_buf); - halbtc8723d1ant_action_bt_idle(btcoexist); - return; - } - - if (scan || link || roam || under_4way) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], scan = %d, link = %d, roam = %d 4way = %d!!!\n", - scan, link, roam, under_4way); - BTC_TRACE(trace_buf); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], wifi is under linkscan process!!\n"); - BTC_TRACE(trace_buf); - - halbtc8723d1ant_action_wifi_linkscan_process(btcoexist); - } else if (wifi_connected) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], wifi is under connected!!\n"); - BTC_TRACE(trace_buf); - - halbtc8723d1ant_action_wifi_connected(btcoexist); - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], wifi is under not-connected!!\n"); - BTC_TRACE(trace_buf); - - halbtc8723d1ant_action_wifi_not_connected(btcoexist); - } -} - -void halbtc8723d1ant_init_coex_dm(IN struct btc_coexist *btcoexist) -{ - /* force to reset coex mechanism */ - halbtc8723d1ant_low_penalty_ra(btcoexist, NORMAL_EXEC, false); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Coex Mechanism Init!!\n"); - BTC_TRACE(trace_buf); - - coex_sta->pop_event_cnt = 0; - coex_sta->cnt_RemoteNameReq = 0; - coex_sta->cnt_ReInit = 0; - coex_sta->cnt_setupLink = 0; - coex_sta->cnt_IgnWlanAct = 0; - coex_sta->cnt_Page = 0; - coex_sta->cnt_RoleSwitch = 0; - - halbtc8723d1ant_query_bt_info(btcoexist); -} - -void halbtc8723d1ant_init_hw_config(IN struct btc_coexist *btcoexist, - IN boolean back_up, IN boolean wifi_only) -{ - u32 u32tmp1 = 0, u32tmp2 = 0; - u16 u16tmp1 = 0; - u8 u8tmp0 = 0, u8tmp1 = 0; - struct btc_board_info *board_info = &btcoexist->board_info; - u8 i = 0; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], 1Ant Init HW Config!!\n"); - BTC_TRACE(trace_buf); - -#if BT_8723D_1ANT_COEX_DBG - u32tmp1 = halbtc8723d1ant_ltecoex_indirect_read_reg(btcoexist, - 0x38); - u32tmp2 = halbtc8723d1ant_ltecoex_indirect_read_reg(btcoexist, - 0x54); - u16tmp1 = btcoexist->btc_read_2byte(btcoexist, 0x948); - u8tmp1 = btcoexist->btc_read_1byte(btcoexist, 0x73); - u8tmp0 = btcoexist->btc_read_1byte(btcoexist, 0x67); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** 0x67 = 0x%x, 0x948 = 0x%x, 0x73 = 0x%x(Before init_hw_config)\n", - u8tmp0, u16tmp1, u8tmp1); - BTC_TRACE(trace_buf); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], **********0x38= 0x%x, 0x54= 0x%x (Before init_hw_config)\n", - u32tmp1, u32tmp2); - BTC_TRACE(trace_buf); -#endif - - coex_sta->bt_coex_supported_feature = 0; - coex_sta->bt_coex_supported_version = 0; - coex_sta->bt_ble_scan_type = 0; - coex_sta->bt_ble_scan_para[0] = 0; - coex_sta->bt_ble_scan_para[1] = 0; - coex_sta->bt_ble_scan_para[2] = 0; - coex_sta->bt_reg_vendor_ac = 0xffff; - coex_sta->bt_reg_vendor_ae = 0xffff; - coex_sta->isolation_btween_wb = BT_8723D_1ANT_DEFAULT_ISOLATION; - coex_sta->gnt_error_cnt = 0; - coex_sta->bt_relink_downcount = 0; - - for (i = 0; i <= 9; i++) - coex_sta->bt_afh_map[i] = 0; - - /* 0xf0[15:12] --> Chip Cut information */ - coex_sta->cut_version = (btcoexist->btc_read_1byte(btcoexist, - 0xf1) & 0xf0) >> 4; - - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x550, 0x8, - 0x1); /* enable TBTT nterrupt */ - - /* BT report packet sample rate */ - btcoexist->btc_write_1byte(btcoexist, 0x790, 0x5); - - /* Init 0x778 = 0x1 for 1-Ant */ - btcoexist->btc_write_1byte(btcoexist, 0x778, 0x1); - - /* Enable PTA (3-wire function form BT side) */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x40, 0x20, 0x1); - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x41, 0x02, 0x1); - - /* Enable PTA (tx/rx signal form WiFi side) */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4c6, 0x10, 0x1); - - halbtc8723d1ant_enable_gnt_to_gpio(btcoexist, true); - - /* check if WL firmware download ok */ - if (btcoexist->btc_read_1byte(btcoexist, 0x80) == 0xc6) - halbtc8723d1ant_post_state_to_bt(btcoexist, - BT_8723D_1ANT_SCOREBOARD_ONOFF, true); - - /* PTA parameter */ - halbtc8723d1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 8); - - halbtc8723d1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 0); - - psd_scan->ant_det_is_ant_det_available = true; - - /* Antenna config */ - if (wifi_only) { - coex_sta->concurrent_rx_mode_on = false; - halbtc8723d1ant_set_ant_path(btcoexist, BTC_ANT_PATH_WIFI, - FORCE_EXEC, - BT_8723D_1ANT_PHASE_WLANONLY_INIT); - - btcoexist->stop_coex_dm = true; - } else { - /*Set BT polluted packet on for Tx rate adaptive not including Tx retry break by PTA, 0x45c[19] =1 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x45e, 0x8, 0x1); - - coex_sta->concurrent_rx_mode_on = true; - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x953, 0x2, 0x1); - /* RF 0x1[0] = 0->Set GNT_WL_RF_Rx always = 1 for con-current Rx */ - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0x1, 0x0); - halbtc8723d1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, - FORCE_EXEC, - BT_8723D_1ANT_PHASE_COEX_INIT); - - btcoexist->stop_coex_dm = false; - } - - if (board_info->btdm_ant_pos == BTC_ANTENNA_AT_MAIN_PORT) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** Single Antenna, Antenna at Main Port: S1**********\n"); - BTC_TRACE(trace_buf); - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** Single Antenna, Antenna at Aux Port: S0**********\n"); - BTC_TRACE(trace_buf); - } - -} - -u32 halbtc8723d1ant_psd_log2base(IN struct btc_coexist *btcoexist, IN u32 val) -{ - u8 j; - u32 tmp, tmp2, val_integerd_b = 0, tindex, shiftcount = 0; - u32 result, val_fractiond_b = 0, table_fraction[21] = {0, 432, 332, 274, 232, 200, - 174, 151, 132, 115, 100, 86, 74, 62, 51, 42, - 32, 23, 15, 7, 0 - }; - - if (val == 0) - return 0; - - tmp = val; - - while (1) { - if (tmp == 1) - break; - else { - tmp = (tmp >> 1); - shiftcount++; - } - } - - val_integerd_b = shiftcount + 1; - - tmp2 = 1; - for (j = 1; j <= val_integerd_b; j++) - tmp2 = tmp2 * 2; - - tmp = (val * 100) / tmp2; - tindex = tmp / 5; - - if (tindex > 20) - tindex = 20; - - val_fractiond_b = table_fraction[tindex]; - - result = val_integerd_b * 100 - val_fractiond_b; - - return result; - -} - -void halbtc8723d1ant_psd_show_antenna_detect_result(IN struct btc_coexist - *btcoexist) -{ - u8 *cli_buf = btcoexist->cli_buf; - struct btc_board_info *board_info = &btcoexist->board_info; - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n============[Antenna Detection info] ============\n"); - CL_PRINTF(cli_buf); - - if (psd_scan->ant_det_result == 12) { /* Get Ant Det from BT */ - - if (board_info->btdm_ant_num_by_ant_det == 1) - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %s (%d~%d)", - "Ant Det Result", "1-Antenna", - BT_8723D_1ANT_ANTDET_PSDTHRES_1ANT, - BT_8723D_1ANT_ANTDET_PSDTHRES_2ANT_GOODISOLATION); - else { - - if (psd_scan->ant_det_psd_scan_peak_val > - (BT_8723D_1ANT_ANTDET_PSDTHRES_2ANT_BADISOLATION) - * 100) - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %s (>%d)", - "Ant Det Result", "2-Antenna (Bad-Isolation)", - BT_8723D_1ANT_ANTDET_PSDTHRES_2ANT_BADISOLATION); - else - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %s (%d~%d)", - "Ant Det Result", "2-Antenna (Good-Isolation)", - BT_8723D_1ANT_ANTDET_PSDTHRES_2ANT_GOODISOLATION, - BT_8723D_1ANT_ANTDET_PSDTHRES_2ANT_BADISOLATION); - } - } else if (psd_scan->ant_det_result == 1) - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s (>%d)", - "Ant Det Result", "2-Antenna (Bad-Isolation)", - BT_8723D_1ANT_ANTDET_PSDTHRES_2ANT_BADISOLATION); - else if (psd_scan->ant_det_result == 2) - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s (%d~%d)", - "Ant Det Result", "2-Antenna (Good-Isolation)", - BT_8723D_1ANT_ANTDET_PSDTHRES_2ANT_GOODISOLATION - + psd_scan->ant_det_thres_offset, - BT_8723D_1ANT_ANTDET_PSDTHRES_2ANT_BADISOLATION); - else - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s (%d~%d)", - "Ant Det Result", "1-Antenna", - BT_8723D_1ANT_ANTDET_PSDTHRES_1ANT, - BT_8723D_1ANT_ANTDET_PSDTHRES_2ANT_GOODISOLATION - + psd_scan->ant_det_thres_offset); - - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s ", - "Antenna Detection Finish", - (board_info->btdm_ant_det_finish - ? "Yes" : "No")); - CL_PRINTF(cli_buf); - - switch (psd_scan->ant_det_result) { - case 0: - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "(BT is not available)"); - break; - case 1: /* 2-Ant bad-isolation */ - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "(BT is available)"); - break; - case 2: /* 2-Ant good-isolation */ - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "(BT is available)"); - break; - case 3: /* 1-Ant */ - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "(BT is available)"); - break; - case 4: - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "(Uncertainty result)"); - break; - case 5: - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "(Pre-Scan fai)"); - break; - case 6: - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "(WiFi is Scanning)"); - break; - case 7: - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "(BT is not idle)"); - break; - case 8: - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "(Abort by WiFi Scanning)"); - break; - case 9: - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "(Antenna Init is not ready)"); - break; - case 10: - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "(BT is Inquiry or page)"); - break; - case 11: - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "(BT is Disabled)"); - case 12: - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "(BT is available, result from BT"); - break; - } - CL_PRINTF(cli_buf); - - if (psd_scan->ant_det_result == 12) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d dB", - "PSD Scan Peak Value", - psd_scan->ant_det_psd_scan_peak_val / 100); - CL_PRINTF(cli_buf); - return; - } - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d", - "Ant Detect Total Count", psd_scan->ant_det_try_count); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d", - "Ant Detect Fail Count", psd_scan->ant_det_fail_count); - CL_PRINTF(cli_buf); - - if ((!board_info->btdm_ant_det_finish) && - (psd_scan->ant_det_result != 5)) - return; - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s", "BT Response", - (psd_scan->ant_det_result ? "ok" : "fail")); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d ms", "BT Tx Time", - psd_scan->ant_det_bt_tx_time); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d", "BT Tx Ch", - psd_scan->ant_det_bt_le_channel); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d", - "WiFi PSD Cent-Ch/Offset/Span", - psd_scan->real_cent_freq, psd_scan->real_offset, - psd_scan->real_span); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d dB", - "PSD Pre-Scan Peak Value", - psd_scan->ant_det_pre_psdscan_peak_val / 100); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s (<= %d)", - "PSD Pre-Scan result", - (psd_scan->ant_det_result != 5 ? "ok" : "fail"), - BT_8723D_1ANT_ANTDET_PSDTHRES_BACKGROUND - + psd_scan->ant_det_thres_offset); - CL_PRINTF(cli_buf); - - if (psd_scan->ant_det_result == 5) - return; - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s dB", - "PSD Scan Peak Value", psd_scan->ant_det_peak_val); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s MHz", - "PSD Scan Peak Freq", psd_scan->ant_det_peak_freq); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s", "TFBGA Package", - (board_info->tfbga_package) ? "Yes" : "No"); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d", - "PSD Threshold Offset", psd_scan->ant_det_thres_offset); - CL_PRINTF(cli_buf); - -} - -void halbtc8723d1ant_psd_showdata(IN struct btc_coexist *btcoexist) -{ - u8 *cli_buf = btcoexist->cli_buf; - u32 delta_freq_per_point; - u32 freq, freq1, freq2, n = 0, i = 0, j = 0, m = 0, psd_rep1, psd_rep2; - - if (psd_scan->ant_det_result == 12) - return; - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n\n============[PSD info] (%d)============\n", - psd_scan->psd_gen_count); - CL_PRINTF(cli_buf); - - if (psd_scan->psd_gen_count == 0) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n No data !!\n"); - CL_PRINTF(cli_buf); - return; - } - - if (psd_scan->psd_point == 0) - delta_freq_per_point = 0; - else - delta_freq_per_point = psd_scan->psd_band_width / - psd_scan->psd_point; - - /* if (psd_scan->is_psd_show_max_only) */ - if (0) { - psd_rep1 = psd_scan->psd_max_value / 100; - psd_rep2 = psd_scan->psd_max_value - psd_rep1 * 100; - - freq = ((psd_scan->real_cent_freq - 20) * 1000000 + - psd_scan->psd_max_value_point * delta_freq_per_point); - freq1 = freq / 1000000; - freq2 = freq / 1000 - freq1 * 1000; - - if (freq2 < 100) - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n Freq = %d.0%d MHz", - freq1, freq2); - else - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n Freq = %d.%d MHz", - freq1, freq2); - - if (psd_rep2 < 10) - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - ", Value = %d.0%d dB, (%d)\n", - psd_rep1, psd_rep2, psd_scan->psd_max_value); - else - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - ", Value = %d.%d dB, (%d)\n", - psd_rep1, psd_rep2, psd_scan->psd_max_value); - - CL_PRINTF(cli_buf); - } else { - m = psd_scan->psd_start_point; - n = psd_scan->psd_start_point; - i = 1; - j = 1; - - while (1) { - do { - freq = ((psd_scan->real_cent_freq - 20) * - 1000000 + m * - delta_freq_per_point); - freq1 = freq / 1000000; - freq2 = freq / 1000 - freq1 * 1000; - - if (i == 1) { - if (freq2 == 0) - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "\r\n Freq%6d.000", - freq1); - else if (freq2 < 100) - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "\r\n Freq%6d.0%2d", - freq1, - freq2); - else - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "\r\n Freq%6d.%3d", - freq1, - freq2); - } else if ((i % 8 == 0) || - (m == psd_scan->psd_stop_point)) { - if (freq2 == 0) - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "%6d.000\n", freq1); - else if (freq2 < 100) - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "%6d.0%2d\n", freq1, - freq2); - else - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "%6d.%3d\n", freq1, - freq2); - } else { - if (freq2 == 0) - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "%6d.000", freq1); - else if (freq2 < 100) - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "%6d.0%2d", freq1, - freq2); - else - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "%6d.%3d", freq1, - freq2); - } - - i++; - m++; - CL_PRINTF(cli_buf); - - } while ((i <= 8) && (m <= psd_scan->psd_stop_point)); - - do { - psd_rep1 = psd_scan->psd_report_max_hold[n] / - 100; - psd_rep2 = psd_scan->psd_report_max_hold[n] - - psd_rep1 * - 100; - - if (j == 1) { - if (psd_rep2 < 10) - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "\r\n Val %7d.0%d", - psd_rep1, - psd_rep2); - else - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "\r\n Val %7d.%d", - psd_rep1, - psd_rep2); - } else if ((j % 8 == 0) || - (n == psd_scan->psd_stop_point)) { - if (psd_rep2 < 10) - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "%7d.0%d\n", psd_rep1, - psd_rep2); - else - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "%7d.%d\n", psd_rep1, - psd_rep2); - } else { - if (psd_rep2 < 10) - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "%7d.0%d", psd_rep1, - psd_rep2); - else - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "%7d.%d", psd_rep1, - psd_rep2); - } - - j++; - n++; - CL_PRINTF(cli_buf); - - } while ((j <= 8) && (n <= psd_scan->psd_stop_point)); - - if ((m > psd_scan->psd_stop_point) || - (n > psd_scan->psd_stop_point)) - break; - else { - i = 1; - j = 1; - } - - } - } - -} - -void halbtc8723d1ant_psd_maxholddata(IN struct btc_coexist *btcoexist, - IN u32 gen_count) -{ - u32 i = 0; - u32 loop_i_max = 0, loop_val_max = 0; - - if (gen_count == 1) { - memcpy(psd_scan->psd_report_max_hold, - psd_scan->psd_report, - BT_8723D_1ANT_ANTDET_PSD_POINTS * sizeof(u32)); - } - - for (i = psd_scan->psd_start_point; - i <= psd_scan->psd_stop_point; i++) { - - /* update max-hold value at each freq point */ - if (psd_scan->psd_report[i] > psd_scan->psd_report_max_hold[i]) - psd_scan->psd_report_max_hold[i] = - psd_scan->psd_report[i]; - - /* search the max value in this seep */ - if (psd_scan->psd_report[i] > loop_val_max) { - loop_val_max = psd_scan->psd_report[i]; - loop_i_max = i; - } - } - - if (gen_count <= BT_8723D_1ANT_ANTDET_PSD_SWWEEPCOUNT) - psd_scan->psd_loop_max_value[gen_count - 1] = loop_val_max; -} - -32 halbtc8723d1ant_psd_getdata(IN struct btc_coexist *btcoexist, IN u32 point) -{ - /* reg 0x808[9:0]: FFT data x */ - /* reg 0x808[22]: 0-->1 to get 1 FFT data y */ - /* reg 0x8b4[15:0]: FFT data y report */ - - u32 val = 0, psd_report = 0; - int k = 0; - - val = btcoexist->btc_read_4byte(btcoexist, 0x808); - - val &= 0xffbffc00; - val |= point; - - btcoexist->btc_write_4byte(btcoexist, 0x808, val); - - val |= 0x00400000; - btcoexist->btc_write_4byte(btcoexist, 0x808, val); - - while (1) { - if (k++ > BT_8723D_1ANT_ANTDET_SWEEPPOINT_DELAY) - break; - } - - val = btcoexist->btc_read_4byte(btcoexist, 0x8b4); - - psd_report = val & 0x0000ffff; - - return psd_report; -} - -boolean halbtc8723d1ant_psd_sweep_point(IN struct btc_coexist *btcoexist, - IN u32 cent_freq, IN s32 offset, IN u32 span, IN u32 points, - IN u32 avgnum, IN u32 loopcnt) -{ - u32 i = 0, val = 0, n = 0, k = 0, j, point_index = 0; - u32 points1 = 0, psd_report = 0; - u32 start_p = 0, stop_p = 0, delta_freq_per_point = 156250; - u32 psd_center_freq = 20 * 10 ^ 6; - boolean outloop = false, scan , roam, is_sweep_ok = true; - u8 flag = 0; - u32 tmp = 0, u32tmp1 = 0; - u32 wifi_original_channel = 1; - u32 psd_sum = 0, avg_cnt = 0; - u32 i_max = 0, val_max = 0, val_max2 = 0; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx PSD Sweep Start!!\n"); - BTC_TRACE(trace_buf); - - do { - switch (flag) { - case 0: /* Get PSD parameters */ - default: - - psd_scan->psd_band_width = 40 * 1000000; - psd_scan->psd_point = points; - psd_scan->psd_start_base = points / 2; - psd_scan->psd_avg_num = avgnum; - psd_scan->real_cent_freq = cent_freq; - psd_scan->real_offset = offset; - psd_scan->real_span = span; - - points1 = psd_scan->psd_point; - delta_freq_per_point = psd_scan->psd_band_width / - psd_scan->psd_point; - - /* PSD point setup */ - val = btcoexist->btc_read_4byte(btcoexist, 0x808); - val &= 0xffff0fff; - - switch (psd_scan->psd_point) { - case 128: - val |= 0x0; - break; - case 256: - default: - val |= 0x00004000; - break; - case 512: - val |= 0x00008000; - break; - case 1024: - val |= 0x0000c000; - break; - } - - switch (psd_scan->psd_avg_num) { - case 1: - val |= 0x0; - break; - case 8: - val |= 0x00001000; - break; - case 16: - val |= 0x00002000; - break; - case 32: - default: - val |= 0x00003000; - break; - } - btcoexist->btc_write_4byte(btcoexist, 0x808, val); - - flag = 1; - break; - case 1: /* calculate the PSD point index from freq/offset/span */ - psd_center_freq = psd_scan->psd_band_width / 2 + - offset * (1000000); - - start_p = psd_scan->psd_start_base + (psd_center_freq - - span * (1000000) / 2) / delta_freq_per_point; - psd_scan->psd_start_point = start_p - - psd_scan->psd_start_base; - - stop_p = psd_scan->psd_start_base + (psd_center_freq + - span * (1000000) / 2) / delta_freq_per_point; - psd_scan->psd_stop_point = stop_p - - psd_scan->psd_start_base - 1; - - flag = 2; - break; - case 2: /* set RF channel/BW/Mode */ - - /* set 3-wire off */ - val = btcoexist->btc_read_4byte(btcoexist, 0x88c); - val |= 0x00300000; - btcoexist->btc_write_4byte(btcoexist, 0x88c, val); - - /* CCK off */ - val = btcoexist->btc_read_4byte(btcoexist, 0x800); - val &= 0xfeffffff; - btcoexist->btc_write_4byte(btcoexist, 0x800, val); - - /* Tx-pause on */ - btcoexist->btc_write_1byte(btcoexist, 0x522, 0x6f); - - /* store WiFi original channel */ - wifi_original_channel = btcoexist->btc_get_rf_reg( - btcoexist, BTC_RF_A, 0x18, 0x3ff); - - /* Set RF channel */ - if (cent_freq == 2484) - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, - 0x18, 0x3ff, 0xe); - else - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, - 0x18, 0x3ff, (cent_freq - 2412) / 5 + - 1); /* WiFi TRx Mask on */ - - /* save original RCK value */ - u32tmp1 = btcoexist->btc_get_rf_reg( - btcoexist, BTC_RF_A, 0x1d, 0xfffff); - - /* Enter debug mode */ - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0xde, - 0x2, 0x1); - - /* Set RF Rx filter corner */ - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1d, - 0xfffff, 0x2e); - - /* Set RF mode = Rx, RF Gain = 0x320a0 */ - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x0, - 0xfffff, 0x320a0); - - while (1) { - if (k++ > BT_8723D_1ANT_ANTDET_SWEEPPOINT_DELAY) - break; - } - flag = 3; - break; - case 3: - psd_scan->psd_gen_count = 0; - for (j = 1; j <= loopcnt; j++) { - - btcoexist->btc_get(btcoexist, - BTC_GET_BL_WIFI_SCAN, &scan); - btcoexist->btc_get(btcoexist, - BTC_GET_BL_WIFI_ROAM, &roam); - - if (scan || roam) { - is_sweep_ok = false; - break; - } - memset(psd_scan->psd_report, 0, - psd_scan->psd_point * sizeof(u32)); - start_p = psd_scan->psd_start_point + - psd_scan->psd_start_base; - stop_p = psd_scan->psd_stop_point + - psd_scan->psd_start_base + 1; - - i = start_p; - point_index = 0; - - while (i < stop_p) { - if (i >= points1) - psd_report = - halbtc8723d1ant_psd_getdata( - btcoexist, i - points1); - else - psd_report = - halbtc8723d1ant_psd_getdata( - btcoexist, i); - - if (psd_report == 0) - tmp = 0; - else - /* tmp = 20*log10((double)psd_report); */ - /* 20*log2(x)/log2(10), log2Base return theresult of the psd_report*100 */ - tmp = 6 * halbtc8723d1ant_psd_log2base( - btcoexist, psd_report); - - n = i - psd_scan->psd_start_base; - psd_scan->psd_report[n] = tmp; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "Point=%d, psd_dB_data = %d\n", - i, psd_scan->psd_report[n]); - BTC_TRACE(trace_buf); - - i++; - - } - - halbtc8723d1ant_psd_maxholddata(btcoexist, j); - - psd_scan->psd_gen_count = j; - - /*Accumulate Max PSD value in this loop if the value > threshold */ - if (psd_scan->psd_loop_max_value[j - 1] >= - 4000) { - psd_sum = psd_sum + - psd_scan->psd_loop_max_value[j - - 1]; - avg_cnt++; - } - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "Loop=%d, Max_dB_data = %d\n", - j, psd_scan->psd_loop_max_value[j - - 1]); - BTC_TRACE(trace_buf); - - } - - if (loopcnt == BT_8723D_1ANT_ANTDET_PSD_SWWEEPCOUNT) { - - /* search the Max Value between each-freq-point-max-hold value of all sweep*/ - for (i = 1; - i <= BT_8723D_1ANT_ANTDET_PSD_SWWEEPCOUNT; - i++) { - - if (i == 1) { - i_max = i; - val_max = psd_scan->psd_loop_max_value[i - - 1]; - val_max2 = - psd_scan->psd_loop_max_value[i - - 1]; - } else if ( - psd_scan->psd_loop_max_value[i - - 1] > val_max) { - val_max2 = val_max; - i_max = i; - val_max = psd_scan->psd_loop_max_value[i - - 1]; - } else if ( - psd_scan->psd_loop_max_value[i - - 1] > val_max2) - val_max2 = - psd_scan->psd_loop_max_value[i - - 1]; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "i = %d, val_hold= %d, val_max = %d, val_max2 = %d\n", - i, psd_scan->psd_loop_max_value[i - - 1], - val_max, val_max2); - - BTC_TRACE(trace_buf); - } - - psd_scan->psd_max_value_point = i_max; - psd_scan->psd_max_value = val_max; - psd_scan->psd_max_value2 = val_max2; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "val_max = %d, val_max2 = %d\n", - psd_scan->psd_max_value, - psd_scan->psd_max_value2); - BTC_TRACE(trace_buf); - } - - if (avg_cnt != 0) { - psd_scan->psd_avg_value = (psd_sum / avg_cnt); - if ((psd_sum % avg_cnt) >= (avg_cnt / 2)) - psd_scan->psd_avg_value++; - } else - psd_scan->psd_avg_value = 0; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "AvgLoop=%d, Avg_dB_data = %d\n", - avg_cnt, psd_scan->psd_avg_value); - BTC_TRACE(trace_buf); - - flag = 100; - break; - case 99: /* error */ - - outloop = true; - break; - case 100: /* recovery */ - - /* set 3-wire on */ - val = btcoexist->btc_read_4byte(btcoexist, 0x88c); - val &= 0xffcfffff; - btcoexist->btc_write_4byte(btcoexist, 0x88c, val); - - /* CCK on */ - val = btcoexist->btc_read_4byte(btcoexist, 0x800); - val |= 0x01000000; - btcoexist->btc_write_4byte(btcoexist, 0x800, val); - - /* Tx-pause off */ - btcoexist->btc_write_1byte(btcoexist, 0x522, 0x0); - - /* PSD off */ - val = btcoexist->btc_read_4byte(btcoexist, 0x808); - val &= 0xffbfffff; - btcoexist->btc_write_4byte(btcoexist, 0x808, val); - - /* restore RF Rx filter corner */ - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1d, - 0xfffff, u32tmp1); - - /* Exit debug mode */ - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0xde, - 0x2, 0x0); - - /* restore WiFi original channel */ - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x18, - 0x3ff, wifi_original_channel); - - outloop = true; - break; - - } - - } while (!outloop); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx PSD Sweep Stop!!\n"); - BTC_TRACE(trace_buf); - return is_sweep_ok; - -} - -boolean halbtc8723d1ant_psd_antenna_detection(IN struct btc_coexist - *btcoexist) -{ - u32 i = 0; - u32 wlpsd_cent_freq = 2484, wlpsd_span = 2; - s32 wlpsd_offset = -4; - u32 bt_tx_time, bt_le_channel; - u8 bt_le_ch[13] = {3, 6, 8, 11, 13, 16, 18, 21, 23, 26, 28, 31, 33}; - - u8 h2c_parameter[3] = {0}, u8tmpa, u8tmpb; - - u8 state = 0; - boolean outloop = false, bt_resp = false, ant_det_finish = false; - u32 freq, freq1, freq2, psd_rep1, psd_rep2, delta_freq_per_point, - u32tmp, u32tmp0, u32tmp1, u32tmp2 ; - struct btc_board_info *board_info = &btcoexist->board_info; - - memset(psd_scan->ant_det_peak_val, 0, 16 * sizeof(u8)); - memset(psd_scan->ant_det_peak_freq, 0, 16 * sizeof(u8)); - - psd_scan->ant_det_bt_tx_time = - BT_8723D_1ANT_ANTDET_BTTXTIME; /* 0.42ms*50 = 20ms (0.42ms = 1 PSD sweep) */ - psd_scan->ant_det_bt_le_channel = BT_8723D_1ANT_ANTDET_BTTXCHANNEL; - - bt_tx_time = psd_scan->ant_det_bt_tx_time; - bt_le_channel = psd_scan->ant_det_bt_le_channel; - - if (board_info->tfbga_package) /* for TFBGA */ - psd_scan->ant_det_thres_offset = 5; - else - psd_scan->ant_det_thres_offset = 0; - - do { - switch (state) { - case 0: - if (bt_le_channel == 39) - wlpsd_cent_freq = 2484; - else { - for (i = 1; i <= 13; i++) { - if (bt_le_ch[i - 1] == - bt_le_channel) { - wlpsd_cent_freq = 2412 - + (i - 1) * 5; - break; - } - } - - if (i == 14) { - - BTC_SPRINTF(trace_buf, - BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Abort!!, Invalid LE channel = %d\n ", - bt_le_channel); - BTC_TRACE(trace_buf); - outloop = true; - break; - } - } - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), BT_LETxTime=%d, BT_LECh = %d\n", - bt_tx_time, bt_le_channel); - BTC_TRACE(trace_buf); - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), wlpsd_cent_freq=%d, wlpsd_offset = %d, wlpsd_span = %d, wlpsd_sweep_count = %d\n", - wlpsd_cent_freq, - wlpsd_offset, - wlpsd_span, - BT_8723D_1ANT_ANTDET_PSD_SWWEEPCOUNT); - BTC_TRACE(trace_buf); - - state = 1; - break; - case 1: /* stop coex DM & set antenna path */ - /* Stop Coex DM */ - btcoexist->stop_coex_dm = true; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Stop Coex DM!!\n"); - BTC_TRACE(trace_buf); - - /* Set TDMA off, */ - halbtc8723d1ant_ps_tdma(btcoexist, FORCE_EXEC, - false, 0); - - /* Set coex table */ - halbtc8723d1ant_coex_table_with_type(btcoexist, - FORCE_EXEC, 0); - - if (board_info->btdm_ant_pos == - BTC_ANTENNA_AT_MAIN_PORT) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Antenna at Main Port\n"); - BTC_TRACE(trace_buf); - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Antenna at Aux Port\n"); - BTC_TRACE(trace_buf); - } - - /* Set Antenna path, switch WiFi to un-certain antenna port */ - /* Set Antenna Path, both GNT_WL/GNT_BT = 1, and control by SW */ - halbtc8723d1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT, - FORCE_EXEC, - BT_8723D_1ANT_PHASE_ANTENNA_DET); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Set Antenna to BT!!\n"); - BTC_TRACE(trace_buf); - - /* Set AFH mask on at WiFi channel 2472MHz +/- 10MHz */ - h2c_parameter[0] = 0x1; - h2c_parameter[1] = 0xd; - h2c_parameter[2] = 0x14; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Set AFH on, Cent-Ch= %d, Mask=%d\n", - h2c_parameter[1], - h2c_parameter[2]); - BTC_TRACE(trace_buf); - - btcoexist->btc_fill_h2c(btcoexist, 0x66, 3, - h2c_parameter); - - u32tmp = btcoexist->btc_read_2byte(btcoexist, 0x948); - u32tmp0 = btcoexist->btc_read_4byte(btcoexist, 0x70); - u32tmp1 = halbtc8723d1ant_ltecoex_indirect_read_reg( - btcoexist, 0x38); - u32tmp2 = halbtc8723d1ant_ltecoex_indirect_read_reg( - btcoexist, 0x54); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** 0x948 = 0x%x, 0x70 = 0x%x, 0x38= 0x%x, 0x54= 0x%x (Before Ant Det)\n", - u32tmp, u32tmp0, u32tmp1, u32tmp2); - BTC_TRACE(trace_buf); - - state = 2; - break; - case 2: /* Pre-sweep background psd */ - if (!halbtc8723d1ant_psd_sweep_point(btcoexist, - wlpsd_cent_freq, wlpsd_offset, wlpsd_span, - BT_8723D_1ANT_ANTDET_PSD_POINTS, - BT_8723D_1ANT_ANTDET_PSD_AVGNUM, 3)) { - ant_det_finish = false; - board_info->btdm_ant_num_by_ant_det = 1; - psd_scan->ant_det_result = 8; - state = 99; - break; - } - - psd_scan->ant_det_pre_psdscan_peak_val = - psd_scan->psd_max_value; - - if (psd_scan->ant_det_pre_psdscan_peak_val > - (BT_8723D_1ANT_ANTDET_PSDTHRES_BACKGROUND - + psd_scan->ant_det_thres_offset) * 100) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Abort Antenna Detection!! becaus background = %d > thres (%d)\n", - psd_scan->ant_det_pre_psdscan_peak_val / - 100, - BT_8723D_1ANT_ANTDET_PSDTHRES_BACKGROUND - + psd_scan->ant_det_thres_offset); - BTC_TRACE(trace_buf); - ant_det_finish = false; - board_info->btdm_ant_num_by_ant_det = 1; - psd_scan->ant_det_result = 5; - state = 99; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Start Antenna Detection!! becaus background = %d <= thres (%d)\n", - psd_scan->ant_det_pre_psdscan_peak_val / - 100, - BT_8723D_1ANT_ANTDET_PSDTHRES_BACKGROUND - + psd_scan->ant_det_thres_offset); - BTC_TRACE(trace_buf); - state = 3; - } - break; - case 3: - - bt_resp = btcoexist->btc_set_bt_ant_detection( - btcoexist, (u8)(bt_tx_time & 0xff), - (u8)(bt_le_channel & 0xff)); - - /* Sync WL Rx PSD with BT Tx time because H2C->Mailbox delay */ - delay_ms(20); - - if (!halbtc8723d1ant_psd_sweep_point(btcoexist, - wlpsd_cent_freq, wlpsd_offset, - wlpsd_span, - BT_8723D_1ANT_ANTDET_PSD_POINTS, - BT_8723D_1ANT_ANTDET_PSD_AVGNUM, - BT_8723D_1ANT_ANTDET_PSD_SWWEEPCOUNT)) { - ant_det_finish = false; - board_info->btdm_ant_num_by_ant_det = 1; - psd_scan->ant_det_result = 8; - state = 99; - break; - } - -#if 1 - psd_scan->ant_det_psd_scan_peak_val = - psd_scan->psd_max_value; -#endif - psd_scan->ant_det_psd_scan_peak_freq = - psd_scan->psd_max_value_point; - state = 4; - break; - case 4: - - if (psd_scan->psd_point == 0) - delta_freq_per_point = 0; - else - delta_freq_per_point = - psd_scan->psd_band_width / - psd_scan->psd_point; - - psd_rep1 = psd_scan->ant_det_psd_scan_peak_val / 100; - psd_rep2 = psd_scan->ant_det_psd_scan_peak_val - - psd_rep1 * - 100; - - freq = ((psd_scan->real_cent_freq - 20) * - 1000000 + psd_scan->psd_max_value_point - * delta_freq_per_point); - freq1 = freq / 1000000; - freq2 = freq / 1000 - freq1 * 1000; - - if (freq2 < 100) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Max Value: Freq = %d.0%d MHz", - freq1, freq2); - BTC_TRACE(trace_buf); - CL_SPRINTF(psd_scan->ant_det_peak_freq, - BT_8723D_1ANT_ANTDET_BUF_LEN, - "%d.0%d", freq1, freq2); - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Max Value: Freq = %d.%d MHz", - freq1, freq2); - BTC_TRACE(trace_buf); - CL_SPRINTF(psd_scan->ant_det_peak_freq, - BT_8723D_1ANT_ANTDET_BUF_LEN, - "%d.%d", freq1, freq2); - } - - if (psd_rep2 < 10) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - ", Value = %d.0%d dB\n", - psd_rep1, psd_rep2); - BTC_TRACE(trace_buf); - CL_SPRINTF(psd_scan->ant_det_peak_val, - BT_8723D_1ANT_ANTDET_BUF_LEN, - "%d.0%d", psd_rep1, psd_rep2); - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - ", Value = %d.%d dB\n", - psd_rep1, psd_rep2); - BTC_TRACE(trace_buf); - CL_SPRINTF(psd_scan->ant_det_peak_val, - BT_8723D_1ANT_ANTDET_BUF_LEN, - "%d.%d", psd_rep1, psd_rep2); - } - - psd_scan->ant_det_is_btreply_available = true; - - if (bt_resp == false) { - psd_scan->ant_det_is_btreply_available = - false; - psd_scan->ant_det_result = 0; - ant_det_finish = false; - board_info->btdm_ant_num_by_ant_det = 1; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), BT Response = Fail\n "); - BTC_TRACE(trace_buf); - } else if (psd_scan->ant_det_psd_scan_peak_val > - (BT_8723D_1ANT_ANTDET_PSDTHRES_2ANT_BADISOLATION) - * 100) { - psd_scan->ant_det_result = 1; - ant_det_finish = true; - board_info->btdm_ant_num_by_ant_det = 2; - coex_sta->isolation_btween_wb = (u8)(85 - - psd_scan->ant_det_psd_scan_peak_val / - 100) & 0xff; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Detect Result = 2-Ant, Bad-Isolation!!\n"); - BTC_TRACE(trace_buf); - } else if (psd_scan->ant_det_psd_scan_peak_val > - (BT_8723D_1ANT_ANTDET_PSDTHRES_2ANT_GOODISOLATION - + psd_scan->ant_det_thres_offset) * 100) { - psd_scan->ant_det_result = 2; - ant_det_finish = true; - board_info->btdm_ant_num_by_ant_det = 2; - coex_sta->isolation_btween_wb = (u8)(85 - - psd_scan->ant_det_psd_scan_peak_val / - 100) & 0xff; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Detect Result = 2-Ant, Good-Isolation!!\n"); - BTC_TRACE(trace_buf); - } else if (psd_scan->ant_det_psd_scan_peak_val > - (BT_8723D_1ANT_ANTDET_PSDTHRES_1ANT) * - 100) { - psd_scan->ant_det_result = 3; - ant_det_finish = true; - board_info->btdm_ant_num_by_ant_det = 1; - coex_sta->isolation_btween_wb = (u8)(85 - - psd_scan->ant_det_psd_scan_peak_val / - 100) & 0xff; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Detect Result = 1-Ant!!\n"); - BTC_TRACE(trace_buf); - } else { - psd_scan->ant_det_result = 4; - ant_det_finish = false; - board_info->btdm_ant_num_by_ant_det = 1; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Detect Result = 1-Ant, un-certainity!!\n"); - BTC_TRACE(trace_buf); - } - - state = 99; - break; - case 99: /* restore setup */ - - /* Set AFH mask off at WiFi channel 2472MHz +/- 10MHz */ - h2c_parameter[0] = 0x0; - h2c_parameter[1] = 0x0; - h2c_parameter[2] = 0x0; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Set AFH on, Cent-Ch= %d, Mask=%d\n", - h2c_parameter[1], h2c_parameter[2]); - BTC_TRACE(trace_buf); - - btcoexist->btc_fill_h2c(btcoexist, 0x66, 3, - h2c_parameter); - - /* Set Antenna Path, GNT_WL/GNT_BT control by PTA */ - /* Set Antenna path, switch WiFi to certain antenna port */ - halbtc8723d1ant_set_ant_path(btcoexist, - BTC_ANT_PATH_AUTO, FORCE_EXEC, - BT_8723D_1ANT_PHASE_2G_RUNTIME); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Set Antenna to PTA\n!!"); - BTC_TRACE(trace_buf); - - btcoexist->stop_coex_dm = false; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Resume Coex DM\n!!"); - BTC_TRACE(trace_buf); - - outloop = true; - break; - } - - } while (!outloop); - - return ant_det_finish; - -} - -boolean halbtc8723d1ant_psd_antenna_detection_check(IN struct btc_coexist - *btcoexist) -{ - static u32 ant_det_count = 0, ant_det_fail_count = 0; - struct btc_board_info *board_info = &btcoexist->board_info; - - boolean scan, roam, ant_det_finish = false; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam); - - ant_det_count++; - - psd_scan->ant_det_try_count = ant_det_count; - - if (scan || roam) { - ant_det_finish = false; - psd_scan->ant_det_result = 6; - } else if (coex_sta->bt_disabled) { - ant_det_finish = false; - psd_scan->ant_det_result = 11; - } else if (coex_sta->num_of_profile >= 1) { - ant_det_finish = false; - psd_scan->ant_det_result = 7; - } else if ( - !psd_scan->ant_det_is_ant_det_available) { /* Antenna initial setup is not ready */ - ant_det_finish = false; - psd_scan->ant_det_result = 9; - } else if (coex_sta->c2h_bt_inquiry_page) { - ant_det_finish = false; - psd_scan->ant_det_result = 10; - } else { - - ant_det_finish = halbtc8723d1ant_psd_antenna_detection( - btcoexist); - - delay_ms(psd_scan->ant_det_bt_tx_time); - } - - /* board_info->ant_det_result = psd_scan->ant_det_result; */ - - if (!ant_det_finish) - ant_det_fail_count++; - - psd_scan->ant_det_fail_count = ant_det_fail_count; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), result = %d, fail_count = %d, finish = %s\n", - psd_scan->ant_det_result, - psd_scan->ant_det_fail_count, - ant_det_finish == true ? "Yes" : "No"); - BTC_TRACE(trace_buf); - - return ant_det_finish; - -} - -/* ************************************************************ - * work around function start with wa_halbtc8723d1ant_ - * ************************************************************ - * ************************************************************ - * extern function start with ex_halbtc8723d1ant_ - * ************************************************************ */ -void ex_halbtc8723d1ant_power_on_setting(IN struct btc_coexist *btcoexist) -{ - struct btc_board_info *board_info = &btcoexist->board_info; - u8 u8tmp = 0x0; - u16 u16tmp = 0x0; - u32 value = 0; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx Execute 8723d 1-Ant PowerOn Setting xxxxxxxxxxxxxxxx!!\n"); - BTC_TRACE(trace_buf); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "Ant Det Finish = %s, Ant Det Number = %d\n", - (board_info->btdm_ant_det_finish ? "Yes" : "No"), - board_info->btdm_ant_num_by_ant_det); - BTC_TRACE(trace_buf); - - btcoexist->stop_coex_dm = true; - psd_scan->ant_det_is_ant_det_available = false; - - /* enable BB, REG_SYS_FUNC_EN such that we can write BB Register correctly. */ - u16tmp = btcoexist->btc_read_2byte(btcoexist, 0x2); - btcoexist->btc_write_2byte(btcoexist, 0x2, u16tmp | BIT(0) | BIT(1)); - - /* Local setting bit define */ - /* BIT0: "0" for no antenna inverse; "1" for antenna inverse */ - /* BIT1: "0" for internal switch; "1" for external switch */ - /* BIT2: "0" for one antenna; "1" for two antenna */ - /* NOTE: here default all internal switch and 1-antenna ==> BIT1=0 and BIT2=0 */ - - /* Set Antenna Path to BT side */ - /* Check efuse 0xc3[6] for Single Antenna Path */ - if (board_info->single_ant_path == 0) { - /* set to S1 */ - board_info->btdm_ant_pos = BTC_ANTENNA_AT_MAIN_PORT; - u8tmp = 0; - value = 1; - } else if (board_info->single_ant_path == 1) { - /* set to S0 */ - board_info->btdm_ant_pos = BTC_ANTENNA_AT_AUX_PORT; - u8tmp = 1; - value = 0; - } - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** (Power On) single_ant_path = %d, btdm_ant_pos = %d **********\n", - board_info->single_ant_path , board_info->btdm_ant_pos); - BTC_TRACE(trace_buf); - - /* Set Antenna Path to BT side */ - halbtc8723d1ant_set_ant_path(btcoexist, - BTC_ANT_PATH_AUTO, - FORCE_EXEC, - BT_8723D_1ANT_PHASE_COEX_POWERON); - - /* Write Single Antenna Position to Registry to tell BT for 8723d. This line can be removed - since BT EFuse also add "single antenna position" in EFuse for 8723d*/ - btcoexist->btc_set(btcoexist, BTC_SET_ACT_ANTPOSREGRISTRY_CTRL, - &value); - - /* Save"single antenna position" info in Local register setting for FW reading, because FW may not ready at power on */ - if (btcoexist->chip_interface == BTC_INTF_PCI) - btcoexist->btc_write_local_reg_1byte(btcoexist, 0x3e0, u8tmp); - else if (btcoexist->chip_interface == BTC_INTF_USB) - btcoexist->btc_write_local_reg_1byte(btcoexist, 0xfe08, u8tmp); - else if (btcoexist->chip_interface == BTC_INTF_SDIO) - btcoexist->btc_write_local_reg_1byte(btcoexist, 0x60, u8tmp); - - /* enable GNT_WL/GNT_BT debug signal to GPIO14/15 */ - halbtc8723d1ant_enable_gnt_to_gpio(btcoexist, true); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** LTE coex Reg 0x38 (Power-On) = 0x%x**********\n", - halbtc8723d1ant_ltecoex_indirect_read_reg(btcoexist, 0x38)); - BTC_TRACE(trace_buf); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** MAC Reg 0x70/ BB Reg 0x948 (Power-On) = 0x%x / 0x%x**********\n", - btcoexist->btc_read_4byte(btcoexist, 0x70), - btcoexist->btc_read_2byte(btcoexist, 0x948)); - BTC_TRACE(trace_buf); - -} - -void ex_halbtc8723d1ant_pre_load_firmware(IN struct btc_coexist *btcoexist) -{ -} - -void ex_halbtc8723d1ant_init_hw_config(IN struct btc_coexist *btcoexist, - IN boolean wifi_only) -{ - halbtc8723d1ant_init_hw_config(btcoexist, true, wifi_only); -} - -void ex_halbtc8723d1ant_init_coex_dm(IN struct btc_coexist *btcoexist) -{ - halbtc8723d1ant_init_coex_dm(btcoexist); -} - -void ex_halbtc8723d1ant_display_coex_info(IN struct btc_coexist *btcoexist) -{ - struct btc_board_info *board_info = &btcoexist->board_info; - struct btc_stack_info *stack_info = &btcoexist->stack_info; - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - u8 *cli_buf = btcoexist->cli_buf; - u8 u8tmp[4], i, ps_tdma_case = 0; - u16 u16tmp[4]; - u32 u32tmp[4]; - u32 fa_ofdm, fa_cck, cca_ofdm, cca_cck; - u32 fw_ver = 0, bt_patch_ver = 0, bt_coex_ver = 0; - static u8 pop_report_in_10s = 0; - u32 phyver = 0; - boolean lte_coex_on = false; - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n ============[BT Coexist info]============"); - CL_PRINTF(cli_buf); - - if (btcoexist->manual_control) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n ============[Under Manual Control]============"); - CL_PRINTF(cli_buf); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n =========================================="); - CL_PRINTF(cli_buf); - } - if (btcoexist->stop_coex_dm) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n ============[Coex is STOPPED]============"); - CL_PRINTF(cli_buf); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n =========================================="); - CL_PRINTF(cli_buf); - } - - if (psd_scan->ant_det_try_count == 0) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %s", - "Ant PG Num/ Mech/ Pos", - board_info->pg_ant_num, board_info->btdm_ant_num, - (board_info->btdm_ant_pos == 1 ? "S1" : "S0")); - CL_PRINTF(cli_buf); - } else { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %d/ %d/ %s (%d/%d/%d)", - "Ant PG Num/ Mech(Ant_Det)/ Pos", - board_info->pg_ant_num, - board_info->btdm_ant_num_by_ant_det, - (board_info->btdm_ant_pos == 1 ? "S1" : "S0"), - psd_scan->ant_det_try_count, - psd_scan->ant_det_fail_count, - psd_scan->ant_det_result); - CL_PRINTF(cli_buf); - - if (board_info->btdm_ant_det_finish) { - - if (psd_scan->ant_det_result != 12) - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %s", - "Ant Det PSD Value", - psd_scan->ant_det_peak_val); - else - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %d", - "Ant Det PSD Value", - psd_scan->ant_det_psd_scan_peak_val - / 100); - CL_PRINTF(cli_buf); - } - } - - if (board_info->ant_det_result_five_complete) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %d/ %d", - "AntDet(Registry) Num/PSD Value", - board_info->btdm_ant_num_by_ant_det, - (board_info->antdetval & 0x7f)); - CL_PRINTF(cli_buf); - } - - bt_patch_ver = btcoexist->bt_info.bt_get_fw_ver; - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, &fw_ver); - phyver = btcoexist->btc_get_bt_phydm_version(btcoexist); - - bt_coex_ver = ((coex_sta->bt_coex_supported_version & 0xff00) >> 8); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %d_%02x/ 0x%02x/ 0x%02x (%s)", - "CoexVer WL/ BT_Desired/ BT_Report", - glcoex_ver_date_8723d_1ant, glcoex_ver_8723d_1ant, - glcoex_ver_btdesired_8723d_1ant, - bt_coex_ver, - (bt_coex_ver == 0xff ? "Unknown" : - (coex_sta->bt_disabled ? "BT-disable" : - (bt_coex_ver >= glcoex_ver_btdesired_8723d_1ant ? - "Match" : "Mis-Match")))); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = 0x%x/ 0x%x/ v%d/ %c", - "W_FW/ B_FW/ Phy/ Kt", - fw_ver, bt_patch_ver, phyver, - coex_sta->cut_version + 65); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x ", - "Wifi channel informed to BT", - coex_dm->wifi_chnl_info[0], coex_dm->wifi_chnl_info[1], - coex_dm->wifi_chnl_info[2]); - CL_PRINTF(cli_buf); - - /* wifi status */ - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s", - "============[Wifi Status]============"); - CL_PRINTF(cli_buf); - btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_WIFI_STATUS); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s", - "============[BT Status]============"); - CL_PRINTF(cli_buf); - - pop_report_in_10s++; - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = [%s/ %d dBm/ %d/ %d] ", - "BT [status/ rssi/ retryCnt/ popCnt]", - ((coex_sta->bt_disabled) ? ("disabled") : (( - coex_sta->c2h_bt_inquiry_page) ? ("inquiry/page") - : ((BT_8723D_1ANT_BT_STATUS_NON_CONNECTED_IDLE == - coex_dm->bt_status) ? "non-connected idle" : - ((BT_8723D_1ANT_BT_STATUS_CONNECTED_IDLE == coex_dm->bt_status) - ? "connected-idle" : "busy")))), - coex_sta->bt_rssi - 100, coex_sta->bt_retry_cnt, - coex_sta->pop_event_cnt); - CL_PRINTF(cli_buf); - - if (pop_report_in_10s >= 5) { - coex_sta->pop_event_cnt = 0; - pop_report_in_10s = 0; - } - - if (coex_sta->num_of_profile != 0) - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %s%s%s%s%s", - "Profiles", - ((bt_link_info->a2dp_exist) ? "A2DP," : ""), - ((bt_link_info->sco_exist) ? "SCO," : ""), - ((bt_link_info->hid_exist) ? - ((coex_sta->hid_busy_num >= 2) ? "HID(4/18)," : - "HID(2/18),") : ""), - ((bt_link_info->pan_exist) ? "PAN," : ""), - ((coex_sta->voice_over_HOGP) ? "Voice" : "")); - else - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = None", - "Profiles"); - - CL_PRINTF(cli_buf); - - if (bt_link_info->a2dp_exist) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %s", - "A2DP Rate/Bitpool/Auto_Slot", - ((coex_sta->is_A2DP_3M) ? "3M" : "No_3M"), - coex_sta->a2dp_bit_pool, - ((coex_sta->is_autoslot) ? "On" : "Off") - ); - CL_PRINTF(cli_buf); - } - - if (bt_link_info->hid_exist) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", - "HID PairNum/Forbid_Slot", - coex_sta->hid_pair_cnt, - coex_sta->forbidden_slot - ); - CL_PRINTF(cli_buf); - } - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %s/ 0x%x", - "Role/RoleSwCnt/IgnWlact/Feature", - ((bt_link_info->slave_role) ? "Slave" : "Master"), - coex_sta->cnt_RoleSwitch, - ((coex_dm->cur_ignore_wlan_act) ? "Yes" : "No"), - coex_sta->bt_coex_supported_feature); - CL_PRINTF(cli_buf); - - if ((coex_sta->bt_ble_scan_type & 0x7) != 0x0) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", - "BLEScan Type/TV/Init/Ble", - coex_sta->bt_ble_scan_type, - (coex_sta->bt_ble_scan_type & 0x1 ? - coex_sta->bt_ble_scan_para[0] : 0x0), - (coex_sta->bt_ble_scan_type & 0x2 ? - coex_sta->bt_ble_scan_para[1] : 0x0), - (coex_sta->bt_ble_scan_type & 0x4 ? - coex_sta->bt_ble_scan_para[2] : 0x0)); - CL_PRINTF(cli_buf); - } - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d/ %d", - "ReInit/ReLink/IgnWlact/Page/NameReq", - coex_sta->cnt_ReInit, - coex_sta->cnt_setupLink, - coex_sta->cnt_IgnWlanAct, - coex_sta->cnt_Page, - coex_sta->cnt_RemoteNameReq - ); - CL_PRINTF(cli_buf); - - halbtc8723d1ant_read_score_board(btcoexist, &u16tmp[0]); - - if ((coex_sta->bt_reg_vendor_ae == 0xffff) || - (coex_sta->bt_reg_vendor_ac == 0xffff)) - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = x/ x/ %04x", - "0xae[4]/0xac[1:0]/Scoreboard", u16tmp[0]); - else - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = 0x%x/ 0x%x/ %04x", - "0xae[4]/0xac[1:0]/Scoreboard", - ((coex_sta->bt_reg_vendor_ae & BIT(4)) >> 4), - coex_sta->bt_reg_vendor_ac & 0x3, u16tmp[0]); - CL_PRINTF(cli_buf); - - if (coex_sta->num_of_profile > 0) { - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x", - "AFH MAP", - coex_sta->bt_afh_map[0], - coex_sta->bt_afh_map[1], - coex_sta->bt_afh_map[2], - coex_sta->bt_afh_map[3], - coex_sta->bt_afh_map[4], - coex_sta->bt_afh_map[5], - coex_sta->bt_afh_map[6], - coex_sta->bt_afh_map[7], - coex_sta->bt_afh_map[8], - coex_sta->bt_afh_map[9] - ); - CL_PRINTF(cli_buf); - } - - for (i = 0; i < BT_INFO_SRC_8723D_1ANT_MAX; i++) { - if (coex_sta->bt_info_c2h_cnt[i]) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %02x %02x %02x %02x %02x %02x %02x (%d)", - glbt_info_src_8723d_1ant[i], - coex_sta->bt_info_c2h[i][0], - coex_sta->bt_info_c2h[i][1], - coex_sta->bt_info_c2h[i][2], - coex_sta->bt_info_c2h[i][3], - coex_sta->bt_info_c2h[i][4], - coex_sta->bt_info_c2h[i][5], - coex_sta->bt_info_c2h[i][6], - coex_sta->bt_info_c2h_cnt[i]); - CL_PRINTF(cli_buf); - } - } - - if (btcoexist->manual_control) - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s", - "============[mechanisms] (before Manual)============"); - else - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s", - "============[Mechanisms]============"); - - CL_PRINTF(cli_buf); - - ps_tdma_case = coex_dm->cur_ps_tdma; - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %02x %02x %02x %02x %02x (case-%d, %s)", - "TDMA", - coex_dm->ps_tdma_para[0], coex_dm->ps_tdma_para[1], - coex_dm->ps_tdma_para[2], coex_dm->ps_tdma_para[3], - coex_dm->ps_tdma_para[4], ps_tdma_case, - (coex_dm->cur_ps_tdma_on ? "TDMA On" : "TDMA Off")); - - CL_PRINTF(cli_buf); - - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x6c0); - u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x6c4); - u32tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0x6c8); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %d/ 0x%x/ 0x%x/ 0x%x", - "Table/0x6c0/0x6c4/0x6c8", - coex_sta->coex_table_type, u32tmp[0], u32tmp[1], u32tmp[2]); - CL_PRINTF(cli_buf); - - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x778); - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x6cc); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = 0x%x/ 0x%x", - "0x778/0x6cc", - u8tmp[0], u32tmp[0]); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s", - "AntDiv/ ForceLPS", - ((board_info->ant_div_cfg) ? "On" : "Off"), - ((coex_sta->force_lps_on) ? "On" : "Off")); - CL_PRINTF(cli_buf); - - u32tmp[0] = halbtc8723d1ant_ltecoex_indirect_read_reg(btcoexist, 0x38); - lte_coex_on = ((u32tmp[0] & BIT(7)) >> 7) ? true : false; - - if (lte_coex_on) { - - u32tmp[0] = halbtc8723d1ant_ltecoex_indirect_read_reg(btcoexist, - 0xa0); - u32tmp[1] = halbtc8723d1ant_ltecoex_indirect_read_reg(btcoexist, - 0xa4); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", - "LTE Coex Table W_L/B_L", - u32tmp[0] & 0xffff, u32tmp[1] & 0xffff); - CL_PRINTF(cli_buf); - - u32tmp[0] = halbtc8723d1ant_ltecoex_indirect_read_reg(btcoexist, - 0xa8); - u32tmp[1] = halbtc8723d1ant_ltecoex_indirect_read_reg(btcoexist, - 0xac); - u32tmp[2] = halbtc8723d1ant_ltecoex_indirect_read_reg(btcoexist, - 0xb0); - u32tmp[3] = halbtc8723d1ant_ltecoex_indirect_read_reg(btcoexist, - 0xb4); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", - "LTE Break Table W_L/B_L/L_W/L_B", - u32tmp[0] & 0xffff, u32tmp[1] & 0xffff, - u32tmp[2] & 0xffff, u32tmp[3] & 0xffff); - CL_PRINTF(cli_buf); - - } - - /* Hw setting */ - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s", - "============[Hw setting]============"); - CL_PRINTF(cli_buf); - /* - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x430); - u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x434); - u16tmp[0] = btcoexist->btc_read_2byte(btcoexist, 0x42a); - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x456); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/0x%x/0x%x/0x%x", - "0x430/0x434/0x42a/0x456", - u32tmp[0], u32tmp[1], u16tmp[0], u8tmp[0]); - CL_PRINTF(cli_buf); - */ - - u32tmp[0] = halbtc8723d1ant_ltecoex_indirect_read_reg(btcoexist, 0x38); - u32tmp[1] = halbtc8723d1ant_ltecoex_indirect_read_reg(btcoexist, 0x54); - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x73); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s", - "LTE Coex/Path Owner", - ((lte_coex_on) ? "On" : "Off") , - ((u8tmp[0] & BIT(2)) ? "WL" : "BT")); - CL_PRINTF(cli_buf); - - if (lte_coex_on) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %d/ %d/ %d/ %d", - "LTE 3Wire/OPMode/UART/UARTMode", - (int)((u32tmp[0] & BIT(6)) >> 6), - (int)((u32tmp[0] & (BIT(5) | BIT(4))) >> 4), - (int)((u32tmp[0] & BIT(3)) >> 3), - (int)(u32tmp[0] & (BIT(2) | BIT(1) | BIT(0)))); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", - "LTE_Busy/UART_Busy", - (int)((u32tmp[1] & BIT(1)) >> 1), (int)(u32tmp[1] & BIT(0))); - CL_PRINTF(cli_buf); - } - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %s (BB:%s)/ %s (BB:%s)/ %s %d", - "GNT_WL_Ctrl/GNT_BT_Ctrl/Dbg", - ((u32tmp[0] & BIT(12)) ? "SW" : "HW"), - ((u32tmp[0] & BIT(8)) ? "SW" : "HW"), - ((u32tmp[0] & BIT(14)) ? "SW" : "HW"), - ((u32tmp[0] & BIT(10)) ? "SW" : "HW"), - ((u8tmp[0] & BIT(3)) ? "On" : "Off"), - coex_sta->gnt_error_cnt); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", - "GNT_WL/GNT_BT", - (int)((u32tmp[1] & BIT(2)) >> 2), - (int)((u32tmp[1] & BIT(3)) >> 3)); - CL_PRINTF(cli_buf); - - u16tmp[0] = btcoexist->btc_read_2byte(btcoexist, 0x948); - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x67); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", - "0x948/0x67[7]", - u16tmp[0], (int)((u8tmp[0] & BIT(7)) >> 7)); - CL_PRINTF(cli_buf); - - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x964); - u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0x864); - u8tmp[2] = btcoexist->btc_read_1byte(btcoexist, 0xab7); - u8tmp[3] = btcoexist->btc_read_1byte(btcoexist, 0xa01); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", - "0x964[1]/0x864[0]/0xab7[5]/0xa01[7]", - (int)((u8tmp[0] & BIT(1)) >> 1), (int)((u8tmp[1] & BIT(0))), - (int)((u8tmp[2] & BIT(3)) >> 3), - (int)((u8tmp[3] & BIT(7)) >> 7)); - CL_PRINTF(cli_buf); - - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x4c6); - u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0x40); - u8tmp[2] = btcoexist->btc_read_1byte(btcoexist, 0x45e); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", - "0x4c6[4]/0x40[5]/0x45e[3](TxRetry)", - (int)((u8tmp[0] & BIT(4)) >> 4), - (int)((u8tmp[1] & BIT(5)) >> 5), - (int)((u8tmp[2] & BIT(3)) >> 3)); - CL_PRINTF(cli_buf); - - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x550); - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x522); - u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0x953); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ %s", - "0x550/0x522/4-RxAGC", - u32tmp[0], u8tmp[0], (u8tmp[1] & 0x2) ? "On" : "Off"); - CL_PRINTF(cli_buf); - - fa_ofdm = btcoexist->btc_phydm_query_PHY_counter(btcoexist, PHYDM_INFO_FA_OFDM); - fa_cck = btcoexist->btc_phydm_query_PHY_counter(btcoexist, PHYDM_INFO_FA_CCK); - cca_ofdm = btcoexist->btc_phydm_query_PHY_counter(btcoexist, PHYDM_INFO_CCA_OFDM); - cca_cck = btcoexist->btc_phydm_query_PHY_counter(btcoexist, PHYDM_INFO_CCA_CCK); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", - "CCK-CCA/CCK-FA/OFDM-CCA/OFDM-FA", - cca_cck, fa_cck, cca_ofdm, fa_ofdm); - CL_PRINTF(cli_buf); - -#if 1 - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d", - "CRC_OK CCK/11g/11n/11n-agg", - coex_sta->crc_ok_cck, coex_sta->crc_ok_11g, - coex_sta->crc_ok_11n, coex_sta->crc_ok_11n_vht); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d", - "CRC_Err CCK/11g/11n/11n-agg", - coex_sta->crc_err_cck, coex_sta->crc_err_11g, - coex_sta->crc_err_11n, coex_sta->crc_err_11n_vht); - CL_PRINTF(cli_buf); -#endif - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s/ %s/ %d", - "WlHiPri/ Locking/ Locked/ Noisy", - (coex_sta->wifi_is_high_pri_task ? "Yes" : "No"), - (coex_sta->cck_lock ? "Yes" : "No"), - (coex_sta->cck_ever_lock ? "Yes" : "No"), - coex_sta->wl_noisy_level); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d %s", - "0x770(Hi-pri rx/tx)", - coex_sta->high_priority_rx, coex_sta->high_priority_tx, - (coex_sta->is_hiPri_rx_overhead ? "(scan overhead!!)" : "")); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d %s", - "0x774(Lo-pri rx/tx)", - coex_sta->low_priority_rx, coex_sta->low_priority_tx, - (bt_link_info->slave_role ? "(Slave!!)" : ( - coex_sta->is_tdma_btautoslot_hang ? "(auto-slot hang!!)" : ""))); - CL_PRINTF(cli_buf); - - btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_COEX_STATISTICS); -} - -void ex_halbtc8723d1ant_ips_notify(IN struct btc_coexist *btcoexist, IN u8 type) -{ - if (btcoexist->manual_control || btcoexist->stop_coex_dm) - return; - - if (BTC_IPS_ENTER == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], IPS ENTER notify\n"); - BTC_TRACE(trace_buf); - coex_sta->under_ips = true; - - /* Write WL "Active" in Score-board for LPS off */ - halbtc8723d1ant_post_state_to_bt(btcoexist, - BT_8723D_1ANT_SCOREBOARD_ACTIVE, false); - - halbtc8723d1ant_post_state_to_bt(btcoexist, - BT_8723D_1ANT_SCOREBOARD_ONOFF, false); - - halbtc8723d1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); - - halbtc8723d1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, - FORCE_EXEC, - BT_8723D_1ANT_PHASE_WLAN_OFF); - - halbtc8723d1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - } else if (BTC_IPS_LEAVE == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], IPS LEAVE notify\n"); - BTC_TRACE(trace_buf); - halbtc8723d1ant_post_state_to_bt(btcoexist, - BT_8723D_1ANT_SCOREBOARD_ACTIVE, true); - - halbtc8723d1ant_post_state_to_bt(btcoexist, - BT_8723D_1ANT_SCOREBOARD_ONOFF, true); - - halbtc8723d1ant_init_hw_config(btcoexist, false, false); - halbtc8723d1ant_init_coex_dm(btcoexist);; - - coex_sta->under_ips = false; - } -} - -void ex_halbtc8723d1ant_lps_notify(IN struct btc_coexist *btcoexist, IN u8 type) -{ - if (btcoexist->manual_control || btcoexist->stop_coex_dm) - return; - - if (BTC_LPS_ENABLE == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], LPS ENABLE notify\n"); - BTC_TRACE(trace_buf); - coex_sta->under_lps = true; - - if (coex_sta->force_lps_on == true) { /* LPS No-32K */ - /* Write WL "Active" in Score-board for PS-TDMA */ - halbtc8723d1ant_post_state_to_bt(btcoexist, - BT_8723D_1ANT_SCOREBOARD_ACTIVE, true); - - } else { /* LPS-32K, need check if this h2c 0x71 can work?? (2015/08/28) */ - /* Write WL "Non-Active" in Score-board for Native-PS */ - halbtc8723d1ant_post_state_to_bt(btcoexist, - BT_8723D_1ANT_SCOREBOARD_ACTIVE, false); - - } - } else if (BTC_LPS_DISABLE == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], LPS DISABLE notify\n"); - BTC_TRACE(trace_buf); - coex_sta->under_lps = false; - - /* Write WL "Active" in Score-board for LPS off */ - halbtc8723d1ant_post_state_to_bt(btcoexist, - BT_8723D_1ANT_SCOREBOARD_ACTIVE, true); - - } -} - -void ex_halbtc8723d1ant_scan_notify(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - boolean wifi_connected = false; - - if (btcoexist->manual_control || - btcoexist->stop_coex_dm) - return; - - coex_sta->freeze_coexrun_by_btinfo = false; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - - halbtc8723d1ant_query_bt_info(btcoexist); - - if (BTC_SCAN_START == type) { - - if (!wifi_connected) - coex_sta->wifi_is_high_pri_task = true; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCAN START notify\n"); - BTC_TRACE(trace_buf); - - halbtc8723d1ant_post_state_to_bt(btcoexist, - BT_8723D_1ANT_SCOREBOARD_SCAN, true); - halbtc8723d1ant_post_state_to_bt(btcoexist, - BT_8723D_1ANT_SCOREBOARD_ACTIVE, true); - - /* Force antenna setup for no scan result issue */ - halbtc8723d1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, - FORCE_EXEC, - BT_8723D_1ANT_PHASE_2G_RUNTIME); - - halbtc8723d1ant_run_coexist_mechanism(btcoexist); - - } else { - - coex_sta->wifi_is_high_pri_task = false; - - btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM, - &coex_sta->scan_ap_num); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCAN FINISH notify (Scan-AP = %d)\n", - coex_sta->scan_ap_num); - BTC_TRACE(trace_buf); - - halbtc8723d1ant_run_coexist_mechanism(btcoexist); - } - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCAN Notify() end\n"); - BTC_TRACE(trace_buf); - -} - -void ex_halbtc8723d1ant_connect_notify(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - boolean wifi_connected = false; - - if (btcoexist->manual_control || - btcoexist->stop_coex_dm) - return; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - - if (BTC_ASSOCIATE_START == type) { - - coex_sta->wifi_is_high_pri_task = true; - - halbtc8723d1ant_post_state_to_bt(btcoexist, - BT_8723D_1ANT_SCOREBOARD_ACTIVE, true); - - halbtc8723d1ant_post_state_to_bt(btcoexist, - BT_8723D_1ANT_SCOREBOARD_SCAN, true); - - /* Force antenna setup for no scan result issue */ - halbtc8723d1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, - FORCE_EXEC, - BT_8723D_1ANT_PHASE_2G_RUNTIME); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], CONNECT START notify\n"); - BTC_TRACE(trace_buf); - - coex_dm->arp_cnt = 0; - - halbtc8723d1ant_run_coexist_mechanism(btcoexist); - - /* To keep TDMA case during connect process, - to avoid changed by Btinfo and runcoexmechanism */ - coex_sta->freeze_coexrun_by_btinfo = true; - } else { - - coex_sta->wifi_is_high_pri_task = false; - coex_sta->freeze_coexrun_by_btinfo = false; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], CONNECT FINISH notify\n"); - BTC_TRACE(trace_buf); - - halbtc8723d1ant_run_coexist_mechanism(btcoexist); - } - -} - -void ex_halbtc8723d1ant_media_status_notify(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - boolean wifi_under_b_mode = false; - - if (btcoexist->manual_control || - btcoexist->stop_coex_dm) - return; - - if (BTC_MEDIA_CONNECT == type) { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], MEDIA connect notify\n"); - BTC_TRACE(trace_buf); - - halbtc8723d1ant_post_state_to_bt(btcoexist, - BT_8723D_1ANT_SCOREBOARD_ACTIVE, true); - - /* Force antenna setup for no scan result issue */ - halbtc8723d1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, - FORCE_EXEC, - BT_8723D_1ANT_PHASE_2G_RUNTIME); - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_B_MODE, - &wifi_under_b_mode); - - /* Set CCK Tx/Rx high Pri except 11b mode */ - if (wifi_under_b_mode) { - btcoexist->btc_write_1byte(btcoexist, 0x6cd, - 0x00); /* CCK Tx */ - btcoexist->btc_write_1byte(btcoexist, 0x6cf, - 0x00); /* CCK Rx */ - } else { - /* btcoexist->btc_write_1byte(btcoexist, 0x6cd, 0x10); */ /*CCK Tx */ - /* btcoexist->btc_write_1byte(btcoexist, 0x6cf, 0x10); */ /*CCK Rx */ - btcoexist->btc_write_1byte(btcoexist, 0x6cd, - 0x00); /* CCK Tx */ - btcoexist->btc_write_1byte(btcoexist, 0x6cf, - 0x10); /* CCK Rx */ - } - - coex_dm->backup_arfr_cnt1 = btcoexist->btc_read_4byte(btcoexist, - 0x430); - coex_dm->backup_arfr_cnt2 = btcoexist->btc_read_4byte(btcoexist, - 0x434); - coex_dm->backup_retry_limit = btcoexist->btc_read_2byte( - btcoexist, 0x42a); - coex_dm->backup_ampdu_max_time = btcoexist->btc_read_1byte( - btcoexist, 0x456); - } else { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], MEDIA disconnect notify\n"); - BTC_TRACE(trace_buf); - - halbtc8723d1ant_post_state_to_bt(btcoexist, - BT_8723D_1ANT_SCOREBOARD_ACTIVE, false); - - btcoexist->btc_write_1byte(btcoexist, 0x6cd, 0x0); /* CCK Tx */ - btcoexist->btc_write_1byte(btcoexist, 0x6cf, 0x0); /* CCK Rx */ - - coex_sta->cck_ever_lock = false; - } - - halbtc8723d1ant_update_wifi_channel_info(btcoexist, type); - -} - -void ex_halbtc8723d1ant_specific_packet_notify(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - boolean under_4way = false; - - if (btcoexist->manual_control || - btcoexist->stop_coex_dm) - return; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS, - &under_4way); - - if (under_4way) { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], specific Packet ---- under_4way!!\n"); - BTC_TRACE(trace_buf); - - coex_sta->wifi_is_high_pri_task = true; - coex_sta->specific_pkt_period_cnt = 2; - } else if (BTC_PACKET_ARP == type) { - - coex_dm->arp_cnt++; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], specific Packet ARP notify -cnt = %d\n", - coex_dm->arp_cnt); - BTC_TRACE(trace_buf); - - } else { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], specific Packet DHCP or EAPOL notify [Type = %d]\n", - type); - BTC_TRACE(trace_buf); - - coex_sta->wifi_is_high_pri_task = true; - coex_sta->specific_pkt_period_cnt = 2; - } - - if (coex_sta->wifi_is_high_pri_task) { - halbtc8723d1ant_post_state_to_bt(btcoexist, - BT_8723D_1ANT_SCOREBOARD_SCAN, true); - halbtc8723d1ant_run_coexist_mechanism(btcoexist); - } -} - -void ex_halbtc8723d1ant_bt_info_notify(IN struct btc_coexist *btcoexist, - IN u8 *tmp_buf, IN u8 length) -{ - u8 i, rsp_source = 0; - boolean wifi_connected = false; - boolean wifi_scan = false, wifi_link = false, wifi_roam = false, - wifi_busy = false; - - if (psd_scan->is_AntDet_running == true) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], bt_info_notify return for AntDet is running\n"); - BTC_TRACE(trace_buf); - return; - } - - rsp_source = tmp_buf[0] & 0xf; - if (rsp_source >= BT_INFO_SRC_8723D_1ANT_MAX) - rsp_source = BT_INFO_SRC_8723D_1ANT_WIFI_FW; - coex_sta->bt_info_c2h_cnt[rsp_source]++; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Bt_info[%d], len=%d, data=[", rsp_source, - length); - BTC_TRACE(trace_buf); - - for (i = 0; i < length; i++) { - coex_sta->bt_info_c2h[rsp_source][i] = tmp_buf[i]; - - if (i == length - 1) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "0x%02x]\n", - tmp_buf[i]); - BTC_TRACE(trace_buf); - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "0x%02x, ", - tmp_buf[i]); - BTC_TRACE(trace_buf); - } - } - - coex_sta->bt_info = coex_sta->bt_info_c2h[rsp_source][1]; - coex_sta->bt_info_ext = coex_sta->bt_info_c2h[rsp_source][4]; - coex_sta->bt_info_ext2 = coex_sta->bt_info_c2h[rsp_source][5]; - - if (BT_INFO_SRC_8723D_1ANT_WIFI_FW != rsp_source) { - - /* if 0xff, it means BT is under WHCK test */ - coex_sta->bt_whck_test = ((coex_sta->bt_info == 0xff) ? true : - false); - - coex_sta->bt_create_connection = (( - coex_sta->bt_info_c2h[rsp_source][2] & 0x80) ? true : - false); - - /* unit: %, value-100 to translate to unit: dBm */ - coex_sta->bt_rssi = coex_sta->bt_info_c2h[rsp_source][3] * 2 + - 10; - - coex_sta->c2h_bt_remote_name_req = (( - coex_sta->bt_info_c2h[rsp_source][2] & 0x20) ? true : - false); - - coex_sta->is_A2DP_3M = ((coex_sta->bt_info_c2h[rsp_source][2] & - 0x10) ? true : false); - - coex_sta->acl_busy = ((coex_sta->bt_info_c2h[rsp_source][1] & - 0x9) ? true : false); - - coex_sta->voice_over_HOGP = ((coex_sta->bt_info_ext & 0x10) ? - true : false); - - coex_sta->c2h_bt_inquiry_page = ((coex_sta->bt_info & - BT_INFO_8723D_1ANT_B_INQ_PAGE) ? true : false); - - coex_sta->a2dp_bit_pool = ((( - coex_sta->bt_info_c2h[rsp_source][1] & 0x49) == 0x49) ? - coex_sta->bt_info_c2h[rsp_source][6] : 0); - - coex_sta->bt_retry_cnt = coex_sta->bt_info_c2h[rsp_source][2] & - 0xf; - - coex_sta->is_autoslot = coex_sta->bt_info_ext2 & 0x8; - - coex_sta->forbidden_slot = coex_sta->bt_info_ext2 & 0x7; - - coex_sta->hid_busy_num = (coex_sta->bt_info_ext2 & 0x30) >> 4; - - coex_sta->hid_pair_cnt = (coex_sta->bt_info_ext2 & 0xc0) >> 6; - - if (coex_sta->bt_retry_cnt >= 1) - coex_sta->pop_event_cnt++; - - if (coex_sta->c2h_bt_remote_name_req) - coex_sta->cnt_RemoteNameReq++; - - if (coex_sta->bt_info_ext & BIT(1)) - coex_sta->cnt_ReInit++; - - if (coex_sta->bt_info_ext & BIT(2)) { - coex_sta->cnt_setupLink++; - coex_sta->is_setupLink = true; - } else - coex_sta->is_setupLink = false; - - if (coex_sta->bt_info_ext & BIT(3)) - coex_sta->cnt_IgnWlanAct++; - - if (coex_sta->bt_info_ext & BIT(6)) - coex_sta->cnt_RoleSwitch++; - - if (coex_sta->bt_create_connection) { - coex_sta->cnt_Page++; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &wifi_scan); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &wifi_link); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &wifi_roam); - - if ((wifi_link) || (wifi_roam) || (wifi_scan) || - (coex_sta->wifi_is_high_pri_task) || (wifi_busy)) { - - halbtc8723d1ant_post_state_to_bt(btcoexist, - BT_8723D_1ANT_SCOREBOARD_SCAN, true); - - } else { - - halbtc8723d1ant_post_state_to_bt(btcoexist, - BT_8723D_1ANT_SCOREBOARD_SCAN, false); - } - } else - halbtc8723d1ant_post_state_to_bt(btcoexist, - BT_8723D_1ANT_SCOREBOARD_SCAN, false); - - /* Here we need to resend some wifi info to BT */ - /* because bt is reset and loss of the info. */ - - if ((!btcoexist->manual_control) && - (!btcoexist->stop_coex_dm)) { - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - - /* Re-Init */ - if ((coex_sta->bt_info_ext & BIT(1))) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT ext info bit1 check, send wifi BW&Chnl to BT!!\n"); - BTC_TRACE(trace_buf); - if (wifi_connected) - halbtc8723d1ant_update_wifi_channel_info( - btcoexist, BTC_MEDIA_CONNECT); - else - halbtc8723d1ant_update_wifi_channel_info( - btcoexist, - BTC_MEDIA_DISCONNECT); - } - - /* If Ignore_WLanAct && not SetUp_Link or Role_Switch */ - if ((coex_sta->bt_info_ext & BIT(3)) && - (!(coex_sta->bt_info_ext & BIT(2))) && - (!(coex_sta->bt_info_ext & BIT(6)))) { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT ext info bit3 check, set BT NOT to ignore Wlan active!!\n"); - BTC_TRACE(trace_buf); - halbtc8723d1ant_ignore_wlan_act(btcoexist, - FORCE_EXEC, false); - } else { - if (coex_sta->bt_info_ext & BIT(2)) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT ignore Wlan active because Re-link!!\n"); - BTC_TRACE(trace_buf); - } else if (coex_sta->bt_info_ext & BIT(6)) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT ignore Wlan active because Role-Switch!!\n"); - BTC_TRACE(trace_buf); - } - } - } - - } - - if ((coex_sta->bt_info_ext & BIT(5))) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT ext info bit4 check, query BLE Scan type!!\n"); - BTC_TRACE(trace_buf); - coex_sta->bt_ble_scan_type = btcoexist->btc_get_ble_scan_type_from_bt(btcoexist); - - if ((coex_sta->bt_ble_scan_type & 0x1) == 0x1) - coex_sta->bt_ble_scan_para[0] = btcoexist->btc_get_ble_scan_para_from_bt(btcoexist, 0x1); - if ((coex_sta->bt_ble_scan_type & 0x2) == 0x2) - coex_sta->bt_ble_scan_para[1] = btcoexist->btc_get_ble_scan_para_from_bt(btcoexist, 0x2); - if ((coex_sta->bt_ble_scan_type & 0x4) == 0x4) - coex_sta->bt_ble_scan_para[2] = btcoexist->btc_get_ble_scan_para_from_bt(btcoexist, 0x4); - } - - halbtc8723d1ant_update_bt_link_info(btcoexist); - - halbtc8723d1ant_run_coexist_mechanism(btcoexist); -} - -void ex_halbtc8723d1ant_rf_status_notify(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], RF Status notify\n"); - BTC_TRACE(trace_buf); - - if (BTC_RF_ON == type) { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], RF is turned ON!!\n"); - BTC_TRACE(trace_buf); - - btcoexist->stop_coex_dm = false; - - halbtc8723d1ant_post_state_to_bt(btcoexist, - BT_8723D_1ANT_SCOREBOARD_ACTIVE, true); - halbtc8723d1ant_post_state_to_bt(btcoexist, - BT_8723D_1ANT_SCOREBOARD_ONOFF, true); - - } else if (BTC_RF_OFF == type) { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], RF is turned OFF!!\n"); - BTC_TRACE(trace_buf); - - halbtc8723d1ant_post_state_to_bt(btcoexist, - BT_8723D_1ANT_SCOREBOARD_ACTIVE, false); - halbtc8723d1ant_post_state_to_bt(btcoexist, - BT_8723D_1ANT_SCOREBOARD_ONOFF, false); - - halbtc8723d1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 0); - - halbtc8723d1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, - FORCE_EXEC, - BT_8723D_1ANT_PHASE_WLAN_OFF); - - btcoexist->stop_coex_dm = true; - } -} - -void ex_halbtc8723d1ant_halt_notify(IN struct btc_coexist *btcoexist) -{ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], Halt notify\n"); - BTC_TRACE(trace_buf); - - halbtc8723d1ant_post_state_to_bt(btcoexist, - BT_8723D_1ANT_SCOREBOARD_ACTIVE, false); - halbtc8723d1ant_post_state_to_bt(btcoexist, - BT_8723D_1ANT_SCOREBOARD_ONOFF, false); - - halbtc8723d1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 0); - - halbtc8723d1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, FORCE_EXEC, - BT_8723D_1ANT_PHASE_WLAN_OFF); - - halbtc8723d1ant_ignore_wlan_act(btcoexist, FORCE_EXEC, true); - - ex_halbtc8723d1ant_media_status_notify(btcoexist, BTC_MEDIA_DISCONNECT); - - btcoexist->stop_coex_dm = true; -} - -void ex_halbtc8723d1ant_pnp_notify(IN struct btc_coexist *btcoexist, - IN u8 pnp_state) -{ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], Pnp notify\n"); - BTC_TRACE(trace_buf); - - if ((BTC_WIFI_PNP_SLEEP == pnp_state) || - (BTC_WIFI_PNP_SLEEP_KEEP_ANT == pnp_state)) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Pnp notify to SLEEP\n"); - BTC_TRACE(trace_buf); - - halbtc8723d1ant_post_state_to_bt(btcoexist, - BT_8723D_1ANT_SCOREBOARD_ACTIVE, false); - halbtc8723d1ant_post_state_to_bt(btcoexist, - BT_8723D_1ANT_SCOREBOARD_ONOFF, false); - - if (BTC_WIFI_PNP_SLEEP_KEEP_ANT == pnp_state) { - - halbtc8723d1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, - FORCE_EXEC, - BT_8723D_1ANT_PHASE_2G_RUNTIME); - } else { - - halbtc8723d1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, - FORCE_EXEC, - BT_8723D_1ANT_PHASE_WLAN_OFF); - } - - btcoexist->stop_coex_dm = true; - } else if (BTC_WIFI_PNP_WAKE_UP == pnp_state) { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Pnp notify to WAKE UP\n"); - BTC_TRACE(trace_buf); - - halbtc8723d1ant_post_state_to_bt(btcoexist, - BT_8723D_1ANT_SCOREBOARD_ACTIVE, true); - halbtc8723d1ant_post_state_to_bt(btcoexist, - BT_8723D_1ANT_SCOREBOARD_ONOFF, true); - - btcoexist->stop_coex_dm = false; - } -} - -void ex_halbtc8723d1ant_coex_dm_reset(IN struct btc_coexist *btcoexist) -{ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], *****************Coex DM Reset*****************\n"); - BTC_TRACE(trace_buf); - - halbtc8723d1ant_init_hw_config(btcoexist, false, false); - halbtc8723d1ant_init_coex_dm(btcoexist); -} - -void ex_halbtc8723d1ant_periodical(IN struct btc_coexist *btcoexist) -{ - - struct btc_board_info *board_info = &btcoexist->board_info; - boolean wifi_busy = false; - u4Byte value = 0; - u32 bt_patch_ver; - static u8 cnt = 0; - boolean bt_relink_finish = false; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ************* Periodical *************\n"); - BTC_TRACE(trace_buf); - -#if (BT_AUTO_REPORT_ONLY_8723D_1ANT == 0) - halbtc8723d1ant_query_bt_info(btcoexist); - -#endif - - halbtc8723d1ant_monitor_bt_ctr(btcoexist); - halbtc8723d1ant_monitor_wifi_ctr(btcoexist); - - halbtc8723d1ant_monitor_bt_enable_disable(btcoexist); - -# if 1 - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - - /* halbtc8723d1ant_read_score_board(btcoexist, &bt_scoreboard_val); */ - - if (wifi_busy) { - halbtc8723d1ant_post_state_to_bt(btcoexist, - BT_8723D_1ANT_SCOREBOARD_UNDERTEST, true); - /* - halbtc8723d1ant_post_state_to_bt(btcoexist, - BT_8723D_1ANT_SCOREBOARD_WLBUSY, true); - - if (bt_scoreboard_val & BIT(6)) - halbtc8723d1ant_query_bt_info(btcoexist); */ - } else { - halbtc8723d1ant_post_state_to_bt(btcoexist, - BT_8723D_1ANT_SCOREBOARD_UNDERTEST, false); - /* - halbtc8723d1ant_post_state_to_bt(btcoexist, - BT_8723D_1ANT_SCOREBOARD_WLBUSY, - false); */ - } -#endif - - if (coex_sta->bt_relink_downcount != 0) { - coex_sta->bt_relink_downcount--; - - if (coex_sta->bt_relink_downcount == 0) - bt_relink_finish = true; - } - - /* for 4-way, DHCP, EAPOL packet */ - if (coex_sta->specific_pkt_period_cnt > 0) { - - coex_sta->specific_pkt_period_cnt--; - - if ((coex_sta->specific_pkt_period_cnt == 0) && - (coex_sta->wifi_is_high_pri_task)) - coex_sta->wifi_is_high_pri_task = false; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ***************** Hi-Pri Task = %s*****************\n", - (coex_sta->wifi_is_high_pri_task ? "Yes" : - "No")); - BTC_TRACE(trace_buf); - - } - - if (!coex_sta->bt_disabled) { - if (coex_sta->bt_coex_supported_feature == 0) - btcoexist->btc_get(btcoexist, BTC_GET_U4_SUPPORTED_FEATURE, - &coex_sta->bt_coex_supported_feature); - - if ((coex_sta->bt_coex_supported_version == 0) || - (coex_sta->bt_coex_supported_version == 0xffff)) - btcoexist->btc_get(btcoexist, BTC_GET_U4_SUPPORTED_VERSION, - &coex_sta->bt_coex_supported_version); - - if (coex_sta->bt_reg_vendor_ac == 0xffff) - coex_sta->bt_reg_vendor_ac = (u16)( - btcoexist->btc_get_bt_reg(btcoexist, 3, - 0xac) & 0xffff); - - if (coex_sta->bt_reg_vendor_ae == 0xffff) - coex_sta->bt_reg_vendor_ae = (u16)( - btcoexist->btc_get_bt_reg(btcoexist, 3, - 0xae) & 0xffff); - - btcoexist->btc_get(btcoexist, BTC_GET_U4_BT_PATCH_VER, - &bt_patch_ver); - btcoexist->bt_info.bt_get_fw_ver = bt_patch_ver; - - if (coex_sta->num_of_profile > 0) { - cnt++; - - if (cnt >= 3) { - btcoexist->btc_get_bt_afh_map_from_bt(btcoexist, 0, - &coex_sta->bt_afh_map[0]); - cnt = 0; - } - } - -#if BT_8723D_1ANT_ANTDET_ENABLE - - if (board_info->btdm_ant_det_finish) { - if ((psd_scan->ant_det_result == 12) && - (psd_scan->ant_det_psd_scan_peak_val == 0) - && (!psd_scan->is_AntDet_running)) { - psd_scan->ant_det_psd_scan_peak_val = - btcoexist->btc_get_ant_det_val_from_bt( - btcoexist) * 100; - - board_info->antdetval = psd_scan->ant_det_psd_scan_peak_val/100; - value = board_info->antdetval; - } - } - -#endif - } - - if (halbtc8723d1ant_is_wifibt_status_changed(btcoexist)) - halbtc8723d1ant_run_coexist_mechanism(btcoexist); - -} - -void ex_halbtc8723d1ant_set_antenna_notify(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - struct btc_board_info *board_info = &btcoexist->board_info; - - if (btcoexist->manual_control || btcoexist->stop_coex_dm) - return; - - if (type == 2) { /* two antenna */ - board_info->ant_div_cfg = true; - halbtc8723d1ant_set_ant_path(btcoexist, BTC_ANT_PATH_WIFI, - FORCE_EXEC, - BT_8723D_1ANT_PHASE_2G_RUNTIME); - } else { /* one antenna */ - halbtc8723d1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, - FORCE_EXEC, - BT_8723D_1ANT_PHASE_2G_RUNTIME); - } -} - -void ex_halbtc8723d1ant_antenna_detection(IN struct btc_coexist *btcoexist, - IN u32 cent_freq, IN u32 offset, IN u32 span, IN u32 seconds) -{ - - static u32 ant_det_count = 0, ant_det_fail_count = 0; - struct btc_board_info *board_info = &btcoexist->board_info; - u16 u16tmp; - u8 AntDetval = 0; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx Ext Call AntennaDetect()!!\n"); - BTC_TRACE(trace_buf); - -#if BT_8723D_1ANT_ANTDET_ENABLE - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx Call AntennaDetect()!!\n"); - BTC_TRACE(trace_buf); - - if (seconds == 0) { - psd_scan->ant_det_try_count = 0; - psd_scan->ant_det_fail_count = 0; - ant_det_count = 0; - ant_det_fail_count = 0; - board_info->btdm_ant_det_finish = false; - board_info->btdm_ant_num_by_ant_det = 1; - return; - } - - if (!board_info->btdm_ant_det_finish) { - psd_scan->ant_det_inteval_count = - psd_scan->ant_det_inteval_count + 2; - - if (psd_scan->ant_det_inteval_count >= - BT_8723D_2ANT_ANTDET_RETRY_INTERVAL) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Antenna Det Timer is up, Try Detect!!\n"); - BTC_TRACE(trace_buf); - - psd_scan->is_AntDet_running = true; - - halbtc8723d1ant_read_score_board(btcoexist, &u16tmp); - - if (u16tmp & BIT( - 2)) { /* Antenna detection is already done before last WL power on */ - board_info->btdm_ant_det_finish = true; - psd_scan->ant_det_try_count = 1; - psd_scan->ant_det_fail_count = 0; - board_info->btdm_ant_num_by_ant_det = (u16tmp & - BIT(3)) ? 1 : 2; - psd_scan->ant_det_result = 12; - - psd_scan->ant_det_psd_scan_peak_val = - btcoexist->btc_get_ant_det_val_from_bt( - btcoexist) * 100; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Antenna Det Result from BT (%d-Ant)\n", - board_info->btdm_ant_num_by_ant_det); - BTC_TRACE(trace_buf); - } else - board_info->btdm_ant_det_finish = - halbtc8723d1ant_psd_antenna_detection_check( - btcoexist); - - board_info->ant_det_result = psd_scan->ant_det_result; - btcoexist->bdontenterLPS = false; - - if (board_info->btdm_ant_det_finish) { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Antenna Det Success!!\n"); - BTC_TRACE(trace_buf); - - if (board_info->btdm_ant_num_by_ant_det == 2) { - board_info->ant_div_cfg = true; - halbtc8723d1ant_set_ant_path(btcoexist, - BTC_ANT_PATH_WIFI, FORCE_EXEC, - BT_8723D_1ANT_PHASE_2G_RUNTIME); - } else - halbtc8723d1ant_set_ant_path(btcoexist, - BTC_ANT_PATH_AUTO, FORCE_EXEC, - BT_8723D_1ANT_PHASE_2G_RUNTIME); - - /*for 8723d, btc_set_bt_trx_mask is just used to - notify BT stop le tx and Ant Det Result , not set BT RF TRx Mask */ - if (psd_scan->ant_det_result != 12) { - - AntDetval = (u8)( - psd_scan->ant_det_psd_scan_peak_val - / 100) & 0x7f; - - AntDetval = - (board_info->btdm_ant_num_by_ant_det - == 1) ? (AntDetval | 0x80) : - AntDetval; - board_info->antdetval = AntDetval; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxx AntennaDetect(), Ant Count = %d, PSD Val = %d\n", - ((AntDetval & - 0x80) ? 1 - : 2), AntDetval - & 0x7f); - BTC_TRACE(trace_buf); - - if (btcoexist->btc_set_bt_trx_mask( - btcoexist, AntDetval)) - BTC_SPRINTF(trace_buf, - BT_TMP_BUF_SIZE, - "xxxxxx AntennaDetect(), Notify BT stop le tx by set_bt_trx_mask ok!\n"); - else - BTC_SPRINTF(trace_buf, - BT_TMP_BUF_SIZE, - "xxxxxx AntennaDetect(), Notify BT stop le tx by set_bt_trx_mask fail!\n"); - - BTC_TRACE(trace_buf); - } else - board_info->antdetval = - psd_scan->ant_det_psd_scan_peak_val/100; - - board_info->btdm_ant_det_complete_fail = false; - - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Antenna Det Fail!!\n"); - BTC_TRACE(trace_buf); - - board_info->btdm_ant_det_complete_fail = true; - } - - psd_scan->ant_det_inteval_count = 0; - psd_scan->is_AntDet_running = false; - /* stimulate coex running */ - halbtc8723d1ant_run_coexist_mechanism( - btcoexist); - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Stimulate Coex running\n!!"); - BTC_TRACE(trace_buf); - - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Antenna Det Timer is not up! (%d)\n", - psd_scan->ant_det_inteval_count); - BTC_TRACE(trace_buf); - - if (psd_scan->ant_det_inteval_count == 8) - btcoexist->bdontenterLPS = true; - else - btcoexist->bdontenterLPS = false; - } - - } -#endif - -} - -void ex_halbtc8723d1ant_display_ant_detection(IN struct btc_coexist *btcoexist) -{ -#if BT_8723D_1ANT_ANTDET_ENABLE - struct btc_board_info *board_info = &btcoexist->board_info; - - if (psd_scan->ant_det_try_count != 0) { - halbtc8723d1ant_psd_show_antenna_detect_result(btcoexist); - - if (board_info->btdm_ant_det_finish) - halbtc8723d1ant_psd_showdata(btcoexist); - } -#endif - -} - -void ex_halbtc8723d1ant_antenna_isolation(IN struct btc_coexist *btcoexist, - IN u32 cent_freq, IN u32 offset, IN u32 span, IN u32 seconds) -{ - -} - -void ex_halbtc8723d1ant_psd_scan(IN struct btc_coexist *btcoexist, - IN u32 cent_freq, IN u32 offset, IN u32 span, IN u32 seconds) -{ - -} - -#endif - -#endif /* #if (BT_SUPPORT == 1 && COEX_SUPPORT == 1) */ - diff --git a/hal/btc/halbtc8723d1ant.h b/hal/btc/halbtc8723d1ant.h deleted file mode 100644 index 76edd5a..0000000 --- a/hal/btc/halbtc8723d1ant.h +++ /dev/null @@ -1,413 +0,0 @@ - -#if (BT_SUPPORT == 1 && COEX_SUPPORT == 1) - -#if (RTL8723D_SUPPORT == 1) - -/* ******************************************* - * The following is for 8723D 1ANT BT Co-exist definition - * ******************************************* */ -#define BT_8723D_1ANT_COEX_DBG 0 -#define BT_AUTO_REPORT_ONLY_8723D_1ANT 1 - -#define BT_INFO_8723D_1ANT_B_FTP BIT(7) -#define BT_INFO_8723D_1ANT_B_A2DP BIT(6) -#define BT_INFO_8723D_1ANT_B_HID BIT(5) -#define BT_INFO_8723D_1ANT_B_SCO_BUSY BIT(4) -#define BT_INFO_8723D_1ANT_B_ACL_BUSY BIT(3) -#define BT_INFO_8723D_1ANT_B_INQ_PAGE BIT(2) -#define BT_INFO_8723D_1ANT_B_SCO_ESCO BIT(1) -#define BT_INFO_8723D_1ANT_B_CONNECTION BIT(0) - -#define BT_INFO_8723D_1ANT_A2DP_BASIC_RATE(_BT_INFO_EXT_) \ - (((_BT_INFO_EXT_&BIT(0))) ? true : false) - -#define BTC_RSSI_COEX_THRESH_TOL_8723D_1ANT 2 - -#define BT_8723D_1ANT_WIFI_NOISY_THRESH 30 /* max: 255 */ -#define BT_8723D_1ANT_DEFAULT_ISOLATION 15 /* unit: dB */ - - -/* for Antenna detection */ -#define BT_8723D_1ANT_ANTDET_PSDTHRES_BACKGROUND 50 -#define BT_8723D_1ANT_ANTDET_PSDTHRES_2ANT_BADISOLATION 70 -#define BT_8723D_1ANT_ANTDET_PSDTHRES_2ANT_GOODISOLATION 55 -#define BT_8723D_1ANT_ANTDET_PSDTHRES_1ANT 35 -#define BT_8723D_1ANT_ANTDET_RETRY_INTERVAL 10 /* retry timer if ant det is fail, unit: second */ -#define BT_8723D_1ANT_ANTDET_SWEEPPOINT_DELAY 60000 -#define BT_8723D_1ANT_ANTDET_ENABLE 1 -#define BT_8723D_1ANT_ANTDET_BTTXTIME 100 -#define BT_8723D_1ANT_ANTDET_BTTXCHANNEL 39 -#define BT_8723D_1ANT_ANTDET_PSD_SWWEEPCOUNT 50 - -#define BT_8723D_1ANT_LTECOEX_INDIRECTREG_ACCESS_TIMEOUT 30000 - -enum bt_8723d_1ant_signal_state { - BT_8723D_1ANT_SIG_STA_SET_TO_LOW = 0x0, - BT_8723D_1ANT_SIG_STA_SET_BY_HW = 0x0, - BT_8723D_1ANT_SIG_STA_SET_TO_HIGH = 0x1, - BT_8723D_1ANT_SIG_STA_MAX -}; - -enum bt_8723d_1ant_path_ctrl_owner { - BT_8723D_1ANT_PCO_BTSIDE = 0x0, - BT_8723D_1ANT_PCO_WLSIDE = 0x1, - BT_8723D_1ANT_PCO_MAX -}; - -enum bt_8723d_1ant_gnt_ctrl_type { - BT_8723D_1ANT_GNT_TYPE_CTRL_BY_PTA = 0x0, - BT_8723D_1ANT_GNT_TYPE_CTRL_BY_SW = 0x1, - BT_8723D_1ANT_GNT_TYPE_MAX -}; - -enum bt_8723d_1ant_gnt_ctrl_block { - BT_8723D_1ANT_GNT_BLOCK_RFC_BB = 0x0, - BT_8723D_1ANT_GNT_BLOCK_RFC = 0x1, - BT_8723D_1ANT_GNT_BLOCK_BB = 0x2, - BT_8723D_1ANT_GNT_BLOCK_MAX -}; - -enum bt_8723d_1ant_lte_coex_table_type { - BT_8723D_1ANT_CTT_WL_VS_LTE = 0x0, - BT_8723D_1ANT_CTT_BT_VS_LTE = 0x1, - BT_8723D_1ANT_CTT_MAX -}; - -enum bt_8723d_1ant_lte_break_table_type { - BT_8723D_1ANT_LBTT_WL_BREAK_LTE = 0x0, - BT_8723D_1ANT_LBTT_BT_BREAK_LTE = 0x1, - BT_8723D_1ANT_LBTT_LTE_BREAK_WL = 0x2, - BT_8723D_1ANT_LBTT_LTE_BREAK_BT = 0x3, - BT_8723D_1ANT_LBTT_MAX -}; - -enum bt_info_src_8723d_1ant { - BT_INFO_SRC_8723D_1ANT_WIFI_FW = 0x0, - BT_INFO_SRC_8723D_1ANT_BT_RSP = 0x1, - BT_INFO_SRC_8723D_1ANT_BT_ACTIVE_SEND = 0x2, - BT_INFO_SRC_8723D_1ANT_MAX -}; - -enum bt_8723d_1ant_bt_status { - BT_8723D_1ANT_BT_STATUS_NON_CONNECTED_IDLE = 0x0, - BT_8723D_1ANT_BT_STATUS_CONNECTED_IDLE = 0x1, - BT_8723D_1ANT_BT_STATUS_INQ_PAGE = 0x2, - BT_8723D_1ANT_BT_STATUS_ACL_BUSY = 0x3, - BT_8723D_1ANT_BT_STATUS_SCO_BUSY = 0x4, - BT_8723D_1ANT_BT_STATUS_ACL_SCO_BUSY = 0x5, - BT_8723D_1ANT_BT_STATUS_MAX -}; - -enum bt_8723d_1ant_wifi_status { - BT_8723D_1ANT_WIFI_STATUS_NON_CONNECTED_IDLE = 0x0, - BT_8723D_1ANT_WIFI_STATUS_NON_CONNECTED_ASSO_AUTH_SCAN = 0x1, - BT_8723D_1ANT_WIFI_STATUS_CONNECTED_SCAN = 0x2, - BT_8723D_1ANT_WIFI_STATUS_CONNECTED_SPECIFIC_PKT = 0x3, - BT_8723D_1ANT_WIFI_STATUS_CONNECTED_IDLE = 0x4, - BT_8723D_1ANT_WIFI_STATUS_CONNECTED_BUSY = 0x5, - BT_8723D_1ANT_WIFI_STATUS_MAX -}; - -enum bt_8723d_1ant_coex_algo { - BT_8723D_1ANT_COEX_ALGO_UNDEFINED = 0x0, - BT_8723D_1ANT_COEX_ALGO_SCO = 0x1, - BT_8723D_1ANT_COEX_ALGO_HID = 0x2, - BT_8723D_1ANT_COEX_ALGO_A2DP = 0x3, - BT_8723D_1ANT_COEX_ALGO_A2DP_PANHS = 0x4, - BT_8723D_1ANT_COEX_ALGO_PANEDR = 0x5, - BT_8723D_1ANT_COEX_ALGO_PANHS = 0x6, - BT_8723D_1ANT_COEX_ALGO_PANEDR_A2DP = 0x7, - BT_8723D_1ANT_COEX_ALGO_PANEDR_HID = 0x8, - BT_8723D_1ANT_COEX_ALGO_HID_A2DP_PANEDR = 0x9, - BT_8723D_1ANT_COEX_ALGO_HID_A2DP = 0xa, - BT_8723D_1ANT_COEX_ALGO_MAX = 0xb, -}; - -enum bt_8723d_1ant_phase { - BT_8723D_1ANT_PHASE_COEX_INIT = 0x0, - BT_8723D_1ANT_PHASE_WLANONLY_INIT = 0x1, - BT_8723D_1ANT_PHASE_WLAN_OFF = 0x2, - BT_8723D_1ANT_PHASE_2G_RUNTIME = 0x3, - BT_8723D_1ANT_PHASE_5G_RUNTIME = 0x4, - BT_8723D_1ANT_PHASE_BTMPMODE = 0x5, - BT_8723D_1ANT_PHASE_ANTENNA_DET = 0x6, - BT_8723D_1ANT_PHASE_COEX_POWERON = 0x7, - BT_8723D_1ANT_PHASE_MAX -}; - -enum bt_8723d_1ant_Scoreboard { - BT_8723D_1ANT_SCOREBOARD_ACTIVE = BIT(0), - BT_8723D_1ANT_SCOREBOARD_ONOFF = BIT(1), - BT_8723D_1ANT_SCOREBOARD_SCAN = BIT(2), - BT_8723D_1ANT_SCOREBOARD_UNDERTEST = BIT(3), - BT_8723D_1ANT_SCOREBOARD_WLBUSY = BIT(6) -}; - -struct coex_dm_8723d_1ant { - /* hw setting */ - u8 pre_ant_pos_type; - u8 cur_ant_pos_type; - /* fw mechanism */ - boolean cur_ignore_wlan_act; - boolean pre_ignore_wlan_act; - u8 pre_ps_tdma; - u8 cur_ps_tdma; - u8 ps_tdma_para[5]; - u8 ps_tdma_du_adj_type; - boolean pre_ps_tdma_on; - boolean cur_ps_tdma_on; - boolean pre_bt_auto_report; - boolean cur_bt_auto_report; - u8 pre_lps; - u8 cur_lps; - u8 pre_rpwm; - u8 cur_rpwm; - - /* sw mechanism */ - boolean pre_low_penalty_ra; - boolean cur_low_penalty_ra; - u32 pre_val0x6c0; - u32 cur_val0x6c0; - u32 pre_val0x6c4; - u32 cur_val0x6c4; - u32 pre_val0x6c8; - u32 cur_val0x6c8; - u8 pre_val0x6cc; - u8 cur_val0x6cc; - boolean limited_dig; - - u32 backup_arfr_cnt1; /* Auto Rate Fallback Retry cnt */ - u32 backup_arfr_cnt2; /* Auto Rate Fallback Retry cnt */ - u16 backup_retry_limit; - u8 backup_ampdu_max_time; - - /* algorithm related */ - u8 pre_algorithm; - u8 cur_algorithm; - u8 bt_status; - u8 wifi_chnl_info[3]; - - u32 pre_ra_mask; - u32 cur_ra_mask; - u8 pre_arfr_type; - u8 cur_arfr_type; - u8 pre_retry_limit_type; - u8 cur_retry_limit_type; - u8 pre_ampdu_time_type; - u8 cur_ampdu_time_type; - u32 arp_cnt; - - u8 error_condition; -}; - -struct coex_sta_8723d_1ant { - boolean bt_disabled; - boolean bt_link_exist; - boolean sco_exist; - boolean a2dp_exist; - boolean hid_exist; - boolean pan_exist; - boolean bt_hi_pri_link_exist; - u8 num_of_profile; - - boolean under_lps; - boolean under_ips; - u32 specific_pkt_period_cnt; - u32 high_priority_tx; - u32 high_priority_rx; - u32 low_priority_tx; - u32 low_priority_rx; - boolean is_hiPri_rx_overhead; - s8 bt_rssi; - boolean bt_tx_rx_mask; - u8 pre_bt_rssi_state; - u8 pre_wifi_rssi_state[4]; - u8 bt_info_c2h[BT_INFO_SRC_8723D_1ANT_MAX][10]; - u32 bt_info_c2h_cnt[BT_INFO_SRC_8723D_1ANT_MAX]; - boolean bt_whck_test; - boolean c2h_bt_inquiry_page; - boolean c2h_bt_remote_name_req; - boolean c2h_bt_page; /* Add for win8.1 page out issue */ - boolean wifi_is_high_pri_task; /* Add for win8.1 page out issue */ - u8 bt_retry_cnt; - u8 bt_info_ext; - u8 bt_info_ext2; - u32 pop_event_cnt; - u8 scan_ap_num; - - u32 crc_ok_cck; - u32 crc_ok_11g; - u32 crc_ok_11n; - u32 crc_ok_11n_vht; - - u32 crc_err_cck; - u32 crc_err_11g; - u32 crc_err_11n; - u32 crc_err_11n_vht; - - boolean cck_lock; - boolean pre_ccklock; - boolean cck_ever_lock; - u8 coex_table_type; - - boolean force_lps_on; - - boolean concurrent_rx_mode_on; - - u16 score_board; - u8 isolation_btween_wb; /* 0~ 50 */ - - u8 a2dp_bit_pool; - u8 cut_version; - boolean acl_busy; - boolean bt_create_connection; - - u32 bt_coex_supported_feature; - u32 bt_coex_supported_version; - - u8 bt_ble_scan_type; - u32 bt_ble_scan_para[3]; - - boolean run_time_state; - boolean freeze_coexrun_by_btinfo; - - boolean is_A2DP_3M; - boolean voice_over_HOGP; - u8 bt_info; - boolean is_autoslot; - u8 forbidden_slot; - u8 hid_busy_num; - u8 hid_pair_cnt; - - u32 cnt_RemoteNameReq; - u32 cnt_setupLink; - u32 cnt_ReInit; - u32 cnt_IgnWlanAct; - u32 cnt_Page; - u32 cnt_RoleSwitch; - - u16 bt_reg_vendor_ac; - u16 bt_reg_vendor_ae; - - boolean is_setupLink; - u8 wl_noisy_level; - u32 gnt_error_cnt; - - u8 bt_afh_map[10]; - u8 bt_relink_downcount; - boolean is_tdma_btautoslot; - boolean is_tdma_btautoslot_hang; -}; - -#define BT_8723D_1ANT_ANTDET_PSD_POINTS 256 /* MAX:1024 */ -#define BT_8723D_1ANT_ANTDET_PSD_AVGNUM 1 /* MAX:3 */ -#define BT_8723D_1ANT_ANTDET_BUF_LEN 16 - -struct psdscan_sta_8723d_1ant { - - u32 ant_det_bt_le_channel; /* BT LE Channel ex:2412 */ - u32 ant_det_bt_tx_time; - u32 ant_det_pre_psdscan_peak_val; - boolean ant_det_is_ant_det_available; - u32 ant_det_psd_scan_peak_val; - boolean ant_det_is_btreply_available; - u32 ant_det_psd_scan_peak_freq; - - u8 ant_det_result; - u8 ant_det_peak_val[BT_8723D_1ANT_ANTDET_BUF_LEN]; - u8 ant_det_peak_freq[BT_8723D_1ANT_ANTDET_BUF_LEN]; - u32 ant_det_try_count; - u32 ant_det_fail_count; - u32 ant_det_inteval_count; - u32 ant_det_thres_offset; - - u32 real_cent_freq; - s32 real_offset; - u32 real_span; - - u32 psd_band_width; /* unit: Hz */ - u32 psd_point; /* 128/256/512/1024 */ - u32 psd_report[1024]; /* unit:dB (20logx), 0~255 */ - u32 psd_report_max_hold[1024]; /* unit:dB (20logx), 0~255 */ - u32 psd_start_point; - u32 psd_stop_point; - u32 psd_max_value_point; - u32 psd_max_value; - u32 psd_max_value2; - u32 psd_avg_value; /* filter loop_max_value that below BT_8723D_1ANT_ANTDET_PSDTHRES_1ANT, and average the rest*/ - u32 psd_loop_max_value[BT_8723D_1ANT_ANTDET_PSD_SWWEEPCOUNT]; /*max value in each loop */ - u32 psd_start_base; - u32 psd_avg_num; /* 1/8/16/32 */ - u32 psd_gen_count; - boolean is_AntDet_running; - boolean is_psd_show_max_only; -}; - -/* ******************************************* - * The following is interface which will notify coex module. - * ******************************************* */ -void ex_halbtc8723d1ant_power_on_setting(IN struct btc_coexist *btcoexist); -void ex_halbtc8723d1ant_pre_load_firmware(IN struct btc_coexist *btcoexist); -void ex_halbtc8723d1ant_init_hw_config(IN struct btc_coexist *btcoexist, - IN boolean wifi_only); -void ex_halbtc8723d1ant_init_coex_dm(IN struct btc_coexist *btcoexist); -void ex_halbtc8723d1ant_ips_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8723d1ant_lps_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8723d1ant_scan_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8723d1ant_connect_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8723d1ant_media_status_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8723d1ant_specific_packet_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8723d1ant_bt_info_notify(IN struct btc_coexist *btcoexist, - IN u8 *tmp_buf, IN u8 length); -void ex_halbtc8723d1ant_rf_status_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8723d1ant_halt_notify(IN struct btc_coexist *btcoexist); -void ex_halbtc8723d1ant_pnp_notify(IN struct btc_coexist *btcoexist, - IN u8 pnp_state); -void ex_halbtc8723d1ant_coex_dm_reset(IN struct btc_coexist *btcoexist); -void ex_halbtc8723d1ant_periodical(IN struct btc_coexist *btcoexist); -void ex_halbtc8723d1ant_set_antenna_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8723d1ant_display_coex_info(IN struct btc_coexist *btcoexist); -void ex_halbtc8723d1ant_antenna_detection(IN struct btc_coexist *btcoexist, - IN u32 cent_freq, IN u32 offset, IN u32 span, IN u32 seconds); -void ex_halbtc8723d1ant_antenna_isolation(IN struct btc_coexist *btcoexist, - IN u32 cent_freq, IN u32 offset, IN u32 span, IN u32 seconds); - -void ex_halbtc8723d1ant_psd_scan(IN struct btc_coexist *btcoexist, - IN u32 cent_freq, IN u32 offset, IN u32 span, IN u32 seconds); -void ex_halbtc8723d1ant_display_ant_detection(IN struct btc_coexist *btcoexist); - -#else -#define ex_halbtc8723d1ant_power_on_setting(btcoexist) -#define ex_halbtc8723d1ant_pre_load_firmware(btcoexist) -#define ex_halbtc8723d1ant_init_hw_config(btcoexist, wifi_only) -#define ex_halbtc8723d1ant_init_coex_dm(btcoexist) -#define ex_halbtc8723d1ant_ips_notify(btcoexist, type) -#define ex_halbtc8723d1ant_lps_notify(btcoexist, type) -#define ex_halbtc8723d1ant_scan_notify(btcoexist, type) -#define ex_halbtc8723d1ant_connect_notify(btcoexist, type) -#define ex_halbtc8723d1ant_media_status_notify(btcoexist, type) -#define ex_halbtc8723d1ant_specific_packet_notify(btcoexist, type) -#define ex_halbtc8723d1ant_bt_info_notify(btcoexist, tmp_buf, length) -#define ex_halbtc8723d1ant_rf_status_notify(btcoexist, type) -#define ex_halbtc8723d1ant_halt_notify(btcoexist) -#define ex_halbtc8723d1ant_pnp_notify(btcoexist, pnp_state) -#define ex_halbtc8723d1ant_coex_dm_reset(btcoexist) -#define ex_halbtc8723d1ant_periodical(btcoexist) -#define ex_halbtc8723d1ant_display_coex_info(btcoexist) -#define ex_halbtc8723d1ant_set_antenna_notify(btcoexist, type) -#define ex_halbtc8723d1ant_antenna_detection(btcoexist, cent_freq, offset, span, seconds) -#define ex_halbtc8723d1ant_antenna_isolation(btcoexist, cent_freq, offset, span, seconds) -#define ex_halbtc8723d1ant_psd_scan(btcoexist, cent_freq, offset, span, seconds) -#define ex_halbtc8723d1ant_display_ant_detection(btcoexist) -#endif - -#endif - diff --git a/hal/btc/halbtc8723d2ant.c b/hal/btc/halbtc8723d2ant.c deleted file mode 100644 index 4d54055..0000000 --- a/hal/btc/halbtc8723d2ant.c +++ /dev/null @@ -1,6556 +0,0 @@ -/* ************************************************************ - * Description: - * - * This file is for RTL8723D Co-exist mechanism - * - * History - * 2012/11/15 Cosa first check in. - * - * ************************************************************ */ - -/* ************************************************************ - * include files - * ************************************************************ */ -#include "mp_precomp.h" - -#if (BT_SUPPORT == 1 && COEX_SUPPORT == 1) - -#if (RTL8723D_SUPPORT == 1) -/* ************************************************************ - * Global variables, these are static variables - * ************************************************************ */ -static u8 *trace_buf = &gl_btc_trace_buf[0]; -static struct coex_dm_8723d_2ant glcoex_dm_8723d_2ant; -static struct coex_dm_8723d_2ant *coex_dm = &glcoex_dm_8723d_2ant; -static struct coex_sta_8723d_2ant glcoex_sta_8723d_2ant; -static struct coex_sta_8723d_2ant *coex_sta = &glcoex_sta_8723d_2ant; -static struct psdscan_sta_8723d_2ant gl_psd_scan_8723d_2ant; -static struct psdscan_sta_8723d_2ant *psd_scan = &gl_psd_scan_8723d_2ant; - -const char *const glbt_info_src_8723d_2ant[] = { - "BT Info[wifi fw]", - "BT Info[bt rsp]", - "BT Info[bt auto report]", -}; -/* ************************************************************ - * BtCoex Version Format: - * 1. date : glcoex_ver_date_XXXXX_1ant - * 2. WifiCoexVersion : glcoex_ver_XXXX_1ant - * 3. BtCoexVersion : glcoex_ver_btdesired_XXXXX_1ant - * 4. others : glcoex_ver_XXXXXX_XXXXX_1ant - * - * Variable should be indicated IC and Antenna numbers !!! - * Please strictly follow this order and naming style !!! - * - * ************************************************************ */ -u32 glcoex_ver_date_8723d_2ant = 20161027; -u32 glcoex_ver_8723d_2ant = 0x0f; -u32 glcoex_ver_btdesired_8723d_2ant = 0x0d; - -/* ************************************************************ - * local function proto type if needed - * ************************************************************ - * ************************************************************ - * local function start with halbtc8723d2ant_ - * ************************************************************ */ -u8 halbtc8723d2ant_bt_rssi_state(u8 *ppre_bt_rssi_state, u8 level_num, - u8 rssi_thresh, u8 rssi_thresh1) -{ - s32 bt_rssi = 0; - u8 bt_rssi_state = *ppre_bt_rssi_state; - - bt_rssi = coex_sta->bt_rssi; - - if (level_num == 2) { - if ((*ppre_bt_rssi_state == BTC_RSSI_STATE_LOW) || - (*ppre_bt_rssi_state == BTC_RSSI_STATE_STAY_LOW)) { - if (bt_rssi >= (rssi_thresh + - BTC_RSSI_COEX_THRESH_TOL_8723D_2ANT)) - bt_rssi_state = BTC_RSSI_STATE_HIGH; - else - bt_rssi_state = BTC_RSSI_STATE_STAY_LOW; - } else { - if (bt_rssi < rssi_thresh) - bt_rssi_state = BTC_RSSI_STATE_LOW; - else - bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH; - } - } else if (level_num == 3) { - if (rssi_thresh > rssi_thresh1) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Rssi thresh error!!\n"); - BTC_TRACE(trace_buf); - return *ppre_bt_rssi_state; - } - - if ((*ppre_bt_rssi_state == BTC_RSSI_STATE_LOW) || - (*ppre_bt_rssi_state == BTC_RSSI_STATE_STAY_LOW)) { - if (bt_rssi >= (rssi_thresh + - BTC_RSSI_COEX_THRESH_TOL_8723D_2ANT)) - bt_rssi_state = BTC_RSSI_STATE_MEDIUM; - else - bt_rssi_state = BTC_RSSI_STATE_STAY_LOW; - } else if ((*ppre_bt_rssi_state == BTC_RSSI_STATE_MEDIUM) || - (*ppre_bt_rssi_state == BTC_RSSI_STATE_STAY_MEDIUM)) { - if (bt_rssi >= (rssi_thresh1 + - BTC_RSSI_COEX_THRESH_TOL_8723D_2ANT)) - bt_rssi_state = BTC_RSSI_STATE_HIGH; - else if (bt_rssi < rssi_thresh) - bt_rssi_state = BTC_RSSI_STATE_LOW; - else - bt_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM; - } else { - if (bt_rssi < rssi_thresh1) - bt_rssi_state = BTC_RSSI_STATE_MEDIUM; - else - bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH; - } - } - - *ppre_bt_rssi_state = bt_rssi_state; - - return bt_rssi_state; -} - -u8 halbtc8723d2ant_wifi_rssi_state(IN struct btc_coexist *btcoexist, - IN u8 *pprewifi_rssi_state, IN u8 level_num, IN u8 rssi_thresh, - IN u8 rssi_thresh1) -{ - s32 wifi_rssi = 0; - u8 wifi_rssi_state = *pprewifi_rssi_state; - - btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi); - - if (level_num == 2) { - if ((*pprewifi_rssi_state == BTC_RSSI_STATE_LOW) || - (*pprewifi_rssi_state == BTC_RSSI_STATE_STAY_LOW)) { - if (wifi_rssi >= (rssi_thresh + - BTC_RSSI_COEX_THRESH_TOL_8723D_2ANT)) - wifi_rssi_state = BTC_RSSI_STATE_HIGH; - else - wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW; - } else { - if (wifi_rssi < rssi_thresh) - wifi_rssi_state = BTC_RSSI_STATE_LOW; - else - wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH; - } - } else if (level_num == 3) { - if (rssi_thresh > rssi_thresh1) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], wifi RSSI thresh error!!\n"); - BTC_TRACE(trace_buf); - return *pprewifi_rssi_state; - } - - if ((*pprewifi_rssi_state == BTC_RSSI_STATE_LOW) || - (*pprewifi_rssi_state == BTC_RSSI_STATE_STAY_LOW)) { - if (wifi_rssi >= (rssi_thresh + - BTC_RSSI_COEX_THRESH_TOL_8723D_2ANT)) - wifi_rssi_state = BTC_RSSI_STATE_MEDIUM; - else - wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW; - } else if ((*pprewifi_rssi_state == BTC_RSSI_STATE_MEDIUM) || - (*pprewifi_rssi_state == BTC_RSSI_STATE_STAY_MEDIUM)) { - if (wifi_rssi >= (rssi_thresh1 + - BTC_RSSI_COEX_THRESH_TOL_8723D_2ANT)) - wifi_rssi_state = BTC_RSSI_STATE_HIGH; - else if (wifi_rssi < rssi_thresh) - wifi_rssi_state = BTC_RSSI_STATE_LOW; - else - wifi_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM; - } else { - if (wifi_rssi < rssi_thresh1) - wifi_rssi_state = BTC_RSSI_STATE_MEDIUM; - else - wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH; - } - } - - *pprewifi_rssi_state = wifi_rssi_state; - - return wifi_rssi_state; -} - -void halbtc8723d2ant_coex_switch_threshold(IN struct btc_coexist *btcoexist, - IN u8 isolation_measuared) -{ - s8 interference_wl_tx = 0, interference_bt_tx = 0; - - interference_wl_tx = BT_8723D_2ANT_WIFI_MAX_TX_POWER - - isolation_measuared; - interference_bt_tx = BT_8723D_2ANT_BT_MAX_TX_POWER - - isolation_measuared; - - coex_sta->wifi_coex_thres = BT_8723D_2ANT_WIFI_RSSI_COEXSWITCH_THRES1; - coex_sta->wifi_coex_thres2 = BT_8723D_2ANT_WIFI_RSSI_COEXSWITCH_THRES2; - - coex_sta->bt_coex_thres = BT_8723D_2ANT_BT_RSSI_COEXSWITCH_THRES1; - coex_sta->bt_coex_thres2 = BT_8723D_2ANT_BT_RSSI_COEXSWITCH_THRES2; -} - -void halbtc8723d2ant_limited_rx(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean rej_ap_agg_pkt, - IN boolean bt_ctrl_agg_buf_size, IN u8 agg_buf_size) -{ - boolean reject_rx_agg = rej_ap_agg_pkt; - boolean bt_ctrl_rx_agg_size = bt_ctrl_agg_buf_size; - u8 rx_agg_size = agg_buf_size; - - /* ============================================ */ - /* Rx Aggregation related setting */ - /* ============================================ */ - btcoexist->btc_set(btcoexist, BTC_SET_BL_TO_REJ_AP_AGG_PKT, - &reject_rx_agg); - /* decide BT control aggregation buf size or not */ - btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_CTRL_AGG_SIZE, - &bt_ctrl_rx_agg_size); - /* aggregation buf size, only work when BT control Rx aggregation size. */ - btcoexist->btc_set(btcoexist, BTC_SET_U1_AGG_BUF_SIZE, &rx_agg_size); - /* real update aggregation setting */ - btcoexist->btc_set(btcoexist, BTC_SET_ACT_AGGREGATE_CTRL, NULL); -} - -void halbtc8723d2ant_query_bt_info(IN struct btc_coexist *btcoexist) -{ - u8 h2c_parameter[1] = {0}; - - h2c_parameter[0] |= BIT(0); /* trigger */ - - btcoexist->btc_fill_h2c(btcoexist, 0x61, 1, h2c_parameter); -} - -void halbtc8723d2ant_monitor_bt_ctr(IN struct btc_coexist *btcoexist) -{ - u32 reg_hp_txrx, reg_lp_txrx, u32tmp; - u32 reg_hp_tx = 0, reg_hp_rx = 0, reg_lp_tx = 0, reg_lp_rx = 0; - static u8 num_of_bt_counter_chk = 0, cnt_slave = 0, cnt_overhead = 0, - cnt_autoslot_hang = 0; - - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - - reg_hp_txrx = 0x770; - reg_lp_txrx = 0x774; - - u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_hp_txrx); - reg_hp_tx = u32tmp & MASKLWORD; - reg_hp_rx = (u32tmp & MASKHWORD) >> 16; - - u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_lp_txrx); - reg_lp_tx = u32tmp & MASKLWORD; - reg_lp_rx = (u32tmp & MASKHWORD) >> 16; - - coex_sta->high_priority_tx = reg_hp_tx; - coex_sta->high_priority_rx = reg_hp_rx; - coex_sta->low_priority_tx = reg_lp_tx; - coex_sta->low_priority_rx = reg_lp_rx; - - if (BT_8723D_2ANT_BT_STATUS_NON_CONNECTED_IDLE == - coex_dm->bt_status) { - - if (coex_sta->high_priority_rx >= 15) { - if (cnt_overhead < 3) - cnt_overhead++; - - if (cnt_overhead == 3) - coex_sta->is_hiPri_rx_overhead = true; - } else { - if (cnt_overhead > 0) - cnt_overhead--; - - if (cnt_overhead == 0) - coex_sta->is_hiPri_rx_overhead = false; - } - } - - /* reset counter */ - btcoexist->btc_write_1byte(btcoexist, 0x76e, 0xc); - - if ((coex_sta->low_priority_tx > 1050) && - (!coex_sta->c2h_bt_inquiry_page)) - coex_sta->pop_event_cnt++; - - if ((coex_sta->low_priority_rx >= 950) && - (coex_sta->low_priority_rx >= coex_sta->low_priority_tx) - && (!coex_sta->under_ips) && (!coex_sta->c2h_bt_inquiry_page) && - (coex_sta->bt_link_exist)) { - if (cnt_slave >= 2) { - bt_link_info->slave_role = true; - cnt_slave = 2; - } else - cnt_slave++; - } else { - if (cnt_slave == 0) { - bt_link_info->slave_role = false; - cnt_slave = 0; - } else - cnt_slave--; - - } - - if (coex_sta->is_tdma_btautoslot) { - if ((coex_sta->low_priority_tx >= 1300) && - (coex_sta->low_priority_rx <= 150)) { - if (cnt_autoslot_hang >= 2) { - coex_sta->is_tdma_btautoslot_hang = true; - cnt_autoslot_hang = 2; - } else - cnt_autoslot_hang++; - } else { - if (cnt_autoslot_hang == 0) { - coex_sta->is_tdma_btautoslot_hang = false; - cnt_autoslot_hang = 0; - } else - cnt_autoslot_hang--; - } - } - - if (!coex_sta->bt_disabled) { - - if ((coex_sta->high_priority_tx == 0) && - (coex_sta->high_priority_rx == 0) && - (coex_sta->low_priority_tx == 0) && - (coex_sta->low_priority_rx == 0)) { - num_of_bt_counter_chk++; - if (num_of_bt_counter_chk >= 3) { - halbtc8723d2ant_query_bt_info(btcoexist); - num_of_bt_counter_chk = 0; - } - } - } - -} - -void halbtc8723d2ant_monitor_wifi_ctr(IN struct btc_coexist *btcoexist) -{ -#if 1 - s32 wifi_rssi = 0; - boolean wifi_busy = false, wifi_under_b_mode = false, - wifi_scan = false; - boolean bt_idle = false, wl_idle = false; - static u8 cck_lock_counter = 0, wl_noisy_count0 = 0, - wl_noisy_count1 = 3, wl_noisy_count2 = 0; - u32 total_cnt, reg_val1, reg_val2, cck_cnt; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_B_MODE, - &wifi_under_b_mode); - - coex_sta->crc_ok_cck = btcoexist->btc_phydm_query_PHY_counter( - btcoexist, PHYDM_INFO_CRC32_OK_CCK); - coex_sta->crc_ok_11g = btcoexist->btc_phydm_query_PHY_counter( - btcoexist, PHYDM_INFO_CRC32_OK_LEGACY); - coex_sta->crc_ok_11n = btcoexist->btc_phydm_query_PHY_counter( - btcoexist, PHYDM_INFO_CRC32_OK_HT); - coex_sta->crc_ok_11n_vht = btcoexist->btc_phydm_query_PHY_counter( - btcoexist, PHYDM_INFO_CRC32_OK_VHT); - - coex_sta->crc_err_cck = btcoexist->btc_phydm_query_PHY_counter( - btcoexist, PHYDM_INFO_CRC32_ERROR_CCK); - coex_sta->crc_err_11g = btcoexist->btc_phydm_query_PHY_counter( - btcoexist, PHYDM_INFO_CRC32_ERROR_LEGACY); - coex_sta->crc_err_11n = btcoexist->btc_phydm_query_PHY_counter( - btcoexist, PHYDM_INFO_CRC32_ERROR_HT); - coex_sta->crc_err_11n_vht = btcoexist->btc_phydm_query_PHY_counter( - btcoexist, PHYDM_INFO_CRC32_ERROR_VHT); - - cck_cnt = coex_sta->crc_ok_cck + coex_sta->crc_err_cck; - - if (cck_cnt > 250) { - if (wl_noisy_count2 < 3) - wl_noisy_count2++; - - if (wl_noisy_count2 == 3) { - wl_noisy_count0 = 0; - wl_noisy_count1 = 0; - } - } else if (cck_cnt < 50) { - if (wl_noisy_count0 < 3) - wl_noisy_count0++; - - if (wl_noisy_count0 == 3) { - wl_noisy_count1 = 0; - wl_noisy_count2 = 0; - } - } else { - if (wl_noisy_count1 < 3) - wl_noisy_count1++; - - if (wl_noisy_count1 == 3) { - wl_noisy_count0 = 0; - wl_noisy_count2 = 0; - } - } - - if (wl_noisy_count2 == 3) - coex_sta->wl_noisy_level = 2; - else if (wl_noisy_count1 == 3) - coex_sta->wl_noisy_level = 1; - else - coex_sta->wl_noisy_level = 0; - - if ((wifi_busy) && (wifi_rssi >= 30) && (!wifi_under_b_mode)) { - total_cnt = coex_sta->crc_ok_cck + coex_sta->crc_ok_11g + - coex_sta->crc_ok_11n + coex_sta->crc_ok_11n_vht; - - if ((coex_dm->bt_status == BT_8723D_2ANT_BT_STATUS_ACL_BUSY) || - (coex_dm->bt_status == BT_8723D_2ANT_BT_STATUS_ACL_SCO_BUSY) || - (coex_dm->bt_status == BT_8723D_2ANT_BT_STATUS_SCO_BUSY)) { - if (coex_sta->crc_ok_cck > (total_cnt - - coex_sta->crc_ok_cck)) { - if (cck_lock_counter < 3) - cck_lock_counter++; - } else { - if (cck_lock_counter > 0) - cck_lock_counter--; - } - - } else { - if (cck_lock_counter > 0) - cck_lock_counter--; - } - } else { - if (cck_lock_counter > 0) - cck_lock_counter--; - } - - if (!coex_sta->pre_ccklock) { - - if (cck_lock_counter >= 3) - coex_sta->cck_lock = true; - else - coex_sta->cck_lock = false; - } else { - if (cck_lock_counter == 0) - coex_sta->cck_lock = false; - else - coex_sta->cck_lock = true; - } - - if (coex_sta->cck_lock) - coex_sta->cck_ever_lock = true; - - coex_sta->pre_ccklock = coex_sta->cck_lock; - -#endif -} - -boolean halbtc8723d2ant_is_wifibt_status_changed(IN struct btc_coexist - *btcoexist) -{ - - static boolean pre_wifi_busy = false, pre_under_4way = false, - pre_bt_hs_on = false, pre_bt_off = false, pre_bt_slave = false; - static u8 pre_hid_busy_num = 0, pre_wl_noisy_level = 0; - boolean wifi_busy = false, under_4way = false, bt_hs_on = false; - boolean wifi_connected = false; - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS, - &under_4way); - - if (coex_sta->bt_disabled != pre_bt_off) { - pre_bt_off = coex_sta->bt_disabled; - - if (coex_sta->bt_disabled) - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT is disabled !!\n"); - else - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT is enabled !!\n"); - - BTC_TRACE(trace_buf); - - coex_sta->bt_coex_supported_feature = 0; - coex_sta->bt_coex_supported_version = 0; - coex_sta->bt_ble_scan_type = 0; - coex_sta->bt_ble_scan_para[0] = 0; - coex_sta->bt_ble_scan_para[1] = 0; - coex_sta->bt_ble_scan_para[2] = 0; - coex_sta->bt_reg_vendor_ac = 0xffff; - coex_sta->bt_reg_vendor_ae = 0xffff; - return true; - } - - if (wifi_connected) { - if (wifi_busy != pre_wifi_busy) { - pre_wifi_busy = wifi_busy; - return true; - } - if (under_4way != pre_under_4way) { - pre_under_4way = under_4way; - return true; - } - if (bt_hs_on != pre_bt_hs_on) { - pre_bt_hs_on = bt_hs_on; - return true; - } - if (coex_sta->wl_noisy_level != pre_wl_noisy_level) { - pre_wl_noisy_level = coex_sta->wl_noisy_level; - return true; - } - } - - if (!coex_sta->bt_disabled) { - if (coex_sta->hid_busy_num != pre_hid_busy_num) { - pre_hid_busy_num = coex_sta->hid_busy_num; - return true; - } - } - - if (bt_link_info->slave_role != pre_bt_slave) { - pre_bt_slave = bt_link_info->slave_role; - return true; - } - - return false; -} - -void halbtc8723d2ant_update_bt_link_info(IN struct btc_coexist *btcoexist) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - boolean bt_hs_on = false; - boolean bt_busy = false; - - coex_sta->num_of_profile = 0; - - /* set link exist status */ - if (!(coex_sta->bt_info & BT_INFO_8723D_2ANT_B_CONNECTION)) { - coex_sta->bt_link_exist = false; - coex_sta->pan_exist = false; - coex_sta->a2dp_exist = false; - coex_sta->hid_exist = false; - coex_sta->sco_exist = false; - } else { /* connection exists */ - coex_sta->bt_link_exist = true; - if (coex_sta->bt_info & BT_INFO_8723D_2ANT_B_FTP) { - coex_sta->pan_exist = true; - coex_sta->num_of_profile++; - } else - coex_sta->pan_exist = false; - - if (coex_sta->bt_info & BT_INFO_8723D_2ANT_B_A2DP) { - coex_sta->a2dp_exist = true; - coex_sta->num_of_profile++; - } else - coex_sta->a2dp_exist = false; - - if (coex_sta->bt_info & BT_INFO_8723D_2ANT_B_HID) { - coex_sta->hid_exist = true; - coex_sta->num_of_profile++; - } else - coex_sta->hid_exist = false; - - if (coex_sta->bt_info & BT_INFO_8723D_2ANT_B_SCO_ESCO) { - coex_sta->sco_exist = true; - coex_sta->num_of_profile++; - } else - coex_sta->sco_exist = false; - - } - - btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); - - bt_link_info->bt_link_exist = coex_sta->bt_link_exist; - bt_link_info->sco_exist = coex_sta->sco_exist; - bt_link_info->a2dp_exist = coex_sta->a2dp_exist; - bt_link_info->pan_exist = coex_sta->pan_exist; - bt_link_info->hid_exist = coex_sta->hid_exist; - bt_link_info->acl_busy = coex_sta->acl_busy; - - /* work around for HS mode. */ - if (bt_hs_on) { - bt_link_info->pan_exist = true; - bt_link_info->bt_link_exist = true; - } - - /* check if Sco only */ - if (bt_link_info->sco_exist && - !bt_link_info->a2dp_exist && - !bt_link_info->pan_exist && - !bt_link_info->hid_exist) - bt_link_info->sco_only = true; - else - bt_link_info->sco_only = false; - - /* check if A2dp only */ - if (!bt_link_info->sco_exist && - bt_link_info->a2dp_exist && - !bt_link_info->pan_exist && - !bt_link_info->hid_exist) - bt_link_info->a2dp_only = true; - else - bt_link_info->a2dp_only = false; - - /* check if Pan only */ - if (!bt_link_info->sco_exist && - !bt_link_info->a2dp_exist && - bt_link_info->pan_exist && - !bt_link_info->hid_exist) - bt_link_info->pan_only = true; - else - bt_link_info->pan_only = false; - - /* check if Hid only */ - if (!bt_link_info->sco_exist && - !bt_link_info->a2dp_exist && - !bt_link_info->pan_exist && - bt_link_info->hid_exist) - bt_link_info->hid_only = true; - else - bt_link_info->hid_only = false; - - if (coex_sta->bt_info & BT_INFO_8723D_2ANT_B_INQ_PAGE) { - coex_dm->bt_status = BT_8723D_2ANT_BT_STATUS_INQ_PAGE; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), BT Inq/page!!!\n"); - } else if (!(coex_sta->bt_info & BT_INFO_8723D_2ANT_B_CONNECTION)) { - coex_dm->bt_status = BT_8723D_2ANT_BT_STATUS_NON_CONNECTED_IDLE; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), BT Non-Connected idle!!!\n"); - } else if (coex_sta->bt_info == BT_INFO_8723D_2ANT_B_CONNECTION) { - /* connection exists but no busy */ - coex_dm->bt_status = BT_8723D_2ANT_BT_STATUS_CONNECTED_IDLE; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), BT Connected-idle!!!\n"); - } else if (((coex_sta->bt_info & BT_INFO_8723D_2ANT_B_SCO_ESCO) || - (coex_sta->bt_info & BT_INFO_8723D_2ANT_B_SCO_BUSY)) && - (coex_sta->bt_info & BT_INFO_8723D_2ANT_B_ACL_BUSY)) { - coex_dm->bt_status = BT_8723D_2ANT_BT_STATUS_ACL_SCO_BUSY; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), BT ACL SCO busy!!!\n"); - } else if ((coex_sta->bt_info & BT_INFO_8723D_2ANT_B_SCO_ESCO) || - (coex_sta->bt_info & BT_INFO_8723D_2ANT_B_SCO_BUSY)) { - coex_dm->bt_status = BT_8723D_2ANT_BT_STATUS_SCO_BUSY; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), BT SCO busy!!!\n"); - } else if (coex_sta->bt_info & BT_INFO_8723D_2ANT_B_ACL_BUSY) { - coex_dm->bt_status = BT_8723D_2ANT_BT_STATUS_ACL_BUSY; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), BT ACL busy!!!\n"); - } else { - coex_dm->bt_status = BT_8723D_2ANT_BT_STATUS_MAX; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), BT Non-Defined state!!!\n"); - } - - BTC_TRACE(trace_buf); - - if ((BT_8723D_2ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) || - (BT_8723D_2ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) || - (BT_8723D_2ANT_BT_STATUS_ACL_SCO_BUSY == coex_dm->bt_status)) - bt_busy = true; - else - bt_busy = false; - - btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bt_busy); -} - -void halbtc8723d2ant_update_wifi_channel_info(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - u8 h2c_parameter[3] = {0}; - u32 wifi_bw; - u8 wifi_central_chnl; - - /* only 2.4G we need to inform bt the chnl mask */ - btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_CENTRAL_CHNL, - &wifi_central_chnl); - if ((BTC_MEDIA_CONNECT == type) && - (wifi_central_chnl <= 14)) { - h2c_parameter[0] = - 0x1; /* enable BT AFH skip WL channel for 8723d because BT Rx LO interference */ - /* h2c_parameter[0] = 0x0; */ - h2c_parameter[1] = wifi_central_chnl; - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw); - if (BTC_WIFI_BW_HT40 == wifi_bw) - h2c_parameter[2] = 0x30; - else - h2c_parameter[2] = 0x20; - } - - coex_dm->wifi_chnl_info[0] = h2c_parameter[0]; - coex_dm->wifi_chnl_info[1] = h2c_parameter[1]; - coex_dm->wifi_chnl_info[2] = h2c_parameter[2]; - - btcoexist->btc_fill_h2c(btcoexist, 0x66, 3, h2c_parameter); - -} - -void halbtc8723d2ant_set_fw_dac_swing_level(IN struct btc_coexist *btcoexist, - IN u8 dac_swing_lvl) -{ - u8 h2c_parameter[1] = {0}; - - /* There are several type of dacswing */ - /* 0x18/ 0x10/ 0xc/ 0x8/ 0x4/ 0x6 */ - h2c_parameter[0] = dac_swing_lvl; - - btcoexist->btc_fill_h2c(btcoexist, 0x64, 1, h2c_parameter); -} - -void halbtc8723d2ant_fw_dac_swing_lvl(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 fw_dac_swing_lvl) -{ - coex_dm->cur_fw_dac_swing_lvl = fw_dac_swing_lvl; - - if (!force_exec) { - if (coex_dm->pre_fw_dac_swing_lvl == - coex_dm->cur_fw_dac_swing_lvl) - return; - } - - halbtc8723d2ant_set_fw_dac_swing_level(btcoexist, - coex_dm->cur_fw_dac_swing_lvl); - - coex_dm->pre_fw_dac_swing_lvl = coex_dm->cur_fw_dac_swing_lvl; -} - -void halbtc8723d2ant_set_fw_dec_bt_pwr(IN struct btc_coexist *btcoexist, - IN u8 dec_bt_pwr_lvl) -{ - u8 h2c_parameter[1] = {0}; - - h2c_parameter[0] = dec_bt_pwr_lvl; - - btcoexist->btc_fill_h2c(btcoexist, 0x62, 1, h2c_parameter); -} - -void halbtc8723d2ant_dec_bt_pwr(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 dec_bt_pwr_lvl) -{ - coex_dm->cur_bt_dec_pwr_lvl = dec_bt_pwr_lvl; - - if (!force_exec) { - if (coex_dm->pre_bt_dec_pwr_lvl == coex_dm->cur_bt_dec_pwr_lvl) - return; - } - halbtc8723d2ant_set_fw_dec_bt_pwr(btcoexist, - coex_dm->cur_bt_dec_pwr_lvl); - - coex_dm->pre_bt_dec_pwr_lvl = coex_dm->cur_bt_dec_pwr_lvl; -} - -void halbtc8723d2ant_set_fw_low_penalty_ra(IN struct btc_coexist - *btcoexist, IN boolean low_penalty_ra) -{ -#if 1 - u8 h2c_parameter[6] = {0}; - - h2c_parameter[0] = 0x6; /* op_code, 0x6= Retry_Penalty */ - - if (low_penalty_ra) { - h2c_parameter[1] |= BIT(0); - h2c_parameter[2] = - 0x00; /* normal rate except MCS7/6/5, OFDM54/48/36 */ - h2c_parameter[3] = 0xf7; /* MCS7 or OFDM54 */ - h2c_parameter[4] = 0xf8; /* MCS6 or OFDM48 */ - h2c_parameter[5] = 0xf9; /* MCS5 or OFDM36 */ - } - - btcoexist->btc_fill_h2c(btcoexist, 0x69, 6, h2c_parameter); -#endif -} - -void halbtc8723d2ant_low_penalty_ra(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean low_penalty_ra) -{ - coex_dm->cur_low_penalty_ra = low_penalty_ra; - - if (!force_exec) { - if (coex_dm->pre_low_penalty_ra == coex_dm->cur_low_penalty_ra) - return; - } - - halbtc8723d2ant_set_fw_low_penalty_ra(btcoexist, - coex_dm->cur_low_penalty_ra); - - coex_dm->pre_low_penalty_ra = coex_dm->cur_low_penalty_ra; -} - -void halbtc8723d2ant_set_bt_auto_report(IN struct btc_coexist *btcoexist, - IN boolean enable_auto_report) -{ - u8 h2c_parameter[1] = {0}; - - h2c_parameter[0] = 0; - - if (enable_auto_report) - h2c_parameter[0] |= BIT(0); - - btcoexist->btc_fill_h2c(btcoexist, 0x68, 1, h2c_parameter); -} - -void halbtc8723d2ant_bt_auto_report(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean enable_auto_report) -{ - coex_dm->cur_bt_auto_report = enable_auto_report; - - if (!force_exec) { - if (coex_dm->pre_bt_auto_report == coex_dm->cur_bt_auto_report) - return; - } - halbtc8723d2ant_set_bt_auto_report(btcoexist, - coex_dm->cur_bt_auto_report); - - coex_dm->pre_bt_auto_report = coex_dm->cur_bt_auto_report; -} - -void halbtc8723d2ant_write_score_board( - IN struct btc_coexist *btcoexist, - IN u16 bitpos, - IN boolean state -) -{ - - static u16 originalval = 0x8002; - - if (state) - originalval = originalval | bitpos; - else - originalval = originalval & (~bitpos); - - btcoexist->btc_write_2byte(btcoexist, 0xaa, originalval); - -} - -void halbtc8723d2ant_read_score_board( - IN struct btc_coexist *btcoexist, - IN u16 *score_board_val -) -{ - - *score_board_val = (btcoexist->btc_read_2byte(btcoexist, - 0xaa)) & 0x7fff; -} - -void halbtc8723d2ant_post_state_to_bt( - IN struct btc_coexist *btcoexist, - IN u16 type, - IN boolean state -) -{ - - halbtc8723d2ant_write_score_board(btcoexist, (u16) type, state); - -} - -void halbtc8723d2ant_monitor_bt_enable_disable(IN struct btc_coexist *btcoexist) -{ - static u32 bt_disable_cnt = 0; - boolean bt_active = true, bt_disabled = false; - u16 u16tmp; - - /* This function check if bt is disabled */ - - /* Read BT on/off status from scoreboard[1], enable this only if BT patch support this feature */ - halbtc8723d2ant_read_score_board(btcoexist, &u16tmp); - - bt_active = u16tmp & BIT(1); - - if (bt_active) { - bt_disable_cnt = 0; - bt_disabled = false; - btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_DISABLE, - &bt_disabled); - } else { - - bt_disable_cnt++; - if (bt_disable_cnt >= 2) { - bt_disabled = true; - bt_disable_cnt = 2; - } - - btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_DISABLE, - &bt_disabled); - } - - if (bt_disabled) - halbtc8723d2ant_low_penalty_ra(btcoexist, NORMAL_EXEC, false); - else - halbtc8723d2ant_low_penalty_ra(btcoexist, NORMAL_EXEC, true); - - if (coex_sta->bt_disabled != bt_disabled) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT is from %s to %s!!\n", - (coex_sta->bt_disabled ? "disabled" : "enabled"), - (bt_disabled ? "disabled" : "enabled")); - BTC_TRACE(trace_buf); - coex_sta->bt_disabled = bt_disabled; - } - -} - -void halbtc8723d2ant_enable_gnt_to_gpio(IN struct btc_coexist *btcoexist, - boolean isenable) -{ -#if BT_8723D_2ANT_COEX_DBG - if (isenable) { - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x73, 0x8, 0x1); - - /* enable GNT_BT to GPIO debug */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4e, 0x40, 0x0); - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, 0x1, 0x0); - - /* 0x48[20] = 0 for GPIO14 = GNT_WL*/ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4a, 0x10, 0x0); - /* 0x40[17] = 0 for GPIO14 = GNT_WL*/ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x42, 0x02, 0x0); - - /* 0x66[9] = 0 for GPIO15 = GNT_BT*/ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, 0x02, 0x0); - /* 0x66[7] = 0 - for GPIO15 = GNT_BT*/ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x66, 0x80, 0x0); - /* 0x8[8] = 0 for GPIO15 = GNT_BT*/ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x9, 0x1, 0x0); - - /* BT Vendor Reg 0x76[0] = 0 for GPIO15 = GNT_BT, this is not set here*/ - } else { - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x73, 0x8, 0x0); - - /* Disable GNT_BT debug to GPIO, and enable chip_wakeup_host */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4e, 0x40, 0x1); - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, 0x1, 0x1); - - /* 0x48[20] = 0 for GPIO14 = GNT_WL*/ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4a, 0x10, 0x1); - } - -#endif -} - -u32 halbtc8723d2ant_ltecoex_indirect_read_reg(IN struct btc_coexist *btcoexist, - IN u16 reg_addr) -{ - u32 j = 0; - - /* wait for ready bit before access 0x7c0 */ - btcoexist->btc_write_4byte(btcoexist, 0x7c0, 0x800F0000 | reg_addr); - - do { - j++; - } while (((btcoexist->btc_read_1byte(btcoexist, - 0x7c3)&BIT(5)) == 0) && - (j < BT_8723D_2ANT_LTECOEX_INDIRECTREG_ACCESS_TIMEOUT)); - - return btcoexist->btc_read_4byte(btcoexist, - 0x7c8); /* get read data */ - -} - -void halbtc8723d2ant_ltecoex_indirect_write_reg(IN struct btc_coexist - *btcoexist, - IN u16 reg_addr, IN u32 bit_mask, IN u32 reg_value) -{ - u32 val, i = 0, j = 0, bitpos = 0; - - if (bit_mask == 0x0) - return; - if (bit_mask == 0xffffffff) { - btcoexist->btc_write_4byte(btcoexist, 0x7c4, - reg_value); /* put write data */ - - /* wait for ready bit before access 0x7c0 */ - do { - j++; - } while (((btcoexist->btc_read_1byte(btcoexist, - 0x7c3)&BIT(5)) == 0) && - (j < BT_8723D_2ANT_LTECOEX_INDIRECTREG_ACCESS_TIMEOUT)); - - btcoexist->btc_write_4byte(btcoexist, 0x7c0, - 0xc00F0000 | reg_addr); - } else { - for (i = 0; i <= 31; i++) { - if (((bit_mask >> i) & 0x1) == 0x1) { - bitpos = i; - break; - } - } - - /* read back register value before write */ - val = halbtc8723d2ant_ltecoex_indirect_read_reg(btcoexist, - reg_addr); - val = (val & (~bit_mask)) | (reg_value << bitpos); - - btcoexist->btc_write_4byte(btcoexist, 0x7c4, - val); /* put write data */ - - /* wait for ready bit before access 0x7c0 */ - do { - j++; - } while (((btcoexist->btc_read_1byte(btcoexist, - 0x7c3)&BIT(5)) == 0) && - (j < BT_8723D_2ANT_LTECOEX_INDIRECTREG_ACCESS_TIMEOUT)); - - btcoexist->btc_write_4byte(btcoexist, 0x7c0, - 0xc00F0000 | reg_addr); - - } - -} - -void halbtc8723d2ant_ltecoex_enable(IN struct btc_coexist *btcoexist, - IN boolean enable) -{ - u8 val; - - val = (enable) ? 1 : 0; - halbtc8723d2ant_ltecoex_indirect_write_reg(btcoexist, 0x38, 0x80, - val); /* 0x38[7] */ - -} - -void halbtc8723d2ant_ltecoex_pathcontrol_owner(IN struct btc_coexist *btcoexist, - IN boolean wifi_control) -{ - u8 val; - - val = (wifi_control) ? 1 : 0; - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x73, 0x4, - val); /* 0x70[26] */ - -} - -void halbtc8723d2ant_ltecoex_set_gnt_bt(IN struct btc_coexist *btcoexist, - IN u8 control_block, IN boolean sw_control, IN u8 state) -{ - u32 val = 0, val_orig = 0; - - if (!sw_control) - val = 0x0; - else if (state & 0x1) - val = 0x3; - else - val = 0x1; - - val_orig = halbtc8723d2ant_ltecoex_indirect_read_reg(btcoexist, - 0x38); - - switch (control_block) { - case BT_8723D_2ANT_GNT_BLOCK_RFC_BB: - default: - val = ((val << 14) | (val << 10)) | (val_orig & 0xffff33ff); - break; - case BT_8723D_2ANT_GNT_BLOCK_RFC: - val = (val << 14) | (val_orig & 0xffff3fff); - break; - case BT_8723D_2ANT_GNT_BLOCK_BB: - val = (val << 10) | (val_orig & 0xfffff3ff); - break; - } - - halbtc8723d2ant_ltecoex_indirect_write_reg(btcoexist, - 0x38, 0xffffffff, val); -} - -void halbtc8723d2ant_ltecoex_set_gnt_wl(IN struct btc_coexist *btcoexist, - IN u8 control_block, IN boolean sw_control, IN u8 state) -{ - u32 val = 0, val_orig = 0; - - if (!sw_control) - val = 0x0; - else if (state & 0x1) - val = 0x3; - else - val = 0x1; - - val_orig = halbtc8723d2ant_ltecoex_indirect_read_reg(btcoexist, - 0x38); - - switch (control_block) { - case BT_8723D_2ANT_GNT_BLOCK_RFC_BB: - default: - val = ((val << 12) | (val << 8)) | (val_orig & 0xffffccff); - break; - case BT_8723D_2ANT_GNT_BLOCK_RFC: - val = (val << 12) | (val_orig & 0xffffcfff); - break; - case BT_8723D_2ANT_GNT_BLOCK_BB: - val = (val << 8) | (val_orig & 0xfffffcff); - break; - } - - halbtc8723d2ant_ltecoex_indirect_write_reg(btcoexist, - 0x38, 0xffffffff, val); -} - -void halbtc8723d2ant_ltecoex_set_coex_table(IN struct btc_coexist *btcoexist, - IN u8 table_type, IN u16 table_content) -{ - u16 reg_addr = 0x0000; - - switch (table_type) { - case BT_8723D_2ANT_CTT_WL_VS_LTE: - reg_addr = 0xa0; - break; - case BT_8723D_2ANT_CTT_BT_VS_LTE: - reg_addr = 0xa4; - break; - } - - if (reg_addr != 0x0000) - halbtc8723d2ant_ltecoex_indirect_write_reg(btcoexist, reg_addr, - 0xffff, table_content); /* 0xa0[15:0] or 0xa4[15:0] */ - -} - -void halbtc8723d2ant_ltecoex_set_break_table(IN struct btc_coexist *btcoexist, - IN u8 table_type, IN u8 table_content) -{ - u16 reg_addr = 0x0000; - - switch (table_type) { - case BT_8723D_2ANT_LBTT_WL_BREAK_LTE: - reg_addr = 0xa8; - break; - case BT_8723D_2ANT_LBTT_BT_BREAK_LTE: - reg_addr = 0xac; - break; - case BT_8723D_2ANT_LBTT_LTE_BREAK_WL: - reg_addr = 0xb0; - break; - case BT_8723D_2ANT_LBTT_LTE_BREAK_BT: - reg_addr = 0xb4; - break; - } - - if (reg_addr != 0x0000) - halbtc8723d2ant_ltecoex_indirect_write_reg(btcoexist, reg_addr, - 0xff, table_content); /* 0xa8[15:0] or 0xb4[15:0] */ - -} - -void halbtc8723d2ant_set_wltoggle_coex_table(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 interval, - IN u8 val0x6c4_b0, IN u8 val0x6c4_b1, IN u8 val0x6c4_b2, - IN u8 val0x6c4_b3) -{ - static u8 pre_h2c_parameter[6] = {0}; - u8 cur_h2c_parameter[6] = {0}; - u8 i, match_cnt = 0; - - cur_h2c_parameter[0] = 0x7; /* op_code, 0x7= wlan toggle slot*/ - - cur_h2c_parameter[1] = interval; - cur_h2c_parameter[2] = val0x6c4_b0; - cur_h2c_parameter[3] = val0x6c4_b1; - cur_h2c_parameter[4] = val0x6c4_b2; - cur_h2c_parameter[5] = val0x6c4_b3; - - if (!force_exec) { - for (i = 1; i <= 5; i++) { - if (cur_h2c_parameter[i] != pre_h2c_parameter[i]) - break; - - match_cnt++; - } - - if (match_cnt == 5) - return; - } - - for (i = 1; i <= 5; i++) - pre_h2c_parameter[i] = cur_h2c_parameter[i]; - - btcoexist->btc_fill_h2c(btcoexist, 0x69, 6, cur_h2c_parameter); -} - -void halbtc8723d2ant_set_coex_table(IN struct btc_coexist *btcoexist, - IN u32 val0x6c0, IN u32 val0x6c4, IN u32 val0x6c8, IN u8 val0x6cc) -{ - btcoexist->btc_write_4byte(btcoexist, 0x6c0, val0x6c0); - - btcoexist->btc_write_4byte(btcoexist, 0x6c4, val0x6c4); - - btcoexist->btc_write_4byte(btcoexist, 0x6c8, val0x6c8); - - btcoexist->btc_write_1byte(btcoexist, 0x6cc, val0x6cc); -} - -void halbtc8723d2ant_coex_table(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u32 val0x6c0, IN u32 val0x6c4, - IN u32 val0x6c8, IN u8 val0x6cc) -{ - coex_dm->cur_val0x6c0 = val0x6c0; - coex_dm->cur_val0x6c4 = val0x6c4; - coex_dm->cur_val0x6c8 = val0x6c8; - coex_dm->cur_val0x6cc = val0x6cc; - - if (!force_exec) { - if ((coex_dm->pre_val0x6c0 == coex_dm->cur_val0x6c0) && - (coex_dm->pre_val0x6c4 == coex_dm->cur_val0x6c4) && - (coex_dm->pre_val0x6c8 == coex_dm->cur_val0x6c8) && - (coex_dm->pre_val0x6cc == coex_dm->cur_val0x6cc)) - return; - } - halbtc8723d2ant_set_coex_table(btcoexist, val0x6c0, val0x6c4, val0x6c8, - val0x6cc); - - coex_dm->pre_val0x6c0 = coex_dm->cur_val0x6c0; - coex_dm->pre_val0x6c4 = coex_dm->cur_val0x6c4; - coex_dm->pre_val0x6c8 = coex_dm->cur_val0x6c8; - coex_dm->pre_val0x6cc = coex_dm->cur_val0x6cc; -} - -void halbtc8723d2ant_coex_table_with_type(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 type) -{ - u32 break_table; - u8 select_table; - - coex_sta->coex_table_type = type; - - if (coex_sta->concurrent_rx_mode_on == true) { - break_table = 0xf0ffffff; /* set WL hi-pri can break BT */ - select_table = - 0xb; /* set Tx response = Hi-Pri (ex: Transmitting ACK,BA,CTS) */ - } else { - break_table = 0xffffff; - select_table = 0x3; - } - - switch (type) { - case 0: - halbtc8723d2ant_coex_table(btcoexist, force_exec, - 0xffffffff, 0xffffffff, break_table, select_table); - break; - case 1: - halbtc8723d2ant_coex_table(btcoexist, force_exec, - 0x55555555, 0x5a5a5a5a, break_table, select_table); - break; - case 2: - halbtc8723d2ant_coex_table(btcoexist, force_exec, - 0x5a5a5a5a, 0x5a5a5a5a, break_table, select_table); - break; - case 3: - halbtc8723d2ant_coex_table(btcoexist, force_exec, - 0xaa555555, 0xaa5a5a5a, break_table, select_table); - break; - case 4: - halbtc8723d2ant_coex_table(btcoexist, force_exec, - 0x55555555, 0x5a5a5a5a, break_table, select_table); - break; - case 5: - halbtc8723d2ant_coex_table(btcoexist, force_exec, - 0x55555555, 0x55555555, break_table, select_table); - break; - case 6: - halbtc8723d2ant_coex_table(btcoexist, force_exec, - 0xa5555555, 0xfafafafa, break_table, select_table); - break; - case 7: - halbtc8723d2ant_coex_table(btcoexist, force_exec, - 0xa5555555, 0xaa5a5a5a, break_table, select_table); - break; - case 8: - halbtc8723d2ant_coex_table(btcoexist, force_exec, - 0xa5555555, 0xfafafafa, break_table, select_table); - break; - case 9: - halbtc8723d2ant_coex_table(btcoexist, force_exec, - 0x5a5a5a5a, 0xaaaa5aaa, break_table, select_table); - break; - default: - break; - } -} - -void halbtc8723d2ant_set_fw_ignore_wlan_act(IN struct btc_coexist *btcoexist, - IN boolean enable) -{ - u8 h2c_parameter[1] = {0}; - - if (enable) { - h2c_parameter[0] |= BIT(0); /* function enable */ - } - - btcoexist->btc_fill_h2c(btcoexist, 0x63, 1, h2c_parameter); -} - -void halbtc8723d2ant_ignore_wlan_act(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean enable) -{ - coex_dm->cur_ignore_wlan_act = enable; - - if (!force_exec) { - if (coex_dm->pre_ignore_wlan_act == - coex_dm->cur_ignore_wlan_act) - return; - } - halbtc8723d2ant_set_fw_ignore_wlan_act(btcoexist, enable); - - coex_dm->pre_ignore_wlan_act = coex_dm->cur_ignore_wlan_act; -} - -void halbtc8723d2ant_set_lps_rpwm(IN struct btc_coexist *btcoexist, - IN u8 lps_val, IN u8 rpwm_val) -{ - u8 lps = lps_val; - u8 rpwm = rpwm_val; - - btcoexist->btc_set(btcoexist, BTC_SET_U1_LPS_VAL, &lps); - btcoexist->btc_set(btcoexist, BTC_SET_U1_RPWM_VAL, &rpwm); -} - -void halbtc8723d2ant_lps_rpwm(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 lps_val, IN u8 rpwm_val) -{ - coex_dm->cur_lps = lps_val; - coex_dm->cur_rpwm = rpwm_val; - - if (!force_exec) { - if ((coex_dm->pre_lps == coex_dm->cur_lps) && - (coex_dm->pre_rpwm == coex_dm->cur_rpwm)) - return; - } - halbtc8723d2ant_set_lps_rpwm(btcoexist, lps_val, rpwm_val); - - coex_dm->pre_lps = coex_dm->cur_lps; - coex_dm->pre_rpwm = coex_dm->cur_rpwm; -} - -void halbtc8723d2ant_ps_tdma_check_for_power_save_state( - IN struct btc_coexist *btcoexist, IN boolean new_ps_state) -{ - u8 lps_mode = 0x0; - u8 h2c_parameter[5] = {0, 0, 0, 0x40, 0}; - - btcoexist->btc_get(btcoexist, BTC_GET_U1_LPS_MODE, &lps_mode); - - if (lps_mode) { /* already under LPS state */ - if (new_ps_state) { - /* keep state under LPS, do nothing. */ - } else { - /* will leave LPS state, turn off psTdma first */ - /*halbtc8723d2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, - 8); */ - btcoexist->btc_fill_h2c(btcoexist, 0x60, 5, - h2c_parameter); - } - } else { /* NO PS state */ - if (new_ps_state) { - /* will enter LPS state, turn off psTdma first */ - /*halbtc8723d2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, - 8);*/ - btcoexist->btc_fill_h2c(btcoexist, 0x60, 5, - h2c_parameter); - } else { - /* keep state under NO PS state, do nothing. */ - } - } -} - -void halbtc8723d2ant_power_save_state(IN struct btc_coexist *btcoexist, - IN u8 ps_type, IN u8 lps_val, IN u8 rpwm_val) -{ - boolean low_pwr_disable = false; - - switch (ps_type) { - case BTC_PS_WIFI_NATIVE: - /* recover to original 32k low power setting */ - low_pwr_disable = false; - btcoexist->btc_set(btcoexist, - BTC_SET_ACT_DISABLE_LOW_POWER, - &low_pwr_disable); - btcoexist->btc_set(btcoexist, BTC_SET_ACT_NORMAL_LPS, - NULL); - coex_sta->force_lps_on = false; - break; - case BTC_PS_LPS_ON: - halbtc8723d2ant_ps_tdma_check_for_power_save_state( - btcoexist, true); - halbtc8723d2ant_lps_rpwm(btcoexist, NORMAL_EXEC, - lps_val, rpwm_val); - /* when coex force to enter LPS, do not enter 32k low power. */ - low_pwr_disable = true; - btcoexist->btc_set(btcoexist, - BTC_SET_ACT_DISABLE_LOW_POWER, - &low_pwr_disable); - /* power save must executed before psTdma. */ - btcoexist->btc_set(btcoexist, BTC_SET_ACT_ENTER_LPS, - NULL); - coex_sta->force_lps_on = true; - break; - case BTC_PS_LPS_OFF: - halbtc8723d2ant_ps_tdma_check_for_power_save_state( - btcoexist, false); - btcoexist->btc_set(btcoexist, BTC_SET_ACT_LEAVE_LPS, - NULL); - coex_sta->force_lps_on = false; - break; - default: - break; - } -} - -void halbtc8723d2ant_set_fw_pstdma(IN struct btc_coexist *btcoexist, - IN u8 byte1, IN u8 byte2, IN u8 byte3, IN u8 byte4, IN u8 byte5) -{ - u8 h2c_parameter[5] = {0}; - u8 real_byte1 = byte1, real_byte5 = byte5; - boolean ap_enable = false; - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - - if (byte5 & BIT(2)) - coex_sta->is_tdma_btautoslot = true; - else - coex_sta->is_tdma_btautoslot = false; - - /* release bt-auto slot for auto-slot hang is detected!! */ - if (coex_sta->is_tdma_btautoslot) - if ((coex_sta->is_tdma_btautoslot_hang) || - (bt_link_info->slave_role)) - byte5 = byte5 & 0xfb; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, - &ap_enable); - - if (ap_enable) { - if (byte1 & BIT(4) && !(byte1 & BIT(5))) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], FW for AP mode\n"); - BTC_TRACE(trace_buf); - real_byte1 &= ~BIT(4); - real_byte1 |= BIT(5); - - real_byte5 |= BIT(5); - real_byte5 &= ~BIT(6); - - halbtc8723d2ant_power_save_state(btcoexist, - BTC_PS_WIFI_NATIVE, 0x0, - 0x0); - } - } else if (byte1 & BIT(4) && !(byte1 & BIT(5))) { - - halbtc8723d2ant_power_save_state( - btcoexist, BTC_PS_LPS_ON, 0x50, - 0x4); - } else { - halbtc8723d2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, - 0x0, - 0x0); - } - - h2c_parameter[0] = real_byte1; - h2c_parameter[1] = byte2; - h2c_parameter[2] = byte3; - h2c_parameter[3] = byte4; - h2c_parameter[4] = real_byte5; - - coex_dm->ps_tdma_para[0] = real_byte1; - coex_dm->ps_tdma_para[1] = byte2; - coex_dm->ps_tdma_para[2] = byte3; - coex_dm->ps_tdma_para[3] = byte4; - coex_dm->ps_tdma_para[4] = real_byte5; - - btcoexist->btc_fill_h2c(btcoexist, 0x60, 5, h2c_parameter); -} - -void halbtc8723d2ant_ps_tdma(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean turn_on, IN u8 type) -{ - - static u8 psTdmaByte4Modify = 0x0, pre_psTdmaByte4Modify = 0x0; - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - - coex_dm->cur_ps_tdma_on = turn_on; - coex_dm->cur_ps_tdma = type; - - /* 0x778 = 0x1 at wifi slot (no blocking BT Low-Pri pkts) */ - if ((bt_link_info->slave_role) && (bt_link_info->a2dp_exist)) - psTdmaByte4Modify = 0x1; - else - psTdmaByte4Modify = 0x0; - - if (pre_psTdmaByte4Modify != psTdmaByte4Modify) { - - force_exec = true; - pre_psTdmaByte4Modify = psTdmaByte4Modify; - } - - if (!force_exec) { - if ((coex_dm->pre_ps_tdma_on == coex_dm->cur_ps_tdma_on) && - (coex_dm->pre_ps_tdma == coex_dm->cur_ps_tdma)) - return; - } - - if (coex_dm->cur_ps_tdma_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** TDMA(on, %d) **********\n", - coex_dm->cur_ps_tdma); - BTC_TRACE(trace_buf); - - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x550, 0x8, - 0x1); /* enable TBTT nterrupt */ - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** TDMA(off, %d) **********\n", - coex_dm->cur_ps_tdma); - BTC_TRACE(trace_buf); - } - - if (turn_on) { - switch (type) { - case 1: - halbtc8723d2ant_set_fw_pstdma(btcoexist, 0x61, - 0x10, 0x03, 0x91, - 0x54 | psTdmaByte4Modify); - break; - case 2: - default: - halbtc8723d2ant_set_fw_pstdma(btcoexist, 0x61, - 0x35, 0x03, 0x11, - 0x11 | psTdmaByte4Modify); - break; - case 3: - halbtc8723d2ant_set_fw_pstdma(btcoexist, 0x61, - 0x3a, 0x3, 0x91, - 0x10 | psTdmaByte4Modify); - break; - case 4: - halbtc8723d2ant_set_fw_pstdma(btcoexist, 0x61, - 0x21, 0x3, 0x91, - 0x10 | psTdmaByte4Modify); - break; - case 5: - halbtc8723d2ant_set_fw_pstdma(btcoexist, 0x61, - 0x25, 0x3, 0x91, - 0x10 | psTdmaByte4Modify); - break; - case 6: - halbtc8723d2ant_set_fw_pstdma(btcoexist, 0x61, - 0x10, 0x3, 0x91, - 0x10 | psTdmaByte4Modify); - break; - case 7: - halbtc8723d2ant_set_fw_pstdma(btcoexist, 0x61, - 0x20, 0x3, 0x91, - 0x10 | psTdmaByte4Modify); - break; - case 8: - halbtc8723d2ant_set_fw_pstdma(btcoexist, 0x61, - 0x15, 0x03, 0x11, - 0x11); - break; - case 10: - halbtc8723d2ant_set_fw_pstdma(btcoexist, 0x61, - 0x30, 0x03, 0x11, - 0x10); - break; - case 11: - halbtc8723d2ant_set_fw_pstdma(btcoexist, 0x61, - 0x35, 0x03, 0x11, - 0x10 | psTdmaByte4Modify); - break; - case 12: - halbtc8723d2ant_set_fw_pstdma(btcoexist, 0x61, - 0x35, 0x03, 0x11, 0x11); - break; - case 13: - halbtc8723d2ant_set_fw_pstdma(btcoexist, 0x61, - 0x1c, 0x03, 0x11, - 0x10 | psTdmaByte4Modify); - break; - case 14: - halbtc8723d2ant_set_fw_pstdma(btcoexist, 0x61, - 0x20, 0x03, 0x11, - 0x11); - break; - case 15: - halbtc8723d2ant_set_fw_pstdma(btcoexist, 0x61, - 0x10, 0x03, 0x11, - 0x14); - break; - case 16: - halbtc8723d2ant_set_fw_pstdma(btcoexist, 0x61, - 0x10, 0x03, 0x11, - 0x15); - break; - case 21: - halbtc8723d2ant_set_fw_pstdma(btcoexist, 0x61, - 0x30, 0x03, 0x11, - 0x10); - break; - case 22: - halbtc8723d2ant_set_fw_pstdma(btcoexist, 0x61, - 0x25, 0x03, 0x11, - 0x10); - break; - case 23: - halbtc8723d2ant_set_fw_pstdma(btcoexist, 0x61, - 0x10, 0x03, 0x11, - 0x10); - break; - case 51: - halbtc8723d2ant_set_fw_pstdma(btcoexist, 0x61, - 0x10, 0x03, 0x91, - 0x10 | psTdmaByte4Modify); - break; - case 101: - halbtc8723d2ant_set_fw_pstdma(btcoexist, 0x51, - 0x10, 0x03, 0x10, - 0x54 | psTdmaByte4Modify); - break; - case 102: - halbtc8723d2ant_set_fw_pstdma(btcoexist, 0x61, - 0x35, 0x03, 0x11, - 0x11 | psTdmaByte4Modify); - break; - case 103: - halbtc8723d2ant_set_fw_pstdma(btcoexist, 0x51, - 0x3a, 0x3, 0x10, - 0x50 | psTdmaByte4Modify); - break; - case 104: - halbtc8723d2ant_set_fw_pstdma(btcoexist, 0x51, - 0x21, 0x3, 0x10, - 0x50 | psTdmaByte4Modify); - break; - case 105: - halbtc8723d2ant_set_fw_pstdma(btcoexist, 0x51, - 0x25, 0x3, 0x10, - 0x50 | psTdmaByte4Modify); - break; - case 106: - halbtc8723d2ant_set_fw_pstdma(btcoexist, 0x51, - 0x10, 0x3, 0x10, - 0x50 | psTdmaByte4Modify); - break; - case 107: - halbtc8723d2ant_set_fw_pstdma(btcoexist, 0x51, - 0x20, 0x3, 0x10, - 0x50 | psTdmaByte4Modify); - break; - case 108: - halbtc8723d2ant_set_fw_pstdma(btcoexist, 0x51, - 0x30, 0x3, 0x10, - 0x50 | psTdmaByte4Modify); - break; - case 109: - halbtc8723d2ant_set_fw_pstdma(btcoexist, 0x55, - 0x10, 0x03, 0x10, - 0x54 | psTdmaByte4Modify); - break; - case 110: - halbtc8723d2ant_set_fw_pstdma(btcoexist, 0x55, - 0x30, 0x03, 0x10, - 0x50 | psTdmaByte4Modify); - break; - case 111: - halbtc8723d2ant_set_fw_pstdma(btcoexist, 0x65, - 0x25, 0x03, 0x11, - 0x11 | psTdmaByte4Modify); - break; - case 151: - halbtc8723d2ant_set_fw_pstdma(btcoexist, 0x51, - 0x10, 0x03, 0x10, - 0x50 | psTdmaByte4Modify); - break; - } - } else { - /* disable PS tdma */ - switch (type) { - case 0: - halbtc8723d2ant_set_fw_pstdma(btcoexist, 0x0, - 0x0, 0x0, 0x40, 0x0); - break; - case 1: - halbtc8723d2ant_set_fw_pstdma(btcoexist, 0x0, - 0x0, 0x0, 0x48, 0x0); - break; - default: - halbtc8723d2ant_set_fw_pstdma(btcoexist, 0x0, - 0x0, 0x0, 0x40, 0x0); - break; - } - } - - /* update pre state */ - coex_dm->pre_ps_tdma_on = coex_dm->cur_ps_tdma_on; - coex_dm->pre_ps_tdma = coex_dm->cur_ps_tdma; -} - -void halbtc8723d2ant_set_ant_path(IN struct btc_coexist *btcoexist, - IN u8 ant_pos_type, IN boolean force_exec, - IN u8 phase) -{ - struct btc_board_info *board_info = &btcoexist->board_info; - u32 u32tmp = 0; - boolean pg_ext_switch = false, is_hw_ant_div_on = false; - u8 h2c_parameter[2] = {0}; - u32 cnt_bt_cal_chk = 0; - u8 u8tmp0 = 0, u8tmp1 = 0; - boolean is_in_mp_mode = false; - u32 u32tmp0 = 0, u32tmp1 = 0, u32tmp2 = 0; - u16 u16tmp0 = 0, u16tmp1 = 0; - - u32tmp1 = halbtc8723d2ant_ltecoex_indirect_read_reg(btcoexist, - 0x38); - - /* To avoid indirect access fail */ - if (((u32tmp1 & 0xf000) >> 12) != ((u32tmp1 & 0x0f00) >> 8)) { - force_exec = true; - coex_sta->gnt_error_cnt++; - } - -#if BT_8723D_2ANT_COEX_DBG - u32tmp2 = halbtc8723d2ant_ltecoex_indirect_read_reg(btcoexist, 0x54); - u16tmp0 = btcoexist->btc_read_2byte(btcoexist, 0xaa); - u16tmp1 = btcoexist->btc_read_2byte(btcoexist, 0x948); - u8tmp1 = btcoexist->btc_read_1byte(btcoexist, 0x73); - u8tmp0 = btcoexist->btc_read_1byte(btcoexist, 0x67); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** 0x67 = 0x%x, 0x948 = 0x%x, 0x73 = 0x%x(Before Set Ant Pat)\n", - u8tmp0, u16tmp1, u8tmp1); - BTC_TRACE(trace_buf); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], **********0x38= 0x%x, 0x54= 0x%x, 0xaa = 0x%x (Before Set Ant Path)\n", - u32tmp1, u32tmp2, u16tmp0); - BTC_TRACE(trace_buf); -#endif - - coex_dm->cur_ant_pos_type = ant_pos_type; - - if (!force_exec) { - if (coex_dm->cur_ant_pos_type == coex_dm->pre_ant_pos_type) { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** Skip Antenna Path Setup because no change!!**********\n"); - BTC_TRACE(trace_buf); - return; - } - } - - coex_dm->pre_ant_pos_type = coex_dm->cur_ant_pos_type; - - switch (phase) { - case BT_8723D_2ANT_PHASE_COEX_POWERON: - /* Set Path control to WL */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, - 0x80, 0x0); - - /* set Path control owner to WL at initial step */ - halbtc8723d2ant_ltecoex_pathcontrol_owner(btcoexist, - BT_8723D_2ANT_PCO_BTSIDE); - - /* set GNT_BT to SW high */ - halbtc8723d2ant_ltecoex_set_gnt_bt(btcoexist, - BT_8723D_2ANT_GNT_BLOCK_RFC_BB, - BT_8723D_2ANT_GNT_TYPE_CTRL_BY_SW, - BT_8723D_2ANT_SIG_STA_SET_TO_HIGH); - /* Set GNT_WL to SW low */ - halbtc8723d2ant_ltecoex_set_gnt_wl(btcoexist, - BT_8723D_2ANT_GNT_BLOCK_RFC_BB, - BT_8723D_2ANT_GNT_TYPE_CTRL_BY_SW, - BT_8723D_2ANT_SIG_STA_SET_TO_HIGH); - - if (BTC_ANT_PATH_AUTO == ant_pos_type) - ant_pos_type = BTC_ANT_PATH_WIFI; - - coex_sta->run_time_state = false; - - break; - case BT_8723D_2ANT_PHASE_COEX_INIT: - /* Disable LTE Coex Function in WiFi side (this should be on if LTE coex is required) */ - halbtc8723d2ant_ltecoex_enable(btcoexist, 0x0); - - /* GNT_WL_LTE always = 1 (this should be config if LTE coex is required) */ - halbtc8723d2ant_ltecoex_set_coex_table( - btcoexist, - BT_8723D_2ANT_CTT_WL_VS_LTE, - 0xffff); - - /* GNT_BT_LTE always = 1 (this should be config if LTE coex is required) */ - halbtc8723d2ant_ltecoex_set_coex_table( - btcoexist, - BT_8723D_2ANT_CTT_BT_VS_LTE, - 0xffff); - - /* Wait If BT IQK running, because Path control owner is at BT during BT IQK (setup by WiFi firmware) */ - while (cnt_bt_cal_chk <= 20) { - u8tmp0 = btcoexist->btc_read_1byte( - btcoexist, - 0x49d); - cnt_bt_cal_chk++; - if (u8tmp0 & BIT(0)) { - BTC_SPRINTF( - trace_buf, - BT_TMP_BUF_SIZE, - "[BTCoex], ########### BT is calibrating (wait cnt=%d) ###########\n", - cnt_bt_cal_chk); - BTC_TRACE( - trace_buf); - delay_ms(50); - } else { - BTC_SPRINTF( - trace_buf, - BT_TMP_BUF_SIZE, - "[BTCoex], ********** BT is NOT calibrating (wait cnt=%d)**********\n", - cnt_bt_cal_chk); - BTC_TRACE( - trace_buf); - break; - } - } - - /* Set Path control to WL */ - btcoexist->btc_write_1byte_bitmask(btcoexist, - 0x67, 0x80, 0x1); - - /* set Path control owner to WL at initial step */ - halbtc8723d2ant_ltecoex_pathcontrol_owner( - btcoexist, - BT_8723D_2ANT_PCO_WLSIDE); - - /* set GNT_BT to SW high */ - halbtc8723d2ant_ltecoex_set_gnt_bt(btcoexist, - BT_8723D_2ANT_GNT_BLOCK_RFC_BB, - BT_8723D_2ANT_GNT_TYPE_CTRL_BY_SW, - BT_8723D_2ANT_SIG_STA_SET_TO_HIGH); - /* Set GNT_WL to SW high */ - halbtc8723d2ant_ltecoex_set_gnt_wl(btcoexist, - BT_8723D_2ANT_GNT_BLOCK_RFC_BB, - BT_8723D_2ANT_GNT_TYPE_CTRL_BY_SW, - BT_8723D_2ANT_SIG_STA_SET_TO_HIGH); - - coex_sta->run_time_state = false; - - if (BTC_ANT_PATH_AUTO == ant_pos_type) { - if (board_info->btdm_ant_pos == - BTC_ANTENNA_AT_MAIN_PORT) - ant_pos_type = - BTC_ANT_WIFI_AT_MAIN; - else - ant_pos_type = - BTC_ANT_WIFI_AT_AUX; - } - - break; - case BT_8723D_2ANT_PHASE_WLANONLY_INIT: - /* Disable LTE Coex Function in WiFi side (this should be on if LTE coex is required) */ - halbtc8723d2ant_ltecoex_enable(btcoexist, 0x0); - - /* GNT_WL_LTE always = 1 (this should be config if LTE coex is required) */ - halbtc8723d2ant_ltecoex_set_coex_table( - btcoexist, - BT_8723D_2ANT_CTT_WL_VS_LTE, - 0xffff); - - /* GNT_BT_LTE always = 1 (this should be config if LTE coex is required) */ - halbtc8723d2ant_ltecoex_set_coex_table( - btcoexist, - BT_8723D_2ANT_CTT_BT_VS_LTE, - 0xffff); - - /* Set Path control to WL */ - btcoexist->btc_write_1byte_bitmask(btcoexist, - 0x67, 0x80, 0x1); - - /* set Path control owner to WL at initial step */ - halbtc8723d2ant_ltecoex_pathcontrol_owner( - btcoexist, - BT_8723D_2ANT_PCO_WLSIDE); - - /* set GNT_BT to SW Low */ - halbtc8723d2ant_ltecoex_set_gnt_bt(btcoexist, - BT_8723D_2ANT_GNT_BLOCK_RFC_BB, - BT_8723D_2ANT_GNT_TYPE_CTRL_BY_SW, - BT_8723D_2ANT_SIG_STA_SET_TO_LOW); - /* Set GNT_WL to SW high */ - halbtc8723d2ant_ltecoex_set_gnt_wl(btcoexist, - BT_8723D_2ANT_GNT_BLOCK_RFC_BB, - BT_8723D_2ANT_GNT_TYPE_CTRL_BY_SW, - BT_8723D_2ANT_SIG_STA_SET_TO_HIGH); - - coex_sta->run_time_state = false; - - if (BTC_ANT_PATH_AUTO == ant_pos_type) { - if (board_info->btdm_ant_pos == - BTC_ANTENNA_AT_MAIN_PORT) - ant_pos_type = - BTC_ANT_WIFI_AT_MAIN; - else - ant_pos_type = - BTC_ANT_WIFI_AT_AUX; - } - - break; - case BT_8723D_2ANT_PHASE_WLAN_OFF: - /* Disable LTE Coex Function in WiFi side */ - halbtc8723d2ant_ltecoex_enable(btcoexist, 0x0); - - /* Set Path control to BT */ - btcoexist->btc_write_1byte_bitmask(btcoexist, - 0x67, 0x80, 0x0); - - /* set Path control owner to BT */ - halbtc8723d2ant_ltecoex_pathcontrol_owner( - btcoexist, - BT_8723D_2ANT_PCO_BTSIDE); - - coex_sta->run_time_state = false; - break; - case BT_8723D_2ANT_PHASE_2G_RUNTIME: - - /* wait for WL/BT IQK finish, keep 0x38 = 0xff00 for WL IQK */ - while (cnt_bt_cal_chk <= 20) { - u8tmp0 = btcoexist->btc_read_1byte( - btcoexist, - 0x1e6); - - u8tmp1 = btcoexist->btc_read_1byte( - btcoexist, - 0x49d); - - cnt_bt_cal_chk++; - if ((u8tmp0 & BIT(0)) || - (u8tmp1 & BIT(0))) { - BTC_SPRINTF(trace_buf, - BT_TMP_BUF_SIZE, - "[BTCoex], ########### WL or BT is IQK (wait cnt=%d)\n", - cnt_bt_cal_chk); - BTC_TRACE(trace_buf); - delay_ms(50); - } else { - BTC_SPRINTF(trace_buf, - BT_TMP_BUF_SIZE, - "[BTCoex], ********** WL and BT is NOT IQK (wait cnt=%d)\n", - cnt_bt_cal_chk); - BTC_TRACE(trace_buf); - break; - } - } - - /* Set Path control to WL */ - /* btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, 0x80, 0x1);*/ - - /* set Path control owner to WL at runtime step */ - halbtc8723d2ant_ltecoex_pathcontrol_owner( - btcoexist, - BT_8723D_2ANT_PCO_WLSIDE); - - halbtc8723d2ant_ltecoex_set_gnt_bt(btcoexist, - BT_8723D_2ANT_GNT_BLOCK_RFC_BB, - BT_8723D_2ANT_GNT_TYPE_CTRL_BY_PTA, - BT_8723D_2ANT_SIG_STA_SET_TO_HIGH); - - /* Set GNT_WL to PTA */ - halbtc8723d2ant_ltecoex_set_gnt_wl(btcoexist, - BT_8723D_2ANT_GNT_BLOCK_RFC_BB, - BT_8723D_2ANT_GNT_TYPE_CTRL_BY_PTA, - BT_8723D_2ANT_SIG_STA_SET_BY_HW); - - coex_sta->run_time_state = true; - - if (BTC_ANT_PATH_AUTO == ant_pos_type) { - if (board_info->btdm_ant_pos == - BTC_ANTENNA_AT_MAIN_PORT) - ant_pos_type = - BTC_ANT_WIFI_AT_MAIN; - else - ant_pos_type = - BTC_ANT_WIFI_AT_AUX; - } - - break; - case BT_8723D_2ANT_PHASE_BTMPMODE: - /* Disable LTE Coex Function in WiFi side */ - halbtc8723d2ant_ltecoex_enable(btcoexist, 0x0); - - /* Set Path control to WL */ - btcoexist->btc_write_1byte_bitmask(btcoexist, - 0x67, 0x80, 0x1); - - /* set Path control owner to WL */ - halbtc8723d2ant_ltecoex_pathcontrol_owner( - btcoexist, - BT_8723D_2ANT_PCO_WLSIDE); - - /* set GNT_BT to SW Hi */ - halbtc8723d2ant_ltecoex_set_gnt_bt(btcoexist, - BT_8723D_2ANT_GNT_BLOCK_RFC_BB, - BT_8723D_2ANT_GNT_TYPE_CTRL_BY_SW, - BT_8723D_2ANT_SIG_STA_SET_TO_HIGH); - - /* Set GNT_WL to SW Lo */ - halbtc8723d2ant_ltecoex_set_gnt_wl(btcoexist, - BT_8723D_2ANT_GNT_BLOCK_RFC_BB, - BT_8723D_2ANT_GNT_TYPE_CTRL_BY_SW, - BT_8723D_2ANT_SIG_STA_SET_TO_LOW); - - coex_sta->run_time_state = false; - - if (BTC_ANT_PATH_AUTO == ant_pos_type) { - if (board_info->btdm_ant_pos == - BTC_ANTENNA_AT_MAIN_PORT) - ant_pos_type = - BTC_ANT_WIFI_AT_MAIN; - else - ant_pos_type = - BTC_ANT_WIFI_AT_AUX; - } - - break; - case BT_8723D_2ANT_PHASE_ANTENNA_DET: - - /* Set Path control to WL */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, - 0x80, 0x1); - - /* set Path control owner to WL */ - halbtc8723d2ant_ltecoex_pathcontrol_owner(btcoexist, - BT_8723D_2ANT_PCO_WLSIDE); - - /* Set Antenna Path, both GNT_WL/GNT_BT = 1, and control by SW */ - /* set GNT_BT to SW high */ - halbtc8723d2ant_ltecoex_set_gnt_bt(btcoexist, - BT_8723D_2ANT_GNT_BLOCK_RFC_BB, - BT_8723D_2ANT_GNT_TYPE_CTRL_BY_SW, - BT_8723D_2ANT_SIG_STA_SET_TO_HIGH); - - /* Set GNT_WL to SW high */ - halbtc8723d2ant_ltecoex_set_gnt_wl(btcoexist, - BT_8723D_2ANT_GNT_BLOCK_RFC_BB, - BT_8723D_2ANT_GNT_TYPE_CTRL_BY_SW, - BT_8723D_2ANT_SIG_STA_SET_TO_HIGH); - - if (BTC_ANT_PATH_AUTO == ant_pos_type) - ant_pos_type = BTC_ANT_WIFI_AT_AUX; - - coex_sta->run_time_state = false; - - break; - } - - is_hw_ant_div_on = board_info->ant_div_cfg; - - if ((is_hw_ant_div_on) && (phase != BT_8723D_2ANT_PHASE_ANTENNA_DET)) - btcoexist->btc_write_2byte(btcoexist, 0x948, 0x140); - else if ((is_hw_ant_div_on == false) && - (phase != BT_8723D_2ANT_PHASE_WLAN_OFF)) { - - switch (ant_pos_type) { - case BTC_ANT_WIFI_AT_MAIN: - - btcoexist->btc_write_2byte(btcoexist, - 0x948, 0x0); - break; - case BTC_ANT_WIFI_AT_AUX: - - btcoexist->btc_write_2byte(btcoexist, - 0x948, 0x280); - break; - } - } - -#if BT_8723D_2ANT_COEX_DBG - u32tmp1 = halbtc8723d2ant_ltecoex_indirect_read_reg(btcoexist, 0x38); - u32tmp2 = halbtc8723d2ant_ltecoex_indirect_read_reg(btcoexist, 0x54); - u16tmp0 = btcoexist->btc_read_2byte(btcoexist, 0xaa); - u16tmp1 = btcoexist->btc_read_2byte(btcoexist, 0x948); - u8tmp1 = btcoexist->btc_read_1byte(btcoexist, 0x73); - u8tmp0 = btcoexist->btc_read_1byte(btcoexist, 0x67); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** 0x67 = 0x%x, 0x948 = 0x%x, 0x73 = 0x%x(After Set Ant Pat)\n", - u8tmp0, u16tmp1, u8tmp1); - BTC_TRACE(trace_buf); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], **********0x38= 0x%x, 0x54= 0x%x, 0xaa= 0x%x (After Set Ant Path)\n", - u32tmp1, u32tmp2, u16tmp0); - BTC_TRACE(trace_buf); -#endif - -} - -u8 halbtc8723d2ant_action_algorithm(IN struct btc_coexist *btcoexist) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - boolean bt_hs_on = false; - u8 algorithm = BT_8723D_2ANT_COEX_ALGO_UNDEFINED; - u8 num_of_diff_profile = 0; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); - - if (!bt_link_info->bt_link_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], No BT link exists!!!\n"); - BTC_TRACE(trace_buf); - return algorithm; - } - - if (bt_link_info->sco_exist) - num_of_diff_profile++; - if (bt_link_info->hid_exist) - num_of_diff_profile++; - if (bt_link_info->pan_exist) - num_of_diff_profile++; - if (bt_link_info->a2dp_exist) - num_of_diff_profile++; - - if (num_of_diff_profile == 0) { - - if (bt_link_info->acl_busy) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], No-Profile busy\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8723D_2ANT_COEX_ALGO_NOPROFILEBUSY; - } - } else if (num_of_diff_profile == 1) { - if (bt_link_info->sco_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCO only\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8723D_2ANT_COEX_ALGO_SCO; - } else { - if (bt_link_info->hid_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], HID only\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8723D_2ANT_COEX_ALGO_HID; - } else if (bt_link_info->a2dp_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], A2DP only\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8723D_2ANT_COEX_ALGO_A2DP; - } else if (bt_link_info->pan_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], PAN(HS) only\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8723D_2ANT_COEX_ALGO_PANHS; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], PAN(EDR) only\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8723D_2ANT_COEX_ALGO_PANEDR; - } - } - } - } else if (num_of_diff_profile == 2) { - if (bt_link_info->sco_exist) { - if (bt_link_info->hid_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCO + HID\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8723D_2ANT_COEX_ALGO_SCO; - } else if (bt_link_info->a2dp_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCO + A2DP ==> A2DP\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8723D_2ANT_COEX_ALGO_A2DP; - } else if (bt_link_info->pan_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCO + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8723D_2ANT_COEX_ALGO_SCO; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCO + PAN(EDR)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8723D_2ANT_COEX_ALGO_PANEDR; - } - } - } else { - if (bt_link_info->hid_exist && - bt_link_info->a2dp_exist) { - { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], HID + A2DP\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8723D_2ANT_COEX_ALGO_HID_A2DP; - } - } else if (bt_link_info->hid_exist && - bt_link_info->pan_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], HID + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8723D_2ANT_COEX_ALGO_HID; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], HID + PAN(EDR)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8723D_2ANT_COEX_ALGO_PANEDR_HID; - } - } else if (bt_link_info->pan_exist && - bt_link_info->a2dp_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], A2DP + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8723D_2ANT_COEX_ALGO_A2DP_PANHS; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], A2DP + PAN(EDR)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8723D_2ANT_COEX_ALGO_PANEDR_A2DP; - } - } - } - } else if (num_of_diff_profile == 3) { - if (bt_link_info->sco_exist) { - if (bt_link_info->hid_exist && - bt_link_info->a2dp_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCO + HID + A2DP ==> HID + A2DP\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8723D_2ANT_COEX_ALGO_HID_A2DP; - } else if (bt_link_info->hid_exist && - bt_link_info->pan_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCO + HID + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8723D_2ANT_COEX_ALGO_PANEDR_HID; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCO + HID + PAN(EDR)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8723D_2ANT_COEX_ALGO_PANEDR_HID; - } - } else if (bt_link_info->pan_exist && - bt_link_info->a2dp_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCO + A2DP + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8723D_2ANT_COEX_ALGO_PANEDR_A2DP; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCO + A2DP + PAN(EDR) ==> HID\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8723D_2ANT_COEX_ALGO_PANEDR_A2DP; - } - } - } else { - if (bt_link_info->hid_exist && - bt_link_info->pan_exist && - bt_link_info->a2dp_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], HID + A2DP + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8723D_2ANT_COEX_ALGO_HID_A2DP_PANEDR; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], HID + A2DP + PAN(EDR)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8723D_2ANT_COEX_ALGO_HID_A2DP_PANEDR; - } - } - } - } else if (num_of_diff_profile >= 3) { - if (bt_link_info->sco_exist) { - if (bt_link_info->hid_exist && - bt_link_info->pan_exist && - bt_link_info->a2dp_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Error!!! SCO + HID + A2DP + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8723D_2ANT_COEX_ALGO_HID_A2DP_PANEDR; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCO + HID + A2DP + PAN(EDR)==>PAN(EDR)+HID\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8723D_2ANT_COEX_ALGO_HID_A2DP_PANEDR; - } - } - } - } - - return algorithm; -} - -void halbtc8723d2ant_action_coex_all_off(IN struct btc_coexist *btcoexist) -{ - - halbtc8723d2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - - /* fw all off */ - halbtc8723d2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); - - halbtc8723d2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0x18); - halbtc8723d2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); -} - -void halbtc8723d2ant_action_bt_whql_test(IN struct btc_coexist *btcoexist) -{ - halbtc8723d2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0x18); - halbtc8723d2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - halbtc8723d2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - - halbtc8723d2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); -} - -void halbtc8723d2ant_action_bt_hs(IN struct btc_coexist *btcoexist) -{ - static u8 prewifi_rssi_state = BTC_RSSI_STATE_LOW; - static u8 pre_bt_rssi_state = BTC_RSSI_STATE_LOW; - u8 wifi_rssi_state, bt_rssi_state; - - static u8 prewifi_rssi_state2 = BTC_RSSI_STATE_LOW; - static u8 pre_bt_rssi_state2 = BTC_RSSI_STATE_LOW; - u8 wifi_rssi_state2, bt_rssi_state2; - boolean wifi_busy = false, wifi_turbo = false; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM, - &coex_sta->scan_ap_num); - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "############# [BTCoex], scan_ap_num = %d, wl_noisy = %d\n", - coex_sta->scan_ap_num, coex_sta->wl_noisy_level); - BTC_TRACE(trace_buf); - -#if 1 - if ((wifi_busy) && (coex_sta->wl_noisy_level == 0)) - wifi_turbo = true; -#endif - - wifi_rssi_state = halbtc8723d2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state, 2, - coex_sta->wifi_coex_thres , 0); - - wifi_rssi_state2 = halbtc8723d2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state2, 2, - coex_sta->wifi_coex_thres2 , 0); - - bt_rssi_state = halbtc8723d2ant_bt_rssi_state(&pre_bt_rssi_state, 2, - coex_sta->bt_coex_thres , 0); - - bt_rssi_state2 = halbtc8723d2ant_bt_rssi_state(&pre_bt_rssi_state2, 2, - coex_sta->bt_coex_thres2 , 0); - - if (BTC_RSSI_HIGH(wifi_rssi_state) && - BTC_RSSI_HIGH(bt_rssi_state)) { - - halbtc8723d2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0x18); - halbtc8723d2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - coex_dm->is_switch_to_1dot5_ant = false; - - halbtc8723d2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - - halbtc8723d2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); - } else if (BTC_RSSI_HIGH(wifi_rssi_state2) && - BTC_RSSI_HIGH(bt_rssi_state2)) { - - halbtc8723d2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0x6); - halbtc8723d2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2); - - coex_dm->is_switch_to_1dot5_ant = false; - - halbtc8723d2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - - halbtc8723d2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); - - } else { - - halbtc8723d2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0x18); - halbtc8723d2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - coex_dm->is_switch_to_1dot5_ant = true; - - halbtc8723d2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - - halbtc8723d2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); - } - -} - -void halbtc8723d2ant_action_bt_inquiry(IN struct btc_coexist *btcoexist) -{ - - boolean wifi_connected = false; - boolean wifi_scan = false, wifi_link = false, wifi_roam = false; - boolean wifi_busy = false; - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &wifi_scan); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &wifi_link); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &wifi_roam); - - if ((coex_sta->bt_create_connection) && ((wifi_link) || (wifi_roam) - || (wifi_scan) || (wifi_busy) || (coex_sta->wifi_is_high_pri_task))) { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi link/roam/Scan/busy/hi-pri-task + BT Inq/Page!!\n"); - BTC_TRACE(trace_buf); - - halbtc8723d2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, - 8); - - if ((bt_link_info->a2dp_exist) && (!bt_link_info->pan_exist)) - halbtc8723d2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 15); - else - halbtc8723d2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 11); - } else if ((!wifi_connected) && (!wifi_scan)) { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi no-link + no-scan + BT Inq/Page!!\n"); - BTC_TRACE(trace_buf); - - halbtc8723d2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - - halbtc8723d2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); - } else if (bt_link_info->pan_exist) { - - halbtc8723d2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 22); - - halbtc8723d2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 8); - - } else if (bt_link_info->a2dp_exist) { - - halbtc8723d2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 16); - - halbtc8723d2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 8); - } else { - - if ((wifi_link) || (wifi_roam) || (wifi_scan) || (wifi_busy) - || (coex_sta->wifi_is_high_pri_task)) - halbtc8723d2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 21); - else - halbtc8723d2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 23); - - halbtc8723d2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 8); - } - - halbtc8723d2ant_fw_dac_swing_lvl(btcoexist, FORCE_EXEC, 0x18); - halbtc8723d2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); -} - -void halbtc8723d2ant_action_bt_relink(IN struct btc_coexist *btcoexist) -{ - halbtc8723d2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 8); - halbtc8723d2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1); - - halbtc8723d2ant_fw_dac_swing_lvl(btcoexist, FORCE_EXEC, 0x18); - halbtc8723d2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - coex_sta->bt_relink_downcount = 2; -} - -void halbtc8723d2ant_action_bt_idle(IN struct btc_coexist *btcoexist) -{ - boolean wifi_busy = false; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - - if (!wifi_busy) { - - halbtc8723d2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 2); - - halbtc8723d2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); - } else { /* if wl busy */ - - if (BT_8723D_1ANT_BT_STATUS_NON_CONNECTED_IDLE == - coex_dm->bt_status) { - - halbtc8723d2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 0); - - halbtc8723d2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); - } else { - - halbtc8723d2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 8); - halbtc8723d2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 12); - } - } - - halbtc8723d2ant_fw_dac_swing_lvl(btcoexist, FORCE_EXEC, 0x18); - halbtc8723d2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - -} - -/* SCO only or SCO+PAN(HS) */ -void halbtc8723d2ant_action_sco(IN struct btc_coexist *btcoexist) -{ - static u8 prewifi_rssi_state = BTC_RSSI_STATE_LOW; - static u8 pre_bt_rssi_state = BTC_RSSI_STATE_LOW; - u8 wifi_rssi_state, bt_rssi_state; - - static u8 prewifi_rssi_state2 = BTC_RSSI_STATE_LOW; - static u8 pre_bt_rssi_state2 = BTC_RSSI_STATE_LOW; - u8 wifi_rssi_state2, bt_rssi_state2; - boolean wifi_busy = false; - u32 wifi_bw = 1; - - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, - &wifi_bw); - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - - wifi_rssi_state = halbtc8723d2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state, 2, - coex_sta->wifi_coex_thres , 0); - - wifi_rssi_state2 = halbtc8723d2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state2, 2, - coex_sta->wifi_coex_thres2 , 0); - - bt_rssi_state = halbtc8723d2ant_bt_rssi_state(&pre_bt_rssi_state, 2, - coex_sta->bt_coex_thres , 0); - - bt_rssi_state2 = halbtc8723d2ant_bt_rssi_state(&pre_bt_rssi_state2, 2, - coex_sta->bt_coex_thres2 , 0); - - if (BTC_RSSI_HIGH(wifi_rssi_state) && - BTC_RSSI_HIGH(bt_rssi_state)) { - - halbtc8723d2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0x18); - halbtc8723d2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - coex_dm->is_switch_to_1dot5_ant = false; - - halbtc8723d2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - - halbtc8723d2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); - } else { - - halbtc8723d2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0x18); - halbtc8723d2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - coex_dm->is_switch_to_1dot5_ant = false; - - halbtc8723d2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, - 1); - halbtc8723d2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 8); - } - -} - -void halbtc8723d2ant_action_hid(IN struct btc_coexist *btcoexist) -{ - static u8 prewifi_rssi_state = BTC_RSSI_STATE_LOW; - static u8 pre_bt_rssi_state = BTC_RSSI_STATE_LOW; - u8 wifi_rssi_state, bt_rssi_state; - - static u8 prewifi_rssi_state2 = BTC_RSSI_STATE_LOW; - static u8 pre_bt_rssi_state2 = BTC_RSSI_STATE_LOW; - u8 wifi_rssi_state2, bt_rssi_state2; - boolean wifi_busy = false; - u32 wifi_bw = 1; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw); - - wifi_rssi_state = halbtc8723d2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state, 2, - coex_sta->wifi_coex_thres , 0); - - wifi_rssi_state2 = halbtc8723d2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state2, 2, - coex_sta->wifi_coex_thres2 , 0); - - bt_rssi_state = halbtc8723d2ant_bt_rssi_state(&pre_bt_rssi_state, 2, - coex_sta->bt_coex_thres , 0); - - bt_rssi_state2 = halbtc8723d2ant_bt_rssi_state(&pre_bt_rssi_state2, 2, - coex_sta->bt_coex_thres2 , 0); - - if (BTC_RSSI_HIGH(wifi_rssi_state) && - BTC_RSSI_HIGH(bt_rssi_state)) { - - halbtc8723d2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0x18); - halbtc8723d2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - coex_dm->is_switch_to_1dot5_ant = false; - - halbtc8723d2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - - halbtc8723d2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); - } else { - - halbtc8723d2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0x18); - halbtc8723d2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - coex_dm->is_switch_to_1dot5_ant = false; - - /*for 4/18 hid */ - if (coex_sta->hid_busy_num >= 2) { - if (wifi_bw == 0) { /* if 11bg mode */ - - halbtc8723d2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 8); - halbtc8723d2ant_set_wltoggle_coex_table(btcoexist, - NORMAL_EXEC, - 0x1, 0xaa, - 0x5a, 0xaa, - 0xaa); - halbtc8723d2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 111); - } else { - - if (wifi_busy) { - halbtc8723d2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 8); - halbtc8723d2ant_set_wltoggle_coex_table(btcoexist, - NORMAL_EXEC, - 0x2, 0xaa, - 0x5a, 0xaa, - 0xaa); - halbtc8723d2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 111); - } else { - - halbtc8723d2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, - 3); - halbtc8723d2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 14); - } - } - } else { - - halbtc8723d2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, - 3); - halbtc8723d2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 14); - } - } - -} - -/* A2DP only / PAN(EDR) only/ A2DP+PAN(HS) */ -void halbtc8723d2ant_action_a2dp(IN struct btc_coexist *btcoexist) -{ - static u8 prewifi_rssi_state = BTC_RSSI_STATE_LOW; - static u8 pre_bt_rssi_state = BTC_RSSI_STATE_LOW; - u8 wifi_rssi_state, bt_rssi_state; - - static u8 prewifi_rssi_state2 = BTC_RSSI_STATE_LOW; - static u8 pre_bt_rssi_state2 = BTC_RSSI_STATE_LOW; - u8 wifi_rssi_state2, bt_rssi_state2; - boolean wifi_busy = false, wifi_turbo = false; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM, - &coex_sta->scan_ap_num); - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "############# [BTCoex], scan_ap_num = %d, wl_noisy = %d\n", - coex_sta->scan_ap_num, coex_sta->wl_noisy_level); - BTC_TRACE(trace_buf); - -#if 1 - if ((wifi_busy) && (coex_sta->wl_noisy_level == 0)) - wifi_turbo = true; -#endif - - wifi_rssi_state = halbtc8723d2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state, 2, - coex_sta->wifi_coex_thres , 0); - - wifi_rssi_state2 = halbtc8723d2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state2, 2, - coex_sta->wifi_coex_thres2 , 0); - - bt_rssi_state = halbtc8723d2ant_bt_rssi_state(&pre_bt_rssi_state, 2, - coex_sta->bt_coex_thres , 0); - - bt_rssi_state2 = halbtc8723d2ant_bt_rssi_state(&pre_bt_rssi_state2, 2, - coex_sta->bt_coex_thres2 , 0); - - if (BTC_RSSI_HIGH(wifi_rssi_state) && - BTC_RSSI_HIGH(bt_rssi_state)) { - - halbtc8723d2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0x18); - halbtc8723d2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - coex_dm->is_switch_to_1dot5_ant = false; - - halbtc8723d2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - - halbtc8723d2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); - } else if (BTC_RSSI_HIGH(wifi_rssi_state2) && - BTC_RSSI_HIGH(bt_rssi_state2)) { - - halbtc8723d2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0x6); - halbtc8723d2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2); - - coex_dm->is_switch_to_1dot5_ant = false; - - halbtc8723d2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); - - if (wifi_busy) - halbtc8723d2ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 1); - else - halbtc8723d2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 2); - } else { - - halbtc8723d2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0x18); - halbtc8723d2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - coex_dm->is_switch_to_1dot5_ant = true; - - if ((coex_sta->bt_relink_downcount != 0) - && (wifi_busy)) { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "############# [BTCoex], BT Re-Link + A2DP + WL busy\n"); - BTC_TRACE(trace_buf); - - halbtc8723d2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); - halbtc8723d2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 5); - - } else { - - if (wifi_turbo) - halbtc8723d2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 6); - else - halbtc8723d2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, - 7); - - if (wifi_busy) - halbtc8723d2ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 101); - else - halbtc8723d2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 102); - } - - } - -} - -void halbtc8723d2ant_action_pan_edr(IN struct btc_coexist *btcoexist) -{ - static u8 prewifi_rssi_state = BTC_RSSI_STATE_LOW; - static u8 pre_bt_rssi_state = BTC_RSSI_STATE_LOW; - u8 wifi_rssi_state, bt_rssi_state; - - static u8 prewifi_rssi_state2 = BTC_RSSI_STATE_LOW; - static u8 pre_bt_rssi_state2 = BTC_RSSI_STATE_LOW; - u8 wifi_rssi_state2, bt_rssi_state2; - boolean wifi_busy = false, wifi_turbo = false; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM, - &coex_sta->scan_ap_num); - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "############# [BTCoex], scan_ap_num = %d, wl_noisy = %d\n", - coex_sta->scan_ap_num, coex_sta->wl_noisy_level); - BTC_TRACE(trace_buf); - -#if 1 - if ((wifi_busy) && (coex_sta->wl_noisy_level == 0)) - wifi_turbo = true; -#endif - - wifi_rssi_state = halbtc8723d2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state, 2, - coex_sta->wifi_coex_thres , 0); - - wifi_rssi_state2 = halbtc8723d2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state2, 2, - coex_sta->wifi_coex_thres2 , 0); - - bt_rssi_state = halbtc8723d2ant_bt_rssi_state(&pre_bt_rssi_state, 2, - coex_sta->bt_coex_thres , 0); - - bt_rssi_state2 = halbtc8723d2ant_bt_rssi_state(&pre_bt_rssi_state2, 2, - coex_sta->bt_coex_thres2 , 0); - - if (BTC_RSSI_HIGH(wifi_rssi_state) && - BTC_RSSI_HIGH(bt_rssi_state)) { - - halbtc8723d2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0x18); - halbtc8723d2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - coex_dm->is_switch_to_1dot5_ant = false; - - halbtc8723d2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - - halbtc8723d2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); - } else if (BTC_RSSI_HIGH(wifi_rssi_state2) && - BTC_RSSI_HIGH(bt_rssi_state2)) { - - halbtc8723d2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0x6); - halbtc8723d2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2); - - coex_dm->is_switch_to_1dot5_ant = false; - - halbtc8723d2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); - - if (wifi_busy) - halbtc8723d2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 3); - else - halbtc8723d2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 4); - } else { - - halbtc8723d2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0x18); - halbtc8723d2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - coex_dm->is_switch_to_1dot5_ant = true; - - if (wifi_turbo) - halbtc8723d2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 6); - else - halbtc8723d2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, - 7); - - if (wifi_busy) - halbtc8723d2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 103); - else - halbtc8723d2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 104); - - } -} - -void halbtc8723d2ant_action_hid_a2dp(IN struct btc_coexist *btcoexist) -{ - static u8 prewifi_rssi_state = BTC_RSSI_STATE_LOW; - static u8 pre_bt_rssi_state = BTC_RSSI_STATE_LOW; - u8 wifi_rssi_state, bt_rssi_state; - - static u8 prewifi_rssi_state2 = BTC_RSSI_STATE_LOW; - static u8 pre_bt_rssi_state2 = BTC_RSSI_STATE_LOW; - u8 wifi_rssi_state2, bt_rssi_state2; - boolean wifi_busy = false; - u32 wifi_bw = 1; - - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, - &wifi_bw); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - - wifi_rssi_state = halbtc8723d2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state, 2, - coex_sta->wifi_coex_thres , 0); - - wifi_rssi_state2 = halbtc8723d2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state2, 2, - coex_sta->wifi_coex_thres2 , 0); - - bt_rssi_state = halbtc8723d2ant_bt_rssi_state(&pre_bt_rssi_state, 2, - coex_sta->bt_coex_thres , 0); - - bt_rssi_state2 = halbtc8723d2ant_bt_rssi_state(&pre_bt_rssi_state2, 2, - coex_sta->bt_coex_thres2 , 0); - - if (BTC_RSSI_HIGH(wifi_rssi_state) && - BTC_RSSI_HIGH(bt_rssi_state)) { - - halbtc8723d2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0x18); - halbtc8723d2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - coex_dm->is_switch_to_1dot5_ant = false; - - halbtc8723d2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - halbtc8723d2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); - } else if (BTC_RSSI_HIGH(wifi_rssi_state2) && - BTC_RSSI_HIGH(bt_rssi_state2)) { - - halbtc8723d2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0x6); - halbtc8723d2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2); - - coex_dm->is_switch_to_1dot5_ant = false; - - halbtc8723d2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); - - if (wifi_busy) - halbtc8723d2ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 1); - else - halbtc8723d2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 2); - } else { - - halbtc8723d2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0x18); - halbtc8723d2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - coex_dm->is_switch_to_1dot5_ant = true; - - if ((coex_sta->bt_relink_downcount != 0) - && (wifi_busy)) { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "############# [BTCoex], BT Re-Link + A2DP + WL busy\n"); - BTC_TRACE(trace_buf); - - halbtc8723d2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); - halbtc8723d2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 5); - } else if (wifi_busy) { - if (coex_sta->hid_busy_num >= 2) { - halbtc8723d2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 8); - if (wifi_bw == 0) /*11bg mode */ - halbtc8723d2ant_set_wltoggle_coex_table(btcoexist, - NORMAL_EXEC, - 0x1, 0xaa, - 0x5a, 0xaa, - 0xaa); - else - halbtc8723d2ant_set_wltoggle_coex_table(btcoexist, - NORMAL_EXEC, - 0x2, 0xaa, - 0x5a, 0xaa, - 0xaa); - halbtc8723d2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 109); - } else { - halbtc8723d2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1); - halbtc8723d2ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 101); - } - } else { - halbtc8723d2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, - 1); - halbtc8723d2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 102); - } - - } - -} - -void halbtc8723d2ant_action_a2dp_pan_hs(IN struct btc_coexist *btcoexist) -{ - static u8 prewifi_rssi_state = BTC_RSSI_STATE_LOW; - static u8 pre_bt_rssi_state = BTC_RSSI_STATE_LOW; - u8 wifi_rssi_state, bt_rssi_state; - - static u8 prewifi_rssi_state2 = BTC_RSSI_STATE_LOW; - static u8 pre_bt_rssi_state2 = BTC_RSSI_STATE_LOW; - u8 wifi_rssi_state2, bt_rssi_state2; - boolean wifi_busy = false, wifi_turbo = false; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM, - &coex_sta->scan_ap_num); - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "############# [BTCoex], scan_ap_num = %d, wl_noisy = %d\n", - coex_sta->scan_ap_num, coex_sta->wl_noisy_level); - BTC_TRACE(trace_buf); - -#if 1 - if ((wifi_busy) && (coex_sta->wl_noisy_level == 0)) - wifi_turbo = true; -#endif - - wifi_rssi_state = halbtc8723d2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state, 2, - coex_sta->wifi_coex_thres , 0); - - wifi_rssi_state2 = halbtc8723d2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state2, 2, - coex_sta->wifi_coex_thres2 , 0); - - bt_rssi_state = halbtc8723d2ant_bt_rssi_state(&pre_bt_rssi_state, 2, - coex_sta->bt_coex_thres , 0); - - bt_rssi_state2 = halbtc8723d2ant_bt_rssi_state(&pre_bt_rssi_state2, 2, - coex_sta->bt_coex_thres2 , 0); - - if (BTC_RSSI_HIGH(wifi_rssi_state) && - BTC_RSSI_HIGH(bt_rssi_state)) { - - halbtc8723d2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0x18); - halbtc8723d2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - coex_dm->is_switch_to_1dot5_ant = false; - - halbtc8723d2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - - halbtc8723d2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); - } else if (BTC_RSSI_HIGH(wifi_rssi_state2) && - BTC_RSSI_HIGH(bt_rssi_state2)) { - - halbtc8723d2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0x6); - halbtc8723d2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2); - - coex_dm->is_switch_to_1dot5_ant = false; - - halbtc8723d2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); - - if (wifi_busy) { - - if ((coex_sta->a2dp_bit_pool > 40) && - (coex_sta->a2dp_bit_pool < 255)) - halbtc8723d2ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 7); - else - halbtc8723d2ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 5); - } else - halbtc8723d2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 6); - - } else { - - halbtc8723d2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0x18); - halbtc8723d2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - coex_dm->is_switch_to_1dot5_ant = true; - - if (wifi_turbo) - halbtc8723d2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 6); - else - halbtc8723d2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, - 7); - - if (wifi_busy) { - - if ((coex_sta->a2dp_bit_pool > 40) && - (coex_sta->a2dp_bit_pool < 255)) - halbtc8723d2ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 107); - else - halbtc8723d2ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 105); - } else - halbtc8723d2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 106); - - } - -} - -/* PAN(EDR)+A2DP */ -void halbtc8723d2ant_action_pan_edr_a2dp(IN struct btc_coexist *btcoexist) -{ - static u8 prewifi_rssi_state = BTC_RSSI_STATE_LOW; - static u8 pre_bt_rssi_state = BTC_RSSI_STATE_LOW; - u8 wifi_rssi_state, bt_rssi_state; - - static u8 prewifi_rssi_state2 = BTC_RSSI_STATE_LOW; - static u8 pre_bt_rssi_state2 = BTC_RSSI_STATE_LOW; - u8 wifi_rssi_state2, bt_rssi_state2; - boolean wifi_busy = false, wifi_turbo = false; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM, - &coex_sta->scan_ap_num); - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "############# [BTCoex], scan_ap_num = %d, wl_noisy = %d\n", - coex_sta->scan_ap_num, coex_sta->wl_noisy_level); - BTC_TRACE(trace_buf); - -#if 1 - if ((wifi_busy) && (coex_sta->wl_noisy_level == 0)) - wifi_turbo = true; -#endif - - wifi_rssi_state = halbtc8723d2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state, 2, - coex_sta->wifi_coex_thres , 0); - - wifi_rssi_state2 = halbtc8723d2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state2, 2, - coex_sta->wifi_coex_thres2 , 0); - - bt_rssi_state = halbtc8723d2ant_bt_rssi_state(&pre_bt_rssi_state, 2, - coex_sta->bt_coex_thres , 0); - - bt_rssi_state2 = halbtc8723d2ant_bt_rssi_state(&pre_bt_rssi_state2, 2, - coex_sta->bt_coex_thres2 , 0); - - if (BTC_RSSI_HIGH(wifi_rssi_state) && - BTC_RSSI_HIGH(bt_rssi_state)) { - - halbtc8723d2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0x18); - halbtc8723d2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - coex_dm->is_switch_to_1dot5_ant = false; - - halbtc8723d2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - halbtc8723d2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); - } else if (BTC_RSSI_HIGH(wifi_rssi_state2) && - BTC_RSSI_HIGH(bt_rssi_state2)) { - - halbtc8723d2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0x6); - halbtc8723d2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2); - - coex_dm->is_switch_to_1dot5_ant = false; - - halbtc8723d2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); - - if (wifi_busy) { - - if (((coex_sta->a2dp_bit_pool > 40) && - (coex_sta->a2dp_bit_pool < 255)) || - (!coex_sta->is_A2DP_3M)) - halbtc8723d2ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 7); - else - halbtc8723d2ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 5); - } else - halbtc8723d2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 6); - } else { - - halbtc8723d2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0x18); - halbtc8723d2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - coex_dm->is_switch_to_1dot5_ant = true; - - if (wifi_turbo) - halbtc8723d2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 6); - else - halbtc8723d2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, - 7); - - if (wifi_busy) { - - if ((coex_sta->a2dp_bit_pool > 40) && - (coex_sta->a2dp_bit_pool < 255)) - halbtc8723d2ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 107); - else if (wifi_turbo) - halbtc8723d2ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 108); - else - halbtc8723d2ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 105); - } else - halbtc8723d2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 106); - - } - -} - -void halbtc8723d2ant_action_pan_edr_hid(IN struct btc_coexist *btcoexist) -{ - static u8 prewifi_rssi_state = BTC_RSSI_STATE_LOW; - static u8 pre_bt_rssi_state = BTC_RSSI_STATE_LOW; - u8 wifi_rssi_state, bt_rssi_state; - - static u8 prewifi_rssi_state2 = BTC_RSSI_STATE_LOW; - static u8 pre_bt_rssi_state2 = BTC_RSSI_STATE_LOW; - u8 wifi_rssi_state2, bt_rssi_state2; - boolean wifi_busy = false; - u32 wifi_bw = 1; - - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, - &wifi_bw); - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - - wifi_rssi_state = halbtc8723d2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state, 2, - coex_sta->wifi_coex_thres , 0); - - wifi_rssi_state2 = halbtc8723d2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state2, 2, - coex_sta->wifi_coex_thres2 , 0); - - bt_rssi_state = halbtc8723d2ant_bt_rssi_state(&pre_bt_rssi_state, 2, - coex_sta->bt_coex_thres , 0); - - bt_rssi_state2 = halbtc8723d2ant_bt_rssi_state(&pre_bt_rssi_state2, 2, - coex_sta->bt_coex_thres2 , 0); - - if (BTC_RSSI_HIGH(wifi_rssi_state) && - BTC_RSSI_HIGH(bt_rssi_state)) { - - halbtc8723d2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0x18); - halbtc8723d2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - coex_dm->is_switch_to_1dot5_ant = false; - - halbtc8723d2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - halbtc8723d2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); - } else if (BTC_RSSI_HIGH(wifi_rssi_state2) && - BTC_RSSI_HIGH(bt_rssi_state2)) { - - halbtc8723d2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0x6); - halbtc8723d2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2); - - coex_dm->is_switch_to_1dot5_ant = false; - - halbtc8723d2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); - - if (wifi_busy) - halbtc8723d2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 3); - else - halbtc8723d2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 4); - } else { - - halbtc8723d2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0x18); - halbtc8723d2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - coex_dm->is_switch_to_1dot5_ant = true; - - if (coex_sta->hid_busy_num >= 2) { - - halbtc8723d2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 8); - if (wifi_bw == 0) /*11bg mode */ - halbtc8723d2ant_set_wltoggle_coex_table(btcoexist, - NORMAL_EXEC, - 0x1, 0xaa, - 0x5a, 0xaa, - 0xaa); - else - halbtc8723d2ant_set_wltoggle_coex_table(btcoexist, - NORMAL_EXEC, - 0x2, 0xaa, - 0x5a, 0xaa, - 0xaa); - halbtc8723d2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 110); - } else { - - halbtc8723d2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1); - - if (wifi_busy) - halbtc8723d2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 103); - else - halbtc8723d2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 104); - } - - } - -} - -/* HID+A2DP+PAN(EDR) */ -void halbtc8723d2ant_action_hid_a2dp_pan_edr(IN struct btc_coexist *btcoexist) -{ - static u8 prewifi_rssi_state = BTC_RSSI_STATE_LOW; - static u8 pre_bt_rssi_state = BTC_RSSI_STATE_LOW; - u8 wifi_rssi_state, bt_rssi_state; - - static u8 prewifi_rssi_state2 = BTC_RSSI_STATE_LOW; - static u8 pre_bt_rssi_state2 = BTC_RSSI_STATE_LOW; - u8 wifi_rssi_state2, bt_rssi_state2; - boolean wifi_busy = false; - u32 wifi_bw = 1; - - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, - &wifi_bw); - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - - wifi_rssi_state = halbtc8723d2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state, 2, - coex_sta->wifi_coex_thres , 0); - - wifi_rssi_state2 = halbtc8723d2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state2, 2, - coex_sta->wifi_coex_thres2 , 0); - - bt_rssi_state = halbtc8723d2ant_bt_rssi_state(&pre_bt_rssi_state, 2, - coex_sta->bt_coex_thres , 0); - - bt_rssi_state2 = halbtc8723d2ant_bt_rssi_state(&pre_bt_rssi_state2, 2, - coex_sta->bt_coex_thres2 , 0); - - if (BTC_RSSI_HIGH(wifi_rssi_state) && - BTC_RSSI_HIGH(bt_rssi_state)) { - - halbtc8723d2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0x18); - halbtc8723d2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - coex_dm->is_switch_to_1dot5_ant = false; - - halbtc8723d2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - halbtc8723d2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); - } else if (BTC_RSSI_HIGH(wifi_rssi_state2) && - BTC_RSSI_HIGH(bt_rssi_state2)) { - - halbtc8723d2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0x6); - halbtc8723d2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2); - - coex_dm->is_switch_to_1dot5_ant = false; - - halbtc8723d2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); - - if (wifi_busy) { - - if (((coex_sta->a2dp_bit_pool > 40) && - (coex_sta->a2dp_bit_pool < 255)) || - (!coex_sta->is_A2DP_3M)) - halbtc8723d2ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 7); - else - halbtc8723d2ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 5); - } else - halbtc8723d2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 6); - } else { - - halbtc8723d2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0x18); - halbtc8723d2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - coex_dm->is_switch_to_1dot5_ant = true; - - if (coex_sta->hid_busy_num >= 2) { - halbtc8723d2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 8); - if (wifi_bw == 0) /*11bg mode */ - halbtc8723d2ant_set_wltoggle_coex_table(btcoexist, - NORMAL_EXEC, - 0x1, 0xaa, - 0x5a, 0xaa, - 0xaa); - else - halbtc8723d2ant_set_wltoggle_coex_table(btcoexist, - NORMAL_EXEC, - 0x2, 0xaa, - 0x5a, 0xaa, - 0xaa); - halbtc8723d2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 110); - } else { - halbtc8723d2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1); - - if (wifi_busy) { - - if ((coex_sta->a2dp_bit_pool > 40) && - (coex_sta->a2dp_bit_pool < 255)) - halbtc8723d2ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 107); - else - halbtc8723d2ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 105); - } else - halbtc8723d2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 106); - } - } - -} - -void halbtc8723d2ant_action_wifi_multi_port(IN struct btc_coexist *btcoexist) -{ - halbtc8723d2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0x18); - halbtc8723d2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - /* hw all off */ - halbtc8723d2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - - halbtc8723d2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); -} - -void halbtc8723d2ant_action_wifi_linkscan_process(IN struct btc_coexist *btcoexist) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - - halbtc8723d2ant_fw_dac_swing_lvl(btcoexist, FORCE_EXEC, 0x18); - halbtc8723d2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - halbtc8723d2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 8); - - if (bt_link_info->pan_exist) { - - halbtc8723d2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 22); - - halbtc8723d2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 8); - - } else if (bt_link_info->a2dp_exist) { - - halbtc8723d2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 15); - - halbtc8723d2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 8); - } else { - - halbtc8723d2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 21); - - halbtc8723d2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 8); - } - -} - -void halbtc8723d2ant_action_wifi_not_connected(IN struct btc_coexist *btcoexist) -{ - halbtc8723d2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - - /* fw all off */ - halbtc8723d2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); - - halbtc8723d2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0x18); - halbtc8723d2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); -} - -void halbtc8723d2ant_action_wifi_connected(IN struct btc_coexist *btcoexist) -{ - switch (coex_dm->cur_algorithm) { - - case BT_8723D_2ANT_COEX_ALGO_SCO: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, algorithm = SCO.\n"); - BTC_TRACE(trace_buf); - halbtc8723d2ant_action_sco(btcoexist); - break; - case BT_8723D_2ANT_COEX_ALGO_HID: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, algorithm = HID.\n"); - BTC_TRACE(trace_buf); - halbtc8723d2ant_action_hid(btcoexist); - break; - case BT_8723D_2ANT_COEX_ALGO_A2DP: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, algorithm = A2DP.\n"); - BTC_TRACE(trace_buf); - halbtc8723d2ant_action_a2dp(btcoexist); - break; - case BT_8723D_2ANT_COEX_ALGO_A2DP_PANHS: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, algorithm = A2DP+PAN(HS).\n"); - BTC_TRACE(trace_buf); - halbtc8723d2ant_action_a2dp_pan_hs(btcoexist); - break; - case BT_8723D_2ANT_COEX_ALGO_PANEDR: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, algorithm = PAN(EDR).\n"); - BTC_TRACE(trace_buf); - halbtc8723d2ant_action_pan_edr(btcoexist); - break; - case BT_8723D_2ANT_COEX_ALGO_PANEDR_A2DP: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, algorithm = PAN+A2DP.\n"); - BTC_TRACE(trace_buf); - halbtc8723d2ant_action_pan_edr_a2dp(btcoexist); - break; - case BT_8723D_2ANT_COEX_ALGO_PANEDR_HID: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, algorithm = PAN(EDR)+HID.\n"); - BTC_TRACE(trace_buf); - halbtc8723d2ant_action_pan_edr_hid(btcoexist); - break; - case BT_8723D_2ANT_COEX_ALGO_HID_A2DP_PANEDR: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, algorithm = HID+A2DP+PAN.\n"); - BTC_TRACE(trace_buf); - halbtc8723d2ant_action_hid_a2dp_pan_edr( - btcoexist); - break; - case BT_8723D_2ANT_COEX_ALGO_HID_A2DP: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, algorithm = HID+A2DP.\n"); - BTC_TRACE(trace_buf); - halbtc8723d2ant_action_hid_a2dp(btcoexist); - break; - case BT_8723D_2ANT_COEX_ALGO_NOPROFILEBUSY: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, algorithm = No-Profile busy.\n"); - BTC_TRACE(trace_buf); - halbtc8723d2ant_action_bt_idle(btcoexist); - break; - default: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, algorithm = coexist All Off!!\n"); - BTC_TRACE(trace_buf); - halbtc8723d2ant_action_coex_all_off(btcoexist); - break; - } - - coex_dm->pre_algorithm = coex_dm->cur_algorithm; - -} - -void halbtc8723d2ant_run_coexist_mechanism(IN struct btc_coexist *btcoexist) -{ - u8 algorithm = 0; - u32 num_of_wifi_link = 0; - u32 wifi_link_status = 0; - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - boolean miracast_plus_bt = false; - boolean scan = false, link = false, roam = false, - under_4way = false, - wifi_connected = false, wifi_under_5g = false, - bt_hs_on = false; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS, - &under_4way); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], RunCoexistMechanism()===>\n"); - BTC_TRACE(trace_buf); - - if (btcoexist->manual_control) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], RunCoexistMechanism(), return for Manual CTRL <===\n"); - BTC_TRACE(trace_buf); - return; - } - - if (btcoexist->stop_coex_dm) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], RunCoexistMechanism(), return for Stop Coex DM <===\n"); - BTC_TRACE(trace_buf); - return; - } - - if (coex_sta->under_ips) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], wifi is under IPS !!!\n"); - BTC_TRACE(trace_buf); - return; - } - - if (!coex_sta->run_time_state) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], return for run_time_state = false !!!\n"); - BTC_TRACE(trace_buf); - return; - } - - if (coex_sta->freeze_coexrun_by_btinfo) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), return for freeze_coexrun_by_btinfo\n"); - BTC_TRACE(trace_buf); - return; - } - - if (coex_sta->bt_whck_test) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT is under WHCK TEST!!!\n"); - BTC_TRACE(trace_buf); - halbtc8723d2ant_action_bt_whql_test(btcoexist); - return; - } - - if (coex_sta->bt_disabled) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT is disabled!!!\n"); - BTC_TRACE(trace_buf); - halbtc8723d2ant_action_coex_all_off(btcoexist); - return; - } - - if (coex_sta->c2h_bt_inquiry_page) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT is under inquiry/page scan !!\n"); - BTC_TRACE(trace_buf); - halbtc8723d2ant_action_bt_inquiry(btcoexist); - return; - } - - if (coex_sta->is_setupLink) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT is re-link !!!\n"); - halbtc8723d2ant_action_bt_relink(btcoexist); - return; - } - - /* for P2P */ - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS, - &wifi_link_status); - num_of_wifi_link = wifi_link_status >> 16; - - if ((num_of_wifi_link >= 2) || - (wifi_link_status & WIFI_P2P_GO_CONNECTED)) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "############# [BTCoex], Multi-Port num_of_wifi_link = %d, wifi_link_status = 0x%x\n", - num_of_wifi_link, wifi_link_status); - BTC_TRACE(trace_buf); - - if (bt_link_info->bt_link_exist) - miracast_plus_bt = true; - else - miracast_plus_bt = false; - - btcoexist->btc_set(btcoexist, BTC_SET_BL_MIRACAST_PLUS_BT, - &miracast_plus_bt); - - if (scan || link || roam || under_4way) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], scan = %d, link = %d, roam = %d 4way = %d!!!\n", - scan, link, roam, under_4way); - BTC_TRACE(trace_buf); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], wifi is under linkscan process + Multi-Port !!\n"); - BTC_TRACE(trace_buf); - - halbtc8723d2ant_action_wifi_linkscan_process(btcoexist); - } else - halbtc8723d2ant_action_wifi_multi_port(btcoexist); - - return; - } else { - miracast_plus_bt = false; - btcoexist->btc_set(btcoexist, BTC_SET_BL_MIRACAST_PLUS_BT, - &miracast_plus_bt); - } - - btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); - - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "############# [BTCoex], BT Is hs\n"); - BTC_TRACE(trace_buf); - halbtc8723d2ant_action_bt_hs(btcoexist); - return; - } - - if ((BT_8723D_2ANT_BT_STATUS_NON_CONNECTED_IDLE == - coex_dm->bt_status) || - (BT_8723D_2ANT_BT_STATUS_CONNECTED_IDLE == - coex_dm->bt_status)) { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, bt idle!!.\n"); - BTC_TRACE(trace_buf); - - halbtc8723d2ant_action_bt_idle(btcoexist); - return; - } - - algorithm = halbtc8723d2ant_action_algorithm(btcoexist); - coex_dm->cur_algorithm = algorithm; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], Algorithm = %d\n", - coex_dm->cur_algorithm); - BTC_TRACE(trace_buf); - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - - if (scan || link || roam || under_4way) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], WiFi is under Link Process !!\n"); - BTC_TRACE(trace_buf); - halbtc8723d2ant_action_wifi_linkscan_process(btcoexist); - } else if (wifi_connected) { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, wifi connected!!.\n"); - BTC_TRACE(trace_buf); - halbtc8723d2ant_action_wifi_connected(btcoexist); - - } else { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, wifi not-connected!!.\n"); - BTC_TRACE(trace_buf); - halbtc8723d2ant_action_wifi_not_connected(btcoexist); - } -} - -void halbtc8723d2ant_init_coex_dm(IN struct btc_coexist *btcoexist) -{ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Coex Mechanism Init!!\n"); - BTC_TRACE(trace_buf); - - halbtc8723d2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0x18); - halbtc8723d2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - /* sw all off */ - halbtc8723d2ant_low_penalty_ra(btcoexist, NORMAL_EXEC, false); - - coex_sta->pop_event_cnt = 0; - coex_sta->cnt_RemoteNameReq = 0; - coex_sta->cnt_ReInit = 0; - coex_sta->cnt_setupLink = 0; - coex_sta->cnt_IgnWlanAct = 0; - coex_sta->cnt_Page = 0; - - halbtc8723d2ant_query_bt_info(btcoexist); -} - -void halbtc8723d2ant_init_hw_config(IN struct btc_coexist *btcoexist, - IN boolean wifi_only) -{ - u8 u8tmp0 = 0, u8tmp1 = 0; - u32 vendor; - u32 u32tmp0 = 0, u32tmp1 = 0, u32tmp2 = 0; - u16 u16tmp1 = 0; - u8 i = 0; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], 2Ant Init HW Config!!\n"); - BTC_TRACE(trace_buf); - -#if BT_8723D_2ANT_COEX_DBG - u32tmp1 = halbtc8723d2ant_ltecoex_indirect_read_reg(btcoexist, - 0x38); - u32tmp2 = halbtc8723d2ant_ltecoex_indirect_read_reg(btcoexist, - 0x54); - u16tmp1 = btcoexist->btc_read_2byte(btcoexist, 0x948); - u8tmp1 = btcoexist->btc_read_1byte(btcoexist, 0x73); - u8tmp0 = btcoexist->btc_read_1byte(btcoexist, 0x67); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** 0x67 = 0x%x, 0x948 = 0x%x, 0x73 = 0x%x(Before init_hw_config)\n", - u8tmp0, u16tmp1, u8tmp1); - BTC_TRACE(trace_buf); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], **********0x38= 0x%x, 0x54= 0x%x (Before init_hw_config)\n", - u32tmp1, u32tmp2); - BTC_TRACE(trace_buf); -#endif - - coex_sta->bt_coex_supported_feature = 0; - coex_sta->bt_coex_supported_version = 0; - coex_sta->bt_ble_scan_type = 0; - coex_sta->bt_ble_scan_para[0] = 0; - coex_sta->bt_ble_scan_para[1] = 0; - coex_sta->bt_ble_scan_para[2] = 0; - coex_sta->bt_reg_vendor_ac = 0xffff; - coex_sta->bt_reg_vendor_ae = 0xffff; - coex_sta->gnt_error_cnt = 0; - coex_sta->bt_relink_downcount = 0; - - for (i = 0; i <= 9; i++) - coex_sta->bt_afh_map[i] = 0; - - /* 0xf0[15:12] --> Chip Cut information */ - coex_sta->cut_version = (btcoexist->btc_read_1byte(btcoexist, - 0xf1) & 0xf0) >> 4; - - coex_sta->dis_ver_info_cnt = 0; - - /* default isolation = 15dB */ - coex_sta->isolation_btween_wb = BT_8723D_2ANT_DEFAULT_ISOLATION; - halbtc8723d2ant_coex_switch_threshold(btcoexist, - coex_sta->isolation_btween_wb); - - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x550, 0x8, - 0x1); /* enable TBTT nterrupt */ - - /* BT report packet sample rate */ - btcoexist->btc_write_1byte(btcoexist, 0x790, 0x5); - - /* Init 0x778 = 0x1 for 2-Ant */ - btcoexist->btc_write_1byte(btcoexist, 0x778, 0x1); - - /* Enable PTA (3-wire function form BT side) */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x40, 0x20, 0x1); - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x41, 0x02, 0x1); - - /* Enable PTA (tx/rx signal form WiFi side) */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4c6, 0x10, 0x1); - - halbtc8723d2ant_enable_gnt_to_gpio(btcoexist, true); - - /* check if WL firmware download ok */ - if (btcoexist->btc_read_1byte(btcoexist, 0x80) == 0xc6) - halbtc8723d2ant_post_state_to_bt(btcoexist, - BT_8723D_2ANT_SCOREBOARD_ONOFF, true); - - /* Enable counter statistics */ - btcoexist->btc_write_1byte(btcoexist, 0x76e, - 0x4); /* 0x76e[3] =1, WLAN_Act control by PTA */ - - /* WLAN_Tx by GNT_WL 0x950[29] = 0 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x953, 0x20, 0x0); - - halbtc8723d2ant_coex_table_with_type(btcoexist, FORCE_EXEC, 0); - - halbtc8723d2ant_ps_tdma(btcoexist, FORCE_EXEC, false, 0); - - psd_scan->ant_det_is_ant_det_available = true; - - if (wifi_only) { - coex_sta->concurrent_rx_mode_on = false; - /* Path config */ - /* Set Antenna Path */ - halbtc8723d2ant_set_ant_path(btcoexist, - BTC_ANT_PATH_AUTO, - FORCE_EXEC, - BT_8723D_2ANT_PHASE_WLANONLY_INIT); - - btcoexist->stop_coex_dm = true; - } else { - /*Set BT polluted packet on for Tx rate adaptive not including Tx retry break by PTA, 0x45c[19] =1 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x45e, 0x8, 0x1); - - coex_sta->concurrent_rx_mode_on = true; - /* btcoexist->btc_write_1byte_bitmask(btcoexist, 0x953, 0x2, 0x1); */ - - /* RF 0x1[0] = 0->Set GNT_WL_RF_Rx always = 1 for con-current Rx */ - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0x1, 0x0); - - /* Path config */ - halbtc8723d2ant_set_ant_path(btcoexist, - BTC_ANT_PATH_AUTO, - FORCE_EXEC, - BT_8723D_2ANT_PHASE_COEX_INIT); - - btcoexist->stop_coex_dm = false; - } - -} - -u32 halbtc8723d2ant_psd_log2base(IN struct btc_coexist *btcoexist, IN u32 val) -{ - u8 j; - u32 tmp, tmp2, val_integerd_b = 0, tindex, shiftcount = 0; - u32 result, val_fractiond_b = 0, table_fraction[21] = {0, 432, 332, 274, 232, 200, - 174, 151, 132, 115, 100, 86, 74, 62, 51, 42, - 32, 23, 15, 7, 0 - }; - - if (val == 0) - return 0; - - tmp = val; - - while (1) { - if (tmp == 1) - break; - else { - tmp = (tmp >> 1); - shiftcount++; - } - } - - val_integerd_b = shiftcount + 1; - - tmp2 = 1; - for (j = 1; j <= val_integerd_b; j++) - tmp2 = tmp2 * 2; - - tmp = (val * 100) / tmp2; - tindex = tmp / 5; - - if (tindex > 20) - tindex = 20; - - val_fractiond_b = table_fraction[tindex]; - - result = val_integerd_b * 100 - val_fractiond_b; - - return result; - -} - -void halbtc8723d2ant_psd_show_antenna_detect_result(IN struct btc_coexist - *btcoexist) -{ - u8 *cli_buf = btcoexist->cli_buf; - struct btc_board_info *board_info = &btcoexist->board_info; - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n============[Antenna Detection info] ============\n"); - CL_PRINTF(cli_buf); - - if (psd_scan->ant_det_result == 12) { /* Get Ant Det from BT */ - - if (board_info->btdm_ant_num_by_ant_det == 1) - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %s (%d~%d)", - "Ant Det Result", "1-Antenna", - BT_8723D_2ANT_ANTDET_PSDTHRES_1ANT, - BT_8723D_2ANT_ANTDET_PSDTHRES_2ANT_GOODISOLATION); - else { - - if (psd_scan->ant_det_psd_scan_peak_val > - (BT_8723D_2ANT_ANTDET_PSDTHRES_2ANT_BADISOLATION) - * 100) - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %s (>%d)", - "Ant Det Result", "2-Antenna (Bad-Isolation)", - BT_8723D_2ANT_ANTDET_PSDTHRES_2ANT_BADISOLATION); - else - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %s (%d~%d)", - "Ant Det Result", "2-Antenna (Good-Isolation)", - BT_8723D_2ANT_ANTDET_PSDTHRES_2ANT_GOODISOLATION - + psd_scan->ant_det_thres_offset, - BT_8723D_2ANT_ANTDET_PSDTHRES_2ANT_BADISOLATION); - } - - } else if (psd_scan->ant_det_result == 1) - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s (>%d)", - "Ant Det Result", "2-Antenna (Bad-Isolation)", - BT_8723D_2ANT_ANTDET_PSDTHRES_2ANT_BADISOLATION); - else if (psd_scan->ant_det_result == 2) - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s (%d~%d)", - "Ant Det Result", "2-Antenna (Good-Isolation)", - BT_8723D_2ANT_ANTDET_PSDTHRES_2ANT_GOODISOLATION - + psd_scan->ant_det_thres_offset, - BT_8723D_2ANT_ANTDET_PSDTHRES_2ANT_BADISOLATION); - else - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s (%d~%d)", - "Ant Det Result", "1-Antenna", - BT_8723D_2ANT_ANTDET_PSDTHRES_1ANT, - BT_8723D_2ANT_ANTDET_PSDTHRES_2ANT_GOODISOLATION - + psd_scan->ant_det_thres_offset); - - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s ", - "Antenna Detection Finish", - (board_info->btdm_ant_det_finish - ? "Yes" : "No")); - CL_PRINTF(cli_buf); - - switch (psd_scan->ant_det_result) { - case 0: - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "(BT is not available)"); - break; - case 1: /* 2-Ant bad-isolation */ - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "(BT is available)"); - break; - case 2: /* 2-Ant good-isolation */ - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "(BT is available)"); - break; - case 3: /* 1-Ant */ - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "(BT is available)"); - break; - case 4: - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "(Uncertainty result)"); - break; - case 5: - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "(Pre-Scan fai)"); - break; - case 6: - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "(WiFi is Scanning)"); - break; - case 7: - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "(BT is not idle)"); - break; - case 8: - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "(Abort by WiFi Scanning)"); - break; - case 9: - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "(Antenna Init is not ready)"); - break; - case 10: - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "(BT is Inquiry or page)"); - break; - case 11: - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "(BT is Disabled)"); - case 12: - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "(BT is available, result from BT"); - break; - } - CL_PRINTF(cli_buf); - - if (psd_scan->ant_det_result == 12) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d dB", - "PSD Scan Peak Value", - psd_scan->ant_det_psd_scan_peak_val / 100); - CL_PRINTF(cli_buf); - return; - } - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d", - "Ant Detect Total Count", psd_scan->ant_det_try_count); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d", - "Ant Detect Fail Count", psd_scan->ant_det_fail_count); - CL_PRINTF(cli_buf); - - if ((!board_info->btdm_ant_det_finish) && - (psd_scan->ant_det_result != 5)) - return; - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s", "BT Response", - (psd_scan->ant_det_result ? "ok" : "fail")); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d ms", "BT Tx Time", - psd_scan->ant_det_bt_tx_time); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d", "BT Tx Ch", - psd_scan->ant_det_bt_le_channel); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d", - "WiFi PSD Cent-Ch/Offset/Span", - psd_scan->real_cent_freq, psd_scan->real_offset, - psd_scan->real_span); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d dB", - "PSD Pre-Scan Peak Value", - psd_scan->ant_det_pre_psdscan_peak_val / 100); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s (<= %d)", - "PSD Pre-Scan result", - (psd_scan->ant_det_result != 5 ? "ok" : "fail"), - BT_8723D_2ANT_ANTDET_PSDTHRES_BACKGROUND - + psd_scan->ant_det_thres_offset); - CL_PRINTF(cli_buf); - - if (psd_scan->ant_det_result == 5) - return; - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s dB", - "PSD Scan Peak Value", psd_scan->ant_det_peak_val); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s MHz", - "PSD Scan Peak Freq", psd_scan->ant_det_peak_freq); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s", "TFBGA Package", - (board_info->tfbga_package) ? "Yes" : "No"); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d", - "PSD Threshold Offset", psd_scan->ant_det_thres_offset); - CL_PRINTF(cli_buf); - -} - -void halbtc8723d2ant_psd_showdata(IN struct btc_coexist *btcoexist) -{ - u8 *cli_buf = btcoexist->cli_buf; - u32 delta_freq_per_point; - u32 freq, freq1, freq2, n = 0, i = 0, j = 0, m = 0, psd_rep1, psd_rep2; - - if (psd_scan->ant_det_result == 12) - return; - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n\n============[PSD info] (%d)============\n", - psd_scan->psd_gen_count); - CL_PRINTF(cli_buf); - - if (psd_scan->psd_gen_count == 0) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n No data !!\n"); - CL_PRINTF(cli_buf); - return; - } - - if (psd_scan->psd_point == 0) - delta_freq_per_point = 0; - else - delta_freq_per_point = psd_scan->psd_band_width / - psd_scan->psd_point; - - /* if (psd_scan->is_psd_show_max_only) */ - if (0) { - psd_rep1 = psd_scan->psd_max_value / 100; - psd_rep2 = psd_scan->psd_max_value - psd_rep1 * 100; - - freq = ((psd_scan->real_cent_freq - 20) * 1000000 + - psd_scan->psd_max_value_point * delta_freq_per_point); - freq1 = freq / 1000000; - freq2 = freq / 1000 - freq1 * 1000; - - if (freq2 < 100) - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n Freq = %d.0%d MHz", - freq1, freq2); - else - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n Freq = %d.%d MHz", - freq1, freq2); - - if (psd_rep2 < 10) - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - ", Value = %d.0%d dB, (%d)\n", - psd_rep1, psd_rep2, psd_scan->psd_max_value); - else - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - ", Value = %d.%d dB, (%d)\n", - psd_rep1, psd_rep2, psd_scan->psd_max_value); - - CL_PRINTF(cli_buf); - } else { - m = psd_scan->psd_start_point; - n = psd_scan->psd_start_point; - i = 1; - j = 1; - - while (1) { - do { - freq = ((psd_scan->real_cent_freq - 20) * - 1000000 + m * - delta_freq_per_point); - freq1 = freq / 1000000; - freq2 = freq / 1000 - freq1 * 1000; - - if (i == 1) { - if (freq2 == 0) - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "\r\n Freq%6d.000", - freq1); - else if (freq2 < 100) - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "\r\n Freq%6d.0%2d", - freq1, - freq2); - else - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "\r\n Freq%6d.%3d", - freq1, - freq2); - } else if ((i % 8 == 0) || - (m == psd_scan->psd_stop_point)) { - if (freq2 == 0) - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "%6d.000\n", freq1); - else if (freq2 < 100) - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "%6d.0%2d\n", freq1, - freq2); - else - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "%6d.%3d\n", freq1, - freq2); - } else { - if (freq2 == 0) - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "%6d.000", freq1); - else if (freq2 < 100) - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "%6d.0%2d", freq1, - freq2); - else - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "%6d.%3d", freq1, - freq2); - } - - i++; - m++; - CL_PRINTF(cli_buf); - - } while ((i <= 8) && (m <= psd_scan->psd_stop_point)); - - do { - psd_rep1 = psd_scan->psd_report_max_hold[n] / - 100; - psd_rep2 = psd_scan->psd_report_max_hold[n] - - psd_rep1 * - 100; - - if (j == 1) { - if (psd_rep2 < 10) - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "\r\n Val %7d.0%d", - psd_rep1, - psd_rep2); - else - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "\r\n Val %7d.%d", - psd_rep1, - psd_rep2); - } else if ((j % 8 == 0) || - (n == psd_scan->psd_stop_point)) { - if (psd_rep2 < 10) - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "%7d.0%d\n", psd_rep1, - psd_rep2); - else - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "%7d.%d\n", psd_rep1, - psd_rep2); - } else { - if (psd_rep2 < 10) - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "%7d.0%d", psd_rep1, - psd_rep2); - else - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "%7d.%d", psd_rep1, - psd_rep2); - } - - j++; - n++; - CL_PRINTF(cli_buf); - - } while ((j <= 8) && (n <= psd_scan->psd_stop_point)); - - if ((m > psd_scan->psd_stop_point) || - (n > psd_scan->psd_stop_point)) - break; - else { - i = 1; - j = 1; - } - - } - } - -} - -void halbtc8723d2ant_psd_maxholddata(IN struct btc_coexist *btcoexist, - IN u32 gen_count) -{ - u32 i = 0; - u32 loop_i_max = 0, loop_val_max = 0; - - if (gen_count == 1) { - memcpy(psd_scan->psd_report_max_hold, - psd_scan->psd_report, - BT_8723D_2ANT_ANTDET_PSD_POINTS * sizeof(u32)); - } - - for (i = psd_scan->psd_start_point; - i <= psd_scan->psd_stop_point; i++) { - - /* update max-hold value at each freq point */ - if (psd_scan->psd_report[i] > psd_scan->psd_report_max_hold[i]) - psd_scan->psd_report_max_hold[i] = - psd_scan->psd_report[i]; - - /* search the max value in this seep */ - if (psd_scan->psd_report[i] > loop_val_max) { - loop_val_max = psd_scan->psd_report[i]; - loop_i_max = i; - } - } - - if (gen_count <= BT_8723D_2ANT_ANTDET_PSD_SWWEEPCOUNT) - psd_scan->psd_loop_max_value[gen_count - 1] = loop_val_max; - -} - -u32 halbtc8723d2ant_psd_getdata(IN struct btc_coexist *btcoexist, IN u32 point) -{ - /* reg 0x808[9:0]: FFT data x */ - /* reg 0x808[22]: 0-->1 to get 1 FFT data y */ - /* reg 0x8b4[15:0]: FFT data y report */ - - u32 val = 0, psd_report = 0; - int k = 0; - - val = btcoexist->btc_read_4byte(btcoexist, 0x808); - - val &= 0xffbffc00; - val |= point; - - btcoexist->btc_write_4byte(btcoexist, 0x808, val); - - val |= 0x00400000; - btcoexist->btc_write_4byte(btcoexist, 0x808, val); - - while (1) { - if (k++ > BT_8723D_2ANT_ANTDET_SWEEPPOINT_DELAY) - break; - } - - val = btcoexist->btc_read_4byte(btcoexist, 0x8b4); - - psd_report = val & 0x0000ffff; - - return psd_report; -} - -boolean halbtc8723d2ant_psd_sweep_point(IN struct btc_coexist *btcoexist, - IN u32 cent_freq, IN s32 offset, IN u32 span, IN u32 points, - IN u32 avgnum, IN u32 loopcnt) -{ - u32 i = 0, val = 0, n = 0, k = 0, j, point_index = 0; - u32 points1 = 0, psd_report = 0; - u32 start_p = 0, stop_p = 0, delta_freq_per_point = 156250; - u32 psd_center_freq = 20 * 10 ^ 6; - boolean outloop = false, scan , roam, is_sweep_ok = true; - u8 flag = 0; - u32 tmp = 0, u32tmp1 = 0; - u32 wifi_original_channel = 1; - u32 psd_sum = 0, avg_cnt = 0; - u32 i_max = 0, val_max = 0, val_max2 = 0; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx PSD Sweep Start!!\n"); - BTC_TRACE(trace_buf); - - do { - switch (flag) { - case 0: /* Get PSD parameters */ - default: - - psd_scan->psd_band_width = 40 * 1000000; - psd_scan->psd_point = points; - psd_scan->psd_start_base = points / 2; - psd_scan->psd_avg_num = avgnum; - psd_scan->real_cent_freq = cent_freq; - psd_scan->real_offset = offset; - psd_scan->real_span = span; - - points1 = psd_scan->psd_point; - delta_freq_per_point = psd_scan->psd_band_width / - psd_scan->psd_point; - - /* PSD point setup */ - val = btcoexist->btc_read_4byte(btcoexist, 0x808); - val &= 0xffff0fff; - - switch (psd_scan->psd_point) { - case 128: - val |= 0x0; - break; - case 256: - default: - val |= 0x00004000; - break; - case 512: - val |= 0x00008000; - break; - case 1024: - val |= 0x0000c000; - break; - } - - switch (psd_scan->psd_avg_num) { - case 1: - val |= 0x0; - break; - case 8: - val |= 0x00001000; - break; - case 16: - val |= 0x00002000; - break; - case 32: - default: - val |= 0x00003000; - break; - } - btcoexist->btc_write_4byte(btcoexist, 0x808, val); - - flag = 1; - break; - case 1: /* calculate the PSD point index from freq/offset/span */ - psd_center_freq = psd_scan->psd_band_width / 2 + - offset * (1000000); - - start_p = psd_scan->psd_start_base + (psd_center_freq - - span * (1000000) / 2) / delta_freq_per_point; - psd_scan->psd_start_point = start_p - - psd_scan->psd_start_base; - - stop_p = psd_scan->psd_start_base + (psd_center_freq + - span * (1000000) / 2) / delta_freq_per_point; - psd_scan->psd_stop_point = stop_p - - psd_scan->psd_start_base - 1; - - flag = 2; - break; - case 2: /* set RF channel/BW/Mode */ - - /* set 3-wire off */ - val = btcoexist->btc_read_4byte(btcoexist, 0x88c); - val |= 0x00300000; - btcoexist->btc_write_4byte(btcoexist, 0x88c, val); - - /* CCK off */ - val = btcoexist->btc_read_4byte(btcoexist, 0x800); - val &= 0xfeffffff; - btcoexist->btc_write_4byte(btcoexist, 0x800, val); - - /* Tx-pause on */ - btcoexist->btc_write_1byte(btcoexist, 0x522, 0x6f); - - /* store WiFi original channel */ - wifi_original_channel = btcoexist->btc_get_rf_reg( - btcoexist, BTC_RF_A, 0x18, 0x3ff); - - /* Set RF channel */ - if (cent_freq == 2484) - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, - 0x18, 0x3ff, 0xe); - else - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, - 0x18, 0x3ff, (cent_freq - 2412) / 5 + - 1); /* WiFi TRx Mask on */ - - /* save original RCK value */ - u32tmp1 = btcoexist->btc_get_rf_reg( - btcoexist, BTC_RF_A, 0x1d, 0xfffff); - - /* Enter debug mode */ - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0xde, - 0x2, 0x1); - - /* Set RF Rx filter corner */ - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1d, - 0xfffff, 0x2e); - - /* Set RF mode = Rx, RF Gain = 0x320a0 */ - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x0, - 0xfffff, 0x320a0); - - while (1) { - if (k++ > BT_8723D_2ANT_ANTDET_SWEEPPOINT_DELAY) - break; - } - flag = 3; - break; - case 3: - psd_scan->psd_gen_count = 0; - for (j = 1; j <= loopcnt; j++) { - - btcoexist->btc_get(btcoexist, - BTC_GET_BL_WIFI_SCAN, &scan); - btcoexist->btc_get(btcoexist, - BTC_GET_BL_WIFI_ROAM, &roam); - - if (scan || roam) { - is_sweep_ok = false; - break; - } - memset(psd_scan->psd_report, 0, - psd_scan->psd_point * sizeof(u32)); - start_p = psd_scan->psd_start_point + - psd_scan->psd_start_base; - stop_p = psd_scan->psd_stop_point + - psd_scan->psd_start_base + 1; - - i = start_p; - point_index = 0; - - while (i < stop_p) { - if (i >= points1) - psd_report = - halbtc8723d2ant_psd_getdata( - btcoexist, i - points1); - else - psd_report = - halbtc8723d2ant_psd_getdata( - btcoexist, i); - - if (psd_report == 0) - tmp = 0; - else - /* tmp = 20*log10((double)psd_report); */ - /* 20*log2(x)/log2(10), log2Base return theresult of the psd_report*100 */ - tmp = 6 * halbtc8723d2ant_psd_log2base( - btcoexist, psd_report); - - n = i - psd_scan->psd_start_base; - psd_scan->psd_report[n] = tmp; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "Point=%d, psd_dB_data = %d\n", - i, psd_scan->psd_report[n]); - BTC_TRACE(trace_buf); - - i++; - - } - - halbtc8723d2ant_psd_maxholddata(btcoexist, j); - - psd_scan->psd_gen_count = j; - - /*Accumulate Max PSD value in this loop if the value > threshold */ - if (psd_scan->psd_loop_max_value[j - 1] >= - 4000) { - psd_sum = psd_sum + - psd_scan->psd_loop_max_value[j - - 1]; - avg_cnt++; - } - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "Loop=%d, Max_dB_data = %d\n", - j, psd_scan->psd_loop_max_value[j - - 1]); - BTC_TRACE(trace_buf); - - } - - if (loopcnt == BT_8723D_2ANT_ANTDET_PSD_SWWEEPCOUNT) { - - /* search the Max Value between each-freq-point-max-hold value of all sweep*/ - for (i = 1; - i <= BT_8723D_2ANT_ANTDET_PSD_SWWEEPCOUNT; - i++) { - - if (i == 1) { - i_max = i; - val_max = psd_scan->psd_loop_max_value[i - - 1]; - val_max2 = - psd_scan->psd_loop_max_value[i - - 1]; - } else if ( - psd_scan->psd_loop_max_value[i - - 1] > val_max) { - val_max2 = val_max; - i_max = i; - val_max = psd_scan->psd_loop_max_value[i - - 1]; - } else if ( - psd_scan->psd_loop_max_value[i - - 1] > val_max2) - val_max2 = - psd_scan->psd_loop_max_value[i - - 1]; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "i = %d, val_hold= %d, val_max = %d, val_max2 = %d\n", - i, psd_scan->psd_loop_max_value[i - - 1], - val_max, val_max2); - - BTC_TRACE(trace_buf); - } - - psd_scan->psd_max_value_point = i_max; - psd_scan->psd_max_value = val_max; - psd_scan->psd_max_value2 = val_max2; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "val_max = %d, val_max2 = %d\n", - psd_scan->psd_max_value, - psd_scan->psd_max_value2); - BTC_TRACE(trace_buf); - } - - if (avg_cnt != 0) { - psd_scan->psd_avg_value = (psd_sum / avg_cnt); - if ((psd_sum % avg_cnt) >= (avg_cnt / 2)) - psd_scan->psd_avg_value++; - } else - psd_scan->psd_avg_value = 0; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "AvgLoop=%d, Avg_dB_data = %d\n", - avg_cnt, psd_scan->psd_avg_value); - BTC_TRACE(trace_buf); - - flag = 100; - break; - case 99: /* error */ - - outloop = true; - break; - case 100: /* recovery */ - - /* set 3-wire on */ - val = btcoexist->btc_read_4byte(btcoexist, 0x88c); - val &= 0xffcfffff; - btcoexist->btc_write_4byte(btcoexist, 0x88c, val); - - /* CCK on */ - val = btcoexist->btc_read_4byte(btcoexist, 0x800); - val |= 0x01000000; - btcoexist->btc_write_4byte(btcoexist, 0x800, val); - - /* Tx-pause off */ - btcoexist->btc_write_1byte(btcoexist, 0x522, 0x0); - - /* PSD off */ - val = btcoexist->btc_read_4byte(btcoexist, 0x808); - val &= 0xffbfffff; - btcoexist->btc_write_4byte(btcoexist, 0x808, val); - - /* restore RF Rx filter corner */ - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1d, - 0xfffff, u32tmp1); - - /* Exit debug mode */ - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0xde, - 0x2, 0x0); - - /* restore WiFi original channel */ - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x18, - 0x3ff, wifi_original_channel); - - outloop = true; - break; - - } - - } while (!outloop); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx PSD Sweep Stop!!\n"); - BTC_TRACE(trace_buf); - return is_sweep_ok; - -} - -boolean halbtc8723d2ant_psd_antenna_detection(IN struct btc_coexist - *btcoexist) -{ - u32 i = 0; - u32 wlpsd_cent_freq = 2484, wlpsd_span = 2; - s32 wlpsd_offset = -4; - u32 bt_tx_time, bt_le_channel; - u8 bt_le_ch[13] = {3, 6, 8, 11, 13, 16, 18, 21, 23, 26, 28, 31, 33}; - - u8 h2c_parameter[3] = {0}, u8tmpa, u8tmpb; - - u8 state = 0; - boolean outloop = false, bt_resp = false, ant_det_finish = false; - u32 freq, freq1, freq2, psd_rep1, psd_rep2, delta_freq_per_point, - u32tmp, u32tmp0, u32tmp1, u32tmp2 ; - struct btc_board_info *board_info = &btcoexist->board_info; - - memset(psd_scan->ant_det_peak_val, 0, 16 * sizeof(u8)); - memset(psd_scan->ant_det_peak_freq, 0, 16 * sizeof(u8)); - - psd_scan->ant_det_bt_tx_time = - BT_8723D_2ANT_ANTDET_BTTXTIME; /* 0.42ms*50 = 20ms (0.42ms = 1 PSD sweep) */ - psd_scan->ant_det_bt_le_channel = BT_8723D_2ANT_ANTDET_BTTXCHANNEL; - - bt_tx_time = psd_scan->ant_det_bt_tx_time; - bt_le_channel = psd_scan->ant_det_bt_le_channel; - - if (board_info->tfbga_package) /* for TFBGA */ - psd_scan->ant_det_thres_offset = 5; - else - psd_scan->ant_det_thres_offset = 0; - - do { - switch (state) { - case 0: - if (bt_le_channel == 39) - wlpsd_cent_freq = 2484; - else { - for (i = 1; i <= 13; i++) { - if (bt_le_ch[i - 1] == - bt_le_channel) { - wlpsd_cent_freq = 2412 - + (i - 1) * 5; - break; - } - } - - if (i == 14) { - - BTC_SPRINTF(trace_buf, - BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Abort!!, Invalid LE channel = %d\n ", - bt_le_channel); - BTC_TRACE(trace_buf); - outloop = true; - break; - } - } - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), BT_LETxTime=%d, BT_LECh = %d\n", - bt_tx_time, bt_le_channel); - BTC_TRACE(trace_buf); - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), wlpsd_cent_freq=%d, wlpsd_offset = %d, wlpsd_span = %d, wlpsd_sweep_count = %d\n", - wlpsd_cent_freq, - wlpsd_offset, - wlpsd_span, - BT_8723D_2ANT_ANTDET_PSD_SWWEEPCOUNT); - BTC_TRACE(trace_buf); - - state = 1; - break; - case 1: /* stop coex DM & set antenna path */ - /* Stop Coex DM */ - btcoexist->stop_coex_dm = true; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Stop Coex DM!!\n"); - BTC_TRACE(trace_buf); - - /* Set TDMA off, */ - halbtc8723d2ant_ps_tdma(btcoexist, FORCE_EXEC, - false, 0); - - /* Set coex table */ - halbtc8723d2ant_coex_table_with_type(btcoexist, - FORCE_EXEC, 0); - - if (board_info->btdm_ant_pos == - BTC_ANTENNA_AT_MAIN_PORT) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Antenna at Main Port\n"); - BTC_TRACE(trace_buf); - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Antenna at Aux Port\n"); - BTC_TRACE(trace_buf); - } - - /* Set Antenna path, switch WiFi to un-certain antenna port */ - /* Set Antenna Path, both GNT_WL/GNT_BT = 1, and control by SW */ - halbtc8723d2ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT, - FORCE_EXEC, - BT_8723D_2ANT_PHASE_ANTENNA_DET); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Set Antenna to BT!!\n"); - BTC_TRACE(trace_buf); - - /* Set AFH mask on at WiFi channel 2472MHz +/- 10MHz */ - h2c_parameter[0] = 0x1; - h2c_parameter[1] = 0xd; - h2c_parameter[2] = 0x14; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Set AFH on, Cent-Ch= %d, Mask=%d\n", - h2c_parameter[1], - h2c_parameter[2]); - BTC_TRACE(trace_buf); - - btcoexist->btc_fill_h2c(btcoexist, 0x66, 3, - h2c_parameter); - - u32tmp = btcoexist->btc_read_2byte(btcoexist, 0x948); - u32tmp0 = btcoexist->btc_read_4byte(btcoexist, 0x70); - u32tmp1 = halbtc8723d2ant_ltecoex_indirect_read_reg( - btcoexist, 0x38); - u32tmp2 = halbtc8723d2ant_ltecoex_indirect_read_reg( - btcoexist, 0x54); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** 0x948 = 0x%x, 0x70 = 0x%x, 0x38= 0x%x, 0x54= 0x%x (Before Ant Det)\n", - u32tmp, u32tmp0, u32tmp1, u32tmp2); - BTC_TRACE(trace_buf); - - state = 2; - break; - case 2: /* Pre-sweep background psd */ - if (!halbtc8723d2ant_psd_sweep_point(btcoexist, - wlpsd_cent_freq, wlpsd_offset, wlpsd_span, - BT_8723D_2ANT_ANTDET_PSD_POINTS, - BT_8723D_2ANT_ANTDET_PSD_AVGNUM, 3)) { - ant_det_finish = false; - board_info->btdm_ant_num_by_ant_det = 1; - psd_scan->ant_det_result = 8; - state = 99; - break; - } - - psd_scan->ant_det_pre_psdscan_peak_val = - psd_scan->psd_max_value; - - if (psd_scan->ant_det_pre_psdscan_peak_val > - (BT_8723D_2ANT_ANTDET_PSDTHRES_BACKGROUND - + psd_scan->ant_det_thres_offset) * 100) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Abort Antenna Detection!! becaus background = %d > thres (%d)\n", - psd_scan->ant_det_pre_psdscan_peak_val / - 100, - BT_8723D_2ANT_ANTDET_PSDTHRES_BACKGROUND - + psd_scan->ant_det_thres_offset); - BTC_TRACE(trace_buf); - ant_det_finish = false; - board_info->btdm_ant_num_by_ant_det = 1; - psd_scan->ant_det_result = 5; - state = 99; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Start Antenna Detection!! becaus background = %d <= thres (%d)\n", - psd_scan->ant_det_pre_psdscan_peak_val / - 100, - BT_8723D_2ANT_ANTDET_PSDTHRES_BACKGROUND - + psd_scan->ant_det_thres_offset); - BTC_TRACE(trace_buf); - state = 3; - } - break; - case 3: - bt_resp = btcoexist->btc_set_bt_ant_detection( - btcoexist, (u8)(bt_tx_time & 0xff), - (u8)(bt_le_channel & 0xff)); - - /* Sync WL Rx PSD with BT Tx time because H2C->Mailbox delay */ - delay_ms(20); - - if (!halbtc8723d2ant_psd_sweep_point(btcoexist, - wlpsd_cent_freq, wlpsd_offset, - wlpsd_span, - BT_8723D_2ANT_ANTDET_PSD_POINTS, - BT_8723D_2ANT_ANTDET_PSD_AVGNUM, - BT_8723D_2ANT_ANTDET_PSD_SWWEEPCOUNT)) { - ant_det_finish = false; - board_info->btdm_ant_num_by_ant_det = 1; - psd_scan->ant_det_result = 8; - state = 99; - break; - } - psd_scan->ant_det_psd_scan_peak_val = - psd_scan->psd_max_value; - psd_scan->ant_det_psd_scan_peak_freq = - psd_scan->psd_max_value_point; - state = 4; - break; - case 4: - - if (psd_scan->psd_point == 0) - delta_freq_per_point = 0; - else - delta_freq_per_point = - psd_scan->psd_band_width / - psd_scan->psd_point; - - psd_rep1 = psd_scan->ant_det_psd_scan_peak_val / 100; - psd_rep2 = psd_scan->ant_det_psd_scan_peak_val - - psd_rep1 * - 100; - - freq = ((psd_scan->real_cent_freq - 20) * - 1000000 + psd_scan->psd_max_value_point - * delta_freq_per_point); - freq1 = freq / 1000000; - freq2 = freq / 1000 - freq1 * 1000; - - if (freq2 < 100) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Max Value: Freq = %d.0%d MHz", - freq1, freq2); - BTC_TRACE(trace_buf); - CL_SPRINTF(psd_scan->ant_det_peak_freq, - BT_8723D_2ANT_ANTDET_BUF_LEN, - "%d.0%d", freq1, freq2); - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Max Value: Freq = %d.%d MHz", - freq1, freq2); - BTC_TRACE(trace_buf); - CL_SPRINTF(psd_scan->ant_det_peak_freq, - BT_8723D_2ANT_ANTDET_BUF_LEN, - "%d.%d", freq1, freq2); - } - - if (psd_rep2 < 10) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - ", Value = %d.0%d dB\n", - psd_rep1, psd_rep2); - BTC_TRACE(trace_buf); - CL_SPRINTF(psd_scan->ant_det_peak_val, - BT_8723D_2ANT_ANTDET_BUF_LEN, - "%d.0%d", psd_rep1, psd_rep2); - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - ", Value = %d.%d dB\n", - psd_rep1, psd_rep2); - BTC_TRACE(trace_buf); - CL_SPRINTF(psd_scan->ant_det_peak_val, - BT_8723D_2ANT_ANTDET_BUF_LEN, - "%d.%d", psd_rep1, psd_rep2); - } - - psd_scan->ant_det_is_btreply_available = true; - - if (bt_resp == false) { - psd_scan->ant_det_is_btreply_available = - false; - psd_scan->ant_det_result = 0; - ant_det_finish = false; - board_info->btdm_ant_num_by_ant_det = 1; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), BT Response = Fail\n "); - BTC_TRACE(trace_buf); - } else if (psd_scan->ant_det_psd_scan_peak_val > - (BT_8723D_2ANT_ANTDET_PSDTHRES_2ANT_BADISOLATION) - * 100) { - psd_scan->ant_det_result = 1; - ant_det_finish = true; - board_info->btdm_ant_num_by_ant_det = 2; - coex_sta->isolation_btween_wb = (u8)(85 - - psd_scan->ant_det_psd_scan_peak_val / - 100) & 0xff; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Detect Result = 2-Ant, Bad-Isolation!!\n"); - BTC_TRACE(trace_buf); - } else if (psd_scan->ant_det_psd_scan_peak_val > - (BT_8723D_2ANT_ANTDET_PSDTHRES_2ANT_GOODISOLATION - + psd_scan->ant_det_thres_offset) * 100) { - psd_scan->ant_det_result = 2; - ant_det_finish = true; - board_info->btdm_ant_num_by_ant_det = 2; - coex_sta->isolation_btween_wb = (u8)(85 - - psd_scan->ant_det_psd_scan_peak_val / - 100) & 0xff; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Detect Result = 2-Ant, Good-Isolation!!\n"); - BTC_TRACE(trace_buf); - } else if (psd_scan->ant_det_psd_scan_peak_val > - (BT_8723D_2ANT_ANTDET_PSDTHRES_1ANT) * - 100) { - psd_scan->ant_det_result = 3; - ant_det_finish = true; - board_info->btdm_ant_num_by_ant_det = 1; - coex_sta->isolation_btween_wb = (u8)(85 - - psd_scan->ant_det_psd_scan_peak_val / - 100) & 0xff; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Detect Result = 1-Ant!!\n"); - BTC_TRACE(trace_buf); - } else { - psd_scan->ant_det_result = 4; - ant_det_finish = false; - board_info->btdm_ant_num_by_ant_det = 1; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Detect Result = 1-Ant, un-certainity!!\n"); - BTC_TRACE(trace_buf); - } - - state = 99; - break; - case 99: /* restore setup */ - - /* Set AFH mask off at WiFi channel 2472MHz +/- 10MHz */ - h2c_parameter[0] = 0x0; - h2c_parameter[1] = 0x0; - h2c_parameter[2] = 0x0; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Set AFH on, Cent-Ch= %d, Mask=%d\n", - h2c_parameter[1], h2c_parameter[2]); - BTC_TRACE(trace_buf); - - btcoexist->btc_fill_h2c(btcoexist, 0x66, 3, - h2c_parameter); - - /* Set Antenna Path, GNT_WL/GNT_BT control by PTA */ - /* Set Antenna path, switch WiFi to certain antenna port */ - halbtc8723d2ant_set_ant_path(btcoexist, - BTC_ANT_PATH_AUTO, FORCE_EXEC, - BT_8723D_2ANT_PHASE_2G_RUNTIME); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Set Antenna to PTA\n!!"); - BTC_TRACE(trace_buf); - - btcoexist->stop_coex_dm = false; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Resume Coex DM\n!!"); - BTC_TRACE(trace_buf); - - outloop = true; - break; - } - - } while (!outloop); - - return ant_det_finish; - -} - -boolean halbtc8723d2ant_psd_antenna_detection_check(IN struct btc_coexist - *btcoexist) -{ - static u32 ant_det_count = 0, ant_det_fail_count = 0; - struct btc_board_info *board_info = &btcoexist->board_info; - - boolean scan, roam, ant_det_finish = false; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam); - - ant_det_count++; - - psd_scan->ant_det_try_count = ant_det_count; - - if (scan || roam) { - ant_det_finish = false; - psd_scan->ant_det_result = 6; - } else if (coex_sta->bt_disabled) { - ant_det_finish = false; - psd_scan->ant_det_result = 11; - } else if (coex_sta->num_of_profile >= 1) { - ant_det_finish = false; - psd_scan->ant_det_result = 7; - } else if ( - !psd_scan->ant_det_is_ant_det_available) { /* Antenna initial setup is not ready */ - ant_det_finish = false; - psd_scan->ant_det_result = 9; - } else if (coex_sta->c2h_bt_inquiry_page) { - ant_det_finish = false; - psd_scan->ant_det_result = 10; - } else { - - ant_det_finish = halbtc8723d2ant_psd_antenna_detection( - btcoexist); - - delay_ms(psd_scan->ant_det_bt_tx_time); - } - - if (!ant_det_finish) - ant_det_fail_count++; - - psd_scan->ant_det_fail_count = ant_det_fail_count; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), result = %d, fail_count = %d, finish = %s\n", - psd_scan->ant_det_result, - psd_scan->ant_det_fail_count, - ant_det_finish == true ? "Yes" : "No"); - BTC_TRACE(trace_buf); - - return ant_det_finish; - -} - -/* ************************************************************ - * work around function start with wa_halbtc8723d2ant_ - * ************************************************************ - * ************************************************************ - * extern function start with ex_halbtc8723d2ant_ - * ************************************************************ */ -void ex_halbtc8723d2ant_power_on_setting(IN struct btc_coexist *btcoexist) -{ - struct btc_board_info *board_info = &btcoexist->board_info; - u8 u8tmp = 0x0; - u16 u16tmp = 0x0; - u32 value = 0; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx Execute 8723d 2-Ant PowerOn Setting xxxxxxxxxxxxxxxx!!\n"); - BTC_TRACE(trace_buf); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "Ant Det Finish = %s, Ant Det Number = %d\n", - (board_info->btdm_ant_det_finish ? "Yes" : "No"), - board_info->btdm_ant_num_by_ant_det); - BTC_TRACE(trace_buf); - - btcoexist->stop_coex_dm = true; - psd_scan->ant_det_is_ant_det_available = false; - - /* enable BB, REG_SYS_FUNC_EN such that we can write BB Register correctly. */ - u16tmp = btcoexist->btc_read_2byte(btcoexist, 0x2); - btcoexist->btc_write_2byte(btcoexist, 0x2, u16tmp | BIT(0) | BIT(1)); - - /* Local setting bit define */ - /* BIT0: "0" for no antenna inverse; "1" for antenna inverse */ - /* BIT1: "0" for internal switch; "1" for external switch */ - /* BIT2: "0" for one antenna; "1" for two antenna */ - /* NOTE: here default all internal switch and 1-antenna ==> BIT1=0 and BIT2=0 */ - - /* Set path control to WL */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, 0x80, 0x1); - btcoexist->btc_write_2byte(btcoexist, 0x948, 0x0); - - /* Check efuse 0xc3[6] for Single Antenna Path */ - if (board_info->single_ant_path == 0) { - /* set to S1 */ - board_info->btdm_ant_pos = BTC_ANTENNA_AT_MAIN_PORT; - u8tmp = 4; - value = 1; - } else if (board_info->single_ant_path == 1) { - /* set to S0 */ - board_info->btdm_ant_pos = BTC_ANTENNA_AT_AUX_PORT; - u8tmp = 5; - value = 0; - } - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** (Power On) single_ant_path = %d, btdm_ant_pos = %d **********\n", - board_info->single_ant_path , board_info->btdm_ant_pos); - BTC_TRACE(trace_buf); - - /* Set Antenna Path to BT side */ - halbtc8723d2ant_set_ant_path(btcoexist, - BTC_ANT_PATH_AUTO, - FORCE_EXEC, - BT_8723D_1ANT_PHASE_COEX_POWERON); - - /* Write Single Antenna Position to Registry to tell BT for 872db. This line can be removed - since BT EFuse also add "single antenna position" in EFuse for 8723d*/ - btcoexist->btc_set(btcoexist, BTC_SET_ACT_ANTPOSREGRISTRY_CTRL, - &value); - - /* Save"single antenna position" info in Local register setting for FW reading, because FW may not ready at power on */ - if (btcoexist->chip_interface == BTC_INTF_PCI) - btcoexist->btc_write_local_reg_1byte(btcoexist, 0x3e0, u8tmp); - else if (btcoexist->chip_interface == BTC_INTF_USB) - btcoexist->btc_write_local_reg_1byte(btcoexist, 0xfe08, u8tmp); - else if (btcoexist->chip_interface == BTC_INTF_SDIO) - btcoexist->btc_write_local_reg_1byte(btcoexist, 0x60, u8tmp); - - /* enable GNT_WL/GNT_BT debug signal to GPIO14/15 */ - halbtc8723d2ant_enable_gnt_to_gpio(btcoexist, true); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** LTE coex Reg 0x38 (Power-On) = 0x%x**********\n", - halbtc8723d2ant_ltecoex_indirect_read_reg(btcoexist, 0x38)); - BTC_TRACE(trace_buf); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** MAC Reg 0x70/ BB Reg 0x948 (Power-On) = 0x%x / 0x%x**********\n", - btcoexist->btc_read_4byte(btcoexist, 0x70), - btcoexist->btc_read_2byte(btcoexist, 0x948)); - BTC_TRACE(trace_buf); -} - -void ex_halbtc8723d2ant_pre_load_firmware(IN struct btc_coexist *btcoexist) -{ - struct btc_board_info *board_info = &btcoexist->board_info; - u8 u8tmp = 0x4; /* Set BIT2 by default since it's 2ant case */ - - /* */ - /* S0 or S1 setting and Local register setting(By the setting fw can get ant number, S0/S1, ... info) */ - /* Local setting bit define */ - /* BIT0: "0" for no antenna inverse; "1" for antenna inverse */ - /* BIT1: "0" for internal switch; "1" for external switch */ - /* BIT2: "0" for one antenna; "1" for two antenna */ - /* NOTE: here default all internal switch and 1-antenna ==> BIT1=0 and BIT2=0 */ - if (btcoexist->chip_interface == BTC_INTF_USB) { - /* fixed at S0 for USB interface */ - u8tmp |= 0x1; /* antenna inverse */ - btcoexist->btc_write_local_reg_1byte(btcoexist, 0xfe08, u8tmp); - } else { - /* for PCIE and SDIO interface, we check efuse 0xc3[6] */ - if (board_info->single_ant_path == 0) { - } else if (board_info->single_ant_path == 1) { - /* set to S0 */ - u8tmp |= 0x1; /* antenna inverse */ - } - - if (btcoexist->chip_interface == BTC_INTF_PCI) - btcoexist->btc_write_local_reg_1byte(btcoexist, 0x3e0, - u8tmp); - else if (btcoexist->chip_interface == BTC_INTF_SDIO) - btcoexist->btc_write_local_reg_1byte(btcoexist, 0x60, - u8tmp); - } -} - -void ex_halbtc8723d2ant_init_hw_config(IN struct btc_coexist *btcoexist, - IN boolean wifi_only) -{ - halbtc8723d2ant_init_hw_config(btcoexist, wifi_only); -} - -void ex_halbtc8723d2ant_init_coex_dm(IN struct btc_coexist *btcoexist) -{ - - halbtc8723d2ant_init_coex_dm(btcoexist); -} - -void ex_halbtc8723d2ant_display_coex_info(IN struct btc_coexist *btcoexist) -{ - struct btc_board_info *board_info = &btcoexist->board_info; - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - u8 *cli_buf = btcoexist->cli_buf; - u8 u8tmp[4], i, ps_tdma_case = 0; - u32 u32tmp[4]; - u16 u16tmp[4]; - u32 fa_ofdm, fa_cck, cca_ofdm, cca_cck, bt_coex_ver = 0; - u32 fw_ver = 0, bt_patch_ver = 0; - static u8 pop_report_in_10s = 0; - u32 phyver = 0; - boolean lte_coex_on = false; - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n ============[BT Coexist info]============"); - CL_PRINTF(cli_buf); - - if (btcoexist->manual_control) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n ============[Under Manual Control]============"); - CL_PRINTF(cli_buf); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n =========================================="); - CL_PRINTF(cli_buf); - } - - if (psd_scan->ant_det_try_count == 0) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %s", - "Ant PG Num/ Mech/ Pos", - board_info->pg_ant_num, board_info->btdm_ant_num, - (board_info->btdm_ant_pos == 1 ? "S1" : "S0")); - CL_PRINTF(cli_buf); - } else { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %d/ %d/ %s (retry=%d/fail=%d/result=%d)", - "Ant PG Num/ Mech(Ant_Det)/ Pos", - board_info->pg_ant_num, - board_info->btdm_ant_num_by_ant_det, - (board_info->btdm_ant_pos == 1 ? "S1" : "S0"), - psd_scan->ant_det_try_count, - psd_scan->ant_det_fail_count, - psd_scan->ant_det_result); - CL_PRINTF(cli_buf); - - if (board_info->btdm_ant_det_finish) { - - if (psd_scan->ant_det_result != 12) - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %s", - "Ant Det PSD Value", - psd_scan->ant_det_peak_val); - else - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %d", - "Ant Det PSD Value", - psd_scan->ant_det_psd_scan_peak_val - / 100); - CL_PRINTF(cli_buf); - } - } - - if (board_info->ant_det_result_five_complete) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %d/ %d", - "AntDet(Registry) Num/PSD Value", - board_info->btdm_ant_num_by_ant_det, - (board_info->antdetval & 0x7f)); - CL_PRINTF(cli_buf); - } - - bt_patch_ver = btcoexist->bt_info.bt_get_fw_ver; - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, &fw_ver); - phyver = btcoexist->btc_get_bt_phydm_version(btcoexist); - - bt_coex_ver = coex_sta->bt_coex_supported_version & 0xff; - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %d_%02x/ 0x%02x/ 0x%02x (%s)", - "CoexVer WL/ BT_Desired/ BT_Report", - glcoex_ver_date_8723d_2ant, glcoex_ver_8723d_2ant, - glcoex_ver_btdesired_8723d_2ant, - bt_coex_ver, - (bt_coex_ver == 0xff ? "Unknown" : - (coex_sta->bt_disabled ? "BT-disable" : - (bt_coex_ver >= glcoex_ver_btdesired_8723d_2ant ? - "Match" : "Mis-Match")))); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = 0x%x/ 0x%x/ v%d/ %c", - "W_FW/ B_FW/ Phy/ Kt", - fw_ver, bt_patch_ver, phyver, - coex_sta->cut_version + 65); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x ", - "Wifi channel informed to BT", - coex_dm->wifi_chnl_info[0], coex_dm->wifi_chnl_info[1], - coex_dm->wifi_chnl_info[2]); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d / %d ", - "Isolation/WL_Thres/BT_Thres", - coex_sta->isolation_btween_wb, - coex_sta->wifi_coex_thres, - coex_sta->bt_coex_thres); - CL_PRINTF(cli_buf); - - /* wifi status */ - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s", - "============[Wifi Status]============"); - CL_PRINTF(cli_buf); - btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_WIFI_STATUS); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s", - "============[BT Status]============"); - CL_PRINTF(cli_buf); - - pop_report_in_10s++; - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = [%s/ %d dBm/ %d/ %d] ", - "BT [status/ rssi/ retryCnt/ popCnt]", - ((coex_sta->bt_disabled) ? ("disabled") : (( - coex_sta->c2h_bt_inquiry_page) ? ("inquiry/page") - : ((BT_8723D_2ANT_BT_STATUS_NON_CONNECTED_IDLE == - coex_dm->bt_status) ? "non-connected idle" : - ((BT_8723D_2ANT_BT_STATUS_CONNECTED_IDLE == coex_dm->bt_status) - ? "connected-idle" : "busy")))), - coex_sta->bt_rssi - 100, coex_sta->bt_retry_cnt, - coex_sta->pop_event_cnt); - CL_PRINTF(cli_buf); - - if (pop_report_in_10s >= 5) { - coex_sta->pop_event_cnt = 0; - pop_report_in_10s = 0; - } - - if (coex_sta->num_of_profile != 0) - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %s%s%s%s%s", - "Profiles", - ((bt_link_info->a2dp_exist) ? "A2DP," : ""), - ((bt_link_info->sco_exist) ? "SCO," : ""), - ((bt_link_info->hid_exist) ? - ((coex_sta->hid_busy_num >= 2) ? "HID(4/18)," : - "HID(2/18),") : ""), - ((bt_link_info->pan_exist) ? "PAN," : ""), - ((coex_sta->voice_over_HOGP) ? "Voice" : "")); - else - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = None", - "Profiles"); - - CL_PRINTF(cli_buf); - - if (bt_link_info->a2dp_exist) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %s", - "A2DP Rate/Bitpool/Auto_Slot", - ((coex_sta->is_A2DP_3M) ? "3M" : "No_3M"), - coex_sta->a2dp_bit_pool, - ((coex_sta->is_autoslot) ? "On" : "Off") - ); - CL_PRINTF(cli_buf); - } - - if (bt_link_info->hid_exist) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", - "HID PairNum/Forbid_Slot", - coex_sta->hid_pair_cnt, - coex_sta->forbidden_slot - ); - CL_PRINTF(cli_buf); - } - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s / %s/ 0x%x/ 0x%x", - "Role/IgnWlanAct/Feature/BLEScan", - ((bt_link_info->slave_role) ? "Slave" : "Master"), - ((coex_dm->cur_ignore_wlan_act) ? "Yes" : "No"), - coex_sta->bt_coex_supported_feature, - coex_sta->bt_ble_scan_type); - CL_PRINTF(cli_buf); - - if ((coex_sta->bt_ble_scan_type & 0x7) != 0x0) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = 0x%08x/ 0x%08x/ 0x%08x", - "BLEScan Intv-Win TV/Init/Ble", - (coex_sta->bt_ble_scan_type & 0x1 ? - coex_sta->bt_ble_scan_para[0] : 0x0), - (coex_sta->bt_ble_scan_type & 0x2 ? - coex_sta->bt_ble_scan_para[1] : 0x0), - (coex_sta->bt_ble_scan_type & 0x4 ? - coex_sta->bt_ble_scan_para[2] : 0x0)); - - CL_PRINTF(cli_buf); - } - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d/ %d", - "ReInit/ReLink/IgnWlact/Page/NameReq", - coex_sta->cnt_ReInit, - coex_sta->cnt_setupLink, - coex_sta->cnt_IgnWlanAct, - coex_sta->cnt_Page, - coex_sta->cnt_RemoteNameReq - ); - CL_PRINTF(cli_buf); - - halbtc8723d2ant_read_score_board(btcoexist, &u16tmp[0]); - - if ((coex_sta->bt_reg_vendor_ae == 0xffff) || - (coex_sta->bt_reg_vendor_ac == 0xffff)) - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = x/ x/ %04x", - "0xae[4]/0xac[1:0]/Scoreboard", u16tmp[0]); - else - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = 0x%x/ 0x%x/ %04x", - "0xae[4]/0xac[1:0]/Scoreboard", - ((coex_sta->bt_reg_vendor_ae & BIT(4)) >> 4), - coex_sta->bt_reg_vendor_ac & 0x3, u16tmp[0]); - CL_PRINTF(cli_buf); - - if (coex_sta->num_of_profile > 0) { - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x", - "AFH MAP", - coex_sta->bt_afh_map[0], - coex_sta->bt_afh_map[1], - coex_sta->bt_afh_map[2], - coex_sta->bt_afh_map[3], - coex_sta->bt_afh_map[4], - coex_sta->bt_afh_map[5], - coex_sta->bt_afh_map[6], - coex_sta->bt_afh_map[7], - coex_sta->bt_afh_map[8], - coex_sta->bt_afh_map[9] - ); - CL_PRINTF(cli_buf); - } - - for (i = 0; i < BT_INFO_SRC_8723D_2ANT_MAX; i++) { - if (coex_sta->bt_info_c2h_cnt[i]) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %02x %02x %02x %02x %02x %02x %02x (%d)", - glbt_info_src_8723d_2ant[i], - coex_sta->bt_info_c2h[i][0], - coex_sta->bt_info_c2h[i][1], - coex_sta->bt_info_c2h[i][2], - coex_sta->bt_info_c2h[i][3], - coex_sta->bt_info_c2h[i][4], - coex_sta->bt_info_c2h[i][5], - coex_sta->bt_info_c2h[i][6], - coex_sta->bt_info_c2h_cnt[i]); - CL_PRINTF(cli_buf); - } - } - - /* Sw mechanism */ - if (btcoexist->manual_control) - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s", - "============[mechanism] (before Manual)============"); - else - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s", - "============[Mechanism]============"); - - CL_PRINTF(cli_buf); - - ps_tdma_case = coex_dm->cur_ps_tdma; - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %02x %02x %02x %02x %02x (case-%d, %s, %s)", - "TDMA", - coex_dm->ps_tdma_para[0], coex_dm->ps_tdma_para[1], - coex_dm->ps_tdma_para[2], coex_dm->ps_tdma_para[3], - coex_dm->ps_tdma_para[4], ps_tdma_case, - (coex_dm->cur_ps_tdma_on ? "TDMA On" : "TDMA Off"), - (coex_dm->is_switch_to_1dot5_ant ? "1.5Ant" : "2Ant")); - CL_PRINTF(cli_buf); - - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x6c0); - u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x6c4); - u32tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0x6c8); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %d/ 0x%x/ 0x%x/ 0x%x", - "Table/0x6c0/0x6c4/0x6c8", - coex_sta->coex_table_type, u32tmp[0], u32tmp[1], u32tmp[2]); - CL_PRINTF(cli_buf); - - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x778); - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x6cc); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = 0x%x/ 0x%x", - "0x778/0x6cc", - u8tmp[0], u32tmp[0]); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s", - "AntDiv/ ForceLPS", - ((board_info->ant_div_cfg) ? "On" : "Off"), - ((coex_sta->force_lps_on) ? "On" : "Off")); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", - "WL_DACSwing/ BT_Dec_Pwr", coex_dm->cur_fw_dac_swing_lvl, - coex_dm->cur_bt_dec_pwr_lvl); - CL_PRINTF(cli_buf); - - u32tmp[0] = halbtc8723d2ant_ltecoex_indirect_read_reg(btcoexist, 0x38); - lte_coex_on = ((u32tmp[0] & BIT(7)) >> 7) ? true : false; - - if (lte_coex_on) { - - u32tmp[0] = halbtc8723d2ant_ltecoex_indirect_read_reg(btcoexist, - 0xa0); - u32tmp[1] = halbtc8723d2ant_ltecoex_indirect_read_reg(btcoexist, - 0xa4); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", - "LTE Coex Table W_L/B_L", - u32tmp[0] & 0xffff, u32tmp[1] & 0xffff); - CL_PRINTF(cli_buf); - - u32tmp[0] = halbtc8723d2ant_ltecoex_indirect_read_reg(btcoexist, - 0xa8); - u32tmp[1] = halbtc8723d2ant_ltecoex_indirect_read_reg(btcoexist, - 0xac); - u32tmp[2] = halbtc8723d2ant_ltecoex_indirect_read_reg(btcoexist, - 0xb0); - u32tmp[3] = halbtc8723d2ant_ltecoex_indirect_read_reg(btcoexist, - 0xb4); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", - "LTE Break Table W_L/B_L/L_W/L_B", - u32tmp[0] & 0xffff, u32tmp[1] & 0xffff, - u32tmp[2] & 0xffff, u32tmp[3] & 0xffff); - CL_PRINTF(cli_buf); - - } - - /* Hw setting */ - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s", - "============[Hw setting]============"); - CL_PRINTF(cli_buf); - /* - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x430); - u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x434); - u16tmp[0] = btcoexist->btc_read_2byte(btcoexist, 0x42a); - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x456); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/0x%x/0x%x/0x%x", - "0x430/0x434/0x42a/0x456", - u32tmp[0], u32tmp[1], u16tmp[0], u8tmp[0]); - CL_PRINTF(cli_buf); - */ - u32tmp[0] = halbtc8723d2ant_ltecoex_indirect_read_reg(btcoexist, 0x38); - u32tmp[1] = halbtc8723d2ant_ltecoex_indirect_read_reg(btcoexist, 0x54); - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x73); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s", - "LTE Coex/Path Owner", - ((lte_coex_on) ? "On" : "Off") , - ((u8tmp[0] & BIT(2)) ? "WL" : "BT")); - CL_PRINTF(cli_buf); - - if (lte_coex_on) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %d/ %d/ %d/ %d", - "LTE 3Wire/OPMode/UART/UARTMode", - (int)((u32tmp[0] & BIT(6)) >> 6), - (int)((u32tmp[0] & (BIT(5) | BIT(4))) >> 4), - (int)((u32tmp[0] & BIT(3)) >> 3), - (int)(u32tmp[0] & (BIT(2) | BIT(1) | BIT(0)))); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", - "LTE_Busy/UART_Busy", - (int)((u32tmp[1] & BIT(1)) >> 1), (int)(u32tmp[1] & BIT(0))); - CL_PRINTF(cli_buf); - } - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %s (BB:%s)/ %s (BB:%s)/ %s %d", - "GNT_WL_Ctrl/GNT_BT_Ctrl/Dbg", - ((u32tmp[0] & BIT(12)) ? "SW" : "HW"), - ((u32tmp[0] & BIT(8)) ? "SW" : "HW"), - ((u32tmp[0] & BIT(14)) ? "SW" : "HW"), - ((u32tmp[0] & BIT(10)) ? "SW" : "HW"), - ((u8tmp[0] & BIT(3)) ? "On" : "Off"), - coex_sta->gnt_error_cnt); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", - "GNT_WL/GNT_BT", - (int)((u32tmp[1] & BIT(2)) >> 2), - (int)((u32tmp[1] & BIT(3)) >> 3)); - CL_PRINTF(cli_buf); - - u16tmp[0] = btcoexist->btc_read_2byte(btcoexist, 0x948); - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x67); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", - "0x948/0x67[7]", - u16tmp[0], (int)((u8tmp[0] & BIT(7)) >> 7)); - CL_PRINTF(cli_buf); - - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x964); - u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0x864); - u8tmp[2] = btcoexist->btc_read_1byte(btcoexist, 0xab7); - u8tmp[3] = btcoexist->btc_read_1byte(btcoexist, 0xa01); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", - "0x964[1]/0x864[0]/0xab7[5]/0xa01[7]", - (int)((u8tmp[0] & BIT(1)) >> 1), (int)((u8tmp[1] & BIT(0))), - (int)((u8tmp[2] & BIT(3)) >> 3), - (int)((u8tmp[3] & BIT(7)) >> 7)); - CL_PRINTF(cli_buf); - - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x4c6); - u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0x40); - u8tmp[2] = btcoexist->btc_read_1byte(btcoexist, 0x45e); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", - "0x4c6[4]/0x40[5]/0x45e[3](TxRetry)", - (int)((u8tmp[0] & BIT(4)) >> 4), - (int)((u8tmp[1] & BIT(5)) >> 5), - (int)((u8tmp[2] & BIT(3)) >> 3)); - CL_PRINTF(cli_buf); - - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x550); - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x522); - u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0x953); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ %s", - "0x550/0x522/4-RxAGC", - u32tmp[0], u8tmp[0], (u8tmp[1] & 0x2) ? "On" : "Off"); - CL_PRINTF(cli_buf); - - fa_ofdm = btcoexist->btc_phydm_query_PHY_counter(btcoexist, PHYDM_INFO_FA_OFDM); - fa_cck = btcoexist->btc_phydm_query_PHY_counter(btcoexist, PHYDM_INFO_FA_CCK); - cca_ofdm = btcoexist->btc_phydm_query_PHY_counter(btcoexist, PHYDM_INFO_CCA_OFDM); - cca_cck = btcoexist->btc_phydm_query_PHY_counter(btcoexist, PHYDM_INFO_CCA_CCK); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", - "CCK-CCA/CCK-FA/OFDM-CCA/OFDM-FA", - cca_cck, fa_cck, cca_ofdm, fa_ofdm); - CL_PRINTF(cli_buf); - -#if 1 - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d", - "CRC_OK CCK/11g/11n/11n-agg", - coex_sta->crc_ok_cck, coex_sta->crc_ok_11g, - coex_sta->crc_ok_11n, coex_sta->crc_ok_11n_vht); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d", - "CRC_Err CCK/11g/11n/11n-agg", - coex_sta->crc_err_cck, coex_sta->crc_err_11g, - coex_sta->crc_err_11n, coex_sta->crc_err_11n_vht); - CL_PRINTF(cli_buf); -#endif - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s/ %s/ %d", - "WlHiPri/ Locking/ Locked/ Noisy", - (coex_sta->wifi_is_high_pri_task ? "Yes" : "No"), - (coex_sta->cck_lock ? "Yes" : "No"), - (coex_sta->cck_ever_lock ? "Yes" : "No"), - coex_sta->wl_noisy_level); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d %s", - "0x770(Hi-pri rx/tx)", - coex_sta->high_priority_rx, coex_sta->high_priority_tx, - (coex_sta->is_hiPri_rx_overhead ? "(scan overhead!!)" : "")); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d %s", - "0x774(Lo-pri rx/tx)", - coex_sta->low_priority_rx, coex_sta->low_priority_tx, - (bt_link_info->slave_role ? "(Slave!!)" : ( - coex_sta->is_tdma_btautoslot_hang ? "(auto-slot hang!!)" : ""))); - CL_PRINTF(cli_buf); - - btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_COEX_STATISTICS); -} - -void ex_halbtc8723d2ant_ips_notify(IN struct btc_coexist *btcoexist, IN u8 type) -{ - if (btcoexist->manual_control || btcoexist->stop_coex_dm) - return; - - if (BTC_IPS_ENTER == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], IPS ENTER notify\n"); - BTC_TRACE(trace_buf); - coex_sta->under_ips = true; - coex_sta->under_lps = false; - - halbtc8723d2ant_post_state_to_bt(btcoexist, - BT_8723D_2ANT_SCOREBOARD_ACTIVE, false); - - halbtc8723d2ant_post_state_to_bt(btcoexist, - BT_8723D_2ANT_SCOREBOARD_ONOFF, false); - - halbtc8723d2ant_set_ant_path(btcoexist, - BTC_ANT_PATH_AUTO, - FORCE_EXEC, - BT_8723D_2ANT_PHASE_WLAN_OFF); - - halbtc8723d2ant_action_coex_all_off(btcoexist); - } else if (BTC_IPS_LEAVE == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], IPS LEAVE notify\n"); - BTC_TRACE(trace_buf); - coex_sta->under_ips = false; - - halbtc8723d2ant_post_state_to_bt(btcoexist, - BT_8723D_2ANT_SCOREBOARD_ACTIVE, true); - - halbtc8723d2ant_post_state_to_bt(btcoexist, - BT_8723D_2ANT_SCOREBOARD_ONOFF, true); - - halbtc8723d2ant_init_hw_config(btcoexist, false); - halbtc8723d2ant_init_coex_dm(btcoexist); - halbtc8723d2ant_query_bt_info(btcoexist); - } -} - -void ex_halbtc8723d2ant_lps_notify(IN struct btc_coexist *btcoexist, IN u8 type) -{ - if (btcoexist->manual_control || btcoexist->stop_coex_dm) - return; - - if (BTC_LPS_ENABLE == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], LPS ENABLE notify\n"); - BTC_TRACE(trace_buf); - coex_sta->under_lps = true; - coex_sta->under_ips = false; - - if (coex_sta->force_lps_on == true) { /* LPS No-32K */ - /* Write WL "Active" in Score-board for PS-TDMA */ - halbtc8723d2ant_post_state_to_bt(btcoexist, - BT_8723D_2ANT_SCOREBOARD_ACTIVE, true); - - } else { /* LPS-32K, need check if this h2c 0x71 can work?? (2015/08/28) */ - /* Write WL "Non-Active" in Score-board for Native-PS */ - halbtc8723d2ant_post_state_to_bt(btcoexist, - BT_8723D_2ANT_SCOREBOARD_ACTIVE, false); - } - - } else if (BTC_LPS_DISABLE == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], LPS DISABLE notify\n"); - BTC_TRACE(trace_buf); - coex_sta->under_lps = false; - - halbtc8723d2ant_post_state_to_bt(btcoexist, - BT_8723D_2ANT_SCOREBOARD_ACTIVE, true); - } -} - -void ex_halbtc8723d2ant_scan_notify(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - u32 u32tmp; - u8 u8tmpa, u8tmpb; - boolean wifi_connected = false; - - if (btcoexist->manual_control || - btcoexist->stop_coex_dm) - return; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - - /* this can't be removed for RF off_on event, or BT would dis-connect */ - halbtc8723d2ant_query_bt_info(btcoexist); - - if (BTC_SCAN_START == type) { - - if (!wifi_connected) - coex_sta->wifi_is_high_pri_task = true; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCAN START notify\n"); - BTC_TRACE(trace_buf); - - halbtc8723d2ant_post_state_to_bt(btcoexist, - BT_8723D_2ANT_SCOREBOARD_SCAN, true); - halbtc8723d2ant_post_state_to_bt(btcoexist, - BT_8723D_2ANT_SCOREBOARD_ACTIVE, true); - - halbtc8723d2ant_set_ant_path(btcoexist, - BTC_ANT_PATH_AUTO, - FORCE_EXEC, - BT_8723D_2ANT_PHASE_2G_RUNTIME); - - halbtc8723d2ant_run_coexist_mechanism(btcoexist); - - } else if (BTC_SCAN_FINISH == type) { - - coex_sta->wifi_is_high_pri_task = false; - - btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM, - &coex_sta->scan_ap_num); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCAN FINISH notify (Scan-AP = %d)\n", - coex_sta->scan_ap_num); - BTC_TRACE(trace_buf); - - halbtc8723d2ant_post_state_to_bt(btcoexist, - BT_8723D_2ANT_SCOREBOARD_SCAN, false); - - halbtc8723d2ant_run_coexist_mechanism(btcoexist); - } - -} - -void ex_halbtc8723d2ant_connect_notify(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - if (btcoexist->manual_control || - btcoexist->stop_coex_dm) - return; - - if (BTC_ASSOCIATE_START == type) { - - coex_sta->wifi_is_high_pri_task = true; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], CONNECT START notify\n"); - BTC_TRACE(trace_buf); - - halbtc8723d2ant_post_state_to_bt(btcoexist, - BT_8723D_2ANT_SCOREBOARD_ACTIVE, true); - halbtc8723d2ant_post_state_to_bt(btcoexist, - BT_8723D_2ANT_SCOREBOARD_ACTIVE, true); - - halbtc8723d2ant_set_ant_path(btcoexist, - BTC_ANT_PATH_AUTO, - FORCE_EXEC, - BT_8723D_2ANT_PHASE_2G_RUNTIME); - - halbtc8723d2ant_run_coexist_mechanism(btcoexist); - /* To keep TDMA case during connect process, - to avoid changed by Btinfo and runcoexmechanism */ - coex_sta->freeze_coexrun_by_btinfo = true; - - coex_dm->arp_cnt = 0; - - } else if (BTC_ASSOCIATE_FINISH == type) { - - coex_sta->wifi_is_high_pri_task = false; - coex_sta->freeze_coexrun_by_btinfo = false; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], CONNECT FINISH notify\n"); - BTC_TRACE(trace_buf); - - halbtc8723d2ant_run_coexist_mechanism(btcoexist); - } -} - -void ex_halbtc8723d2ant_media_status_notify(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - u8 h2c_parameter[3] = {0}; - u32 wifi_bw; - u8 wifi_central_chnl; - u8 ap_num = 0; - boolean wifi_under_b_mode = false; - - if (btcoexist->manual_control || - btcoexist->stop_coex_dm) - return; - - if (BTC_MEDIA_CONNECT == type) { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], MEDIA connect notify\n"); - BTC_TRACE(trace_buf); - - halbtc8723d2ant_post_state_to_bt(btcoexist, - BT_8723D_2ANT_SCOREBOARD_ACTIVE, true); - - halbtc8723d2ant_set_ant_path(btcoexist, - BTC_ANT_PATH_AUTO, - FORCE_EXEC, - BT_8723D_2ANT_PHASE_2G_RUNTIME); - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_B_MODE, - &wifi_under_b_mode); - - /* Set CCK Tx/Rx high Pri except 11b mode */ - if (wifi_under_b_mode) { - btcoexist->btc_write_1byte(btcoexist, 0x6cd, - 0x00); /* CCK Tx */ - btcoexist->btc_write_1byte(btcoexist, 0x6cf, - 0x00); /* CCK Rx */ - } else { - - btcoexist->btc_write_1byte(btcoexist, 0x6cd, - 0x00); /* CCK Tx */ - btcoexist->btc_write_1byte(btcoexist, 0x6cf, - 0x10); /* CCK Rx */ - } - - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], MEDIA disconnect notify\n"); - BTC_TRACE(trace_buf); - - btcoexist->btc_write_1byte(btcoexist, 0x6cd, 0x0); /* CCK Tx */ - btcoexist->btc_write_1byte(btcoexist, 0x6cf, 0x0); /* CCK Rx */ - - halbtc8723d2ant_post_state_to_bt(btcoexist, - BT_8723D_2ANT_SCOREBOARD_ACTIVE, false); - } - - halbtc8723d2ant_update_wifi_channel_info(btcoexist, type); -} - -void ex_halbtc8723d2ant_specific_packet_notify(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - boolean under_4way = false; - - if (btcoexist->manual_control || - btcoexist->stop_coex_dm) - return; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS, - &under_4way); - - if (under_4way) { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], specific Packet ---- under_4way!!\n"); - BTC_TRACE(trace_buf); - - coex_sta->wifi_is_high_pri_task = true; - coex_sta->specific_pkt_period_cnt = 2; - - } else if (BTC_PACKET_ARP == type) { - - coex_dm->arp_cnt++; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], specific Packet ARP notify -cnt = %d\n", - coex_dm->arp_cnt); - BTC_TRACE(trace_buf); - - } else { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], specific Packet DHCP or EAPOL notify [Type = %d]\n", - type); - BTC_TRACE(trace_buf); - - coex_sta->wifi_is_high_pri_task = true; - coex_sta->specific_pkt_period_cnt = 2; - } - - if (coex_sta->wifi_is_high_pri_task) { - halbtc8723d2ant_post_state_to_bt(btcoexist, - BT_8723D_2ANT_SCOREBOARD_ACTIVE, true); - halbtc8723d2ant_run_coexist_mechanism(btcoexist); - } - -} - -void ex_halbtc8723d2ant_bt_info_notify(IN struct btc_coexist *btcoexist, - IN u8 *tmp_buf, IN u8 length) -{ - u8 i, rsp_source = 0; - boolean wifi_connected = false; - boolean wifi_scan = false, wifi_link = false, wifi_roam = false, - wifi_busy = false; - - if (psd_scan->is_AntDet_running == true) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], bt_info_notify return for AntDet is running\n"); - BTC_TRACE(trace_buf); - return; - } - - rsp_source = tmp_buf[0] & 0xf; - if (rsp_source >= BT_INFO_SRC_8723D_2ANT_MAX) - rsp_source = BT_INFO_SRC_8723D_2ANT_WIFI_FW; - coex_sta->bt_info_c2h_cnt[rsp_source]++; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Bt_info[%d], len=%d, data=[", rsp_source, - length); - BTC_TRACE(trace_buf); - - for (i = 0; i < length; i++) { - coex_sta->bt_info_c2h[rsp_source][i] = tmp_buf[i]; - - if (i == length - 1) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "0x%02x]\n", - tmp_buf[i]); - BTC_TRACE(trace_buf); - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "0x%02x, ", - tmp_buf[i]); - BTC_TRACE(trace_buf); - } - } - - coex_sta->bt_info = coex_sta->bt_info_c2h[rsp_source][1]; - coex_sta->bt_info_ext = coex_sta->bt_info_c2h[rsp_source][4]; - coex_sta->bt_info_ext2 = coex_sta->bt_info_c2h[rsp_source][5]; - - if (BT_INFO_SRC_8723D_2ANT_WIFI_FW != rsp_source) { - - /* if 0xff, it means BT is under WHCK test */ - coex_sta->bt_whck_test = ((coex_sta->bt_info == 0xff) ? true : - false); - - coex_sta->bt_create_connection = (( - coex_sta->bt_info_c2h[rsp_source][2] & 0x80) ? true : - false); - - /* unit: %, value-100 to translate to unit: dBm */ - coex_sta->bt_rssi = coex_sta->bt_info_c2h[rsp_source][3] * 2 + - 10; - - coex_sta->c2h_bt_remote_name_req = (( - coex_sta->bt_info_c2h[rsp_source][2] & 0x20) ? true : - false); - - coex_sta->is_A2DP_3M = ((coex_sta->bt_info_c2h[rsp_source][2] & - 0x10) ? true : false); - - coex_sta->acl_busy = ((coex_sta->bt_info_c2h[rsp_source][1] & - 0x9) ? true : false); - - coex_sta->voice_over_HOGP = ((coex_sta->bt_info_ext & 0x10) ? - true : false); - - coex_sta->c2h_bt_inquiry_page = ((coex_sta->bt_info & - BT_INFO_8723D_2ANT_B_INQ_PAGE) ? true : false); - - coex_sta->a2dp_bit_pool = ((( - coex_sta->bt_info_c2h[rsp_source][1] & 0x49) == 0x49) ? - coex_sta->bt_info_c2h[rsp_source][6] : 0); - - coex_sta->bt_retry_cnt = coex_sta->bt_info_c2h[rsp_source][2] & - 0xf; - - coex_sta->is_autoslot = coex_sta->bt_info_ext2 & 0x8; - - coex_sta->forbidden_slot = coex_sta->bt_info_ext2 & 0x7; - - coex_sta->hid_busy_num = (coex_sta->bt_info_ext2 & 0x30) >> 4; - - coex_sta->hid_pair_cnt = (coex_sta->bt_info_ext2 & 0xc0) >> 6; - - if (coex_sta->bt_retry_cnt >= 1) - coex_sta->pop_event_cnt++; - - if (coex_sta->c2h_bt_remote_name_req) - coex_sta->cnt_RemoteNameReq++; - - if (coex_sta->bt_info_ext & BIT(1)) - coex_sta->cnt_ReInit++; - - if (coex_sta->bt_info_ext & BIT(2)) { - coex_sta->cnt_setupLink++; - coex_sta->is_setupLink = true; - } else - coex_sta->is_setupLink = false; - - if (coex_sta->bt_info_ext & BIT(3)) - coex_sta->cnt_IgnWlanAct++; - - if (coex_sta->bt_create_connection) { - coex_sta->cnt_Page++; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &wifi_scan); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &wifi_link); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &wifi_roam); - - if ((wifi_link) || (wifi_roam) || (wifi_scan) || - (coex_sta->wifi_is_high_pri_task) || (wifi_busy)) { - - halbtc8723d2ant_post_state_to_bt(btcoexist, - BT_8723D_2ANT_SCOREBOARD_SCAN, true); - - } else { - - halbtc8723d2ant_post_state_to_bt(btcoexist, - BT_8723D_2ANT_SCOREBOARD_SCAN, false); - } - } else - halbtc8723d2ant_post_state_to_bt(btcoexist, - BT_8723D_2ANT_SCOREBOARD_SCAN, false); - - /* Here we need to resend some wifi info to BT */ - /* because bt is reset and loss of the info. */ - - if ((!btcoexist->manual_control) && - (!btcoexist->stop_coex_dm)) { - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - - /* Re-Init */ - if ((coex_sta->bt_info_ext & BIT(1))) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT ext info bit1 check, send wifi BW&Chnl to BT!!\n"); - BTC_TRACE(trace_buf); - if (wifi_connected) - halbtc8723d2ant_update_wifi_channel_info( - btcoexist, BTC_MEDIA_CONNECT); - else - halbtc8723d2ant_update_wifi_channel_info( - btcoexist, - BTC_MEDIA_DISCONNECT); - } - - /* If Ignore_WLanAct && not SetUp_Link or Role_Switch */ - if ((coex_sta->bt_info_ext & BIT(3)) && - (!(coex_sta->bt_info_ext & BIT(2))) && - (!(coex_sta->bt_info_ext & BIT(6)))) { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT ext info bit3 check, set BT NOT to ignore Wlan active!!\n"); - BTC_TRACE(trace_buf); - halbtc8723d2ant_ignore_wlan_act(btcoexist, - FORCE_EXEC, false); - } else { - if (coex_sta->bt_info_ext & BIT(2)) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT ignore Wlan active because Re-link!!\n"); - BTC_TRACE(trace_buf); - } else if (coex_sta->bt_info_ext & BIT(6)) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT ignore Wlan active because Role-Switch!!\n"); - BTC_TRACE(trace_buf); - } - } - } - - } - - if ((coex_sta->bt_info_ext & BIT(5))) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT ext info bit4 check, query BLE Scan type!!\n"); - BTC_TRACE(trace_buf); - coex_sta->bt_ble_scan_type = btcoexist->btc_get_ble_scan_type_from_bt(btcoexist); - - if ((coex_sta->bt_ble_scan_type & 0x1) == 0x1) - coex_sta->bt_ble_scan_para[0] = btcoexist->btc_get_ble_scan_para_from_bt(btcoexist, 0x1); - if ((coex_sta->bt_ble_scan_type & 0x2) == 0x2) - coex_sta->bt_ble_scan_para[1] = btcoexist->btc_get_ble_scan_para_from_bt(btcoexist, 0x2); - if ((coex_sta->bt_ble_scan_type & 0x4) == 0x4) - coex_sta->bt_ble_scan_para[2] = btcoexist->btc_get_ble_scan_para_from_bt(btcoexist, 0x4); - } - - halbtc8723d2ant_update_bt_link_info(btcoexist); - - halbtc8723d2ant_run_coexist_mechanism(btcoexist); -} - -void ex_halbtc8723d2ant_rf_status_notify(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], RF Status notify\n"); - BTC_TRACE(trace_buf); - - if (BTC_RF_ON == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], RF is turned ON!!\n"); - BTC_TRACE(trace_buf); - - btcoexist->stop_coex_dm = false; - - halbtc8723d2ant_post_state_to_bt(btcoexist, - BT_8723D_2ANT_SCOREBOARD_ACTIVE, true); - halbtc8723d2ant_post_state_to_bt(btcoexist, - BT_8723D_2ANT_SCOREBOARD_ONOFF, true); - } else if (BTC_RF_OFF == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], RF is turned OFF!!\n"); - BTC_TRACE(trace_buf); - - halbtc8723d2ant_set_ant_path(btcoexist, - BTC_ANT_PATH_AUTO, - FORCE_EXEC, - BT_8723D_2ANT_PHASE_WLAN_OFF); - - halbtc8723d2ant_action_coex_all_off(btcoexist); - - halbtc8723d2ant_post_state_to_bt(btcoexist, - BT_8723D_2ANT_SCOREBOARD_ACTIVE, false); - halbtc8723d2ant_post_state_to_bt(btcoexist, - BT_8723D_2ANT_SCOREBOARD_ONOFF, false); - btcoexist->stop_coex_dm = true; - - } -} - -void ex_halbtc8723d2ant_halt_notify(IN struct btc_coexist *btcoexist) -{ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], Halt notify\n"); - BTC_TRACE(trace_buf); - - halbtc8723d2ant_set_ant_path(btcoexist, - BTC_ANT_PATH_AUTO, - FORCE_EXEC, - BT_8723D_2ANT_PHASE_WLAN_OFF); - - ex_halbtc8723d2ant_media_status_notify(btcoexist, BTC_MEDIA_DISCONNECT); - - halbtc8723d2ant_post_state_to_bt(btcoexist, - BT_8723D_2ANT_SCOREBOARD_ACTIVE, false); - halbtc8723d2ant_post_state_to_bt(btcoexist, - BT_8723D_2ANT_SCOREBOARD_ONOFF, false); -} - -void ex_halbtc8723d2ant_pnp_notify(IN struct btc_coexist *btcoexist, - IN u8 pnp_state) -{ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], Pnp notify\n"); - BTC_TRACE(trace_buf); - - if ((BTC_WIFI_PNP_SLEEP == pnp_state) || - (BTC_WIFI_PNP_SLEEP_KEEP_ANT == pnp_state)) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Pnp notify to SLEEP\n"); - BTC_TRACE(trace_buf); - - /* Sinda 20150819, workaround for driver skip leave IPS/LPS to speed up sleep time. */ - /* Driver do not leave IPS/LPS when driver is going to sleep, so BTCoexistence think wifi is still under IPS/LPS */ - /* BT should clear UnderIPS/UnderLPS state to avoid mismatch state after wakeup. */ - coex_sta->under_ips = false; - coex_sta->under_lps = false; - - halbtc8723d2ant_post_state_to_bt(btcoexist, - BT_8723D_2ANT_SCOREBOARD_ACTIVE, false); - halbtc8723d2ant_post_state_to_bt(btcoexist, - BT_8723D_2ANT_SCOREBOARD_ONOFF, false); - - if (BTC_WIFI_PNP_SLEEP_KEEP_ANT == pnp_state) { - - halbtc8723d2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, - FORCE_EXEC, - BT_8723D_2ANT_PHASE_2G_RUNTIME); - } else { - - halbtc8723d2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, - FORCE_EXEC, - BT_8723D_2ANT_PHASE_WLAN_OFF); - } - - } else if (BTC_WIFI_PNP_WAKE_UP == pnp_state) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Pnp notify to WAKE UP\n"); - BTC_TRACE(trace_buf); - - halbtc8723d2ant_post_state_to_bt(btcoexist, - BT_8723D_2ANT_SCOREBOARD_ACTIVE, true); - halbtc8723d2ant_post_state_to_bt(btcoexist, - BT_8723D_2ANT_SCOREBOARD_ONOFF, true); - } -} - -void ex_halbtc8723d2ant_periodical(IN struct btc_coexist *btcoexist) -{ - struct btc_board_info *board_info = &btcoexist->board_info; - boolean wifi_busy = false; - u32 bt_patch_ver; - static u8 cnt = 0; - boolean bt_relink_finish = false; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ************* Periodical *************\n"); - BTC_TRACE(trace_buf); - -#if (BT_AUTO_REPORT_ONLY_8723D_2ANT == 0) - halbtc8723d2ant_query_bt_info(btcoexist); -#endif - - halbtc8723d2ant_monitor_bt_ctr(btcoexist); - halbtc8723d2ant_monitor_wifi_ctr(btcoexist); - halbtc8723d2ant_monitor_bt_enable_disable(btcoexist); - -# if 1 - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - - /* halbtc8723d2ant_read_score_board(btcoexist, &bt_scoreboard_val); */ - - if (wifi_busy) { - halbtc8723d2ant_post_state_to_bt(btcoexist, - BT_8723D_2ANT_SCOREBOARD_UNDERTEST, true); - /* - halbtc8723d2ant_post_state_to_bt(btcoexist, - BT_8723D_2ANT_SCOREBOARD_WLBUSY, true); - - if (bt_scoreboard_val & BIT(6)) - halbtc8723d2ant_query_bt_info(btcoexist); */ - } else { - halbtc8723d2ant_post_state_to_bt(btcoexist, - BT_8723D_2ANT_SCOREBOARD_UNDERTEST, false); - /* - halbtc8723d2ant_post_state_to_bt(btcoexist, - BT_8723D_2ANT_SCOREBOARD_WLBUSY, - false); */ - } -#endif - - if (coex_sta->bt_relink_downcount != 0) { - coex_sta->bt_relink_downcount--; - - if (coex_sta->bt_relink_downcount == 0) - bt_relink_finish = true; - } - - /* for 4-way, DHCP, EAPOL packet */ - if (coex_sta->specific_pkt_period_cnt > 0) { - - coex_sta->specific_pkt_period_cnt--; - - if ((coex_sta->specific_pkt_period_cnt == 0) && - (coex_sta->wifi_is_high_pri_task)) - coex_sta->wifi_is_high_pri_task = false; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ***************** Hi-Pri Task = %s*****************\n", - (coex_sta->wifi_is_high_pri_task ? "Yes" : - "No")); - BTC_TRACE(trace_buf); - - } - - if (!coex_sta->bt_disabled) { - if (coex_sta->bt_coex_supported_feature == 0) - btcoexist->btc_get(btcoexist, BTC_GET_U4_SUPPORTED_FEATURE, - &coex_sta->bt_coex_supported_feature); - - if ((coex_sta->bt_coex_supported_version == 0) || - (coex_sta->bt_coex_supported_version == 0xffff)) - btcoexist->btc_get(btcoexist, BTC_GET_U4_SUPPORTED_VERSION, - &coex_sta->bt_coex_supported_version); - - if (coex_sta->bt_reg_vendor_ac == 0xffff) - coex_sta->bt_reg_vendor_ac = (u16)( - btcoexist->btc_get_bt_reg(btcoexist, 3, - 0xac) & 0xffff); - - if (coex_sta->bt_reg_vendor_ae == 0xffff) - coex_sta->bt_reg_vendor_ae = (u16)( - btcoexist->btc_get_bt_reg(btcoexist, 3, - 0xae) & 0xffff); - - btcoexist->btc_get(btcoexist, BTC_GET_U4_BT_PATCH_VER, - &bt_patch_ver); - btcoexist->bt_info.bt_get_fw_ver = bt_patch_ver; - - if (coex_sta->num_of_profile > 0) { - cnt++; - - if (cnt >= 3) { - btcoexist->btc_get_bt_afh_map_from_bt(btcoexist, 0, - &coex_sta->bt_afh_map[0]); - cnt = 0; - } - } - -#if BT_8723D_2ANT_ANTDET_ENABLE - - if (board_info->btdm_ant_det_finish) { - if ((psd_scan->ant_det_result == 12) && - (psd_scan->ant_det_psd_scan_peak_val == 0) - && (!psd_scan->is_AntDet_running)) - psd_scan->ant_det_psd_scan_peak_val = - btcoexist->btc_get_ant_det_val_from_bt( - btcoexist) * 100; - } - -#endif - } - - if (halbtc8723d2ant_is_wifibt_status_changed(btcoexist)) - halbtc8723d2ant_run_coexist_mechanism(btcoexist); -} - -void ex_halbtc8723d2ant_set_antenna_notify(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - struct btc_board_info *board_info = &btcoexist->board_info; - - if (btcoexist->manual_control || btcoexist->stop_coex_dm) - return; - - if (type == 2) { /* two antenna */ - board_info->ant_div_cfg = true; - - halbtc8723d2ant_set_ant_path(btcoexist, BTC_ANT_PATH_WIFI, - FORCE_EXEC, - BT_8723D_2ANT_PHASE_2G_RUNTIME); - - } else { /* one antenna */ - - halbtc8723d2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, - FORCE_EXEC, - BT_8723D_2ANT_PHASE_2G_RUNTIME); - - } -} - -void ex_halbtc8723d2ant_antenna_detection(IN struct btc_coexist *btcoexist, - IN u32 cent_freq, IN u32 offset, IN u32 span, IN u32 seconds) -{ - - static u32 ant_det_count = 0, ant_det_fail_count = 0; - struct btc_board_info *board_info = &btcoexist->board_info; - u16 u16tmp; - u8 AntDetval = 0; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx Ext Call AntennaDetect()!!\n"); - BTC_TRACE(trace_buf); - -#if BT_8723D_2ANT_ANTDET_ENABLE - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx Call AntennaDetect()!!\n"); - BTC_TRACE(trace_buf); - - if (seconds == 0) { - psd_scan->ant_det_try_count = 0; - psd_scan->ant_det_fail_count = 0; - ant_det_count = 0; - ant_det_fail_count = 0; - board_info->btdm_ant_det_finish = false; - board_info->btdm_ant_num_by_ant_det = 1; - return; - } - - if (!board_info->btdm_ant_det_finish) { - psd_scan->ant_det_inteval_count = - psd_scan->ant_det_inteval_count + 2; - - if (psd_scan->ant_det_inteval_count >= - BT_8723D_2ANT_ANTDET_RETRY_INTERVAL) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Antenna Det Timer is up, Try Detect!!\n"); - BTC_TRACE(trace_buf); - - psd_scan->is_AntDet_running = true; - - halbtc8723d2ant_read_score_board(btcoexist, &u16tmp); - - if (u16tmp & BIT( - 2)) { /* Antenna detection is already done before last WL power on */ - board_info->btdm_ant_det_finish = true; - psd_scan->ant_det_try_count = 1; - psd_scan->ant_det_fail_count = 0; - board_info->btdm_ant_num_by_ant_det = (u16tmp & - BIT(3)) ? 1 : 2; - psd_scan->ant_det_result = 12; - - psd_scan->ant_det_psd_scan_peak_val = - btcoexist->btc_get_ant_det_val_from_bt( - btcoexist) * 100; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Antenna Det Result from BT (%d-Ant)\n", - board_info->btdm_ant_num_by_ant_det); - BTC_TRACE(trace_buf); - } else - board_info->btdm_ant_det_finish = - halbtc8723d2ant_psd_antenna_detection_check( - btcoexist); - - btcoexist->bdontenterLPS = false; - - if (board_info->btdm_ant_det_finish) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Antenna Det Success!!\n"); - BTC_TRACE(trace_buf); - - /*for 8723d, btc_set_bt_trx_mask is just used to - notify BT stop le tx and Ant Det Result , not set BT RF TRx Mask */ - if (psd_scan->ant_det_result != 12) { - - AntDetval = (u8)( - psd_scan->ant_det_psd_scan_peak_val - / 100) & 0x7f; - - AntDetval = - (board_info->btdm_ant_num_by_ant_det - == 1) ? (AntDetval | 0x80) : - AntDetval; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxx AntennaDetect(), Ant Count = %d, PSD Val = %d\n", - ((AntDetval & - 0x80) ? 1 - : 2), AntDetval - & 0x7f); - BTC_TRACE(trace_buf); - - if (btcoexist->btc_set_bt_trx_mask( - btcoexist, AntDetval)) - BTC_SPRINTF(trace_buf, - BT_TMP_BUF_SIZE, - "xxxxxx AntennaDetect(), Notify BT stop le tx by set_bt_trx_mask ok!\n"); - else - BTC_SPRINTF(trace_buf, - BT_TMP_BUF_SIZE, - "xxxxxx AntennaDetect(), Notify BT stop le tx by set_bt_trx_mask fail!\n"); - - BTC_TRACE(trace_buf); - } else - board_info->antdetval = - psd_scan->ant_det_psd_scan_peak_val/100; - - board_info->btdm_ant_det_complete_fail = false; - - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Antenna Det Fail!!\n"); - BTC_TRACE(trace_buf); - } - - psd_scan->ant_det_inteval_count = 0; - psd_scan->is_AntDet_running = false; - - /* stimulate coex running */ - halbtc8723d2ant_run_coexist_mechanism( - btcoexist); - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Stimulate Coex running\n!!"); - BTC_TRACE(trace_buf); - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Antenna Det Timer is not up! (%d)\n", - psd_scan->ant_det_inteval_count); - BTC_TRACE(trace_buf); - - if (psd_scan->ant_det_inteval_count == 8) - btcoexist->bdontenterLPS = true; - else - btcoexist->bdontenterLPS = false; - } - - } -#endif - -} - -void ex_halbtc8723d2ant_display_ant_detection(IN struct btc_coexist *btcoexist) -{ - -#if BT_8723D_2ANT_ANTDET_ENABLE - struct btc_board_info *board_info = &btcoexist->board_info; - - if (psd_scan->ant_det_try_count != 0) { - halbtc8723d2ant_psd_show_antenna_detect_result(btcoexist); - - if (board_info->btdm_ant_det_finish) - halbtc8723d2ant_psd_showdata(btcoexist); - } -#endif - -} - -#endif - -#endif /* #if (RTL8723D_SUPPORT == 1) */ - diff --git a/hal/btc/halbtc8723d2ant.h b/hal/btc/halbtc8723d2ant.h deleted file mode 100644 index 1472796..0000000 --- a/hal/btc/halbtc8723d2ant.h +++ /dev/null @@ -1,418 +0,0 @@ - -#if (BT_SUPPORT == 1 && COEX_SUPPORT == 1) - -#if (RTL8723D_SUPPORT == 1) - -/* ******************************************* - * The following is for 8723D 2Ant BT Co-exist definition - * ******************************************* */ -#define BT_8723D_2ANT_COEX_DBG 0 -#define BT_AUTO_REPORT_ONLY_8723D_2ANT 1 - - -#define BT_INFO_8723D_2ANT_B_FTP BIT(7) -#define BT_INFO_8723D_2ANT_B_A2DP BIT(6) -#define BT_INFO_8723D_2ANT_B_HID BIT(5) -#define BT_INFO_8723D_2ANT_B_SCO_BUSY BIT(4) -#define BT_INFO_8723D_2ANT_B_ACL_BUSY BIT(3) -#define BT_INFO_8723D_2ANT_B_INQ_PAGE BIT(2) -#define BT_INFO_8723D_2ANT_B_SCO_ESCO BIT(1) -#define BT_INFO_8723D_2ANT_B_CONNECTION BIT(0) - -#define BTC_RSSI_COEX_THRESH_TOL_8723D_2ANT 2 - - -#define BT_8723D_2ANT_WIFI_RSSI_COEXSWITCH_THRES1 80 /* unit: % WiFi RSSI Threshold for 2-Ant free-run/2-Ant TDMA translation, default = 42 */ -#define BT_8723D_2ANT_BT_RSSI_COEXSWITCH_THRES1 80 /* unit: % BT RSSI Threshold for 2-Ant free-run/2-Ant TDMA translation, default = 46 */ -#define BT_8723D_2ANT_WIFI_RSSI_COEXSWITCH_THRES2 80 /* unit: % WiFi RSSI Threshold for 1-Ant TDMA/1-Ant PS-TDMA translation, default = 42 */ -#define BT_8723D_2ANT_BT_RSSI_COEXSWITCH_THRES2 80 /* unit: % BT RSSI Threshold for 1-Ant TDMA/1-Ant PS-TDMA translation, default = 46 */ -#define BT_8723D_2ANT_DEFAULT_ISOLATION 15 /* unit: dB */ -#define BT_8723D_2ANT_WIFI_MAX_TX_POWER 15 /* unit: dBm */ -#define BT_8723D_2ANT_BT_MAX_TX_POWER 3 /* unit: dBm */ -#define BT_8723D_2ANT_WIFI_SIR_THRES1 -15 /* unit: dB */ -#define BT_8723D_2ANT_WIFI_SIR_THRES2 -30 /* unit: dB */ -#define BT_8723D_2ANT_BT_SIR_THRES1 -15 /* unit: dB */ -#define BT_8723D_2ANT_BT_SIR_THRES2 -30 /* unit: dB */ - - -/* for Antenna detection */ -#define BT_8723D_2ANT_ANTDET_PSDTHRES_BACKGROUND 50 -#define BT_8723D_2ANT_ANTDET_PSDTHRES_2ANT_BADISOLATION 70 -#define BT_8723D_2ANT_ANTDET_PSDTHRES_2ANT_GOODISOLATION 52 -#define BT_8723D_2ANT_ANTDET_PSDTHRES_1ANT 40 -#define BT_8723D_2ANT_ANTDET_RETRY_INTERVAL 10 /* retry timer if ant det is fail, unit: second */ -#define BT_8723D_2ANT_ANTDET_SWEEPPOINT_DELAY 60000 -#define BT_8723D_2ANT_ANTDET_ENABLE 1 -#define BT_8723D_2ANT_ANTDET_BTTXTIME 100 -#define BT_8723D_2ANT_ANTDET_BTTXCHANNEL 39 -#define BT_8723D_2ANT_ANTDET_PSD_SWWEEPCOUNT 50 - - -#define BT_8723D_2ANT_LTECOEX_INDIRECTREG_ACCESS_TIMEOUT 30000 - -enum bt_8723d_2ant_signal_state { - BT_8723D_2ANT_SIG_STA_SET_TO_LOW = 0x0, - BT_8723D_2ANT_SIG_STA_SET_BY_HW = 0x0, - BT_8723D_2ANT_SIG_STA_SET_TO_HIGH = 0x1, - BT_8723D_2ANT_SIG_STA_MAX -}; - -enum bt_8723d_2ant_path_ctrl_owner { - BT_8723D_2ANT_PCO_BTSIDE = 0x0, - BT_8723D_2ANT_PCO_WLSIDE = 0x1, - BT_8723D_2ANT_PCO_MAX -}; - -enum bt_8723d_2ant_gnt_ctrl_type { - BT_8723D_2ANT_GNT_TYPE_CTRL_BY_PTA = 0x0, - BT_8723D_2ANT_GNT_TYPE_CTRL_BY_SW = 0x1, - BT_8723D_2ANT_GNT_TYPE_MAX -}; - -enum bt_8723d_2ant_gnt_ctrl_block { - BT_8723D_2ANT_GNT_BLOCK_RFC_BB = 0x0, - BT_8723D_2ANT_GNT_BLOCK_RFC = 0x1, - BT_8723D_2ANT_GNT_BLOCK_BB = 0x2, - BT_8723D_2ANT_GNT_BLOCK_MAX -}; - -enum bt_8723d_2ant_lte_coex_table_type { - BT_8723D_2ANT_CTT_WL_VS_LTE = 0x0, - BT_8723D_2ANT_CTT_BT_VS_LTE = 0x1, - BT_8723D_2ANT_CTT_MAX -}; - -enum bt_8723d_2ant_lte_break_table_type { - BT_8723D_2ANT_LBTT_WL_BREAK_LTE = 0x0, - BT_8723D_2ANT_LBTT_BT_BREAK_LTE = 0x1, - BT_8723D_2ANT_LBTT_LTE_BREAK_WL = 0x2, - BT_8723D_2ANT_LBTT_LTE_BREAK_BT = 0x3, - BT_8723D_2ANT_LBTT_MAX -}; - -enum bt_info_src_8723d_2ant { - BT_INFO_SRC_8723D_2ANT_WIFI_FW = 0x0, - BT_INFO_SRC_8723D_2ANT_BT_RSP = 0x1, - BT_INFO_SRC_8723D_2ANT_BT_ACTIVE_SEND = 0x2, - BT_INFO_SRC_8723D_2ANT_MAX -}; - -enum bt_8723d_2ant_bt_status { - BT_8723D_2ANT_BT_STATUS_NON_CONNECTED_IDLE = 0x0, - BT_8723D_2ANT_BT_STATUS_CONNECTED_IDLE = 0x1, - BT_8723D_2ANT_BT_STATUS_INQ_PAGE = 0x2, - BT_8723D_2ANT_BT_STATUS_ACL_BUSY = 0x3, - BT_8723D_2ANT_BT_STATUS_SCO_BUSY = 0x4, - BT_8723D_2ANT_BT_STATUS_ACL_SCO_BUSY = 0x5, - BT_8723D_2ANT_BT_STATUS_MAX -}; - -enum bt_8723d_2ant_coex_algo { - BT_8723D_2ANT_COEX_ALGO_UNDEFINED = 0x0, - BT_8723D_2ANT_COEX_ALGO_SCO = 0x1, - BT_8723D_2ANT_COEX_ALGO_HID = 0x2, - BT_8723D_2ANT_COEX_ALGO_A2DP = 0x3, - BT_8723D_2ANT_COEX_ALGO_A2DP_PANHS = 0x4, - BT_8723D_2ANT_COEX_ALGO_PANEDR = 0x5, - BT_8723D_2ANT_COEX_ALGO_PANHS = 0x6, - BT_8723D_2ANT_COEX_ALGO_PANEDR_A2DP = 0x7, - BT_8723D_2ANT_COEX_ALGO_PANEDR_HID = 0x8, - BT_8723D_2ANT_COEX_ALGO_HID_A2DP_PANEDR = 0x9, - BT_8723D_2ANT_COEX_ALGO_HID_A2DP = 0xa, - BT_8723D_2ANT_COEX_ALGO_NOPROFILEBUSY = 0xb, - BT_8723D_2ANT_COEX_ALGO_MAX -}; - -enum bt_8723d_2ant_phase { - BT_8723D_2ANT_PHASE_COEX_INIT = 0x0, - BT_8723D_2ANT_PHASE_WLANONLY_INIT = 0x1, - BT_8723D_2ANT_PHASE_WLAN_OFF = 0x2, - BT_8723D_2ANT_PHASE_2G_RUNTIME = 0x3, - BT_8723D_2ANT_PHASE_5G_RUNTIME = 0x4, - BT_8723D_2ANT_PHASE_BTMPMODE = 0x5, - BT_8723D_2ANT_PHASE_ANTENNA_DET = 0x6, - BT_8723D_2ANT_PHASE_COEX_POWERON = 0x7, - BT_8723D_2ANT_PHASE_MAX -}; - -enum bt_8723d_2ant_Scoreboard { - BT_8723D_2ANT_SCOREBOARD_ACTIVE = BIT(0), - BT_8723D_2ANT_SCOREBOARD_ONOFF = BIT(1), - BT_8723D_2ANT_SCOREBOARD_SCAN = BIT(2), - BT_8723D_2ANT_SCOREBOARD_UNDERTEST = BIT(3), - BT_8723D_2ANT_SCOREBOARD_WLBUSY = BIT(6) -}; - - - -struct coex_dm_8723d_2ant { - /* fw mechanism */ - u8 pre_bt_dec_pwr_lvl; - u8 cur_bt_dec_pwr_lvl; - u8 pre_fw_dac_swing_lvl; - u8 cur_fw_dac_swing_lvl; - boolean cur_ignore_wlan_act; - boolean pre_ignore_wlan_act; - u8 pre_ps_tdma; - u8 cur_ps_tdma; - u8 ps_tdma_para[5]; - u8 ps_tdma_du_adj_type; - boolean reset_tdma_adjust; - boolean pre_ps_tdma_on; - boolean cur_ps_tdma_on; - boolean pre_bt_auto_report; - boolean cur_bt_auto_report; - - /* sw mechanism */ - boolean pre_rf_rx_lpf_shrink; - boolean cur_rf_rx_lpf_shrink; - u32 bt_rf_0x1e_backup; - boolean pre_low_penalty_ra; - boolean cur_low_penalty_ra; - boolean pre_dac_swing_on; - u32 pre_dac_swing_lvl; - boolean cur_dac_swing_on; - u32 cur_dac_swing_lvl; - boolean pre_adc_back_off; - boolean cur_adc_back_off; - boolean pre_agc_table_en; - boolean cur_agc_table_en; - u32 pre_val0x6c0; - u32 cur_val0x6c0; - u32 pre_val0x6c4; - u32 cur_val0x6c4; - u32 pre_val0x6c8; - u32 cur_val0x6c8; - u8 pre_val0x6cc; - u8 cur_val0x6cc; - boolean limited_dig; - - /* algorithm related */ - u8 pre_algorithm; - u8 cur_algorithm; - u8 bt_status; - u8 wifi_chnl_info[3]; - - boolean need_recover0x948; - u32 backup0x948; - - u8 pre_lps; - u8 cur_lps; - u8 pre_rpwm; - u8 cur_rpwm; - - boolean is_switch_to_1dot5_ant; - u8 switch_thres_offset; - u32 arp_cnt; - - u8 pre_ant_pos_type; - u8 cur_ant_pos_type; -}; - -struct coex_sta_8723d_2ant { - boolean bt_disabled; - boolean bt_link_exist; - boolean sco_exist; - boolean a2dp_exist; - boolean hid_exist; - boolean pan_exist; - - boolean under_lps; - boolean under_ips; - u32 high_priority_tx; - u32 high_priority_rx; - u32 low_priority_tx; - u32 low_priority_rx; - boolean is_hiPri_rx_overhead; - u8 bt_rssi; - boolean bt_tx_rx_mask; - u8 pre_bt_rssi_state; - u8 pre_wifi_rssi_state[4]; - u8 bt_info_c2h[BT_INFO_SRC_8723D_2ANT_MAX][10]; - u32 bt_info_c2h_cnt[BT_INFO_SRC_8723D_2ANT_MAX]; - boolean bt_whck_test; - boolean c2h_bt_inquiry_page; - boolean c2h_bt_remote_name_req; - u8 bt_retry_cnt; - u8 bt_info_ext; - u8 bt_info_ext2; - u32 pop_event_cnt; - u8 scan_ap_num; - - u32 crc_ok_cck; - u32 crc_ok_11g; - u32 crc_ok_11n; - u32 crc_ok_11n_vht; - - u32 crc_err_cck; - u32 crc_err_11g; - u32 crc_err_11n; - u32 crc_err_11n_vht; - - boolean cck_lock; - boolean pre_ccklock; - boolean cck_ever_lock; - u8 coex_table_type; - boolean force_lps_on; - - u8 dis_ver_info_cnt; - - u8 a2dp_bit_pool; - u8 cut_version; - - boolean concurrent_rx_mode_on; - - u16 score_board; - u8 isolation_btween_wb; /* 0~ 50 */ - u8 wifi_coex_thres; - u8 bt_coex_thres; - u8 wifi_coex_thres2; - u8 bt_coex_thres2; - - u8 num_of_profile; - boolean acl_busy; - boolean bt_create_connection; - boolean wifi_is_high_pri_task; - u32 specific_pkt_period_cnt; - u32 bt_coex_supported_feature; - u32 bt_coex_supported_version; - - u8 bt_ble_scan_type; - u32 bt_ble_scan_para[3]; - - boolean run_time_state; - boolean freeze_coexrun_by_btinfo; - - boolean is_A2DP_3M; - boolean voice_over_HOGP; - u8 bt_info; - boolean is_autoslot; - u8 forbidden_slot; - u8 hid_busy_num; - u8 hid_pair_cnt; - - u32 cnt_RemoteNameReq; - u32 cnt_setupLink; - u32 cnt_ReInit; - u32 cnt_IgnWlanAct; - u32 cnt_Page; - u32 cnt_RoleSwitch; - - u16 bt_reg_vendor_ac; - u16 bt_reg_vendor_ae; - - boolean is_setupLink; - boolean wl_noisy_level; - u32 gnt_error_cnt; - - u8 bt_afh_map[10]; - u8 bt_relink_downcount; - boolean is_tdma_btautoslot; - boolean is_tdma_btautoslot_hang; -}; - -#define BT_8723D_2ANT_ANTDET_PSD_POINTS 256 /* MAX:1024 */ -#define BT_8723D_2ANT_ANTDET_PSD_AVGNUM 1 /* MAX:3 */ -#define BT_8723D_2ANT_ANTDET_BUF_LEN 16 - -struct psdscan_sta_8723d_2ant { - - u32 ant_det_bt_le_channel; /* BT LE Channel ex:2412 */ - u32 ant_det_bt_tx_time; - u32 ant_det_pre_psdscan_peak_val; - boolean ant_det_is_ant_det_available; - u32 ant_det_psd_scan_peak_val; - boolean ant_det_is_btreply_available; - u32 ant_det_psd_scan_peak_freq; - - u8 ant_det_result; - u8 ant_det_peak_val[BT_8723D_2ANT_ANTDET_BUF_LEN]; - u8 ant_det_peak_freq[BT_8723D_2ANT_ANTDET_BUF_LEN]; - u32 ant_det_try_count; - u32 ant_det_fail_count; - u32 ant_det_inteval_count; - u32 ant_det_thres_offset; - - u32 real_cent_freq; - s32 real_offset; - u32 real_span; - - u32 psd_band_width; /* unit: Hz */ - u32 psd_point; /* 128/256/512/1024 */ - u32 psd_report[1024]; /* unit:dB (20logx), 0~255 */ - u32 psd_report_max_hold[1024]; /* unit:dB (20logx), 0~255 */ - u32 psd_start_point; - u32 psd_stop_point; - u32 psd_max_value_point; - u32 psd_max_value; - u32 psd_max_value2; - u32 psd_avg_value; /* filter loop_max_value that below BT_8723D_1ANT_ANTDET_PSDTHRES_1ANT, and average the rest*/ - u32 psd_loop_max_value[BT_8723D_2ANT_ANTDET_PSD_SWWEEPCOUNT]; /*max value in each loop */ - u32 psd_start_base; - u32 psd_avg_num; /* 1/8/16/32 */ - u32 psd_gen_count; - boolean is_AntDet_running; - boolean is_psd_show_max_only; -}; - - -/* ******************************************* - * The following is interface which will notify coex module. - * ******************************************* */ -void ex_halbtc8723d2ant_power_on_setting(IN struct btc_coexist *btcoexist); -void ex_halbtc8723d2ant_pre_load_firmware(IN struct btc_coexist *btcoexist); -void ex_halbtc8723d2ant_init_hw_config(IN struct btc_coexist *btcoexist, - IN boolean wifi_only); -void ex_halbtc8723d2ant_init_coex_dm(IN struct btc_coexist *btcoexist); -void ex_halbtc8723d2ant_ips_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8723d2ant_lps_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8723d2ant_scan_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8723d2ant_connect_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8723d2ant_media_status_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8723d2ant_specific_packet_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8723d2ant_bt_info_notify(IN struct btc_coexist *btcoexist, - IN u8 *tmp_buf, IN u8 length); -void ex_halbtc8723d2ant_rf_status_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8723d2ant_halt_notify(IN struct btc_coexist *btcoexist); -void ex_halbtc8723d2ant_pnp_notify(IN struct btc_coexist *btcoexist, - IN u8 pnp_state); -void ex_halbtc8723d2ant_set_antenna_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8723d2ant_periodical(IN struct btc_coexist *btcoexist); -void ex_halbtc8723d2ant_display_coex_info(IN struct btc_coexist *btcoexist); -void ex_halbtc8723d2ant_antenna_detection(IN struct btc_coexist *btcoexist, - IN u32 cent_freq, IN u32 offset, IN u32 span, IN u32 seconds); -void ex_halbtc8723d2ant_display_ant_detection(IN struct btc_coexist *btcoexist); - - -#else -#define ex_halbtc8723d2ant_power_on_setting(btcoexist) -#define ex_halbtc8723d2ant_pre_load_firmware(btcoexist) -#define ex_halbtc8723d2ant_init_hw_config(btcoexist, wifi_only) -#define ex_halbtc8723d2ant_init_coex_dm(btcoexist) -#define ex_halbtc8723d2ant_ips_notify(btcoexist, type) -#define ex_halbtc8723d2ant_lps_notify(btcoexist, type) -#define ex_halbtc8723d2ant_scan_notify(btcoexist, type) -#define ex_halbtc8723d2ant_connect_notify(btcoexist, type) -#define ex_halbtc8723d2ant_media_status_notify(btcoexist, type) -#define ex_halbtc8723d2ant_specific_packet_notify(btcoexist, type) -#define ex_halbtc8723d2ant_bt_info_notify(btcoexist, tmp_buf, length) -#define ex_halbtc8723d2ant_rf_status_notify(btcoexist, type) -#define ex_halbtc8723d2ant_halt_notify(btcoexist) -#define ex_halbtc8723d2ant_pnp_notify(btcoexist, pnp_state) -#define ex_halbtc8723d2ant_periodical(btcoexist) -#define ex_halbtc8723d2ant_display_coex_info(btcoexist) -#define ex_halbtc8723d2ant_set_antenna_notify(btcoexist, type) -#define ex_halbtc8723d2ant_display_ant_detection(btcoexist) -#define ex_halbtc8723d2ant_antenna_detection(btcoexist, cent_freq, offset, span, seconds) -#endif - -#endif - diff --git a/hal/btc/halbtc8812a1ant.c b/hal/btc/halbtc8812a1ant.c deleted file mode 100644 index f1cefab..0000000 --- a/hal/btc/halbtc8812a1ant.c +++ /dev/null @@ -1,3461 +0,0 @@ -/* ************************************************************ - * Description: - * - * This file is for RTL8812A Co-exist mechanism - * - * History - * 2012/11/15 Cosa first check in. - * - * ************************************************************ */ - -/* ************************************************************ - * include files - * ************************************************************ */ -#include "mp_precomp.h" - -#if (BT_SUPPORT == 1 && COEX_SUPPORT == 1) - -#if (RTL8812A_SUPPORT == 1) -/* ************************************************************ - * Global variables, these are static variables - * ************************************************************ */ -static u8 *trace_buf = &gl_btc_trace_buf[0]; -static struct coex_dm_8812a_1ant glcoex_dm_8812a_1ant; -static struct coex_dm_8812a_1ant *coex_dm = &glcoex_dm_8812a_1ant; -static struct coex_sta_8812a_1ant glcoex_sta_8812a_1ant; -static struct coex_sta_8812a_1ant *coex_sta = &glcoex_sta_8812a_1ant; - -const char *const glbt_info_src_8812a_1ant[] = { - "BT Info[wifi fw]", - "BT Info[bt rsp]", - "BT Info[bt auto report]", -}; - -u32 glcoex_ver_date_8812a_1ant = 20140708; -u32 glcoex_ver_8812a_1ant = 0x52; - -/* ************************************************************ - * local function proto type if needed - * ************************************************************ - * ************************************************************ - * local function start with halbtc8812a1ant_ - * ************************************************************ */ -u8 halbtc8812a1ant_bt_rssi_state(u8 level_num, u8 rssi_thresh, u8 rssi_thresh1) -{ - s32 bt_rssi = 0; - u8 bt_rssi_state = coex_sta->pre_bt_rssi_state; - - bt_rssi = coex_sta->bt_rssi; - - if (level_num == 2) { - if ((coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_LOW) || - (coex_sta->pre_bt_rssi_state == - BTC_RSSI_STATE_STAY_LOW)) { - if (bt_rssi >= (rssi_thresh + - BTC_RSSI_COEX_THRESH_TOL_8812A_1ANT)) - bt_rssi_state = BTC_RSSI_STATE_HIGH; - else - bt_rssi_state = BTC_RSSI_STATE_STAY_LOW; - } else { - if (bt_rssi < rssi_thresh) - bt_rssi_state = BTC_RSSI_STATE_LOW; - else - bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH; - } - } else if (level_num == 3) { - if (rssi_thresh > rssi_thresh1) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Rssi thresh error!!\n"); - BTC_TRACE(trace_buf); - return coex_sta->pre_bt_rssi_state; - } - - if ((coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_LOW) || - (coex_sta->pre_bt_rssi_state == - BTC_RSSI_STATE_STAY_LOW)) { - if (bt_rssi >= (rssi_thresh + - BTC_RSSI_COEX_THRESH_TOL_8812A_1ANT)) - bt_rssi_state = BTC_RSSI_STATE_MEDIUM; - else - bt_rssi_state = BTC_RSSI_STATE_STAY_LOW; - } else if ((coex_sta->pre_bt_rssi_state == - BTC_RSSI_STATE_MEDIUM) || - (coex_sta->pre_bt_rssi_state == - BTC_RSSI_STATE_STAY_MEDIUM)) { - if (bt_rssi >= (rssi_thresh1 + - BTC_RSSI_COEX_THRESH_TOL_8812A_1ANT)) - bt_rssi_state = BTC_RSSI_STATE_HIGH; - else if (bt_rssi < rssi_thresh) - bt_rssi_state = BTC_RSSI_STATE_LOW; - else - bt_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM; - } else { - if (bt_rssi < rssi_thresh1) - bt_rssi_state = BTC_RSSI_STATE_MEDIUM; - else - bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH; - } - } - - coex_sta->pre_bt_rssi_state = bt_rssi_state; - - return bt_rssi_state; -} - -u8 halbtc8812a1ant_wifi_rssi_state(IN struct btc_coexist *btcoexist, - IN u8 index, IN u8 level_num, IN u8 rssi_thresh, IN u8 rssi_thresh1) -{ - s32 wifi_rssi = 0; - u8 wifi_rssi_state = coex_sta->pre_wifi_rssi_state[index]; - - btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi); - - if (level_num == 2) { - if ((coex_sta->pre_wifi_rssi_state[index] == BTC_RSSI_STATE_LOW) - || - (coex_sta->pre_wifi_rssi_state[index] == - BTC_RSSI_STATE_STAY_LOW)) { - if (wifi_rssi >= (rssi_thresh + - BTC_RSSI_COEX_THRESH_TOL_8812A_1ANT)) - wifi_rssi_state = BTC_RSSI_STATE_HIGH; - else - wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW; - } else { - if (wifi_rssi < rssi_thresh) - wifi_rssi_state = BTC_RSSI_STATE_LOW; - else - wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH; - } - } else if (level_num == 3) { - if (rssi_thresh > rssi_thresh1) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], wifi RSSI thresh error!!\n"); - BTC_TRACE(trace_buf); - return coex_sta->pre_wifi_rssi_state[index]; - } - - if ((coex_sta->pre_wifi_rssi_state[index] == BTC_RSSI_STATE_LOW) - || - (coex_sta->pre_wifi_rssi_state[index] == - BTC_RSSI_STATE_STAY_LOW)) { - if (wifi_rssi >= (rssi_thresh + - BTC_RSSI_COEX_THRESH_TOL_8812A_1ANT)) - wifi_rssi_state = BTC_RSSI_STATE_MEDIUM; - else - wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW; - } else if ((coex_sta->pre_wifi_rssi_state[index] == - BTC_RSSI_STATE_MEDIUM) || - (coex_sta->pre_wifi_rssi_state[index] == - BTC_RSSI_STATE_STAY_MEDIUM)) { - if (wifi_rssi >= (rssi_thresh1 + - BTC_RSSI_COEX_THRESH_TOL_8812A_1ANT)) - wifi_rssi_state = BTC_RSSI_STATE_HIGH; - else if (wifi_rssi < rssi_thresh) - wifi_rssi_state = BTC_RSSI_STATE_LOW; - else - wifi_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM; - } else { - if (wifi_rssi < rssi_thresh1) - wifi_rssi_state = BTC_RSSI_STATE_MEDIUM; - else - wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH; - } - } - - coex_sta->pre_wifi_rssi_state[index] = wifi_rssi_state; - - return wifi_rssi_state; -} - -void halbtc8812a1ant_update_ra_mask(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u32 dis_rate_mask) -{ - coex_dm->cur_ra_mask = dis_rate_mask; - - if (force_exec || (coex_dm->pre_ra_mask != coex_dm->cur_ra_mask)) - btcoexist->btc_set(btcoexist, BTC_SET_ACT_UPDATE_RAMASK, - &coex_dm->cur_ra_mask); - coex_dm->pre_ra_mask = coex_dm->cur_ra_mask; -} - -/* to check 0x430/0x434 is correct?? */ -void halbtc8812a1ant_auto_rate_fallback_retry(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 type) -{ - boolean wifi_under_b_mode = false; - - coex_dm->cur_arfr_type = type; - - if (force_exec || (coex_dm->pre_arfr_type != coex_dm->cur_arfr_type)) { - switch (coex_dm->cur_arfr_type) { - case 0: /* normal mode */ - btcoexist->btc_write_4byte(btcoexist, 0x430, - coex_dm->backup_arfr_cnt1); - btcoexist->btc_write_4byte(btcoexist, 0x434, - coex_dm->backup_arfr_cnt2); - break; - case 1: - btcoexist->btc_get(btcoexist, - BTC_GET_BL_WIFI_UNDER_B_MODE, - &wifi_under_b_mode); - if (wifi_under_b_mode) { - btcoexist->btc_write_4byte(btcoexist, - 0x430, 0x0); - btcoexist->btc_write_4byte(btcoexist, - 0x434, 0x01010101); - } else { - btcoexist->btc_write_4byte(btcoexist, - 0x430, 0x0); - btcoexist->btc_write_4byte(btcoexist, - 0x434, 0x04030201); - } - break; - default: - break; - } - } - - coex_dm->pre_arfr_type = coex_dm->cur_arfr_type; -} - -/* to check 0x42a ?? */ -void halbtc8812a1ant_retry_limit(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 type) -{ - coex_dm->cur_retry_limit_type = type; - - if (force_exec || - (coex_dm->pre_retry_limit_type != - coex_dm->cur_retry_limit_type)) { - switch (coex_dm->cur_retry_limit_type) { - case 0: /* normal mode */ - btcoexist->btc_write_2byte(btcoexist, 0x42a, - coex_dm->backup_retry_limit); - break; - case 1: /* retry limit=8 */ - btcoexist->btc_write_2byte(btcoexist, 0x42a, - 0x0808); - break; - default: - break; - } - } - - coex_dm->pre_retry_limit_type = coex_dm->cur_retry_limit_type; -} - -/* to check 0x456?? */ -void halbtc8812a1ant_ampdu_max_time(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 type) -{ - coex_dm->cur_ampdu_time_type = type; - - if (force_exec || - (coex_dm->pre_ampdu_time_type != coex_dm->cur_ampdu_time_type)) { - switch (coex_dm->cur_ampdu_time_type) { - case 0: /* normal mode */ - btcoexist->btc_write_1byte(btcoexist, 0x456, - coex_dm->backup_ampdu_max_time); - break; - case 1: /* AMPDU timw = 0x38 * 32us */ - btcoexist->btc_write_1byte(btcoexist, 0x456, - 0x38); - break; - default: - break; - } - } - - coex_dm->pre_ampdu_time_type = coex_dm->cur_ampdu_time_type; -} - -void halbtc8812a1ant_limited_tx(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 ra_mask_type, IN u8 arfr_type, - IN u8 retry_limit_type, IN u8 ampdu_time_type) -{ - switch (ra_mask_type) { - case 0: /* normal mode */ - halbtc8812a1ant_update_ra_mask(btcoexist, force_exec, - 0x0); - break; - case 1: /* disable cck 1/2 */ - halbtc8812a1ant_update_ra_mask(btcoexist, force_exec, - 0x00000003); - break; - case 2: /* disable cck 1/2/5.5, ofdm 6/9/12/18/24, mcs 0/1/2/3/4 */ - halbtc8812a1ant_update_ra_mask(btcoexist, force_exec, - 0x0001f1f7); - break; - default: - break; - } - - halbtc8812a1ant_auto_rate_fallback_retry(btcoexist, force_exec, - arfr_type); - halbtc8812a1ant_retry_limit(btcoexist, force_exec, retry_limit_type); - halbtc8812a1ant_ampdu_max_time(btcoexist, force_exec, ampdu_time_type); -} - -void halbtc8812a1ant_limited_rx(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean rej_ap_agg_pkt, - IN boolean bt_ctrl_agg_buf_size, IN u8 agg_buf_size) -{ - boolean reject_rx_agg = rej_ap_agg_pkt; - boolean bt_ctrl_rx_agg_size = bt_ctrl_agg_buf_size; - u8 rx_agg_size = agg_buf_size; - - /* ============================================ */ - /* Rx Aggregation related setting */ - /* ============================================ */ - btcoexist->btc_set(btcoexist, BTC_SET_BL_TO_REJ_AP_AGG_PKT, - &reject_rx_agg); - /* decide BT control aggregation buf size or not */ - btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_CTRL_AGG_SIZE, - &bt_ctrl_rx_agg_size); - /* aggregation buf size, only work when BT control Rx aggregation size. */ - btcoexist->btc_set(btcoexist, BTC_SET_U1_AGG_BUF_SIZE, &rx_agg_size); - /* real update aggregation setting */ - btcoexist->btc_set(btcoexist, BTC_SET_ACT_AGGREGATE_CTRL, NULL); - - -} - -void halbtc8812a1ant_query_bt_info(IN struct btc_coexist *btcoexist) -{ - u8 data_len = 3; - u8 buf[5] = {0}; - - if (!coex_sta->bt_disabled) { - if (!coex_sta->bt_info_query_cnt || - (coex_sta->bt_info_c2h_cnt[BT_INFO_SRC_8812A_1ANT_BT_RSP] - - coex_sta->bt_info_query_cnt) > 2) { - buf[0] = data_len; - buf[1] = 0x1; /* polling enable, 1=enable, 0=disable */ - buf[2] = 0x2; /* polling time in seconds */ - buf[3] = 0x1; /* auto report enable, 1=enable, 0=disable */ - - btcoexist->btc_set(btcoexist, BTC_SET_ACT_CTRL_BT_INFO, - (void *)&buf[0]); - } - } - coex_sta->bt_info_query_cnt++; -} - -void halbtc8812a1ant_monitor_bt_ctr(IN struct btc_coexist *btcoexist) -{ - u32 reg_hp_txrx, reg_lp_txrx, u32tmp; - u32 reg_hp_tx = 0, reg_hp_rx = 0, reg_lp_tx = 0, reg_lp_rx = 0; - static u8 num_of_bt_counter_chk = 0; - - reg_hp_txrx = 0x770; - reg_lp_txrx = 0x774; - - u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_hp_txrx); - reg_hp_tx = u32tmp & MASKLWORD; - reg_hp_rx = (u32tmp & MASKHWORD) >> 16; - - u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_lp_txrx); - reg_lp_tx = u32tmp & MASKLWORD; - reg_lp_rx = (u32tmp & MASKHWORD) >> 16; - - coex_sta->high_priority_tx = reg_hp_tx; - coex_sta->high_priority_rx = reg_hp_rx; - coex_sta->low_priority_tx = reg_lp_tx; - coex_sta->low_priority_rx = reg_lp_rx; - - if ((coex_sta->low_priority_tx > 1150) && - (!coex_sta->c2h_bt_inquiry_page)) - coex_sta->pop_event_cnt++; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Hi-Pri Rx/Tx: %d/%d, Lo-Pri Rx/Tx: %d/%d\n", - reg_hp_rx, reg_hp_tx, reg_lp_rx, reg_lp_tx); - BTC_TRACE(trace_buf); - - /* reset counter */ - btcoexist->btc_write_1byte(btcoexist, 0x76e, 0xc); - - if ((reg_hp_tx == 0) && (reg_hp_rx == 0) && (reg_lp_tx == 0) && - (reg_lp_rx == 0)) { - num_of_bt_counter_chk++; - if (num_of_bt_counter_chk >= 3) { - halbtc8812a1ant_query_bt_info(btcoexist); - num_of_bt_counter_chk = 0; - } - } -} - -/* to check registers */ -void halbtc8812a1ant_monitor_wifi_ctr(IN struct btc_coexist *btcoexist) -{ - s32 wifi_rssi = 0; - boolean wifi_busy = false, wifi_under_b_mode = false; - static u8 cck_lock_counter = 0; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_B_MODE, - &wifi_under_b_mode); - - if (coex_sta->under_ips) { - coex_sta->crc_ok_cck = 0; - coex_sta->crc_ok_11g = 0; - coex_sta->crc_ok_11n = 0; - coex_sta->crc_ok_11n_agg = 0; - - coex_sta->crc_err_cck = 0; - coex_sta->crc_err_11g = 0; - coex_sta->crc_err_11n = 0; - coex_sta->crc_err_11n_agg = 0; - } else { - coex_sta->crc_ok_cck = btcoexist->btc_read_2byte(btcoexist, - 0xf04); - coex_sta->crc_ok_11g = btcoexist->btc_read_2byte(btcoexist, - 0xf14); - coex_sta->crc_ok_11n = btcoexist->btc_read_2byte(btcoexist, - 0xf10); - coex_sta->crc_ok_11n_agg = btcoexist->btc_read_2byte(btcoexist, - 0xf40); - - coex_sta->crc_err_cck = btcoexist->btc_read_2byte(btcoexist, - 0xf06); - coex_sta->crc_err_11g = btcoexist->btc_read_2byte(btcoexist, - 0xf16); - coex_sta->crc_err_11n = btcoexist->btc_read_2byte(btcoexist, - 0xf12); - coex_sta->crc_err_11n_agg = btcoexist->btc_read_2byte(btcoexist, - 0xf42); - } - - - /* reset counter */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0xb58, 0x1, 0x1); - btcoexist->btc_write_1byte_bitmask(btcoexist, 0xb58, 0x1, 0x0); - - if ((wifi_busy) && (wifi_rssi >= 30) && (!wifi_under_b_mode)) { - if ((coex_dm->bt_status == BT_8812A_1ANT_BT_STATUS_ACL_BUSY) || - (coex_dm->bt_status == - BT_8812A_1ANT_BT_STATUS_ACL_SCO_BUSY) || - (coex_dm->bt_status == - BT_8812A_1ANT_BT_STATUS_SCO_BUSY)) { - if (coex_sta->crc_ok_cck > (coex_sta->crc_ok_11g + - coex_sta->crc_ok_11n + - coex_sta->crc_ok_11n_agg)) { - if (cck_lock_counter < 5) - cck_lock_counter++; - } else { - if (cck_lock_counter > 0) - cck_lock_counter--; - } - - } else { - if (cck_lock_counter > 0) - cck_lock_counter--; - } - } else { - if (cck_lock_counter > 0) - cck_lock_counter--; - } - - if (!coex_sta->pre_ccklock) { - - if (cck_lock_counter >= 5) - coex_sta->cck_lock = true; - else - coex_sta->cck_lock = false; - } else { - if (cck_lock_counter == 0) - coex_sta->cck_lock = false; - else - coex_sta->cck_lock = true; - } - - coex_sta->pre_ccklock = coex_sta->cck_lock; - - -} - -boolean halbtc8812a1ant_is_wifi_status_changed(IN struct btc_coexist *btcoexist) -{ - static boolean pre_wifi_busy = false, pre_under_4way = false, - pre_bt_hs_on = false; - boolean wifi_busy = false, under_4way = false, bt_hs_on = false; - boolean wifi_connected = false; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS, - &under_4way); - - if (wifi_connected) { - if (wifi_busy != pre_wifi_busy) { - pre_wifi_busy = wifi_busy; - return true; - } - if (under_4way != pre_under_4way) { - pre_under_4way = under_4way; - return true; - } - if (bt_hs_on != pre_bt_hs_on) { - pre_bt_hs_on = bt_hs_on; - return true; - } - } - - return false; -} - -void halbtc8812a1ant_update_bt_link_info(IN struct btc_coexist *btcoexist) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - boolean bt_hs_on = false; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); - - bt_link_info->bt_link_exist = coex_sta->bt_link_exist; - bt_link_info->sco_exist = coex_sta->sco_exist; - bt_link_info->a2dp_exist = coex_sta->a2dp_exist; - bt_link_info->pan_exist = coex_sta->pan_exist; - bt_link_info->hid_exist = coex_sta->hid_exist; - - /* work around for HS mode. */ - if (bt_hs_on) { - bt_link_info->pan_exist = true; - bt_link_info->bt_link_exist = true; - } - - /* check if Sco only */ - if (bt_link_info->sco_exist && - !bt_link_info->a2dp_exist && - !bt_link_info->pan_exist && - !bt_link_info->hid_exist) - bt_link_info->sco_only = true; - else - bt_link_info->sco_only = false; - - /* check if A2dp only */ - if (!bt_link_info->sco_exist && - bt_link_info->a2dp_exist && - !bt_link_info->pan_exist && - !bt_link_info->hid_exist) - bt_link_info->a2dp_only = true; - else - bt_link_info->a2dp_only = false; - - /* check if Pan only */ - if (!bt_link_info->sco_exist && - !bt_link_info->a2dp_exist && - bt_link_info->pan_exist && - !bt_link_info->hid_exist) - bt_link_info->pan_only = true; - else - bt_link_info->pan_only = false; - - /* check if Hid only */ - if (!bt_link_info->sco_exist && - !bt_link_info->a2dp_exist && - !bt_link_info->pan_exist && - bt_link_info->hid_exist) - bt_link_info->hid_only = true; - else - bt_link_info->hid_only = false; -} - -u8 halbtc8812a1ant_action_algorithm(IN struct btc_coexist *btcoexist) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - boolean bt_hs_on = false; - u8 algorithm = BT_8812A_1ANT_COEX_ALGO_UNDEFINED; - u8 num_of_diff_profile = 0; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); - - if (!bt_link_info->bt_link_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], No BT link exists!!!\n"); - BTC_TRACE(trace_buf); - return algorithm; - } - - if (bt_link_info->sco_exist) - num_of_diff_profile++; - if (bt_link_info->hid_exist) - num_of_diff_profile++; - if (bt_link_info->pan_exist) - num_of_diff_profile++; - if (bt_link_info->a2dp_exist) - num_of_diff_profile++; - - if (num_of_diff_profile == 1) { - if (bt_link_info->sco_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = SCO only\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8812A_1ANT_COEX_ALGO_SCO; - } else { - if (bt_link_info->hid_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = HID only\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8812A_1ANT_COEX_ALGO_HID; - } else if (bt_link_info->a2dp_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = A2DP only\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8812A_1ANT_COEX_ALGO_A2DP; - } else if (bt_link_info->pan_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = PAN(HS) only\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8812A_1ANT_COEX_ALGO_PANHS; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = PAN(EDR) only\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8812A_1ANT_COEX_ALGO_PANEDR; - } - } - } - } else if (num_of_diff_profile == 2) { - if (bt_link_info->sco_exist) { - if (bt_link_info->hid_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = SCO + HID\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8812A_1ANT_COEX_ALGO_HID; - } else if (bt_link_info->a2dp_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = SCO + A2DP ==> SCO\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8812A_1ANT_COEX_ALGO_SCO; - } else if (bt_link_info->pan_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = SCO + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8812A_1ANT_COEX_ALGO_SCO; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = SCO + PAN(EDR)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8812A_1ANT_COEX_ALGO_PANEDR_HID; - } - } - } else { - if (bt_link_info->hid_exist && - bt_link_info->a2dp_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = HID + A2DP\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8812A_1ANT_COEX_ALGO_HID_A2DP; - } else if (bt_link_info->hid_exist && - bt_link_info->pan_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = HID + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8812A_1ANT_COEX_ALGO_HID_A2DP; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = HID + PAN(EDR)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8812A_1ANT_COEX_ALGO_PANEDR_HID; - } - } else if (bt_link_info->pan_exist && - bt_link_info->a2dp_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = A2DP + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8812A_1ANT_COEX_ALGO_A2DP_PANHS; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = A2DP + PAN(EDR)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8812A_1ANT_COEX_ALGO_PANEDR_A2DP; - } - } - } - } else if (num_of_diff_profile == 3) { - if (bt_link_info->sco_exist) { - if (bt_link_info->hid_exist && - bt_link_info->a2dp_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = SCO + HID + A2DP ==> HID\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8812A_1ANT_COEX_ALGO_HID; - } else if (bt_link_info->hid_exist && - bt_link_info->pan_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = SCO + HID + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8812A_1ANT_COEX_ALGO_HID_A2DP; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = SCO + HID + PAN(EDR)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8812A_1ANT_COEX_ALGO_PANEDR_HID; - } - } else if (bt_link_info->pan_exist && - bt_link_info->a2dp_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = SCO + A2DP + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8812A_1ANT_COEX_ALGO_SCO; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = SCO + A2DP + PAN(EDR) ==> HID\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8812A_1ANT_COEX_ALGO_PANEDR_HID; - } - } - } else { - if (bt_link_info->hid_exist && - bt_link_info->pan_exist && - bt_link_info->a2dp_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = HID + A2DP + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8812A_1ANT_COEX_ALGO_HID_A2DP; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = HID + A2DP + PAN(EDR)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8812A_1ANT_COEX_ALGO_HID_A2DP_PANEDR; - } - } - } - } else if (num_of_diff_profile >= 3) { - if (bt_link_info->sco_exist) { - if (bt_link_info->hid_exist && - bt_link_info->pan_exist && - bt_link_info->a2dp_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Error!!! BT Profile = SCO + HID + A2DP + PAN(HS)\n"); - BTC_TRACE(trace_buf); - - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = SCO + HID + A2DP + PAN(EDR)==>PAN(EDR)+HID\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8812A_1ANT_COEX_ALGO_PANEDR_HID; - } - } - } - } - - return algorithm; -} - -void halbtc8812a1ant_set_bt_auto_report(IN struct btc_coexist *btcoexist, - IN boolean enable_auto_report) -{ - u8 h2c_parameter[1] = {0}; - - h2c_parameter[0] = 0; - - if (enable_auto_report) - h2c_parameter[0] |= BIT(0); - - btcoexist->btc_fill_h2c(btcoexist, 0x68, 1, h2c_parameter); -} - -void halbtc8812a1ant_bt_auto_report(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean enable_auto_report) -{ - coex_dm->cur_bt_auto_report = enable_auto_report; - - if (!force_exec) { - if (coex_dm->pre_bt_auto_report == coex_dm->cur_bt_auto_report) - return; - } - halbtc8812a1ant_set_bt_auto_report(btcoexist, - coex_dm->cur_bt_auto_report); - - coex_dm->pre_bt_auto_report = coex_dm->cur_bt_auto_report; -} - -/* to check */ -void halbtc8812a1ant_set_sw_penalty_tx_rate_adaptive(IN struct btc_coexist - *btcoexist, IN boolean low_penalty_ra) -{ - u8 tmp_u1; - - tmp_u1 = btcoexist->btc_read_1byte(btcoexist, 0x4fd); - tmp_u1 |= BIT(0); - if (low_penalty_ra) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Tx rate adaptive, set low penalty!!\n"); - BTC_TRACE(trace_buf); - tmp_u1 &= ~BIT(2); - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Tx rate adaptive, set normal!!\n"); - BTC_TRACE(trace_buf); - tmp_u1 |= BIT(2); - } - - btcoexist->btc_write_1byte(btcoexist, 0x4fd, tmp_u1); -} - -void halbtc8812a1ant_low_penalty_ra(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean low_penalty_ra) -{ - coex_dm->cur_low_penalty_ra = low_penalty_ra; - - if (!force_exec) { - if (coex_dm->pre_low_penalty_ra == coex_dm->cur_low_penalty_ra) - return; - } - halbtc8812a1ant_set_sw_penalty_tx_rate_adaptive(btcoexist, - coex_dm->cur_low_penalty_ra); - - coex_dm->pre_low_penalty_ra = coex_dm->cur_low_penalty_ra; -} - -void halbtc8812a1ant_set_coex_table(IN struct btc_coexist *btcoexist, - IN u32 val0x6c0, IN u32 val0x6c4, IN u32 val0x6c8, IN u8 val0x6cc) -{ - btcoexist->btc_write_4byte(btcoexist, 0x6c0, val0x6c0); - - btcoexist->btc_write_4byte(btcoexist, 0x6c4, val0x6c4); - - btcoexist->btc_write_4byte(btcoexist, 0x6c8, val0x6c8); - - btcoexist->btc_write_1byte(btcoexist, 0x6cc, val0x6cc); -} - -void halbtc8812a1ant_coex_table(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u32 val0x6c0, IN u32 val0x6c4, - IN u32 val0x6c8, IN u8 val0x6cc) -{ - coex_dm->cur_val0x6c0 = val0x6c0; - coex_dm->cur_val0x6c4 = val0x6c4; - coex_dm->cur_val0x6c8 = val0x6c8; - coex_dm->cur_val0x6cc = val0x6cc; - - if (!force_exec) { - if ((coex_dm->pre_val0x6c0 == coex_dm->cur_val0x6c0) && - (coex_dm->pre_val0x6c4 == coex_dm->cur_val0x6c4) && - (coex_dm->pre_val0x6c8 == coex_dm->cur_val0x6c8) && - (coex_dm->pre_val0x6cc == coex_dm->cur_val0x6cc)) - return; - } - halbtc8812a1ant_set_coex_table(btcoexist, val0x6c0, val0x6c4, val0x6c8, - val0x6cc); - - coex_dm->pre_val0x6c0 = coex_dm->cur_val0x6c0; - coex_dm->pre_val0x6c4 = coex_dm->cur_val0x6c4; - coex_dm->pre_val0x6c8 = coex_dm->cur_val0x6c8; - coex_dm->pre_val0x6cc = coex_dm->cur_val0x6cc; -} - -void halbtc8812a1ant_coex_table_with_type(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 type) -{ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** CoexTable(%d) **********\n", type); - BTC_TRACE(trace_buf); - - coex_sta->coex_table_type = type; - - switch (type) { - case 0: - halbtc8812a1ant_coex_table(btcoexist, force_exec, - 0x55555555, 0x55555555, 0xffffff, 0x3); - break; - case 1: - halbtc8812a1ant_coex_table(btcoexist, force_exec, - 0x55555555, 0x5a5a5a5a, 0xffffff, 0x3); - break; - case 2: - halbtc8812a1ant_coex_table(btcoexist, force_exec, - 0x5a5a5a5a, 0x5a5a5a5a, 0xffffff, 0x3); - break; - case 3: - halbtc8812a1ant_coex_table(btcoexist, force_exec, - 0x55555555, 0x5a5a5a5a, 0xffffff, 0x3); - break; - case 4: - halbtc8812a1ant_coex_table(btcoexist, force_exec, - 0x55555555, 0xaaaa5a5a, 0xffffff, 0x3); - break; - case 5: - halbtc8812a1ant_coex_table(btcoexist, force_exec, - 0x5a5a5a5a, 0xaa5a5a5a, 0xffffff, 0x3); - break; - case 6: - halbtc8812a1ant_coex_table(btcoexist, force_exec, - 0x55555555, 0xaaaaaaaa, 0xffffff, 0x3); - break; - case 7: - halbtc8812a1ant_coex_table(btcoexist, force_exec, - 0xaaaaaaaa, 0xaaaaaaaa, 0xffffff, 0x3); - break; - default: - break; - } -} - -void halbtc8812a1ant_set_fw_ignore_wlan_act(IN struct btc_coexist *btcoexist, - IN boolean enable) -{ - u8 data_len = 3; - u8 buf[5] = {0}; - - buf[0] = data_len; - buf[1] = 0x1; /* OP_Code */ - buf[2] = 0x1; /* OP_Code_Length */ - if (enable) - buf[3] = 0x1; /* OP_Code_Content */ - else - buf[3] = 0x0; - - btcoexist->btc_set(btcoexist, BTC_SET_ACT_CTRL_BT_COEX, - (void *)&buf[0]); -} - -void halbtc8812a1ant_ignore_wlan_act(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean enable) -{ - coex_dm->cur_ignore_wlan_act = enable; - - if (!force_exec) { - if (coex_dm->pre_ignore_wlan_act == - coex_dm->cur_ignore_wlan_act) - return; - } - halbtc8812a1ant_set_fw_ignore_wlan_act(btcoexist, enable); - - coex_dm->pre_ignore_wlan_act = coex_dm->cur_ignore_wlan_act; -} - -void halbtc8812a1ant_set_lps_rpwm(IN struct btc_coexist *btcoexist, - IN u8 lps_val, IN u8 rpwm_val) -{ - u8 lps = lps_val; - u8 rpwm = rpwm_val; - - btcoexist->btc_set(btcoexist, BTC_SET_U1_LPS_VAL, &lps); - btcoexist->btc_set(btcoexist, BTC_SET_U1_RPWM_VAL, &rpwm); -} - -void halbtc8812a1ant_lps_rpwm(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 lps_val, IN u8 rpwm_val) -{ - coex_dm->cur_lps = lps_val; - coex_dm->cur_rpwm = rpwm_val; - - if (!force_exec) { - if ((coex_dm->pre_lps == coex_dm->cur_lps) && - (coex_dm->pre_rpwm == coex_dm->cur_rpwm)) - return; - } - halbtc8812a1ant_set_lps_rpwm(btcoexist, lps_val, rpwm_val); - - coex_dm->pre_lps = coex_dm->cur_lps; - coex_dm->pre_rpwm = coex_dm->cur_rpwm; -} - -void halbtc8812a1ant_sw_mechanism(IN struct btc_coexist *btcoexist, - IN boolean low_penalty_ra) -{ - halbtc8812a1ant_low_penalty_ra(btcoexist, NORMAL_EXEC, low_penalty_ra); -} - -/* to check force_exec */ -void halbtc8812a1ant_set_ant_path(IN struct btc_coexist *btcoexist, - IN u8 ant_pos_type, IN boolean force_exec, IN boolean init_hwcfg, - IN boolean wifi_off) -{ - u8 u8tmp = 0; - - coex_dm->cur_ant_pos_type = ant_pos_type; - - if (init_hwcfg) { - btcoexist->btc_write_1byte(btcoexist, 0xcb3, 0x77); - btcoexist->btc_write_4byte(btcoexist, 0x900, 0x00000400); - btcoexist->btc_write_1byte(btcoexist, 0x76d, 0x1); - } else if (wifi_off) { - btcoexist->btc_write_1byte(btcoexist, 0xcb3, 0x77); - u8tmp = btcoexist->btc_read_1byte(btcoexist, 0xcb7); - u8tmp &= ~BIT(3); - u8tmp |= BIT(2); - btcoexist->btc_write_1byte(btcoexist, 0xcb7, u8tmp); - } - - if (force_exec || - (coex_dm->cur_ant_pos_type != coex_dm->pre_ant_pos_type)) { - /* ext switch setting */ - switch (ant_pos_type) { - case BTC_ANT_PATH_WIFI: - u8tmp = btcoexist->btc_read_1byte(btcoexist, - 0xcb7); - u8tmp |= BIT(3); - u8tmp &= ~BIT(2); - btcoexist->btc_write_1byte(btcoexist, 0xcb7, - u8tmp); - break; - case BTC_ANT_PATH_BT: - u8tmp = btcoexist->btc_read_1byte(btcoexist, - 0xcb7); - u8tmp &= ~BIT(3); - u8tmp |= BIT(2); - btcoexist->btc_write_1byte(btcoexist, 0xcb7, - u8tmp); - break; - default: - case BTC_ANT_PATH_PTA: - u8tmp = btcoexist->btc_read_1byte(btcoexist, - 0xcb7); - u8tmp |= BIT(3); - u8tmp &= ~BIT(2); - btcoexist->btc_write_1byte(btcoexist, 0xcb7, - u8tmp); - break; - } - } - - coex_dm->pre_ant_pos_type = coex_dm->cur_ant_pos_type; -} - -void halbtc8812a1ant_set_fw_pstdma(IN struct btc_coexist *btcoexist, - IN u8 byte1, IN u8 byte2, IN u8 byte3, IN u8 byte4, IN u8 byte5) -{ - u8 h2c_parameter[5] = {0}; - u8 real_byte1 = byte1, real_byte5 = byte5; - boolean ap_enable = false; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, - &ap_enable); - - if (ap_enable) { - if (byte1 & BIT(4) && !(byte1 & BIT(5))) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], FW for 1Ant AP mode\n"); - BTC_TRACE(trace_buf); - real_byte1 &= ~BIT(4); - real_byte1 |= BIT(5); - - real_byte5 |= BIT(5); - real_byte5 &= ~BIT(6); - } - } - - h2c_parameter[0] = real_byte1; - h2c_parameter[1] = byte2; - h2c_parameter[2] = byte3; - h2c_parameter[3] = byte4; - h2c_parameter[4] = real_byte5; - - coex_dm->ps_tdma_para[0] = real_byte1; - coex_dm->ps_tdma_para[1] = byte2; - coex_dm->ps_tdma_para[2] = byte3; - coex_dm->ps_tdma_para[3] = byte4; - coex_dm->ps_tdma_para[4] = real_byte5; - - btcoexist->btc_fill_h2c(btcoexist, 0x60, 5, h2c_parameter); -} - - -void halbtc8812a1ant_ps_tdma(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean turn_on, IN u8 type) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - boolean wifi_busy = false; - u8 rssi_adjust_val = 0; - u8 ps_tdma_byte4_val = 0x50, ps_tdma_byte0_val = 0x51, - ps_tdma_byte3_val = 0x10; - s8 wifi_duration_adjust = 0x0; - static boolean pre_wifi_busy = false; - - coex_dm->cur_ps_tdma_on = turn_on; - coex_dm->cur_ps_tdma = type; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - - if (wifi_busy != pre_wifi_busy) { - force_exec = true; - pre_wifi_busy = wifi_busy; - } - - if (coex_dm->cur_ps_tdma_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** TDMA(on, %d) **********\n", - coex_dm->cur_ps_tdma); - BTC_TRACE(trace_buf); - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** TDMA(off, %d) **********\n", - coex_dm->cur_ps_tdma); - BTC_TRACE(trace_buf); - } - - if (!force_exec) { - if ((coex_dm->pre_ps_tdma_on == coex_dm->cur_ps_tdma_on) && - (coex_dm->pre_ps_tdma == coex_dm->cur_ps_tdma)) - return; - } - - if (coex_sta->scan_ap_num <= 5) - wifi_duration_adjust = 2; - else if (coex_sta->scan_ap_num >= 40) - wifi_duration_adjust = -15; - else if (coex_sta->scan_ap_num >= 20) - wifi_duration_adjust = -10; - - if (!coex_sta->force_lps_on) { /* only for A2DP-only case 1/2/9/11 while wifi noisy threshold > 30 */ - ps_tdma_byte0_val = 0x61; /* no null-pkt */ - ps_tdma_byte3_val = 0x11; /* no tx-pause at BT-slot */ - ps_tdma_byte4_val = 0x10; /* 0x778 = d/1 toggle */ - } - - if ((type == 3) || (type == 13) || (type == 14)) { - ps_tdma_byte4_val = ps_tdma_byte4_val & - 0xbf; /* no dynamic slot for multi-profile */ - - if (!wifi_busy) - ps_tdma_byte4_val = ps_tdma_byte4_val | - 0x1; /* 0x778 = 0x1 at wifi slot (no blocking BT Low-Pri pkts) */ - } - - if (bt_link_info->slave_role == true) - ps_tdma_byte4_val = ps_tdma_byte4_val | - 0x1; /* 0x778 = 0x1 at wifi slot (no blocking BT Low-Pri pkts) */ - - if (turn_on) { - switch (type) { - default: - halbtc8812a1ant_set_fw_pstdma(btcoexist, 0x51, - 0x1a, 0x1a, 0x0, ps_tdma_byte4_val); - break; - case 1: - halbtc8812a1ant_set_fw_pstdma(btcoexist, - ps_tdma_byte0_val, 0x3a + - wifi_duration_adjust, 0x03, - ps_tdma_byte3_val, ps_tdma_byte4_val); - break; - case 2: - halbtc8812a1ant_set_fw_pstdma(btcoexist, - ps_tdma_byte0_val, 0x2d + - wifi_duration_adjust, 0x03, - ps_tdma_byte3_val, ps_tdma_byte4_val); - break; - case 3: - halbtc8812a1ant_set_fw_pstdma(btcoexist, 0x51, - 0x1d, 0x1d, 0x0, ps_tdma_byte4_val); - break; - case 4: - halbtc8812a1ant_set_fw_pstdma(btcoexist, 0x93, - 0x15, 0x3, 0x14, 0x0); - break; - case 5: - halbtc8812a1ant_set_fw_pstdma(btcoexist, 0x61, - 0x15, 0x3, 0x11, 0x11); - break; - case 6: - halbtc8812a1ant_set_fw_pstdma(btcoexist, 0x61, - 0x20, 0x3, 0x11, 0x11); - break; - case 7: - halbtc8812a1ant_set_fw_pstdma(btcoexist, 0x13, - 0xc, 0x5, 0x0, 0x0); - break; - case 8: - halbtc8812a1ant_set_fw_pstdma(btcoexist, 0x93, - 0x25, 0x3, 0x10, 0x0); - break; - case 9: - halbtc8812a1ant_set_fw_pstdma(btcoexist, - ps_tdma_byte0_val, 0x21, 0x3, - ps_tdma_byte3_val, ps_tdma_byte4_val); - break; - case 10: - halbtc8812a1ant_set_fw_pstdma(btcoexist, 0x13, - 0xa, 0xa, 0x0, 0x40); - break; - case 11: - halbtc8812a1ant_set_fw_pstdma(btcoexist, - ps_tdma_byte0_val, 0x21, 0x03, - ps_tdma_byte3_val, ps_tdma_byte4_val); - break; - case 12: - halbtc8812a1ant_set_fw_pstdma(btcoexist, 0x51, - 0x0a, 0x0a, 0x0, 0x50); - break; - case 13: - halbtc8812a1ant_set_fw_pstdma(btcoexist, 0x51, - 0x12, 0x12, 0x0, ps_tdma_byte4_val); - break; - case 14: - halbtc8812a1ant_set_fw_pstdma(btcoexist, 0x51, - 0x21, 0x3, 0x10, ps_tdma_byte4_val); - break; - case 15: - halbtc8812a1ant_set_fw_pstdma(btcoexist, 0x13, - 0xa, 0x3, 0x8, 0x0); - break; - case 16: - halbtc8812a1ant_set_fw_pstdma(btcoexist, 0x93, - 0x15, 0x3, 0x10, 0x0); - break; - case 18: - halbtc8812a1ant_set_fw_pstdma(btcoexist, 0x93, - 0x25, 0x3, 0x10, 0x0); - break; - case 20: - halbtc8812a1ant_set_fw_pstdma(btcoexist, 0x61, - 0x3f, 0x03, 0x11, 0x10); - break; - case 21: - halbtc8812a1ant_set_fw_pstdma(btcoexist, 0x61, - 0x25, 0x03, 0x11, 0x11); - break; - case 22: - halbtc8812a1ant_set_fw_pstdma(btcoexist, 0x61, - 0x25, 0x03, 0x11, 0x10); - break; - case 23: - halbtc8812a1ant_set_fw_pstdma(btcoexist, 0xe3, - 0x25, 0x3, 0x31, 0x18); - break; - case 24: - halbtc8812a1ant_set_fw_pstdma(btcoexist, 0xe3, - 0x15, 0x3, 0x31, 0x18); - break; - case 25: - halbtc8812a1ant_set_fw_pstdma(btcoexist, 0xe3, - 0xa, 0x3, 0x31, 0x18); - break; - case 26: - halbtc8812a1ant_set_fw_pstdma(btcoexist, 0xe3, - 0xa, 0x3, 0x31, 0x18); - break; - case 27: - halbtc8812a1ant_set_fw_pstdma(btcoexist, 0xe3, - 0x25, 0x3, 0x31, 0x98); - break; - case 28: - halbtc8812a1ant_set_fw_pstdma(btcoexist, 0x69, - 0x25, 0x3, 0x31, 0x0); - break; - case 29: - halbtc8812a1ant_set_fw_pstdma(btcoexist, 0xab, - 0x1a, 0x1a, 0x1, 0x10); - break; - case 30: - halbtc8812a1ant_set_fw_pstdma(btcoexist, 0x51, - 0x30, 0x3, 0x10, 0x10); - break; - case 31: - halbtc8812a1ant_set_fw_pstdma(btcoexist, 0xd3, - 0x1a, 0x1a, 0, 0x58); - break; - case 32: - halbtc8812a1ant_set_fw_pstdma(btcoexist, 0x61, - 0x35, 0x3, 0x11, 0x11); - break; - case 33: - halbtc8812a1ant_set_fw_pstdma(btcoexist, 0xa3, - 0x25, 0x3, 0x30, 0x90); - break; - case 34: - halbtc8812a1ant_set_fw_pstdma(btcoexist, 0x53, - 0x1a, 0x1a, 0x0, 0x10); - break; - case 35: - halbtc8812a1ant_set_fw_pstdma(btcoexist, 0x63, - 0x1a, 0x1a, 0x0, 0x10); - break; - case 36: - halbtc8812a1ant_set_fw_pstdma(btcoexist, 0xd3, - 0x12, 0x3, 0x14, 0x50); - break; - case 40: /* SoftAP only with no sta associated,BT disable ,TDMA mode for power saving */ - /* here softap mode screen off will cost 70-80mA for phone */ - halbtc8812a1ant_set_fw_pstdma(btcoexist, 0x23, - 0x18, 0x00, 0x10, 0x24); - break; - } - } else { - - /* disable PS tdma */ - switch (type) { - case 8: /* PTA Control */ - halbtc8812a1ant_set_fw_pstdma(btcoexist, 0x8, - 0x0, 0x0, 0x0, 0x0); - break; - case 0: - default: /* Software control, Antenna at BT side */ - halbtc8812a1ant_set_fw_pstdma(btcoexist, 0x0, - 0x0, 0x0, 0x0, 0x0); - break; - } - } - rssi_adjust_val = 0; - btcoexist->btc_set(btcoexist, - BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE, &rssi_adjust_val); - - - /* update pre state */ - coex_dm->pre_ps_tdma_on = coex_dm->cur_ps_tdma_on; - coex_dm->pre_ps_tdma = coex_dm->cur_ps_tdma; -} - -boolean halbtc8812a1ant_is_common_action(IN struct btc_coexist *btcoexist) -{ - boolean common = false, wifi_connected = false, wifi_busy = false; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - - if (!wifi_connected && - BT_8812A_1ANT_BT_STATUS_NON_CONNECTED_IDLE == - coex_dm->bt_status) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi non connected-idle + BT non connected-idle!!\n"); - BTC_TRACE(trace_buf); - - /* halbtc8812a1ant_sw_mechanism(btcoexist, false); */ - - common = true; - } else if (wifi_connected && - (BT_8812A_1ANT_BT_STATUS_NON_CONNECTED_IDLE == - coex_dm->bt_status)) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi connected + BT non connected-idle!!\n"); - BTC_TRACE(trace_buf); - - /* halbtc8812a1ant_sw_mechanism(btcoexist, false); */ - - common = true; - } else if (!wifi_connected && - (BT_8812A_1ANT_BT_STATUS_CONNECTED_IDLE == coex_dm->bt_status)) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi non connected-idle + BT connected-idle!!\n"); - BTC_TRACE(trace_buf); - - /* halbtc8812a1ant_sw_mechanism(btcoexist, false); */ - - common = true; - } else if (wifi_connected && - (BT_8812A_1ANT_BT_STATUS_CONNECTED_IDLE == coex_dm->bt_status)) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi connected + BT connected-idle!!\n"); - BTC_TRACE(trace_buf); - - /* halbtc8812a1ant_sw_mechanism(btcoexist, false); */ - - common = true; - } else if (!wifi_connected && - (BT_8812A_1ANT_BT_STATUS_CONNECTED_IDLE != coex_dm->bt_status)) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi non connected-idle + BT Busy!!\n"); - BTC_TRACE(trace_buf); - - /* halbtc8812a1ant_sw_mechanism(btcoexist, false); */ - - common = true; - } else { - if (wifi_busy) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi Connected-Busy + BT Busy!!\n"); - BTC_TRACE(trace_buf); - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi Connected-Idle + BT Busy!!\n"); - BTC_TRACE(trace_buf); - } - - common = false; - } - - return common; -} - - -void halbtc8812a1ant_tdma_duration_adjust_for_acl(IN struct btc_coexist - *btcoexist, IN u8 wifi_status) -{ - static s32 up, dn, m, n, wait_count; - s32 result; /* 0: no change, +1: increase WiFi duration, -1: decrease WiFi duration */ - u8 retry_count = 0, bt_info_ext; - boolean wifi_busy = false; - - if (BT_8812A_1ANT_WIFI_STATUS_CONNECTED_BUSY == wifi_status) - wifi_busy = true; - else - wifi_busy = false; - - if ((BT_8812A_1ANT_WIFI_STATUS_NON_CONNECTED_ASSO_AUTH_SCAN == - wifi_status) || - (BT_8812A_1ANT_WIFI_STATUS_CONNECTED_SCAN == wifi_status) || - (BT_8812A_1ANT_WIFI_STATUS_CONNECTED_SPECIFIC_PKT == - wifi_status)) { - if (coex_dm->cur_ps_tdma != 1 && - coex_dm->cur_ps_tdma != 2 && - coex_dm->cur_ps_tdma != 3 && - coex_dm->cur_ps_tdma != 9) { - halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 9); - coex_dm->ps_tdma_du_adj_type = 9; - - up = 0; - dn = 0; - m = 1; - n = 3; - result = 0; - wait_count = 0; - } - return; - } - - if (!coex_dm->auto_tdma_adjust) { - coex_dm->auto_tdma_adjust = true; - - halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 2); - coex_dm->ps_tdma_du_adj_type = 2; - /* ============ */ - up = 0; - dn = 0; - m = 1; - n = 3; - result = 0; - wait_count = 0; - } else { - /* acquire the BT TRx retry count from BT_Info byte2 */ - retry_count = coex_sta->bt_retry_cnt; - bt_info_ext = coex_sta->bt_info_ext; - - if ((coex_sta->low_priority_tx) > 1150 || - (coex_sta->low_priority_rx) > 1250) - retry_count++; - - result = 0; - wait_count++; - - if (retry_count == - 0) { /* no retry in the last 2-second duration */ - up++; - dn--; - - if (dn <= 0) - dn = 0; - - if (up >= n) { /* if retry count during continuous n*2 seconds is 0, enlarge WiFi duration */ - wait_count = 0; - n = 3; - up = 0; - dn = 0; - result = 1; - } - } else if (retry_count <= - 3) { /* <=3 retry in the last 2-second duration */ - up--; - dn++; - - if (up <= 0) - up = 0; - - if (dn == 2) { /* if continuous 2 retry count(every 2 seconds) >0 and < 3, reduce WiFi duration */ - if (wait_count <= 2) - m++; /* to avoid loop between the two levels */ - else - m = 1; - - if (m >= 20) /* maximum of m = 20 ' will recheck if need to adjust wifi duration in maximum time interval 120 seconds */ - m = 20; - - n = 3 * m; - up = 0; - dn = 0; - wait_count = 0; - result = -1; - } - } else { /* retry count > 3, once retry count > 3, to reduce WiFi duration */ - if (wait_count == 1) - m++; /* to avoid loop between the two levels */ - else - m = 1; - - if (m >= 20) /* maximum of m = 20 ' will recheck if need to adjust wifi duration in maximum time interval 120 seconds */ - m = 20; - - n = 3 * m; - up = 0; - dn = 0; - wait_count = 0; - result = -1; - } - - if (result == -1) { - if ((BT_INFO_8812A_1ANT_A2DP_BASIC_RATE(bt_info_ext)) && - ((coex_dm->cur_ps_tdma == 1) || - (coex_dm->cur_ps_tdma == 2))) { - halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 9); - coex_dm->ps_tdma_du_adj_type = 9; - } else if (coex_dm->cur_ps_tdma == 1) { - halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 2); - coex_dm->ps_tdma_du_adj_type = 2; - } else if (coex_dm->cur_ps_tdma == 2) { - halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 9); - coex_dm->ps_tdma_du_adj_type = 9; - } else if (coex_dm->cur_ps_tdma == 9) { - halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 11); - coex_dm->ps_tdma_du_adj_type = 11; - } - } else if (result == 1) { - if ((BT_INFO_8812A_1ANT_A2DP_BASIC_RATE(bt_info_ext)) && - ((coex_dm->cur_ps_tdma == 1) || - (coex_dm->cur_ps_tdma == 2))) { - halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 9); - coex_dm->ps_tdma_du_adj_type = 9; - } else if (coex_dm->cur_ps_tdma == 11) { - halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 9); - coex_dm->ps_tdma_du_adj_type = 9; - } else if (coex_dm->cur_ps_tdma == 9) { - halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 2); - coex_dm->ps_tdma_du_adj_type = 2; - } else if (coex_dm->cur_ps_tdma == 2) { - halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 1); - coex_dm->ps_tdma_du_adj_type = 1; - } - } else { /* no change */ - /* Bryant Modify - if(wifi_busy != pre_wifi_busy) - { - pre_wifi_busy = wifi_busy; - halbtc8812a1ant_ps_tdma(btcoexist, FORCE_EXEC, true, coex_dm->cur_ps_tdma); - } - */ - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** TDMA(on, %d) **********\n", - coex_dm->cur_ps_tdma); - BTC_TRACE(trace_buf); - } - - if (coex_dm->cur_ps_tdma != 1 && - coex_dm->cur_ps_tdma != 2 && - coex_dm->cur_ps_tdma != 9 && - coex_dm->cur_ps_tdma != 11) { - /* recover to previous adjust type */ - halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - coex_dm->ps_tdma_du_adj_type); - } - } -} - -void halbtc8812a1ant_ps_tdma_check_for_power_save_state( - IN struct btc_coexist *btcoexist, IN boolean new_ps_state) -{ - u8 lps_mode = 0x0; - - btcoexist->btc_get(btcoexist, BTC_GET_U1_LPS_MODE, &lps_mode); - - if (lps_mode) { /* already under LPS state */ - if (new_ps_state) { - /* keep state under LPS, do nothing. */ - } else { - /* will leave LPS state, turn off psTdma first */ - halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, - 8); - } - } else { /* NO PS state */ - if (new_ps_state) { - /* will enter LPS state, turn off psTdma first */ - halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, - 8); - } else { - /* keep state under NO PS state, do nothing. */ - } - } -} - -void halbtc8812a1ant_power_save_state(IN struct btc_coexist *btcoexist, - IN u8 ps_type, IN u8 lps_val, IN u8 rpwm_val) -{ - boolean low_pwr_disable = false; - - switch (ps_type) { - case BTC_PS_WIFI_NATIVE: - /* recover to original 32k low power setting */ - low_pwr_disable = false; - btcoexist->btc_set(btcoexist, - BTC_SET_ACT_DISABLE_LOW_POWER, - &low_pwr_disable); - btcoexist->btc_set(btcoexist, BTC_SET_ACT_NORMAL_LPS, - NULL); - coex_sta->force_lps_on = false; - break; - case BTC_PS_LPS_ON: - halbtc8812a1ant_ps_tdma_check_for_power_save_state( - btcoexist, true); - halbtc8812a1ant_lps_rpwm(btcoexist, NORMAL_EXEC, - lps_val, rpwm_val); - /* when coex force to enter LPS, do not enter 32k low power. */ - low_pwr_disable = true; - btcoexist->btc_set(btcoexist, - BTC_SET_ACT_DISABLE_LOW_POWER, - &low_pwr_disable); - /* power save must executed before psTdma. */ - btcoexist->btc_set(btcoexist, BTC_SET_ACT_ENTER_LPS, - NULL); - coex_sta->force_lps_on = true; - break; - case BTC_PS_LPS_OFF: - halbtc8812a1ant_ps_tdma_check_for_power_save_state( - btcoexist, false); - btcoexist->btc_set(btcoexist, BTC_SET_ACT_LEAVE_LPS, - NULL); - coex_sta->force_lps_on = false; - break; - default: - break; - } -} - -void halbtc8812a1ant_action_wifi_only(IN struct btc_coexist *btcoexist) -{ - halbtc8812a1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 0); - halbtc8812a1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 8); - halbtc8812a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA, FORCE_EXEC, - false, false); -} - -void halbtc8812a1ant_monitor_bt_enable_disable(IN struct btc_coexist *btcoexist) -{ - static u32 bt_disable_cnt = 0; - boolean bt_active = true, bt_disabled = false; - - /* This function check if bt is disabled */ - - if (coex_sta->high_priority_tx == 0 && - coex_sta->high_priority_rx == 0 && - coex_sta->low_priority_tx == 0 && - coex_sta->low_priority_rx == 0) - bt_active = false; - if (coex_sta->high_priority_tx == 0xffff && - coex_sta->high_priority_rx == 0xffff && - coex_sta->low_priority_tx == 0xffff && - coex_sta->low_priority_rx == 0xffff) - bt_active = false; - if (bt_active) { - bt_disable_cnt = 0; - bt_disabled = false; - btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_DISABLE, - &bt_disabled); - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT is enabled !!\n"); - BTC_TRACE(trace_buf); - } else { - bt_disable_cnt++; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], bt all counters=0, %d times!!\n", - bt_disable_cnt); - BTC_TRACE(trace_buf); - if (bt_disable_cnt >= 2) { - bt_disabled = true; - btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_DISABLE, - &bt_disabled); - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT is disabled !!\n"); - BTC_TRACE(trace_buf); - halbtc8812a1ant_action_wifi_only(btcoexist); - } - } - if (coex_sta->bt_disabled != bt_disabled) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT is from %s to %s!!\n", - (coex_sta->bt_disabled ? "disabled" : "enabled"), - (bt_disabled ? "disabled" : "enabled")); - BTC_TRACE(trace_buf); - coex_sta->bt_disabled = bt_disabled; - if (!bt_disabled) { - } else { - btcoexist->btc_set(btcoexist, BTC_SET_ACT_LEAVE_LPS, - NULL); - btcoexist->btc_set(btcoexist, BTC_SET_ACT_NORMAL_LPS, - NULL); - } - } -} - -/* ********************************************* - * - * Software Coex Mechanism start - * - * ********************************************* */ - -/* SCO only or SCO+PAN(HS) */ - -/* -void halbtc8812a1ant_action_sco(IN struct btc_coexist* btcoexist) -{ - halbtc8812a1ant_sw_mechanism(btcoexist, true); -} - - -void halbtc8812a1ant_action_hid(IN struct btc_coexist* btcoexist) -{ - halbtc8812a1ant_sw_mechanism(btcoexist, true); -} - - -void halbtc8812a1ant_action_a2dp(IN struct btc_coexist* btcoexist) -{ - halbtc8812a1ant_sw_mechanism(btcoexist, false); -} - -void halbtc8812a1ant_action_a2dp_pan_hs(IN struct btc_coexist* btcoexist) -{ - halbtc8812a1ant_sw_mechanism(btcoexist, false); -} - -void halbtc8812a1ant_action_pan_edr(IN struct btc_coexist* btcoexist) -{ - halbtc8812a1ant_sw_mechanism(btcoexist, false); -} - - -void halbtc8812a1ant_action_pan_hs(IN struct btc_coexist* btcoexist) -{ - halbtc8812a1ant_sw_mechanism(btcoexist, false); -} - - -void halbtc8812a1ant_action_pan_edr_a2dp(IN struct btc_coexist* btcoexist) -{ - halbtc8812a1ant_sw_mechanism(btcoexist, false); -} - -void halbtc8812a1ant_action_pan_edr_hid(IN struct btc_coexist* btcoexist) -{ - halbtc8812a1ant_sw_mechanism(btcoexist, true); -} - - -void halbtc8812a1ant_action_hid_a2dp_pan_edr(IN struct btc_coexist* btcoexist) -{ - halbtc8812a1ant_sw_mechanism(btcoexist, true); -} - -void halbtc8812a1ant_action_hid_a2dp(IN struct btc_coexist* btcoexist) -{ - halbtc8812a1ant_sw_mechanism(btcoexist, true); -} - -*/ - -/* ********************************************* - * - * Non-Software Coex Mechanism start - * - * ********************************************* */ -void halbtc8812a1ant_action_wifi_multi_port(IN struct btc_coexist *btcoexist) -{ - halbtc8812a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0, - 0x0); - - halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8); - halbtc8812a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA, NORMAL_EXEC, - false, false); - halbtc8812a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2); -} - -void halbtc8812a1ant_action_hs(IN struct btc_coexist *btcoexist) -{ - halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 5); - halbtc8812a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2); -} - -void halbtc8812a1ant_action_bt_inquiry(IN struct btc_coexist *btcoexist) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - boolean wifi_connected = false, ap_enable = false, wifi_busy = false, - bt_busy = false; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, - &ap_enable); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bt_busy); - - if ((!wifi_connected) && (!coex_sta->wifi_is_high_pri_task)) { - halbtc8812a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, - 0x0, 0x0); - halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8); - halbtc8812a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA, - NORMAL_EXEC, false, false); - halbtc8812a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - } else if ((bt_link_info->sco_exist) || (bt_link_info->hid_exist) || - (bt_link_info->a2dp_exist)) { - /* SCO/HID/A2DP busy */ - halbtc8812a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, - 0x0, 0x0); - halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32); - - halbtc8812a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); - } else if ((bt_link_info->pan_exist) || (wifi_busy)) { - halbtc8812a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, - 0x0, 0x0); - halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20); - - halbtc8812a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); - } else { - halbtc8812a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, - 0x0, 0x0); - halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8); - halbtc8812a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA, - NORMAL_EXEC, false, false); - halbtc8812a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7); - } -} - -void halbtc8812a1ant_action_bt_sco_hid_only_busy(IN struct btc_coexist - *btcoexist, IN u8 wifi_status) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - boolean wifi_connected = false; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - - /* tdma and coex table */ - - if (bt_link_info->sco_exist) { - halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 5); - halbtc8812a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 5); - } else { /* HID */ - halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 6); - halbtc8812a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 5); - } -} - -void halbtc8812a1ant_action_wifi_connected_bt_acl_busy(IN struct btc_coexist - *btcoexist, IN u8 wifi_status) -{ - u8 bt_rssi_state; - - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - - bt_rssi_state = halbtc8812a1ant_bt_rssi_state(2, 28, 0); - - if ((coex_sta->low_priority_rx >= 950) && (!coex_sta->under_ips)) - bt_link_info->slave_role = true; - else - bt_link_info->slave_role = false; - - if (bt_link_info->hid_only) { /* HID */ - halbtc8812a1ant_action_bt_sco_hid_only_busy(btcoexist, - wifi_status); - coex_dm->auto_tdma_adjust = false; - return; - } else if (bt_link_info->a2dp_only) { /* A2DP */ - if (BT_8812A_1ANT_WIFI_STATUS_CONNECTED_IDLE == wifi_status) { - halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 32); - halbtc8812a1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 4); - coex_dm->auto_tdma_adjust = false; - } else { - halbtc8812a1ant_tdma_duration_adjust_for_acl(btcoexist, - wifi_status); - halbtc8812a1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 4); - coex_dm->auto_tdma_adjust = true; - } - } else if (((bt_link_info->a2dp_exist) && (bt_link_info->pan_exist)) || - (bt_link_info->hid_exist && bt_link_info->a2dp_exist && - bt_link_info->pan_exist)) { /* A2DP+PAN(OPP,FTP), HID+A2DP+PAN(OPP,FTP) */ - halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 13); - halbtc8812a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); - coex_dm->auto_tdma_adjust = false; - } else if (bt_link_info->hid_exist && - bt_link_info->a2dp_exist) { /* HID+A2DP */ - halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 14); - coex_dm->auto_tdma_adjust = false; - - halbtc8812a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 3); - } else if ((bt_link_info->pan_only) || (bt_link_info->hid_exist && - bt_link_info->pan_exist)) { /* PAN(OPP,FTP), HID+PAN(OPP,FTP) */ - halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 3); - halbtc8812a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); - coex_dm->auto_tdma_adjust = false; - } else { - /* BT no-profile busy (0x9) */ - halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32); - halbtc8812a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); - coex_dm->auto_tdma_adjust = false; - } -} - -void halbtc8812a1ant_action_wifi_not_connected(IN struct btc_coexist *btcoexist) -{ - /* power save state */ - halbtc8812a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0, - 0x0); - - /* tdma and coex table */ - halbtc8812a1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 8); - halbtc8812a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA, NORMAL_EXEC, - false, false); - halbtc8812a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); -} - -void halbtc8812a1ant_action_wifi_not_connected_scan(IN struct btc_coexist - *btcoexist) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - - halbtc8812a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0, - 0x0); - - /* tdma and coex table */ - if (BT_8812A_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) { - if (bt_link_info->a2dp_exist) { - halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 32); - halbtc8812a1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 4); - } else if (bt_link_info->a2dp_exist && - bt_link_info->pan_exist) { - halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 22); - halbtc8812a1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 4); - } else { - halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 20); - halbtc8812a1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 4); - } - } else if ((BT_8812A_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) || - (BT_8812A_1ANT_BT_STATUS_ACL_SCO_BUSY == - coex_dm->bt_status)) { - halbtc8812a1ant_action_bt_sco_hid_only_busy(btcoexist, - BT_8812A_1ANT_WIFI_STATUS_CONNECTED_SCAN); - } else { - /* Bryant Add */ - halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8); - halbtc8812a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA, - NORMAL_EXEC, false, false); - halbtc8812a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2); - } -} - -void halbtc8812a1ant_action_wifi_not_connected_asso_auth( - IN struct btc_coexist *btcoexist) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - - halbtc8812a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0, - 0x0); - - /* tdma and coex table */ - if ((bt_link_info->sco_exist) || (bt_link_info->hid_exist) || - (bt_link_info->a2dp_exist)) { - halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32); - halbtc8812a1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 4); - } else if (bt_link_info->pan_exist) { - halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20); - halbtc8812a1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 4); - } else { - halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8); - halbtc8812a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA, - NORMAL_EXEC, false, false); - halbtc8812a1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 2); - } -} - -void halbtc8812a1ant_action_wifi_connected_scan(IN struct btc_coexist - *btcoexist) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - - halbtc8812a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0, - 0x0); - - /* tdma and coex table */ - if (BT_8812A_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) { - if (bt_link_info->a2dp_exist) { - halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 32); - halbtc8812a1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 4); - } else if (bt_link_info->a2dp_exist && - bt_link_info->pan_exist) { - halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 22); - halbtc8812a1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 4); - } else { - halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 20); - halbtc8812a1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 4); - } - } else if ((BT_8812A_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) || - (BT_8812A_1ANT_BT_STATUS_ACL_SCO_BUSY == - coex_dm->bt_status)) { - halbtc8812a1ant_action_bt_sco_hid_only_busy(btcoexist, - BT_8812A_1ANT_WIFI_STATUS_CONNECTED_SCAN); - } else { - /* Bryant Add */ - halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8); - halbtc8812a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA, - NORMAL_EXEC, false, false); - halbtc8812a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2); - } -} - -void halbtc8812a1ant_action_wifi_connected_specific_packet( - IN struct btc_coexist *btcoexist) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - - halbtc8812a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0, - 0x0); - - /* tdma and coex table */ - if ((bt_link_info->sco_exist) || (bt_link_info->hid_exist) || - (bt_link_info->a2dp_exist)) { - halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32); - halbtc8812a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); - } else if (bt_link_info->pan_exist) { - halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20); - halbtc8812a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); - } else { - halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8); - halbtc8812a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA, - NORMAL_EXEC, false, false); - halbtc8812a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2); - } -} - -void halbtc8812a1ant_action_wifi_connected(IN struct btc_coexist *btcoexist) -{ - boolean wifi_busy = false; - boolean scan = false, link = false, roam = false; - boolean under_4way = false, ap_enable = false; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], CoexForWifiConnect()===>\n"); - BTC_TRACE(trace_buf); - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS, - &under_4way); - if (under_4way) { - halbtc8812a1ant_action_wifi_connected_specific_packet(btcoexist); - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], CoexForWifiConnect(), return for wifi is under 4way<===\n"); - BTC_TRACE(trace_buf); - return; - } - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam); - if (scan || link || roam) { - if (scan) - halbtc8812a1ant_action_wifi_connected_scan(btcoexist); - else - halbtc8812a1ant_action_wifi_connected_specific_packet( - btcoexist); - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], CoexForWifiConnect(), return for wifi is under scan<===\n"); - BTC_TRACE(trace_buf); - return; - } - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, - &ap_enable); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - - /* power save state */ - if (!ap_enable && - BT_8812A_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status && - !btcoexist->bt_link_info.hid_only) { - if (btcoexist->bt_link_info.a2dp_only) { /* A2DP */ - if (!wifi_busy) - halbtc8812a1ant_power_save_state(btcoexist, - BTC_PS_WIFI_NATIVE, 0x0, 0x0); - else { /* busy */ - if (coex_sta->scan_ap_num >= - BT_8812A_1ANT_WIFI_NOISY_THRESH) /* no force LPS, no PS-TDMA, use pure TDMA */ - halbtc8812a1ant_power_save_state( - btcoexist, BTC_PS_WIFI_NATIVE, - 0x0, 0x0); - else - halbtc8812a1ant_power_save_state( - btcoexist, BTC_PS_LPS_ON, 0x50, - 0x4); - } - } else if ((coex_sta->pan_exist == false) && - (coex_sta->a2dp_exist == false) && - (coex_sta->hid_exist == false)) - halbtc8812a1ant_power_save_state(btcoexist, - BTC_PS_WIFI_NATIVE, 0x0, 0x0); - else - halbtc8812a1ant_power_save_state(btcoexist, - BTC_PS_LPS_ON, 0x50, 0x4); - } else - halbtc8812a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, - 0x0, 0x0); - - /* tdma and coex table */ - if (!wifi_busy) { - if (BT_8812A_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) { - halbtc8812a1ant_action_wifi_connected_bt_acl_busy( - btcoexist, - BT_8812A_1ANT_WIFI_STATUS_CONNECTED_IDLE); - } else if ((BT_8812A_1ANT_BT_STATUS_SCO_BUSY == - coex_dm->bt_status) || - (BT_8812A_1ANT_BT_STATUS_ACL_SCO_BUSY == - coex_dm->bt_status)) { - halbtc8812a1ant_action_bt_sco_hid_only_busy(btcoexist, - BT_8812A_1ANT_WIFI_STATUS_CONNECTED_IDLE); - } else { - halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, - 8); - halbtc8812a1ant_set_ant_path(btcoexist, - BTC_ANT_PATH_PTA, NORMAL_EXEC, false, false); - if ((coex_sta->high_priority_tx) + - (coex_sta->high_priority_rx) <= 60) - halbtc8812a1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 2); - else - halbtc8812a1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 7); - } - } else { - if (BT_8812A_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) { - halbtc8812a1ant_action_wifi_connected_bt_acl_busy( - btcoexist, - BT_8812A_1ANT_WIFI_STATUS_CONNECTED_BUSY); - } else if ((BT_8812A_1ANT_BT_STATUS_SCO_BUSY == - coex_dm->bt_status) || - (BT_8812A_1ANT_BT_STATUS_ACL_SCO_BUSY == - coex_dm->bt_status)) { - halbtc8812a1ant_action_bt_sco_hid_only_busy(btcoexist, - BT_8812A_1ANT_WIFI_STATUS_CONNECTED_BUSY); - } else { - halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, - 8); - halbtc8812a1ant_set_ant_path(btcoexist, - BTC_ANT_PATH_PTA, NORMAL_EXEC, false, false); - if ((coex_sta->high_priority_tx) + - (coex_sta->high_priority_rx) <= 60) - halbtc8812a1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 2); - else - halbtc8812a1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 7); - } - } -} - -void halbtc8812a1ant_run_sw_coexist_mechanism(IN struct btc_coexist *btcoexist) -{ - u8 algorithm = 0; - - algorithm = halbtc8812a1ant_action_algorithm(btcoexist); - coex_dm->cur_algorithm = algorithm; - - if (halbtc8812a1ant_is_common_action(btcoexist)) { - - } else { - switch (coex_dm->cur_algorithm) { - case BT_8812A_1ANT_COEX_ALGO_SCO: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action algorithm = SCO.\n"); - BTC_TRACE(trace_buf); - /* halbtc8812a1ant_action_sco(btcoexist); */ - break; - case BT_8812A_1ANT_COEX_ALGO_HID: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action algorithm = HID.\n"); - BTC_TRACE(trace_buf); - /* halbtc8812a1ant_action_hid(btcoexist); */ - break; - case BT_8812A_1ANT_COEX_ALGO_A2DP: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action algorithm = A2DP.\n"); - BTC_TRACE(trace_buf); - /* halbtc8812a1ant_action_a2dp(btcoexist); */ - break; - case BT_8812A_1ANT_COEX_ALGO_A2DP_PANHS: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action algorithm = A2DP+PAN(HS).\n"); - BTC_TRACE(trace_buf); - /* halbtc8812a1ant_action_a2dp_pan_hs(btcoexist); */ - break; - case BT_8812A_1ANT_COEX_ALGO_PANEDR: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action algorithm = PAN(EDR).\n"); - BTC_TRACE(trace_buf); - /* halbtc8812a1ant_action_pan_edr(btcoexist); */ - break; - case BT_8812A_1ANT_COEX_ALGO_PANHS: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action algorithm = HS mode.\n"); - BTC_TRACE(trace_buf); - /* halbtc8812a1ant_action_pan_hs(btcoexist); */ - break; - case BT_8812A_1ANT_COEX_ALGO_PANEDR_A2DP: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action algorithm = PAN+A2DP.\n"); - BTC_TRACE(trace_buf); - /* halbtc8812a1ant_action_pan_edr_a2dp(btcoexist); */ - break; - case BT_8812A_1ANT_COEX_ALGO_PANEDR_HID: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action algorithm = PAN(EDR)+HID.\n"); - BTC_TRACE(trace_buf); - /* halbtc8812a1ant_action_pan_edr_hid(btcoexist); */ - break; - case BT_8812A_1ANT_COEX_ALGO_HID_A2DP_PANEDR: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action algorithm = HID+A2DP+PAN.\n"); - BTC_TRACE(trace_buf); - /* halbtc8812a1ant_action_hid_a2dp_pan_edr(btcoexist); */ - break; - case BT_8812A_1ANT_COEX_ALGO_HID_A2DP: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action algorithm = HID+A2DP.\n"); - BTC_TRACE(trace_buf); - /* halbtc8812a1ant_action_hid_a2dp(btcoexist); */ - break; - default: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action algorithm = coexist All Off!!\n"); - BTC_TRACE(trace_buf); - /* halbtc8812a1ant_coex_all_off(btcoexist); */ - break; - } - coex_dm->pre_algorithm = coex_dm->cur_algorithm; - } -} - -void halbtc8812a1ant_run_coexist_mechanism(IN struct btc_coexist *btcoexist) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - boolean wifi_connected = false, bt_hs_on = false; - boolean increase_scan_dev_num = false; - boolean bt_ctrl_agg_buf_size = false; - boolean miracast_plus_bt = false; - u8 agg_buf_size = 5; - u32 wifi_link_status = 0; - u32 num_of_wifi_link = 0, wifi_bw; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], RunCoexistMechanism()===>\n"); - BTC_TRACE(trace_buf); - - if (btcoexist->manual_control) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], RunCoexistMechanism(), return for Manual CTRL <===\n"); - BTC_TRACE(trace_buf); - return; - } - - if (btcoexist->stop_coex_dm) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], RunCoexistMechanism(), return for Stop Coex DM <===\n"); - BTC_TRACE(trace_buf); - return; - } - - if (coex_sta->under_ips) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], wifi is under IPS !!!\n"); - BTC_TRACE(trace_buf); - return; - } - - if ((BT_8812A_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) || - (BT_8812A_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) || - (BT_8812A_1ANT_BT_STATUS_ACL_SCO_BUSY == coex_dm->bt_status)) - increase_scan_dev_num = true; - - btcoexist->btc_set(btcoexist, BTC_SET_BL_INC_SCAN_DEV_NUM, - &increase_scan_dev_num); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS, - &wifi_link_status); - num_of_wifi_link = wifi_link_status >> 16; - - if ((num_of_wifi_link >= 2) || - (wifi_link_status & WIFI_P2P_GO_CONNECTED)) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "############# [BTCoex], Multi-Port num_of_wifi_link = %d, wifi_link_status = 0x%x\n", - num_of_wifi_link, wifi_link_status); - BTC_TRACE(trace_buf); - - if (bt_link_info->bt_link_exist) { - halbtc8812a1ant_limited_tx(btcoexist, NORMAL_EXEC, 1, 1, - 0, 1); - miracast_plus_bt = true; - } else { - halbtc8812a1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, - 0, 0); - miracast_plus_bt = false; - } - btcoexist->btc_set(btcoexist, BTC_SET_BL_MIRACAST_PLUS_BT, - &miracast_plus_bt); - halbtc8812a1ant_limited_rx(btcoexist, NORMAL_EXEC, false, - bt_ctrl_agg_buf_size, agg_buf_size); - - if ((bt_link_info->a2dp_exist) && - (coex_sta->c2h_bt_inquiry_page)) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "############# [BTCoex], BT Is Inquirying\n"); - BTC_TRACE(trace_buf); - halbtc8812a1ant_action_bt_inquiry(btcoexist); - } else - halbtc8812a1ant_action_wifi_multi_port(btcoexist); - - return; - } - - miracast_plus_bt = false; - btcoexist->btc_set(btcoexist, BTC_SET_BL_MIRACAST_PLUS_BT, - &miracast_plus_bt); - - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw); - - if ((bt_link_info->bt_link_exist) && (wifi_connected)) { - halbtc8812a1ant_limited_tx(btcoexist, NORMAL_EXEC, 1, 1, 0, 1); - - if (bt_link_info->sco_exist) - halbtc8812a1ant_limited_rx(btcoexist, NORMAL_EXEC, true, - false, 0x5); - else { - if (BTC_WIFI_BW_HT40 == wifi_bw) - halbtc8812a1ant_limited_rx(btcoexist, NORMAL_EXEC, - false, true, 0x10); - else - halbtc8812a1ant_limited_rx(btcoexist, NORMAL_EXEC, - false, true, 0x8); - } - - halbtc8812a1ant_sw_mechanism(btcoexist, true); - halbtc8812a1ant_run_sw_coexist_mechanism( - btcoexist); /* just print debug message */ - } else { - halbtc8812a1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0); - - halbtc8812a1ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, - 0x5); - - halbtc8812a1ant_sw_mechanism(btcoexist, false); - halbtc8812a1ant_run_sw_coexist_mechanism( - btcoexist); /* //just print debug message */ - } - - btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); - if (coex_sta->c2h_bt_inquiry_page) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "############# [BTCoex], BT Is Inquirying\n"); - BTC_TRACE(trace_buf); - halbtc8812a1ant_action_bt_inquiry(btcoexist); - return; - } else if (bt_hs_on) { - halbtc8812a1ant_action_hs(btcoexist); - return; - } - - - if (!wifi_connected) { - boolean scan = false, link = false, roam = false; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], wifi is non connected-idle !!!\n"); - BTC_TRACE(trace_buf); - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam); - - if (scan || link || roam) { - if (scan) - halbtc8812a1ant_action_wifi_not_connected_scan( - btcoexist); - else - halbtc8812a1ant_action_wifi_not_connected_asso_auth( - btcoexist); - } else - halbtc8812a1ant_action_wifi_not_connected(btcoexist); - } else /* wifi LPS/Busy */ - halbtc8812a1ant_action_wifi_connected(btcoexist); -} - -void halbtc8812a1ant_init_coex_dm(IN struct btc_coexist *btcoexist) -{ - /* force to reset coex mechanism */ - - /* sw all off */ - halbtc8812a1ant_sw_mechanism(btcoexist, false); - - /* halbtc8812a1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 8); */ - /* halbtc8812a1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 0); */ - - coex_sta->pop_event_cnt = 0; -} - -void halbtc8812a1ant_init_hw_config(IN struct btc_coexist *btcoexist, - IN boolean back_up, IN boolean wifi_only) -{ - u8 u8tmp = 0; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], 1Ant Init HW Config!!\n"); - BTC_TRACE(trace_buf); - - /* ant sw control to BT */ - halbtc8812a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT, FORCE_EXEC, - true, false); - - /* 0x790[5:0]=0x5 */ - u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x790); - u8tmp &= 0xc0; - u8tmp |= 0x5; - btcoexist->btc_write_1byte(btcoexist, 0x790, u8tmp); - - /* PTA parameter */ - btcoexist->btc_write_1byte(btcoexist, 0x6cc, 0x0); - btcoexist->btc_write_4byte(btcoexist, 0x6c8, 0xffff); - btcoexist->btc_write_4byte(btcoexist, 0x6c4, 0x55555555); - btcoexist->btc_write_4byte(btcoexist, 0x6c0, 0x55555555); - - /* coex parameters */ - btcoexist->btc_write_1byte(btcoexist, 0x778, 0x1); - - /* enable counter statistics */ - btcoexist->btc_write_1byte(btcoexist, 0x76e, 0x4); - - /* enable PTA */ - btcoexist->btc_write_1byte(btcoexist, 0x40, 0x20); - - /* bt clock related */ - u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x4); - u8tmp |= BIT(7); - btcoexist->btc_write_1byte(btcoexist, 0x4, u8tmp); - - /* bt clock related */ - u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x7); - u8tmp |= BIT(1); - btcoexist->btc_write_1byte(btcoexist, 0x7, u8tmp); -} - -/* ************************************************************ - * work around function start with wa_halbtc8812a1ant_ - * ************************************************************ - * ************************************************************ - * extern function start with ex_halbtc8812a1ant_ - * ************************************************************ */ -void ex_halbtc8812a1ant_power_on_setting(IN struct btc_coexist *btcoexist) -{ -} - -void ex_halbtc8812a1ant_pre_load_firmware(IN struct btc_coexist *btcoexist) -{ -} - -void ex_halbtc8812a1ant_init_hw_config(IN struct btc_coexist *btcoexist, - IN boolean wifi_only) -{ - halbtc8812a1ant_init_hw_config(btcoexist, true, wifi_only); - btcoexist->stop_coex_dm = false; -} - -void ex_halbtc8812a1ant_init_coex_dm(IN struct btc_coexist *btcoexist) -{ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Coex Mechanism Init!!\n"); - BTC_TRACE(trace_buf); - - btcoexist->stop_coex_dm = false; - - halbtc8812a1ant_init_coex_dm(btcoexist); - - halbtc8812a1ant_query_bt_info(btcoexist); -} - -void ex_halbtc8812a1ant_display_coex_info(IN struct btc_coexist *btcoexist) -{ - struct btc_board_info *board_info = &btcoexist->board_info; - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - u8 *cli_buf = btcoexist->cli_buf; - u8 u8tmp[4], i, bt_info_ext, ps_tdma_case = 0; - u32 u32tmp[4]; - u32 fw_ver = 0, bt_patch_ver = 0; - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n ============[BT Coexist info]============"); - CL_PRINTF(cli_buf); - - if (btcoexist->manual_control) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n ============[Under Manual Control]============"); - CL_PRINTF(cli_buf); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n =========================================="); - CL_PRINTF(cli_buf); - } - if (btcoexist->stop_coex_dm) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n ============[Coex is STOPPED]============"); - CL_PRINTF(cli_buf); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n =========================================="); - CL_PRINTF(cli_buf); - } - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d ", - "Ant PG number/ Ant mechanism:", - board_info->pg_ant_num, board_info->btdm_ant_num); - CL_PRINTF(cli_buf); - - btcoexist->btc_get(btcoexist, BTC_GET_U4_BT_PATCH_VER, &bt_patch_ver); - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, &fw_ver); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %d_%d/ 0x%x/ 0x%x(%d)", - "CoexVer/ FwVer/ PatchVer", - glcoex_ver_date_8812a_1ant, glcoex_ver_8812a_1ant, fw_ver, - bt_patch_ver, bt_patch_ver); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x ", - "Wifi channel informed to BT", - coex_dm->wifi_chnl_info[0], coex_dm->wifi_chnl_info[1], - coex_dm->wifi_chnl_info[2]); - CL_PRINTF(cli_buf); - - /* wifi status */ - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s", - "============[Wifi Status]============"); - CL_PRINTF(cli_buf); - btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_WIFI_STATUS); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s", - "============[BT Status]============"); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = [%s/ %d/ %d] ", - "BT [status/ rssi/ retryCnt]", - ((coex_sta->bt_disabled) ? ("disabled") : (( - coex_sta->c2h_bt_inquiry_page) ? ("inquiry/page scan") - : ((BT_8812A_1ANT_BT_STATUS_NON_CONNECTED_IDLE == - coex_dm->bt_status) ? "non-connected idle" : - ((BT_8812A_1ANT_BT_STATUS_CONNECTED_IDLE == coex_dm->bt_status) - ? "connected-idle" : "busy")))), - coex_sta->bt_rssi, coex_sta->bt_retry_cnt); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d / %d / %d", - "SCO/HID/PAN/A2DP", - bt_link_info->sco_exist, bt_link_info->hid_exist, - bt_link_info->pan_exist, bt_link_info->a2dp_exist); - CL_PRINTF(cli_buf); - btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_BT_LINK_INFO); - - bt_info_ext = coex_sta->bt_info_ext; - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s", - "BT Info A2DP rate", - (bt_info_ext & BIT(0)) ? "Basic rate" : "EDR rate"); - CL_PRINTF(cli_buf); - - for (i = 0; i < BT_INFO_SRC_8812A_1ANT_MAX; i++) { - if (coex_sta->bt_info_c2h_cnt[i]) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %02x %02x %02x %02x %02x %02x %02x(%d)", - glbt_info_src_8812a_1ant[i], - coex_sta->bt_info_c2h[i][0], - coex_sta->bt_info_c2h[i][1], - coex_sta->bt_info_c2h[i][2], - coex_sta->bt_info_c2h[i][3], - coex_sta->bt_info_c2h[i][4], - coex_sta->bt_info_c2h[i][5], - coex_sta->bt_info_c2h[i][6], - coex_sta->bt_info_c2h_cnt[i]); - CL_PRINTF(cli_buf); - } - } - - if (!btcoexist->manual_control) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s", - "============[mechanisms]============"); - CL_PRINTF(cli_buf); - - ps_tdma_case = coex_dm->cur_ps_tdma; - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %02x %02x %02x %02x %02x case-%d", - "PS TDMA", - coex_dm->ps_tdma_para[0], coex_dm->ps_tdma_para[1], - coex_dm->ps_tdma_para[2], coex_dm->ps_tdma_para[3], - coex_dm->ps_tdma_para[4], ps_tdma_case); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x ", - "Latest error condition(should be 0)", - coex_dm->error_condition); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d ", - "IgnWlanAct", - coex_dm->cur_ignore_wlan_act); - CL_PRINTF(cli_buf); - } - - /* Hw setting */ - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s", - "============[Hw setting]============"); - CL_PRINTF(cli_buf); - - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x778); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0x778", - u8tmp[0]); - CL_PRINTF(cli_buf); - - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0xcb3); - u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0xcb7); - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x900); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", - "0xcb3/0xcb7/0x900", - u8tmp[0], u8tmp[1], u32tmp[0]); - CL_PRINTF(cli_buf); - - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x40); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0x40", - u8tmp[0]); - CL_PRINTF(cli_buf); - - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x550); - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x522); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", - "0x550(bcn ctrl)/0x522", - u32tmp[0], u8tmp[0]); - CL_PRINTF(cli_buf); - - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xc50); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0xc50(dig)", - u32tmp[0]); - CL_PRINTF(cli_buf); - - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x6c0); - u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x6c4); - u32tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0x6c8); - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x6cc); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", - "0x6c0/0x6c4/0x6c8/0x6cc(coexTable)", - u32tmp[0], u32tmp[1], u32tmp[2], u8tmp[0]); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", - "0x770(hp rx[31:16]/tx[15:0])", - coex_sta->high_priority_rx, coex_sta->high_priority_tx); - CL_PRINTF(cli_buf); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", - "0x774(lp rx[31:16]/tx[15:0])", - coex_sta->low_priority_rx, coex_sta->low_priority_tx); - CL_PRINTF(cli_buf); - - btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_COEX_STATISTICS); -} - - - -void ex_halbtc8812a1ant_ips_notify(IN struct btc_coexist *btcoexist, IN u8 type) -{ - if (btcoexist->manual_control || btcoexist->stop_coex_dm) - return; - - if (BTC_IPS_ENTER == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], IPS ENTER notify\n"); - BTC_TRACE(trace_buf); - coex_sta->under_ips = true; - - halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); - halbtc8812a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT, - FORCE_EXEC, false, true); - halbtc8812a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - } else if (BTC_IPS_LEAVE == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], IPS LEAVE notify\n"); - BTC_TRACE(trace_buf); - - halbtc8812a1ant_init_hw_config(btcoexist, false, false); - halbtc8812a1ant_init_coex_dm(btcoexist); - halbtc8812a1ant_query_bt_info(btcoexist); - - coex_sta->under_ips = false; - } -} - -void ex_halbtc8812a1ant_lps_notify(IN struct btc_coexist *btcoexist, IN u8 type) -{ - if (btcoexist->manual_control || btcoexist->stop_coex_dm) - return; - - if (BTC_LPS_ENABLE == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], LPS ENABLE notify\n"); - BTC_TRACE(trace_buf); - coex_sta->under_lps = true; - } else if (BTC_LPS_DISABLE == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], LPS DISABLE notify\n"); - BTC_TRACE(trace_buf); - coex_sta->under_lps = false; - } -} - -void ex_halbtc8812a1ant_scan_notify(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - boolean wifi_connected = false, bt_hs_on = false; - u32 wifi_link_status = 0; - u32 num_of_wifi_link = 0; - boolean bt_ctrl_agg_buf_size = false; - u8 agg_buf_size = 5; - - if (btcoexist->manual_control || - btcoexist->stop_coex_dm) - return; - - if (BTC_SCAN_START == type) { - coex_sta->wifi_is_high_pri_task = true; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCAN START notify\n"); - BTC_TRACE(trace_buf); - - halbtc8812a1ant_ps_tdma(btcoexist, FORCE_EXEC, false, - 8); /* Force antenna setup for no scan result issue */ - halbtc8812a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA, - FORCE_EXEC, false, false); - } else { - coex_sta->wifi_is_high_pri_task = false; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCAN FINISH notify\n"); - BTC_TRACE(trace_buf); - - btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM, - &coex_sta->scan_ap_num); - } - - if (coex_sta->bt_disabled) - return; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - - halbtc8812a1ant_query_bt_info(btcoexist); - - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS, - &wifi_link_status); - num_of_wifi_link = wifi_link_status >> 16; - if (num_of_wifi_link >= 2) { - halbtc8812a1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0); - halbtc8812a1ant_limited_rx(btcoexist, NORMAL_EXEC, false, - bt_ctrl_agg_buf_size, agg_buf_size); - halbtc8812a1ant_action_wifi_multi_port(btcoexist); - return; - } - - if (coex_sta->c2h_bt_inquiry_page) { - halbtc8812a1ant_action_bt_inquiry(btcoexist); - return; - } else if (bt_hs_on) { - halbtc8812a1ant_action_hs(btcoexist); - return; - } - - if (BTC_SCAN_START == type) { - if (!wifi_connected) /* non-connected scan */ - halbtc8812a1ant_action_wifi_not_connected_scan( - btcoexist); - else /* wifi is connected */ - halbtc8812a1ant_action_wifi_connected_scan(btcoexist); - } else if (BTC_SCAN_FINISH == type) { - if (!wifi_connected) /* non-connected scan */ - halbtc8812a1ant_action_wifi_not_connected(btcoexist); - else - halbtc8812a1ant_action_wifi_connected(btcoexist); - } -} - -void ex_halbtc8812a1ant_connect_notify(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - boolean wifi_connected = false, bt_hs_on = false; - u32 wifi_link_status = 0; - u32 num_of_wifi_link = 0; - boolean bt_ctrl_agg_buf_size = false; - u8 agg_buf_size = 5; - - if (btcoexist->manual_control || - btcoexist->stop_coex_dm || - coex_sta->bt_disabled) - return; - - if (BTC_ASSOCIATE_START == type) { - coex_sta->wifi_is_high_pri_task = true; - halbtc8812a1ant_ps_tdma(btcoexist, FORCE_EXEC, false, - 8); /* Force antenna setup for no scan result issue */ - halbtc8812a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA, - FORCE_EXEC, false, false); - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], CONNECT START notify\n"); - BTC_TRACE(trace_buf); - coex_dm->arp_cnt = 0; - } else { - coex_sta->wifi_is_high_pri_task = false; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], CONNECT FINISH notify\n"); - BTC_TRACE(trace_buf); - /* coex_dm->arp_cnt = 0; */ - } - - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS, - &wifi_link_status); - num_of_wifi_link = wifi_link_status >> 16; - if (num_of_wifi_link >= 2) { - halbtc8812a1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0); - halbtc8812a1ant_limited_rx(btcoexist, NORMAL_EXEC, false, - bt_ctrl_agg_buf_size, agg_buf_size); - halbtc8812a1ant_action_wifi_multi_port(btcoexist); - return; - } - - btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); - if (coex_sta->c2h_bt_inquiry_page) { - halbtc8812a1ant_action_bt_inquiry(btcoexist); - return; - } else if (bt_hs_on) { - halbtc8812a1ant_action_hs(btcoexist); - return; - } - - if (BTC_ASSOCIATE_START == type) - halbtc8812a1ant_action_wifi_not_connected_asso_auth(btcoexist); - else if (BTC_ASSOCIATE_FINISH == type) { - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - if (!wifi_connected) /* non-connected scan */ - halbtc8812a1ant_action_wifi_not_connected(btcoexist); - else - halbtc8812a1ant_action_wifi_connected(btcoexist); - } -} - -/* to check registers... */ -void ex_halbtc8812a1ant_media_status_notify(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - u8 data_len = 5; - u8 buf[6] = {0}; - u8 h2c_parameter[3] = {0}; - u32 wifi_bw; - u8 wifi_central_chnl; - boolean wifi_under_b_mode = false; - - if (btcoexist->manual_control || - btcoexist->stop_coex_dm || - coex_sta->bt_disabled) - return; - - if (BTC_MEDIA_CONNECT == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], MEDIA connect notify\n"); - BTC_TRACE(trace_buf); - halbtc8812a1ant_ps_tdma(btcoexist, FORCE_EXEC, false, - 8); /* Force antenna setup for no scan result issue */ - halbtc8812a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA, - FORCE_EXEC, false, false); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_B_MODE, - &wifi_under_b_mode); -#if 0 - /* Set CCK Tx/Rx high Pri except 11b mode */ - if (wifi_under_b_mode) { - btcoexist->btc_write_1byte(btcoexist, 0x6cd, - 0x00); /* CCK Tx */ - btcoexist->btc_write_1byte(btcoexist, 0x6cf, - 0x00); /* CCK Rx */ - } else { - btcoexist->btc_write_1byte(btcoexist, 0x6cd, - 0x10); /* CCK Tx */ - btcoexist->btc_write_1byte(btcoexist, 0x6cf, - 0x10); /* CCK Rx */ - } -#endif - coex_dm->backup_arfr_cnt1 = btcoexist->btc_read_4byte(btcoexist, - 0x430); - coex_dm->backup_arfr_cnt2 = btcoexist->btc_read_4byte(btcoexist, - 0x434); - coex_dm->backup_retry_limit = btcoexist->btc_read_2byte( - btcoexist, 0x42a); - coex_dm->backup_ampdu_max_time = btcoexist->btc_read_1byte( - btcoexist, 0x456); - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], MEDIA disconnect notify\n"); - BTC_TRACE(trace_buf); - coex_dm->arp_cnt = 0; - - btcoexist->btc_write_1byte(btcoexist, 0x6cd, 0x0); /* CCK Tx */ - btcoexist->btc_write_1byte(btcoexist, 0x6cf, 0x0); /* CCK Rx */ - } - - /* only 2.4G we need to inform bt the chnl mask */ - btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_CENTRAL_CHNL, - &wifi_central_chnl); - if ((BTC_MEDIA_CONNECT == type) && - (wifi_central_chnl <= 14)) { - /* h2c_parameter[0] = 0x1; */ - h2c_parameter[0] = 0x0; - h2c_parameter[1] = wifi_central_chnl; - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw); - if (BTC_WIFI_BW_HT40 == wifi_bw) - h2c_parameter[2] = 0x30; - else - h2c_parameter[2] = 0x20; - } - - coex_dm->wifi_chnl_info[0] = h2c_parameter[0]; - coex_dm->wifi_chnl_info[1] = h2c_parameter[1]; - coex_dm->wifi_chnl_info[2] = h2c_parameter[2]; - - buf[0] = data_len; - buf[1] = 0x5; /* OP_Code */ - buf[2] = 0x3; /* OP_Code_Length */ - buf[3] = h2c_parameter[0]; /* OP_Code_Content */ - buf[4] = h2c_parameter[1]; - buf[5] = h2c_parameter[2]; - - btcoexist->btc_set(btcoexist, BTC_SET_ACT_CTRL_BT_COEX, - (void *)&buf[0]); -} - -void ex_halbtc8812a1ant_specific_packet_notify(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - boolean bt_hs_on = false; - u32 wifi_link_status = 0; - u32 num_of_wifi_link = 0; - boolean bt_ctrl_agg_buf_size = false; - u8 agg_buf_size = 5; - - if (btcoexist->manual_control || - btcoexist->stop_coex_dm || - coex_sta->bt_disabled) - return; - - if (BTC_PACKET_DHCP == type || - BTC_PACKET_EAPOL == type || - BTC_PACKET_ARP == type) { - if (BTC_PACKET_ARP == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], specific Packet ARP notify\n"); - BTC_TRACE(trace_buf); - - coex_dm->arp_cnt++; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ARP Packet Count = %d\n", - coex_dm->arp_cnt); - BTC_TRACE(trace_buf); - - if (coex_dm->arp_cnt >= - 10) /* if APR PKT > 10 after connect, do not go to ActionWifiConnectedSpecificPacket(btcoexist) */ - coex_sta->wifi_is_high_pri_task = false; - else - coex_sta->wifi_is_high_pri_task = true; - } else { - coex_sta->wifi_is_high_pri_task = true; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], specific Packet DHCP or EAPOL notify\n"); - BTC_TRACE(trace_buf); - } - } else { - coex_sta->wifi_is_high_pri_task = false; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], specific Packet [Type = %d] notify\n", type); - BTC_TRACE(trace_buf); - } - - coex_sta->specific_pkt_period_cnt = 0; - - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS, - &wifi_link_status); - num_of_wifi_link = wifi_link_status >> 16; - if (num_of_wifi_link >= 2) { - halbtc8812a1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0); - halbtc8812a1ant_limited_rx(btcoexist, NORMAL_EXEC, false, - bt_ctrl_agg_buf_size, agg_buf_size); - halbtc8812a1ant_action_wifi_multi_port(btcoexist); - return; - } - - btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); - if (coex_sta->c2h_bt_inquiry_page) { - halbtc8812a1ant_action_bt_inquiry(btcoexist); - return; - } else if (bt_hs_on) { - halbtc8812a1ant_action_hs(btcoexist); - return; - } - - if (BTC_PACKET_DHCP == type || - BTC_PACKET_EAPOL == type || - ((BTC_PACKET_ARP == type) && (coex_sta->wifi_is_high_pri_task))) - halbtc8812a1ant_action_wifi_connected_specific_packet(btcoexist); -} - -void ex_halbtc8812a1ant_bt_info_notify(IN struct btc_coexist *btcoexist, - IN u8 *tmp_buf, IN u8 length) -{ - u8 bt_info = 0; - u8 i, rsp_source = 0; - boolean wifi_connected = false; - boolean bt_busy = false; - - coex_sta->c2h_bt_info_req_sent = false; - - rsp_source = tmp_buf[0] & 0xf; - if (rsp_source >= BT_INFO_SRC_8812A_1ANT_MAX) - rsp_source = BT_INFO_SRC_8812A_1ANT_WIFI_FW; - coex_sta->bt_info_c2h_cnt[rsp_source]++; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Bt info[%d], length=%d, hex data=[", rsp_source, - length); - BTC_TRACE(trace_buf); - for (i = 0; i < length; i++) { - coex_sta->bt_info_c2h[rsp_source][i] = tmp_buf[i]; - if (i == 1) - bt_info = tmp_buf[i]; - if (i == length - 1) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "0x%02x]\n", - tmp_buf[i]); - BTC_TRACE(trace_buf); - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "0x%02x, ", - tmp_buf[i]); - BTC_TRACE(trace_buf); - } - } - - if (BT_INFO_SRC_8812A_1ANT_WIFI_FW != rsp_source) { - coex_sta->bt_retry_cnt = /* [3:0] */ - coex_sta->bt_info_c2h[rsp_source][2] & 0xf; - - if (coex_sta->bt_retry_cnt >= 1) - coex_sta->pop_event_cnt++; - - if (coex_sta->bt_info_c2h[rsp_source][2] & 0x20) - coex_sta->c2h_bt_page = true; - else - coex_sta->c2h_bt_page = false; - - coex_sta->bt_rssi = - coex_sta->bt_info_c2h[rsp_source][3] * 2 - 90; - /* coex_sta->bt_info_c2h[rsp_source][3]*2+10; */ - - coex_sta->bt_info_ext = - coex_sta->bt_info_c2h[rsp_source][4]; - - coex_sta->bt_tx_rx_mask = (coex_sta->bt_info_c2h[rsp_source][2] - & 0x40); - btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TX_RX_MASK, - &coex_sta->bt_tx_rx_mask); - if (!coex_sta->bt_tx_rx_mask) { - /* BT into is responded by BT FW and BT RF REG 0x3C != 0x15 => Need to switch BT TRx Mask */ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Switch BT TRx Mask since BT RF REG 0x3C != 0x15\n"); - BTC_TRACE(trace_buf); - btcoexist->btc_set_bt_reg(btcoexist, BTC_BT_REG_RF, - 0x3c, 0x15); - } - - /* Here we need to resend some wifi info to BT */ - /* because bt is reset and loss of the info. */ - if (coex_sta->bt_info_ext & BIT(1)) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT ext info bit1 check, send wifi BW&Chnl to BT!!\n"); - BTC_TRACE(trace_buf); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - if (wifi_connected) - ex_halbtc8812a1ant_media_status_notify( - btcoexist, BTC_MEDIA_CONNECT); - else - ex_halbtc8812a1ant_media_status_notify( - btcoexist, BTC_MEDIA_DISCONNECT); - } - - if (coex_sta->bt_info_ext & BIT(3)) { - if (!btcoexist->manual_control && - !btcoexist->stop_coex_dm) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT ext info bit3 check, set BT NOT to ignore Wlan active!!\n"); - BTC_TRACE(trace_buf); - halbtc8812a1ant_ignore_wlan_act(btcoexist, - FORCE_EXEC, false); - } - } else { - /* BT already NOT ignore Wlan active, do nothing here. */ - } -#if (BT_AUTO_REPORT_ONLY_8812A_1ANT == 0) - if ((coex_sta->bt_info_ext & BIT(4))) { - /* BT auto report already enabled, do nothing */ - } else - halbtc8812a1ant_bt_auto_report(btcoexist, FORCE_EXEC, - true); -#endif - } - - /* check BIT2 first ==> check if bt is under inquiry or page scan */ - if (bt_info & BT_INFO_8812A_1ANT_B_INQ_PAGE) - coex_sta->c2h_bt_inquiry_page = true; - else - coex_sta->c2h_bt_inquiry_page = false; - - /* set link exist status */ - if (!(bt_info & BT_INFO_8812A_1ANT_B_CONNECTION)) { - coex_sta->bt_link_exist = false; - coex_sta->pan_exist = false; - coex_sta->a2dp_exist = false; - coex_sta->hid_exist = false; - coex_sta->sco_exist = false; - } else { /* connection exists */ - coex_sta->bt_link_exist = true; - if (bt_info & BT_INFO_8812A_1ANT_B_FTP) - coex_sta->pan_exist = true; - else - coex_sta->pan_exist = false; - if (bt_info & BT_INFO_8812A_1ANT_B_A2DP) - coex_sta->a2dp_exist = true; - else - coex_sta->a2dp_exist = false; - if (bt_info & BT_INFO_8812A_1ANT_B_HID) - coex_sta->hid_exist = true; - else - coex_sta->hid_exist = false; - if (bt_info & BT_INFO_8812A_1ANT_B_SCO_ESCO) - coex_sta->sco_exist = true; - else - coex_sta->sco_exist = false; - } - - halbtc8812a1ant_update_bt_link_info(btcoexist); - - bt_info = bt_info & - 0x1f; /* mask profile bit for connect-ilde identification ( for CSR case: A2DP idle --> 0x41) */ - - if (!(bt_info & BT_INFO_8812A_1ANT_B_CONNECTION)) { - coex_dm->bt_status = BT_8812A_1ANT_BT_STATUS_NON_CONNECTED_IDLE; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), BT Non-Connected idle!!!\n"); - BTC_TRACE(trace_buf); - } else if (bt_info == - BT_INFO_8812A_1ANT_B_CONNECTION) { /* connection exists but no busy */ - coex_dm->bt_status = BT_8812A_1ANT_BT_STATUS_CONNECTED_IDLE; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), BT Connected-idle!!!\n"); - BTC_TRACE(trace_buf); - } else if ((bt_info & BT_INFO_8812A_1ANT_B_SCO_ESCO) || - (bt_info & BT_INFO_8812A_1ANT_B_SCO_BUSY)) { - coex_dm->bt_status = BT_8812A_1ANT_BT_STATUS_SCO_BUSY; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), BT SCO busy!!!\n"); - BTC_TRACE(trace_buf); - } else if (bt_info & BT_INFO_8812A_1ANT_B_ACL_BUSY) { - if (BT_8812A_1ANT_BT_STATUS_ACL_BUSY != coex_dm->bt_status) - coex_dm->auto_tdma_adjust = false; - coex_dm->bt_status = BT_8812A_1ANT_BT_STATUS_ACL_BUSY; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), BT ACL busy!!!\n"); - BTC_TRACE(trace_buf); - } else { - coex_dm->bt_status = BT_8812A_1ANT_BT_STATUS_MAX; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), BT Non-Defined state!!!\n"); - BTC_TRACE(trace_buf); - } - - if ((BT_8812A_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) || - (BT_8812A_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) || - (BT_8812A_1ANT_BT_STATUS_ACL_SCO_BUSY == coex_dm->bt_status)) - bt_busy = true; - else - bt_busy = false; - btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bt_busy); - - halbtc8812a1ant_run_coexist_mechanism(btcoexist); -} - -void ex_halbtc8812a1ant_rf_status_notify(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], RF Status notify\n"); - BTC_TRACE(trace_buf); - - if (BTC_RF_ON == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], RF is turned ON!!\n"); - BTC_TRACE(trace_buf); - btcoexist->stop_coex_dm = false; - } else if (BTC_RF_OFF == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], RF is turned OFF!!\n"); - BTC_TRACE(trace_buf); - - halbtc8812a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, - 0x0, 0x0); - halbtc8812a1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 0); - halbtc8812a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT, - FORCE_EXEC, false, true); - - halbtc8812a1ant_ignore_wlan_act(btcoexist, FORCE_EXEC, true); - btcoexist->stop_coex_dm = true; - } -} - -void ex_halbtc8812a1ant_halt_notify(IN struct btc_coexist *btcoexist) -{ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], Halt notify\n"); - BTC_TRACE(trace_buf); - - halbtc8812a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0, - 0x0); - halbtc8812a1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 0); - halbtc8812a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT, FORCE_EXEC, - false, true); - - halbtc8812a1ant_ignore_wlan_act(btcoexist, FORCE_EXEC, true); - - ex_halbtc8812a1ant_media_status_notify(btcoexist, BTC_MEDIA_DISCONNECT); - - btcoexist->stop_coex_dm = true; -} - -void ex_halbtc8812a1ant_pnp_notify(IN struct btc_coexist *btcoexist, - IN u8 pnp_state) -{ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], Pnp notify\n"); - BTC_TRACE(trace_buf); - - if (BTC_WIFI_PNP_SLEEP == pnp_state) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Pnp notify to SLEEP\n"); - BTC_TRACE(trace_buf); - - halbtc8812a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, - 0x0, 0x0); - halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); - halbtc8812a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT, - FORCE_EXEC, false, true); - halbtc8812a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2); - - /* Sinda 20150819, workaround for driver skip leave IPS/LPS to speed up sleep time. */ - /* Driver do not leave IPS/LPS when driver is going to sleep, so BTCoexistence think wifi is still under IPS/LPS */ - /* BT should clear UnderIPS/UnderLPS state to avoid mismatch state after wakeup. */ - coex_sta->under_ips = false; - coex_sta->under_lps = false; - btcoexist->stop_coex_dm = true; - } else if (BTC_WIFI_PNP_WAKE_UP == pnp_state) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Pnp notify to WAKE UP\n"); - BTC_TRACE(trace_buf); - btcoexist->stop_coex_dm = false; - halbtc8812a1ant_init_hw_config(btcoexist, false, false); - halbtc8812a1ant_init_coex_dm(btcoexist); - halbtc8812a1ant_query_bt_info(btcoexist); - } -} - -void ex_halbtc8812a1ant_coex_dm_reset(IN struct btc_coexist *btcoexist) -{ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], *****************Coex DM Reset*****************\n"); - BTC_TRACE(trace_buf); - - halbtc8812a1ant_init_hw_config(btcoexist, false, false); - halbtc8812a1ant_init_coex_dm(btcoexist); -} - -void ex_halbtc8812a1ant_periodical(IN struct btc_coexist *btcoexist) -{ -#if (BT_AUTO_REPORT_ONLY_8812A_1ANT == 0) - halbtc8812a1ant_query_bt_info(btcoexist); - halbtc8812a1ant_monitor_bt_enable_disable(btcoexist); -#else - halbtc8812a1ant_monitor_bt_ctr(btcoexist); - halbtc8812a1ant_monitor_wifi_ctr(btcoexist); - - if (halbtc8812a1ant_is_wifi_status_changed(btcoexist) || - coex_dm->auto_tdma_adjust) - halbtc8812a1ant_run_coexist_mechanism(btcoexist); - - coex_sta->specific_pkt_period_cnt++; -#endif -} - -void ex_halbtc8812a1ant_dbg_control(IN struct btc_coexist *btcoexist, - IN u8 op_code, IN u8 op_len, IN u8 *pdata) -{ - switch (op_code) { - case BTC_DBG_SET_COEX_NORMAL: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Set CoexMode to Normal\n"); - BTC_TRACE(trace_buf); - btcoexist->manual_control = false; - halbtc8812a1ant_init_coex_dm(btcoexist); - break; - case BTC_DBG_SET_COEX_WIFI_ONLY: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Set CoexMode to Wifi Only\n"); - BTC_TRACE(trace_buf); - btcoexist->manual_control = true; - halbtc8812a1ant_power_save_state(btcoexist, - BTC_PS_WIFI_NATIVE, 0x0, 0x0); - halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, - 9); - break; - case BTC_DBG_SET_COEX_BT_ONLY: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Set CoexMode to BT only\n"); - BTC_TRACE(trace_buf); - btcoexist->manual_control = true; - halbtc8812a1ant_power_save_state(btcoexist, - BTC_PS_WIFI_NATIVE, 0x0, 0x0); - halbtc8812a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, - 0); - break; - case BTC_DBG_SET_COEX_DEC_BT_PWR: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Set Dec BT power\n"); - BTC_TRACE(trace_buf); - { - u8 data_len = 4; - u8 buf[6] = {0}; - u8 dec_bt_pwr = 0, pwr_level = 0; - - if (op_len == 2) { - dec_bt_pwr = pdata[0]; - pwr_level = pdata[1]; - - buf[0] = data_len; - buf[1] = 0x3; /* OP_Code */ - buf[2] = 0x2; /* OP_Code_Length */ - - buf[3] = dec_bt_pwr; /* OP_Code_Content */ - buf[4] = pwr_level; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Set Dec BT power=%d, pwr_level=%d\n", - dec_bt_pwr, pwr_level); - BTC_TRACE(trace_buf); - btcoexist->btc_set(btcoexist, - BTC_SET_ACT_CTRL_BT_COEX, - (void *)&buf[0]); - } - } - break; - - case BTC_DBG_SET_COEX_BT_AFH_MAP: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Set BT AFH Map\n"); - BTC_TRACE(trace_buf); - { - u8 data_len = 5; - u8 buf[6] = {0}; - - if (op_len == 3) { - buf[0] = data_len; - buf[1] = 0x5; /* OP_Code */ - buf[2] = 0x3; /* OP_Code_Length */ - - buf[3] = pdata[0]; /* OP_Code_Content */ - buf[4] = pdata[1]; - buf[5] = pdata[2]; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Set BT AFH Map = %02x %02x %02x\n", - pdata[0], pdata[1], pdata[2]); - BTC_TRACE(trace_buf); - btcoexist->btc_set(btcoexist, - BTC_SET_ACT_CTRL_BT_COEX, - (void *)&buf[0]); - } - } - break; - - case BTC_DBG_SET_COEX_BT_IGNORE_WLAN_ACT: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Set BT Ignore Wlan Active\n"); - BTC_TRACE(trace_buf); - { - u8 data_len = 3; - u8 buf[6] = {0}; - - if (op_len == 1) { - buf[0] = data_len; - buf[1] = 0x1; /* OP_Code */ - buf[2] = 0x1; /* OP_Code_Length */ - - buf[3] = pdata[0]; /* OP_Code_Content */ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Set BT Ignore Wlan Active = 0x%x\n", - pdata[0]); - BTC_TRACE(trace_buf); - - btcoexist->btc_set(btcoexist, - BTC_SET_ACT_CTRL_BT_COEX, - (void *)&buf[0]); - } - } - break; - default: - break; - } -} - -#endif - -#endif /* #if (BT_SUPPORT == 1 && COEX_SUPPORT == 1) */ diff --git a/hal/btc/halbtc8812a1ant.h b/hal/btc/halbtc8812a1ant.h deleted file mode 100644 index e786d37..0000000 --- a/hal/btc/halbtc8812a1ant.h +++ /dev/null @@ -1,230 +0,0 @@ - -#if (BT_SUPPORT == 1 && COEX_SUPPORT == 1) - -#if (RTL8812A_SUPPORT == 1) - -/* ******************************************* - * The following is for 8812A 1ANT BT Co-exist definition - * ******************************************* */ -#define BT_AUTO_REPORT_ONLY_8812A_1ANT 1 - -#define BT_INFO_8812A_1ANT_B_FTP BIT(7) -#define BT_INFO_8812A_1ANT_B_A2DP BIT(6) -#define BT_INFO_8812A_1ANT_B_HID BIT(5) -#define BT_INFO_8812A_1ANT_B_SCO_BUSY BIT(4) -#define BT_INFO_8812A_1ANT_B_ACL_BUSY BIT(3) -#define BT_INFO_8812A_1ANT_B_INQ_PAGE BIT(2) -#define BT_INFO_8812A_1ANT_B_SCO_ESCO BIT(1) -#define BT_INFO_8812A_1ANT_B_CONNECTION BIT(0) - -#define BT_INFO_8812A_1ANT_A2DP_BASIC_RATE(_BT_INFO_EXT_) \ - (((_BT_INFO_EXT_&BIT(0))) ? true : false) - -#define BTC_RSSI_COEX_THRESH_TOL_8812A_1ANT 2 - -#define BT_8812A_1ANT_WIFI_NOISY_THRESH 30 /* max: 255 */ - -enum bt_info_src_8812a_1ant { - BT_INFO_SRC_8812A_1ANT_WIFI_FW = 0x0, - BT_INFO_SRC_8812A_1ANT_BT_RSP = 0x1, - BT_INFO_SRC_8812A_1ANT_BT_ACTIVE_SEND = 0x2, - BT_INFO_SRC_8812A_1ANT_MAX -}; - -enum bt_8812a_1ant_bt_status { - BT_8812A_1ANT_BT_STATUS_NON_CONNECTED_IDLE = 0x0, - BT_8812A_1ANT_BT_STATUS_CONNECTED_IDLE = 0x1, - BT_8812A_1ANT_BT_STATUS_INQ_PAGE = 0x2, - BT_8812A_1ANT_BT_STATUS_ACL_BUSY = 0x3, - BT_8812A_1ANT_BT_STATUS_SCO_BUSY = 0x4, - BT_8812A_1ANT_BT_STATUS_ACL_SCO_BUSY = 0x5, - BT_8812A_1ANT_BT_STATUS_MAX -}; - -enum bt_8812a_1ant_wifi_status { - BT_8812A_1ANT_WIFI_STATUS_NON_CONNECTED_IDLE = 0x0, - BT_8812A_1ANT_WIFI_STATUS_NON_CONNECTED_ASSO_AUTH_SCAN = 0x1, - BT_8812A_1ANT_WIFI_STATUS_CONNECTED_SCAN = 0x2, - BT_8812A_1ANT_WIFI_STATUS_CONNECTED_SPECIFIC_PKT = 0x3, - BT_8812A_1ANT_WIFI_STATUS_CONNECTED_IDLE = 0x4, - BT_8812A_1ANT_WIFI_STATUS_CONNECTED_BUSY = 0x5, - BT_8812A_1ANT_WIFI_STATUS_MAX -}; - -enum bt_8812a_1ant_coex_algo { - BT_8812A_1ANT_COEX_ALGO_UNDEFINED = 0x0, - BT_8812A_1ANT_COEX_ALGO_SCO = 0x1, - BT_8812A_1ANT_COEX_ALGO_HID = 0x2, - BT_8812A_1ANT_COEX_ALGO_A2DP = 0x3, - BT_8812A_1ANT_COEX_ALGO_A2DP_PANHS = 0x4, - BT_8812A_1ANT_COEX_ALGO_PANEDR = 0x5, - BT_8812A_1ANT_COEX_ALGO_PANHS = 0x6, - BT_8812A_1ANT_COEX_ALGO_PANEDR_A2DP = 0x7, - BT_8812A_1ANT_COEX_ALGO_PANEDR_HID = 0x8, - BT_8812A_1ANT_COEX_ALGO_HID_A2DP_PANEDR = 0x9, - BT_8812A_1ANT_COEX_ALGO_HID_A2DP = 0xa, - BT_8812A_1ANT_COEX_ALGO_MAX = 0xb, -}; - -struct coex_dm_8812a_1ant { - /* hw setting */ - u8 pre_ant_pos_type; - u8 cur_ant_pos_type; - /* fw mechanism */ - boolean cur_ignore_wlan_act; - boolean pre_ignore_wlan_act; - u8 pre_ps_tdma; - u8 cur_ps_tdma; - u8 ps_tdma_para[5]; - u8 ps_tdma_du_adj_type; - boolean auto_tdma_adjust; - boolean pre_ps_tdma_on; - boolean cur_ps_tdma_on; - boolean pre_bt_auto_report; - boolean cur_bt_auto_report; - u8 pre_lps; - u8 cur_lps; - u8 pre_rpwm; - u8 cur_rpwm; - - /* sw mechanism */ - boolean pre_low_penalty_ra; - boolean cur_low_penalty_ra; - u32 pre_val0x6c0; - u32 cur_val0x6c0; - u32 pre_val0x6c4; - u32 cur_val0x6c4; - u32 pre_val0x6c8; - u32 cur_val0x6c8; - u8 pre_val0x6cc; - u8 cur_val0x6cc; - boolean limited_dig; - - u32 backup_arfr_cnt1; /* Auto Rate Fallback Retry cnt */ - u32 backup_arfr_cnt2; /* Auto Rate Fallback Retry cnt */ - u16 backup_retry_limit; - u8 backup_ampdu_max_time; - - /* algorithm related */ - u8 pre_algorithm; - u8 cur_algorithm; - u8 bt_status; - u8 wifi_chnl_info[3]; - - u32 pre_ra_mask; - u32 cur_ra_mask; - u8 pre_arfr_type; - u8 cur_arfr_type; - u8 pre_retry_limit_type; - u8 cur_retry_limit_type; - u8 pre_ampdu_time_type; - u8 cur_ampdu_time_type; - u32 arp_cnt; - - u8 error_condition; -}; - -struct coex_sta_8812a_1ant { - boolean bt_disabled; - boolean bt_link_exist; - boolean sco_exist; - boolean a2dp_exist; - boolean hid_exist; - boolean pan_exist; - - boolean under_lps; - boolean under_ips; - u32 specific_pkt_period_cnt; - u32 high_priority_tx; - u32 high_priority_rx; - u32 low_priority_tx; - u32 low_priority_rx; - s8 bt_rssi; - boolean bt_tx_rx_mask; - u8 pre_bt_rssi_state; - u8 pre_wifi_rssi_state[4]; - boolean c2h_bt_info_req_sent; - u8 bt_info_c2h[BT_INFO_SRC_8812A_1ANT_MAX][10]; - u32 bt_info_c2h_cnt[BT_INFO_SRC_8812A_1ANT_MAX]; - u32 bt_info_query_cnt; - boolean c2h_bt_inquiry_page; - boolean c2h_bt_page; /* Add for win8.1 page out issue */ - boolean wifi_is_high_pri_task; /* Add for win8.1 page out issue */ - u8 bt_retry_cnt; - u8 bt_info_ext; - u32 pop_event_cnt; - u8 scan_ap_num; - - u32 crc_ok_cck; - u32 crc_ok_11g; - u32 crc_ok_11n; - u32 crc_ok_11n_agg; - - u32 crc_err_cck; - u32 crc_err_11g; - u32 crc_err_11n; - u32 crc_err_11n_agg; - - boolean cck_lock; - boolean pre_ccklock; - u8 coex_table_type; - - boolean force_lps_on; -}; - -/* ******************************************* - * The following is interface which will notify coex module. - * ******************************************* */ -void ex_halbtc8812a1ant_power_on_setting(IN struct btc_coexist *btcoexist); -void ex_halbtc8812a1ant_pre_load_firmware(IN struct btc_coexist *btcoexist); -void ex_halbtc8812a1ant_init_hw_config(IN struct btc_coexist *btcoexist, - IN boolean wifi_only); -void ex_halbtc8812a1ant_init_coex_dm(IN struct btc_coexist *btcoexist); -void ex_halbtc8812a1ant_ips_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8812a1ant_lps_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8812a1ant_scan_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8812a1ant_connect_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8812a1ant_media_status_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8812a1ant_specific_packet_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8812a1ant_bt_info_notify(IN struct btc_coexist *btcoexist, - IN u8 *tmp_buf, IN u8 length); -void ex_halbtc8812a1ant_rf_status_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8812a1ant_halt_notify(IN struct btc_coexist *btcoexist); -void ex_halbtc8812a1ant_pnp_notify(IN struct btc_coexist *btcoexist, - IN u8 pnp_state); -void ex_halbtc8812a1ant_coex_dm_reset(IN struct btc_coexist *btcoexist); -void ex_halbtc8812a1ant_periodical(IN struct btc_coexist *btcoexist); -void ex_halbtc8812a1ant_dbg_control(IN struct btc_coexist *btcoexist, - IN u8 op_code, IN u8 op_len, IN u8 *pdata); -void ex_halbtc8812a1ant_display_coex_info(IN struct btc_coexist *btcoexist); - -#else -#define ex_halbtc8812a1ant_power_on_setting(btcoexist) -#define ex_halbtc8812a1ant_pre_load_firmware(btcoexist) -#define ex_halbtc8812a1ant_init_hw_config(btcoexist, wifi_only) -#define ex_halbtc8812a1ant_init_coex_dm(btcoexist) -#define ex_halbtc8812a1ant_ips_notify(btcoexist, type) -#define ex_halbtc8812a1ant_lps_notify(btcoexist, type) -#define ex_halbtc8812a1ant_scan_notify(btcoexist, type) -#define ex_halbtc8812a1ant_connect_notify(btcoexist, type) -#define ex_halbtc8812a1ant_media_status_notify(btcoexist, type) -#define ex_halbtc8812a1ant_specific_packet_notify(btcoexist, type) -#define ex_halbtc8812a1ant_bt_info_notify(btcoexist, tmp_buf, length) -#define ex_halbtc8812a1ant_rf_status_notify(btcoexist, type) -#define ex_halbtc8812a1ant_halt_notify(btcoexist) -#define ex_halbtc8812a1ant_pnp_notify(btcoexist, pnp_state) -#define ex_halbtc8812a1ant_coex_dm_reset(btcoexist) -#define ex_halbtc8812a1ant_periodical(btcoexist) -#define ex_halbtc8812a1ant_dbg_control(btcoexist, op_code, op_len, pdata) -#define ex_halbtc8812a1ant_display_coex_info(btcoexist) - -#endif - -#endif diff --git a/hal/btc/halbtc8812a2ant.c b/hal/btc/halbtc8812a2ant.c deleted file mode 100644 index 038405b..0000000 --- a/hal/btc/halbtc8812a2ant.c +++ /dev/null @@ -1,5624 +0,0 @@ -/* ************************************************************ - * Description: - * - * This file is for RTL8812A Co-exist mechanism - * - * History - * 2012/08/22 Cosa first check in. - * 2012/11/14 Cosa Revise for 8812A 2Ant out sourcing. - * - * ************************************************************ */ - -/* ************************************************************ - * include files - * ************************************************************ */ -#include "mp_precomp.h" - -#if (BT_SUPPORT == 1 && COEX_SUPPORT == 1) - - -#if (RTL8812A_SUPPORT == 1) -/* ************************************************************ - * Global variables, these are static variables - * ************************************************************ */ -static u8 *trace_buf = &gl_btc_trace_buf[0]; -static struct coex_dm_8812a_2ant glcoex_dm_8812a_2ant; -static struct coex_dm_8812a_2ant *coex_dm = &glcoex_dm_8812a_2ant; -static struct coex_sta_8812a_2ant glcoex_sta_8812a_2ant; -static struct coex_sta_8812a_2ant *coex_sta = &glcoex_sta_8812a_2ant; - -const char *const glbt_info_src_8812a_2ant[] = { - "BT Info[wifi fw]", - "BT Info[bt rsp]", - "BT Info[bt auto report]", -}; -/* ************************************************************ - * BtCoex Version Format: - * 1. date : glcoex_ver_date_XXXXX_1ant - * 2. WifiCoexVersion : glcoex_ver_XXXX_1ant - * 3. BtCoexVersion : glcoex_ver_btdesired_XXXXX_1ant - * 4. others : glcoex_ver_XXXXXX_XXXXX_1ant - * - * Variable should be indicated IC and Antenna numbers !!! - * Please strictly follow this order and naming style !!! - * - * ************************************************************ */ -u32 glcoex_ver_date_8812a_2ant = 20160818; -u32 glcoex_ver_8812a_2ant = 0x3c; -u32 glcoex_ver_btdesired_8812a_2ant = 0x3c; -/*1. add coex. log for wifi/BT coex. version*/ - -/* ************************************************************ -* local function proto type if needed -* ************************************************************ -* ************************************************************ -* local function start with halbtc8812a2ant_ -* ************************************************************ */ -u8 halbtc8812a2ant_bt_rssi_state(u8 level_num, u8 rssi_thresh, u8 rssi_thresh1) -{ - s32 bt_rssi = 0; - u8 bt_rssi_state = coex_sta->pre_bt_rssi_state; - - bt_rssi = coex_sta->bt_rssi; - - if (level_num == 2) { - if ((coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_LOW) || - (coex_sta->pre_bt_rssi_state == - BTC_RSSI_STATE_STAY_LOW)) { - if (bt_rssi >= (rssi_thresh + - BTC_RSSI_COEX_THRESH_TOL_8812A_2ANT)) - bt_rssi_state = BTC_RSSI_STATE_HIGH; - else - bt_rssi_state = BTC_RSSI_STATE_STAY_LOW; - } else { - if (bt_rssi < rssi_thresh) - bt_rssi_state = BTC_RSSI_STATE_LOW; - else - bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH; - } - } else if (level_num == 3) { - if (rssi_thresh > rssi_thresh1) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Rssi thresh error!!\n"); - BTC_TRACE(trace_buf); - return coex_sta->pre_bt_rssi_state; - } - - if ((coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_LOW) || - (coex_sta->pre_bt_rssi_state == - BTC_RSSI_STATE_STAY_LOW)) { - if (bt_rssi >= (rssi_thresh + - BTC_RSSI_COEX_THRESH_TOL_8812A_2ANT)) - bt_rssi_state = BTC_RSSI_STATE_MEDIUM; - else - bt_rssi_state = BTC_RSSI_STATE_STAY_LOW; - } else if ((coex_sta->pre_bt_rssi_state == - BTC_RSSI_STATE_MEDIUM) || - (coex_sta->pre_bt_rssi_state == - BTC_RSSI_STATE_STAY_MEDIUM)) { - if (bt_rssi >= (rssi_thresh1 + - BTC_RSSI_COEX_THRESH_TOL_8812A_2ANT)) - bt_rssi_state = BTC_RSSI_STATE_HIGH; - else if (bt_rssi < rssi_thresh) - bt_rssi_state = BTC_RSSI_STATE_LOW; - else - bt_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM; - } else { - if (bt_rssi < rssi_thresh1) - bt_rssi_state = BTC_RSSI_STATE_MEDIUM; - else - bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH; - } - } - - coex_sta->pre_bt_rssi_state = bt_rssi_state; - - return bt_rssi_state; -} - - -u8 halbtc8812a2ant_wifi_rssi_state(IN struct btc_coexist *btcoexist, - IN u8 index, IN u8 level_num, IN u8 rssi_thresh, IN u8 rssi_thresh1) -{ - s32 wifi_rssi = 0; - u8 wifi_rssi_state = coex_sta->pre_wifi_rssi_state[index]; - - btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi); - - if (level_num == 2) { - if ((coex_sta->pre_wifi_rssi_state[index] == BTC_RSSI_STATE_LOW) - || - (coex_sta->pre_wifi_rssi_state[index] == - BTC_RSSI_STATE_STAY_LOW)) { - if (wifi_rssi >= (rssi_thresh + - BTC_RSSI_COEX_THRESH_TOL_8812A_2ANT)) - wifi_rssi_state = BTC_RSSI_STATE_HIGH; - else - wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW; - } else { - if (wifi_rssi < rssi_thresh) - wifi_rssi_state = BTC_RSSI_STATE_LOW; - else - wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH; - } - } else if (level_num == 3) { - if (rssi_thresh > rssi_thresh1) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], wifi RSSI thresh error!!\n"); - BTC_TRACE(trace_buf); - return coex_sta->pre_wifi_rssi_state[index]; - } - - if ((coex_sta->pre_wifi_rssi_state[index] == BTC_RSSI_STATE_LOW) - || - (coex_sta->pre_wifi_rssi_state[index] == - BTC_RSSI_STATE_STAY_LOW)) { - if (wifi_rssi >= (rssi_thresh + - BTC_RSSI_COEX_THRESH_TOL_8812A_2ANT)) - wifi_rssi_state = BTC_RSSI_STATE_MEDIUM; - else - wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW; - } else if ((coex_sta->pre_wifi_rssi_state[index] == - BTC_RSSI_STATE_MEDIUM) || - (coex_sta->pre_wifi_rssi_state[index] == - BTC_RSSI_STATE_STAY_MEDIUM)) { - if (wifi_rssi >= (rssi_thresh1 + - BTC_RSSI_COEX_THRESH_TOL_8812A_2ANT)) - wifi_rssi_state = BTC_RSSI_STATE_HIGH; - else if (wifi_rssi < rssi_thresh) - wifi_rssi_state = BTC_RSSI_STATE_LOW; - else - wifi_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM; - } else { - if (wifi_rssi < rssi_thresh1) - wifi_rssi_state = BTC_RSSI_STATE_MEDIUM; - else - wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH; - } - } - - coex_sta->pre_wifi_rssi_state[index] = wifi_rssi_state; - - return wifi_rssi_state; -} - - -void halbtc8812a2ant_set_enable_pta(IN struct btc_coexist *btcoexist, - IN boolean enablePTA) -{ - if (enablePTA) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], PTA is enable!\n"); - BTC_TRACE(trace_buf); - btcoexist->btc_write_1byte(btcoexist, 0x40, 0x20); - - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], PTA is disable!\n"); - BTC_TRACE(trace_buf); - btcoexist->btc_write_1byte(btcoexist, 0x40, 0x00); - - } -} - -void halbtc8812a2ant_enable_pta(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean enable) -{ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], %s turn Enable PTA %s\n", - (force_exec ? "force to" : ""), (enable ? "ON" : "OFF")); - BTC_TRACE(trace_buf); - coex_dm->cur_enable_pta = enable; - - if (!force_exec) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], pre_enable_pta = %d, cur_enable_pta = %d!!\n", - coex_dm->pre_enable_pta, coex_dm->cur_enable_pta); - BTC_TRACE(trace_buf); - - if (coex_dm->pre_enable_pta == coex_dm->cur_enable_pta) - return; - } - halbtc8812a2ant_set_enable_pta(btcoexist, enable); - - - coex_dm->pre_enable_pta = coex_dm->cur_enable_pta; -} - -u32 halbtc8812a2ant_decide_ra_mask(IN struct btc_coexist *btcoexist, - IN u32 ra_mask_type) -{ - u32 dis_ra_mask = 0x0; - - switch (ra_mask_type) { - case 0: /* normal mode */ - dis_ra_mask = 0x0; - break; - case 1: /* disable cck 1/2 */ - dis_ra_mask = 0x00000003; - break; - case 2: /* disable cck 1/2/5.5, ofdm 6/9/12/18/24, mcs 0/1/2/3/4 */ - dis_ra_mask = 0x0001f1f7; - break; - default: - break; - } - - return dis_ra_mask; -} - -void halbtc8812a2ant_update_ra_mask(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u32 dis_rate_mask) -{ - coex_dm->cur_ra_mask = dis_rate_mask; - - if (force_exec || (coex_dm->pre_ra_mask != coex_dm->cur_ra_mask)) - btcoexist->btc_set(btcoexist, BTC_SET_ACT_UPDATE_RAMASK, - &coex_dm->cur_ra_mask); - coex_dm->pre_ra_mask = coex_dm->cur_ra_mask; -} - -void halbtc8812a2ant_auto_rate_fallback_retry(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 type) -{ - boolean wifi_under_b_mode = false; - - coex_dm->cur_arfr_type = type; - - if (force_exec || (coex_dm->pre_arfr_type != coex_dm->cur_arfr_type)) { - switch (coex_dm->cur_arfr_type) { - case 0: /* normal mode */ - btcoexist->btc_write_4byte(btcoexist, 0x430, - coex_dm->backup_arfr_cnt1); - btcoexist->btc_write_4byte(btcoexist, 0x434, - coex_dm->backup_arfr_cnt2); - break; - case 1: - btcoexist->btc_get(btcoexist, - BTC_GET_BL_WIFI_UNDER_B_MODE, - &wifi_under_b_mode); - if (wifi_under_b_mode) { - btcoexist->btc_write_4byte(btcoexist, - 0x430, 0x0); - btcoexist->btc_write_4byte(btcoexist, - 0x434, 0x01010101); - } else { - btcoexist->btc_write_4byte(btcoexist, - 0x430, 0x0); - btcoexist->btc_write_4byte(btcoexist, - 0x434, 0x04030201); - } - break; - default: - break; - } - } - - coex_dm->pre_arfr_type = coex_dm->cur_arfr_type; -} - -void halbtc8812a2ant_retry_limit(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 type) -{ - coex_dm->cur_retry_limit_type = type; - - if (force_exec || - (coex_dm->pre_retry_limit_type != - coex_dm->cur_retry_limit_type)) { - switch (coex_dm->cur_retry_limit_type) { - case 0: /* normal mode */ - btcoexist->btc_write_2byte(btcoexist, 0x42a, - coex_dm->backup_retry_limit); - break; - case 1: /* retry limit=8 */ - btcoexist->btc_write_2byte(btcoexist, 0x42a, - 0x0808); - break; - default: - break; - } - } - - coex_dm->pre_retry_limit_type = coex_dm->cur_retry_limit_type; -} - -void halbtc8812a2ant_ampdu_max_time(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 type) -{ - coex_dm->cur_ampdu_time_type = type; - - if (force_exec || - (coex_dm->pre_ampdu_time_type != coex_dm->cur_ampdu_time_type)) { - switch (coex_dm->cur_ampdu_time_type) { - case 0: /* normal mode */ - btcoexist->btc_write_1byte(btcoexist, 0x456, - coex_dm->backup_ampdu_max_time); - break; - case 1: /* AMPDU timw = 0x38 * 32us */ - btcoexist->btc_write_1byte(btcoexist, 0x456, - 0x38); - break; - default: - break; - } - } - - coex_dm->pre_ampdu_time_type = coex_dm->cur_ampdu_time_type; -} - -void halbtc8812a2ant_limited_tx(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 ra_mask_type, IN u8 arfr_type, - IN u8 retry_limit_type, IN u8 ampdu_time_type) -{ - u32 dis_ra_mask = 0x0; - - coex_dm->cur_ra_mask_type = ra_mask_type; - dis_ra_mask = halbtc8812a2ant_decide_ra_mask(btcoexist, ra_mask_type); - halbtc8812a2ant_update_ra_mask(btcoexist, force_exec, dis_ra_mask); - - halbtc8812a2ant_auto_rate_fallback_retry(btcoexist, force_exec, - arfr_type); - halbtc8812a2ant_retry_limit(btcoexist, force_exec, retry_limit_type); - halbtc8812a2ant_ampdu_max_time(btcoexist, force_exec, ampdu_time_type); -} - -void halbtc8812a2ant_limited_rx(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean rej_ap_agg_pkt, - IN boolean bt_ctrl_agg_buf_size, IN u8 agg_buf_size) -{ - boolean reject_rx_agg = rej_ap_agg_pkt; - boolean bt_ctrl_rx_agg_size = bt_ctrl_agg_buf_size; - u8 rx_agg_size = agg_buf_size; - - /* ============================================ */ - /* Rx Aggregation related setting */ - /* ============================================ */ - btcoexist->btc_set(btcoexist, BTC_SET_BL_TO_REJ_AP_AGG_PKT, - &reject_rx_agg); - /* decide BT control aggregation buf size or not */ - btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_CTRL_AGG_SIZE, - &bt_ctrl_rx_agg_size); - /* aggregation buf size, only work when BT control Rx aggregation size. */ - btcoexist->btc_set(btcoexist, BTC_SET_U1_AGG_BUF_SIZE, &rx_agg_size); - /* real update aggregation setting */ - btcoexist->btc_set(btcoexist, BTC_SET_ACT_AGGREGATE_CTRL, NULL); - - -} - -void halbtc8812a2ant_monitor_bt_ctr(IN struct btc_coexist *btcoexist) -{ - u32 reg_hp_txrx, reg_lp_txrx, u32tmp; - u32 reg_hp_tx = 0, reg_hp_rx = 0, reg_lp_tx = 0, reg_lp_rx = 0; - - reg_hp_txrx = 0x770; - reg_lp_txrx = 0x774; - - u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_hp_txrx); - reg_hp_tx = u32tmp & MASKLWORD; - reg_hp_rx = (u32tmp & MASKHWORD) >> 16; - - u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_lp_txrx); - reg_lp_tx = u32tmp & MASKLWORD; - reg_lp_rx = (u32tmp & MASKHWORD) >> 16; - - coex_sta->high_priority_tx = reg_hp_tx; - coex_sta->high_priority_rx = reg_hp_rx; - coex_sta->low_priority_tx = reg_lp_tx; - coex_sta->low_priority_rx = reg_lp_rx; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], High Priority Tx/Rx (reg 0x%x)=0x%x(%d)/0x%x(%d)\n", - reg_hp_txrx, reg_hp_tx, reg_hp_tx, reg_hp_rx, reg_hp_rx); - BTC_TRACE(trace_buf); - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Low Priority Tx/Rx (reg 0x%x)=0x%x(%d)/0x%x(%d)\n", - reg_lp_txrx, reg_lp_tx, reg_lp_tx, reg_lp_rx, reg_lp_rx); - BTC_TRACE(trace_buf); - - /* reset counter */ - btcoexist->btc_write_1byte(btcoexist, 0x76e, 0xc); -} - - -void halbtc8812a2ant_monitor_wifi_ctr(IN struct btc_coexist *btcoexist) -{ -#if 1 - - coex_sta->crc_ok_cck = - btcoexist->btc_phydm_query_PHY_counter( - btcoexist, - PHYDM_INFO_CRC32_OK_CCK); - coex_sta->crc_ok_11g = - btcoexist->btc_phydm_query_PHY_counter( - btcoexist, - PHYDM_INFO_CRC32_OK_LEGACY); - coex_sta->crc_ok_11n = - btcoexist->btc_phydm_query_PHY_counter( - btcoexist, - PHYDM_INFO_CRC32_OK_HT); - coex_sta->crc_ok_11n_vht = - btcoexist->btc_phydm_query_PHY_counter( - btcoexist, - PHYDM_INFO_CRC32_OK_VHT); - - coex_sta->crc_err_cck = - btcoexist->btc_phydm_query_PHY_counter( - btcoexist, - PHYDM_INFO_CRC32_ERROR_CCK); - coex_sta->crc_err_11g = - btcoexist->btc_phydm_query_PHY_counter( - btcoexist, - PHYDM_INFO_CRC32_ERROR_LEGACY); - coex_sta->crc_err_11n = - btcoexist->btc_phydm_query_PHY_counter( - btcoexist, - PHYDM_INFO_CRC32_ERROR_HT); - coex_sta->crc_err_11n_vht = - btcoexist->btc_phydm_query_PHY_counter( - btcoexist, - PHYDM_INFO_CRC32_ERROR_VHT); -#endif -} - - -void halbtc8812a2ant_query_bt_info(IN struct btc_coexist *btcoexist) -{ - u8 data_len = 3; - u8 buf[5] = {0}; - /* 8812a watch btifo to check BT enable/disable - * if(!btcoexist->bt_info.bt_disabled) */ - { - if (!coex_sta->bt_info_query_cnt || - (coex_sta->bt_info_c2h_cnt[BT_INFO_SRC_8812A_2ANT_BT_RSP] - - coex_sta->bt_info_query_cnt) > 2) { - buf[0] = data_len; - buf[1] = 0x1; /* polling enable, 1=enable, 0=disable */ - buf[2] = 0x2; /* polling time in seconds */ - buf[3] = 0x1; /* auto report enable, 1=enable, 0=disable */ - - btcoexist->btc_set(btcoexist, BTC_SET_ACT_CTRL_BT_INFO, - (void *)&buf[0]); - } - } - coex_sta->bt_info_query_cnt++; -} - -boolean halbtc8812a2ant_is_wifi_status_changed(IN struct btc_coexist *btcoexist) -{ - static boolean pre_wifi_busy = false, pre_under_4way = false, - pre_bt_hs_on = false; - boolean wifi_busy = false, under_4way = false, bt_hs_on = false; - boolean wifi_connected = false; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS, - &under_4way); - - if (wifi_connected) { - if (wifi_busy != pre_wifi_busy) { - pre_wifi_busy = wifi_busy; - return true; - } - if (under_4way != pre_under_4way) { - pre_under_4way = under_4way; - return true; - } - if (bt_hs_on != pre_bt_hs_on) { - pre_bt_hs_on = bt_hs_on; - return true; - } - } - - return false; -} - -void halbtc8812a2ant_update_bt_link_info(IN struct btc_coexist *btcoexist) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - boolean bt_hs_on = false; - -#if 1/* (BT_AUTO_REPORT_ONLY_8812A_2ANT == 1) / profile from bt patch */ - btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); - - bt_link_info->bt_link_exist = coex_sta->bt_link_exist; - bt_link_info->sco_exist = coex_sta->sco_exist; - bt_link_info->a2dp_exist = coex_sta->a2dp_exist; - bt_link_info->pan_exist = coex_sta->pan_exist; - bt_link_info->hid_exist = coex_sta->hid_exist; - bt_link_info->acl_busy = coex_sta->acl_busy; - - /* work around for HS mode. */ - if (bt_hs_on) { - bt_link_info->pan_exist = true; - bt_link_info->bt_link_exist = true; - } -#else /* profile from bt stack */ - bt_link_info->bt_link_exist = stack_info->bt_link_exist; - bt_link_info->sco_exist = stack_info->sco_exist; - bt_link_info->a2dp_exist = stack_info->a2dp_exist; - bt_link_info->pan_exist = stack_info->pan_exist; - bt_link_info->hid_exist = stack_info->hid_exist; - - /* for win-8 stack HID report error */ - if (!stack_info->hid_exist) - stack_info->hid_exist = - coex_sta->hid_exist; /* sync BTInfo with BT firmware and stack */ - /* when stack HID report error, here we use the info from bt fw. */ - if (!stack_info->bt_link_exist) - stack_info->bt_link_exist = coex_sta->bt_link_exist; -#endif - /* check if Sco only */ - if (bt_link_info->sco_exist && - !bt_link_info->a2dp_exist && - !bt_link_info->pan_exist && - !bt_link_info->hid_exist) - bt_link_info->sco_only = true; - else - bt_link_info->sco_only = false; - - /* check if A2dp only */ - if (!bt_link_info->sco_exist && - bt_link_info->a2dp_exist && - !bt_link_info->pan_exist && - !bt_link_info->hid_exist) - bt_link_info->a2dp_only = true; - else - bt_link_info->a2dp_only = false; - - /* check if Pan only */ - if (!bt_link_info->sco_exist && - !bt_link_info->a2dp_exist && - bt_link_info->pan_exist && - !bt_link_info->hid_exist) - bt_link_info->pan_only = true; - else - bt_link_info->pan_only = false; - - /* check if Hid only */ - if (!bt_link_info->sco_exist && - !bt_link_info->a2dp_exist && - !bt_link_info->pan_exist && - bt_link_info->hid_exist) - bt_link_info->hid_only = true; - else - bt_link_info->hid_only = false; -} - -u8 halbtc8812a2ant_action_algorithm(IN struct btc_coexist *btcoexist) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - struct btc_stack_info *stack_info = &btcoexist->stack_info; - boolean bt_hs_on = false; - u8 algorithm = BT_8812A_2ANT_COEX_ALGO_UNDEFINED; - u8 num_of_diff_profile = 0; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); - - if (!bt_link_info->bt_link_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], No BT link exists!!!\n"); - BTC_TRACE(trace_buf); - return algorithm; - } - - if (bt_link_info->sco_exist) - num_of_diff_profile++; - if (bt_link_info->hid_exist) - num_of_diff_profile++; - if (bt_link_info->pan_exist) - num_of_diff_profile++; - if (bt_link_info->a2dp_exist) - num_of_diff_profile++; - - if (num_of_diff_profile == 0) { - if (bt_link_info->acl_busy) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ACL Busy only\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8812A_2ANT_COEX_ALGO_PANEDR; - } - } else if (num_of_diff_profile == 1) { - if (bt_link_info->sco_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCO only\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8812A_2ANT_COEX_ALGO_SCO; - } else { - if (bt_link_info->hid_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], HID only\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8812A_2ANT_COEX_ALGO_HID; - } else if (bt_link_info->a2dp_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], A2DP only\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8812A_2ANT_COEX_ALGO_A2DP; - } else if (bt_link_info->pan_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], PAN(HS) only\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8812A_2ANT_COEX_ALGO_PANHS; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], PAN(EDR) only\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8812A_2ANT_COEX_ALGO_PANEDR; - } - } - } - } else if (num_of_diff_profile == 2) { - if (bt_link_info->sco_exist) { - if (bt_link_info->hid_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCO + HID\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8812A_2ANT_COEX_ALGO_SCO_HID; - } else if (bt_link_info->a2dp_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCO + A2DP ==> SCO\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8812A_2ANT_COEX_ALGO_PANEDR_HID; - } else if (bt_link_info->pan_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCO + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8812A_2ANT_COEX_ALGO_SCO; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCO + PAN(EDR)\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8812A_2ANT_COEX_ALGO_SCO; - } - } - } else { - if (bt_link_info->hid_exist && - bt_link_info->a2dp_exist) { - if (stack_info->num_of_hid >= 2) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], HID*2 + A2DP\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8812A_2ANT_COEX_ALGO_HID_A2DP_PANEDR; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], HID + A2DP\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8812A_2ANT_COEX_ALGO_HID_A2DP; - } - } else if (bt_link_info->hid_exist && - bt_link_info->pan_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], HID + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8812A_2ANT_COEX_ALGO_HID; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], HID + PAN(EDR)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8812A_2ANT_COEX_ALGO_PANEDR_HID; - } - } else if (bt_link_info->pan_exist && - bt_link_info->a2dp_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], A2DP + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8812A_2ANT_COEX_ALGO_A2DP_PANHS; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], A2DP + PAN(EDR)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8812A_2ANT_COEX_ALGO_PANEDR_A2DP; - } - } - } - } else if (num_of_diff_profile == 3) { - if (bt_link_info->sco_exist) { - if (bt_link_info->hid_exist && - bt_link_info->a2dp_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCO + HID + A2DP ==> HID\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8812A_2ANT_COEX_ALGO_PANEDR_HID; - } else if (bt_link_info->hid_exist && - bt_link_info->pan_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCO + HID + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8812A_2ANT_COEX_ALGO_SCO_HID; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCO + HID + PAN(EDR)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8812A_2ANT_COEX_ALGO_SCO_HID; - } - } else if (bt_link_info->pan_exist && - bt_link_info->a2dp_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCO + A2DP + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8812A_2ANT_COEX_ALGO_SCO; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCO + A2DP + PAN(EDR) ==> HID\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8812A_2ANT_COEX_ALGO_PANEDR_HID; - } - } - } else { - if (bt_link_info->hid_exist && - bt_link_info->pan_exist && - bt_link_info->a2dp_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], HID + A2DP + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8812A_2ANT_COEX_ALGO_HID_A2DP_PANHS; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], HID + A2DP + PAN(EDR)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8812A_2ANT_COEX_ALGO_HID_A2DP_PANEDR; - } - } - } - } else if (num_of_diff_profile >= 3) { - if (bt_link_info->sco_exist) { - if (bt_link_info->hid_exist && - bt_link_info->pan_exist && - bt_link_info->a2dp_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Error!!! SCO + HID + A2DP + PAN(HS)\n"); - BTC_TRACE(trace_buf); - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCO + HID + A2DP + PAN(EDR)==>PAN(EDR)+HID\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8812A_2ANT_COEX_ALGO_PANEDR_HID; - } - } - } - } - - return algorithm; -} - -void halbtc8812a2ant_set_fw_dac_swing_level(IN struct btc_coexist *btcoexist, - IN u8 dac_swing_lvl) -{ - u8 h2c_parameter[1] = {0}; - - /* There are several type of dacswing */ - /* 0x18/ 0x10/ 0xc/ 0x8/ 0x4/ 0x6 */ - h2c_parameter[0] = dac_swing_lvl; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Set Dac Swing Level=0x%x\n", - dac_swing_lvl); - BTC_TRACE(trace_buf); - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], FW write 0x64=0x%x\n", - h2c_parameter[0]); - BTC_TRACE(trace_buf); - - btcoexist->btc_fill_h2c(btcoexist, 0x64, 1, h2c_parameter); -} - -void halbtc8812a2ant_set_fw_dec_bt_pwr(IN struct btc_coexist *btcoexist, - IN u8 dec_bt_pwr_lvl) -{ - u8 data_len = 4; - u8 buf[6] = {0}; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], decrease Bt Power level = %d\n", - dec_bt_pwr_lvl); - BTC_TRACE(trace_buf); - - buf[0] = data_len; - buf[1] = 0x3; /* OP_Code */ - buf[2] = 0x2; /* OP_Code_Length */ - if (dec_bt_pwr_lvl) - buf[3] = 0x1; /* OP_Code_Content */ - else - buf[3] = 0x0; - buf[4] = dec_bt_pwr_lvl;/* pwr_level */ - - btcoexist->btc_set(btcoexist, BTC_SET_ACT_CTRL_BT_COEX, - (void *)&buf[0]); -} - -void halbtc8812a2ant_dec_bt_pwr(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 dec_bt_pwr_lvl) -{ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], %s Dec BT power level = %d\n", - (force_exec ? "force to" : ""), dec_bt_pwr_lvl); - BTC_TRACE(trace_buf); - - coex_dm->cur_bt_dec_pwr_lvl = dec_bt_pwr_lvl; - - if (!force_exec) { - if (coex_dm->pre_bt_dec_pwr_lvl == coex_dm->cur_bt_dec_pwr_lvl) - return; - } - halbtc8812a2ant_set_fw_dec_bt_pwr(btcoexist, - coex_dm->cur_bt_dec_pwr_lvl); - - coex_dm->pre_bt_dec_pwr_lvl = coex_dm->cur_bt_dec_pwr_lvl; -} - -void halbtc8812a2ant_fw_dac_swing_lvl(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 fw_dac_swing_lvl) -{ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], %s set FW Dac Swing level = %d\n", - (force_exec ? "force to" : ""), fw_dac_swing_lvl); - BTC_TRACE(trace_buf); - coex_dm->cur_fw_dac_swing_lvl = fw_dac_swing_lvl; - - if (!force_exec) { - if (coex_dm->pre_fw_dac_swing_lvl == - coex_dm->cur_fw_dac_swing_lvl) - return; - } - - halbtc8812a2ant_set_fw_dac_swing_level(btcoexist, - coex_dm->cur_fw_dac_swing_lvl); - - coex_dm->pre_fw_dac_swing_lvl = coex_dm->cur_fw_dac_swing_lvl; -} - -void halbtc8812a2ant_set_sw_rf_rx_lpf_corner(IN struct btc_coexist *btcoexist, - IN boolean rx_rf_shrink_on) -{ - if (rx_rf_shrink_on) { - /* Shrink RF Rx LPF corner */ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Shrink RF Rx LPF corner!!\n"); - BTC_TRACE(trace_buf); - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1e, 0xfffff, - 0xffffc); - } else { - /* Resume RF Rx LPF corner */ - /* After initialized, we can use coex_dm->bt_rf_0x1e_backup */ - if (btcoexist->initilized) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Resume RF Rx LPF corner!!\n"); - BTC_TRACE(trace_buf); - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1e, - 0xfffff, coex_dm->bt_rf_0x1e_backup); - } - } -} - -void halbtc8812a2ant_rf_shrink(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean rx_rf_shrink_on) -{ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], %s turn Rx RF Shrink = %s\n", - (force_exec ? "force to" : ""), - ((rx_rf_shrink_on) ? "ON" : "OFF")); - BTC_TRACE(trace_buf); - coex_dm->cur_rf_rx_lpf_shrink = rx_rf_shrink_on; - - if (!force_exec) { - if (coex_dm->pre_rf_rx_lpf_shrink == - coex_dm->cur_rf_rx_lpf_shrink) - return; - } - halbtc8812a2ant_set_sw_rf_rx_lpf_corner(btcoexist, - coex_dm->cur_rf_rx_lpf_shrink); - - coex_dm->pre_rf_rx_lpf_shrink = coex_dm->cur_rf_rx_lpf_shrink; -} - -void halbtc8812a2ant_set_sw_penalty_tx_rate_adaptive(IN struct btc_coexist - *btcoexist, IN boolean low_penalty_ra) -{ - u8 tmp_u1; - - tmp_u1 = btcoexist->btc_read_1byte(btcoexist, 0x4fd); - tmp_u1 |= BIT(0); - if (low_penalty_ra) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Tx rate adaptive, set low penalty!!\n"); - BTC_TRACE(trace_buf); - tmp_u1 &= ~BIT(2); - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Tx rate adaptive, set normal!!\n"); - BTC_TRACE(trace_buf); - tmp_u1 |= BIT(2); - } - - btcoexist->btc_write_1byte(btcoexist, 0x4fd, tmp_u1); -} - -void halbtc8812a2ant_low_penalty_ra(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean low_penalty_ra) -{ - return; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], %s turn LowPenaltyRA = %s\n", - (force_exec ? "force to" : ""), - ((low_penalty_ra) ? "ON" : "OFF")); - BTC_TRACE(trace_buf); - coex_dm->cur_low_penalty_ra = low_penalty_ra; - - if (!force_exec) { - if (coex_dm->pre_low_penalty_ra == coex_dm->cur_low_penalty_ra) - return; - } - halbtc8812a2ant_set_sw_penalty_tx_rate_adaptive(btcoexist, - coex_dm->cur_low_penalty_ra); - - coex_dm->pre_low_penalty_ra = coex_dm->cur_low_penalty_ra; -} - -void halbtc8812a2ant_set_dac_swing_reg(IN struct btc_coexist *btcoexist, - IN u32 level) -{ - u8 val = (u8)level; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Write SwDacSwing = 0x%x\n", - level); - BTC_TRACE(trace_buf); - btcoexist->btc_write_1byte_bitmask(btcoexist, 0xc5b, 0x3e, val); -} - -void halbtc8812a2ant_set_sw_full_time_dac_swing(IN struct btc_coexist - *btcoexist, IN boolean sw_dac_swing_on, IN u32 sw_dac_swing_lvl) -{ - if (sw_dac_swing_on) - halbtc8812a2ant_set_dac_swing_reg(btcoexist, sw_dac_swing_lvl); - else - halbtc8812a2ant_set_dac_swing_reg(btcoexist, 0x18); -} - - -void halbtc8812a2ant_dac_swing(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean dac_swing_on, IN u32 dac_swing_lvl) -{ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], %s turn DacSwing=%s, dac_swing_lvl=0x%x\n", - (force_exec ? "force to" : ""), ((dac_swing_on) ? "ON" : "OFF"), - dac_swing_lvl); - BTC_TRACE(trace_buf); - coex_dm->cur_dac_swing_on = dac_swing_on; - coex_dm->cur_dac_swing_lvl = dac_swing_lvl; - - if (!force_exec) { - if ((coex_dm->pre_dac_swing_on == coex_dm->cur_dac_swing_on) && - (coex_dm->pre_dac_swing_lvl == - coex_dm->cur_dac_swing_lvl)) - return; - } - delay_ms(30); - halbtc8812a2ant_set_sw_full_time_dac_swing(btcoexist, dac_swing_on, - dac_swing_lvl); - - coex_dm->pre_dac_swing_on = coex_dm->cur_dac_swing_on; - coex_dm->pre_dac_swing_lvl = coex_dm->cur_dac_swing_lvl; -} - -void halbtc8812a2ant_set_adc_back_off(IN struct btc_coexist *btcoexist, - IN boolean adc_back_off) -{ - if (adc_back_off) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BB BackOff Level On!\n"); - BTC_TRACE(trace_buf); - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x8db, 0x60, 0x3); - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BB BackOff Level Off!\n"); - BTC_TRACE(trace_buf); - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x8db, 0x60, 0x1); - } -} - -void halbtc8812a2ant_adc_back_off(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean adc_back_off) -{ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], %s turn AdcBackOff = %s\n", - (force_exec ? "force to" : ""), - ((adc_back_off) ? "ON" : "OFF")); - BTC_TRACE(trace_buf); - - coex_dm->cur_adc_back_off = adc_back_off; - - if (!force_exec) { - if (coex_dm->pre_adc_back_off == coex_dm->cur_adc_back_off) - return; - } - halbtc8812a2ant_set_adc_back_off(btcoexist, coex_dm->cur_adc_back_off); - - coex_dm->pre_adc_back_off = coex_dm->cur_adc_back_off; -} - -void halbtc8812a2ant_set_agc_table(IN struct btc_coexist *btcoexist, - IN boolean agc_table_en) -{ - u8 rssi_adjust_val = 0; - - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0xef, 0xfffff, 0x02000); - if (agc_table_en) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Agc Table On!\n"); - BTC_TRACE(trace_buf); - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x3b, 0xfffff, - 0x28F4B); - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x3b, 0xfffff, - 0x10AB2); - rssi_adjust_val = 8; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Agc Table Off!\n"); - BTC_TRACE(trace_buf); - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x3b, 0xfffff, - 0x2884B); - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x3b, 0xfffff, - 0x104B2); - } - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0xef, 0xfffff, 0x0); - - /* set rssi_adjust_val for wifi module. */ - btcoexist->btc_set(btcoexist, BTC_SET_U1_RSSI_ADJ_VAL_FOR_AGC_TABLE_ON, - &rssi_adjust_val); -} - -void halbtc8812a2ant_agc_table(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean agc_table_en) -{ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], %s %s Agc Table\n", - (force_exec ? "force to" : ""), - ((agc_table_en) ? "Enable" : "Disable")); - BTC_TRACE(trace_buf); - coex_dm->cur_agc_table_en = agc_table_en; - - if (!force_exec) { - if (coex_dm->pre_agc_table_en == coex_dm->cur_agc_table_en) - return; - } - halbtc8812a2ant_set_agc_table(btcoexist, agc_table_en); - - coex_dm->pre_agc_table_en = coex_dm->cur_agc_table_en; -} - -void halbtc8812a2ant_set_coex_table(IN struct btc_coexist *btcoexist, - IN u32 val0x6c0, IN u32 val0x6c4, IN u32 val0x6c8, IN u8 val0x6cc) -{ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], set coex table, set 0x6c0=0x%x\n", val0x6c0); - BTC_TRACE(trace_buf); - btcoexist->btc_write_4byte(btcoexist, 0x6c0, val0x6c0); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], set coex table, set 0x6c4=0x%x\n", val0x6c4); - BTC_TRACE(trace_buf); - btcoexist->btc_write_4byte(btcoexist, 0x6c4, val0x6c4); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], set coex table, set 0x6c8=0x%x\n", val0x6c8); - BTC_TRACE(trace_buf); - btcoexist->btc_write_4byte(btcoexist, 0x6c8, val0x6c8); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], set coex table, set 0x6cc=0x%x\n", val0x6cc); - BTC_TRACE(trace_buf); - btcoexist->btc_write_1byte(btcoexist, 0x6cc, val0x6cc); -} - -void halbtc8812a2ant_coex_table(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u32 val0x6c0, IN u32 val0x6c4, - IN u32 val0x6c8, IN u8 val0x6cc) -{ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], %s write Coex Table 0x6c0=0x%x, 0x6c4=0x%x, 0x6c8=0x%x, 0x6cc=0x%x\n", - (force_exec ? "force to" : ""), val0x6c0, val0x6c4, val0x6c8, - val0x6cc); - BTC_TRACE(trace_buf); - coex_dm->cur_val0x6c0 = val0x6c0; - coex_dm->cur_val0x6c4 = val0x6c4; - coex_dm->cur_val0x6c8 = val0x6c8; - coex_dm->cur_val0x6cc = val0x6cc; - - if (!force_exec) { - if ((coex_dm->pre_val0x6c0 == coex_dm->cur_val0x6c0) && - (coex_dm->pre_val0x6c4 == coex_dm->cur_val0x6c4) && - (coex_dm->pre_val0x6c8 == coex_dm->cur_val0x6c8) && - (coex_dm->pre_val0x6cc == coex_dm->cur_val0x6cc)) - return; - } - halbtc8812a2ant_set_coex_table(btcoexist, val0x6c0, val0x6c4, val0x6c8, - val0x6cc); - - coex_dm->pre_val0x6c0 = coex_dm->cur_val0x6c0; - coex_dm->pre_val0x6c4 = coex_dm->cur_val0x6c4; - coex_dm->pre_val0x6c8 = coex_dm->cur_val0x6c8; - coex_dm->pre_val0x6cc = coex_dm->cur_val0x6cc; -} - -void halbtc8812a2ant_coex_table_with_type(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 type) -{ - switch (type) { - case 0: - halbtc8812a2ant_coex_table(btcoexist, force_exec, - 0x55555555, 0x5a5a5a5a, 0xffffff, 0x3); - break; - case 1: - halbtc8812a2ant_coex_table(btcoexist, force_exec, - 0x5a5a5a5a, 0x5a5a5a5a, 0xffffff, 0x3); - break; - case 2: - halbtc8812a2ant_coex_table(btcoexist, force_exec, - 0x55555555, 0x5ffb5ffb, 0xffffff, 0x3); - break; - case 3: - halbtc8812a2ant_coex_table(btcoexist, force_exec, - 0x5fdf5fdf, 0x5fdb5fdb, 0xffffff, 0x3); - break; - case 4: - halbtc8812a2ant_coex_table(btcoexist, force_exec, - 0xdfffdfff, 0x5fdb5fdb, 0xffffff, 0x3); - break; - case 5: - halbtc8812a2ant_coex_table(btcoexist, force_exec, - 0x5ddd5ddd, 0x5fdb5fdb, 0xffffff, 0x3); - break; - case 6: - halbtc8812a2ant_coex_table(btcoexist, force_exec, - 0x5fff5fff, 0x5a5a5a5a, 0xffffff, 0x3); - break; - case 7: - if (coex_sta->scan_ap_num <= 5) - halbtc8812a2ant_coex_table(btcoexist, - force_exec, 0xffffffff, 0xfafafafa, - 0xffffff, 0x3); - else - halbtc8812a2ant_coex_table(btcoexist, - force_exec, 0xffffffff, 0x5a5a5a5a, - 0xffffff, 0x3); - break; - case 8: - halbtc8812a2ant_coex_table(btcoexist, force_exec, - 0x5f5f5f5f, 0x5a5a5a5a, 0xffffff, 0x3); - break; - - default: - break; - } -} - -void halbtc8812a2ant_set_fw_ignore_wlan_act(IN struct btc_coexist *btcoexist, - IN boolean enable) -{ - u8 data_len = 3; - u8 buf[5] = {0}; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], %s BT Ignore Wlan_Act\n", - (enable ? "Enable" : "Disable")); - BTC_TRACE(trace_buf); - - buf[0] = data_len; - buf[1] = 0x1; /* OP_Code */ - buf[2] = 0x1; /* OP_Code_Length */ - if (enable) - buf[3] = 0x1; /* OP_Code_Content */ - else - buf[3] = 0x0; - - btcoexist->btc_set(btcoexist, BTC_SET_ACT_CTRL_BT_COEX, - (void *)&buf[0]); -} - -void halbtc8812a2ant_ignore_wlan_act(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean enable) -{ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], %s turn Ignore WlanAct %s\n", - (force_exec ? "force to" : ""), (enable ? "ON" : "OFF")); - BTC_TRACE(trace_buf); - coex_dm->cur_ignore_wlan_act = enable; - - if (!force_exec) { - if (coex_dm->pre_ignore_wlan_act == - coex_dm->cur_ignore_wlan_act) - return; - } - halbtc8812a2ant_set_fw_ignore_wlan_act(btcoexist, enable); - - coex_dm->pre_ignore_wlan_act = coex_dm->cur_ignore_wlan_act; -} - -void halbtc8812a2ant_set_fw_pstdma(IN struct btc_coexist *btcoexist, - IN u8 byte1, IN u8 byte2, IN u8 byte3, IN u8 byte4, IN u8 byte5) -{ - u8 h2c_parameter[5] = {0}; - u8 real_byte1 = byte1, real_byte5 = byte5; - boolean ap_enable = false; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, - &ap_enable); - - if (ap_enable) { - if (byte1 & BIT(4) && !(byte1 & BIT(5))) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], FW for 1Ant AP mode\n"); - BTC_TRACE(trace_buf); - real_byte1 &= ~BIT(4); - real_byte1 |= BIT(5); - - real_byte5 |= BIT(5); - real_byte5 &= ~BIT(6); - } - } - - h2c_parameter[0] = real_byte1; - h2c_parameter[1] = byte2; - h2c_parameter[2] = byte3; - h2c_parameter[3] = byte4; - h2c_parameter[4] = real_byte5; - - - coex_dm->ps_tdma_para[0] = real_byte1; - coex_dm->ps_tdma_para[1] = byte2; - coex_dm->ps_tdma_para[2] = byte3; - coex_dm->ps_tdma_para[3] = byte4; - coex_dm->ps_tdma_para[4] = real_byte5; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], PS-TDMA H2C cmd =0x%x%08x\n", - h2c_parameter[0], - h2c_parameter[1] << 24 | h2c_parameter[2] << 16 | - h2c_parameter[3] << 8 | h2c_parameter[4]); - - BTC_TRACE(trace_buf); - btcoexist->btc_fill_h2c(btcoexist, 0x60, 5, h2c_parameter); -} - -void halbtc8812a2ant_set_lps_rpwm(IN struct btc_coexist *btcoexist, - IN u8 lps_val, IN u8 rpwm_val) -{ - u8 lps = lps_val; - u8 rpwm = rpwm_val; - - btcoexist->btc_set(btcoexist, BTC_SET_U1_LPS_VAL, &lps); - btcoexist->btc_set(btcoexist, BTC_SET_U1_RPWM_VAL, &rpwm); -} - -void halbtc8812a2ant_lps_rpwm(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 lps_val, IN u8 rpwm_val) -{ - coex_dm->cur_lps = lps_val; - coex_dm->cur_rpwm = rpwm_val; - - if (!force_exec) { - if ((coex_dm->pre_lps == coex_dm->cur_lps) && - (coex_dm->pre_rpwm == coex_dm->cur_rpwm)) - return; - } - halbtc8812a2ant_set_lps_rpwm(btcoexist, lps_val, rpwm_val); - - coex_dm->pre_lps = coex_dm->cur_lps; - coex_dm->pre_rpwm = coex_dm->cur_rpwm; -} - -void halbtc8812a2ant_sw_mechanism1(IN struct btc_coexist *btcoexist, - IN boolean shrink_rx_lpf, IN boolean low_penalty_ra, - IN boolean limited_dig, IN boolean bt_lna_constrain) -{ - /* - u32 wifi_bw; - - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw); - - if(BTC_WIFI_BW_HT40 != wifi_bw) - { - if (shrink_rx_lpf) - shrink_rx_lpf = false; - } - */ - - halbtc8812a2ant_rf_shrink(btcoexist, NORMAL_EXEC, shrink_rx_lpf); - /* halbtc8812a2ant_low_penalty_ra(btcoexist, NORMAL_EXEC, low_penalty_ra); */ -} - -void halbtc8812a2ant_sw_mechanism2(IN struct btc_coexist *btcoexist, - IN boolean agc_table_shift, IN boolean adc_back_off, - IN boolean sw_dac_swing, IN u32 dac_swing_lvl) -{ - /* halbtc8812a2ant_agc_table(btcoexist, NORMAL_EXEC, agc_table_shift); */ - halbtc8812a2ant_adc_back_off(btcoexist, NORMAL_EXEC, adc_back_off); - halbtc8812a2ant_dac_swing(btcoexist, NORMAL_EXEC, sw_dac_swing, - dac_swing_lvl); -} - -void halbtc8812a2ant_set_ant_path(IN struct btc_coexist *btcoexist, - IN u8 ant_pos_type, IN boolean init_hwcfg, IN boolean wifi_off) -{ - u8 u8tmp = 0; - - if (init_hwcfg) { - btcoexist->btc_write_4byte(btcoexist, 0x900, 0x00000400); - btcoexist->btc_write_1byte(btcoexist, 0x76d, 0x1); - } else if (wifi_off) { - - } - - /* ext switch setting */ - switch (ant_pos_type) { - case BTC_ANT_WIFI_AT_CPL_MAIN: - u8tmp = btcoexist->btc_read_1byte(btcoexist, 0xcb7); - u8tmp &= ~BIT(2); - u8tmp |= BIT(3); - btcoexist->btc_write_1byte(btcoexist, 0xcb7, u8tmp); - break; - case BTC_ANT_WIFI_AT_CPL_AUX: - u8tmp = btcoexist->btc_read_1byte(btcoexist, 0xcb7); - u8tmp &= ~BIT(3); - u8tmp |= BIT(2); - btcoexist->btc_write_1byte(btcoexist, 0xcb7, u8tmp); - break; - default: - break; - } -} - -void halbtc8812a2ant_ps_tdma(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean turn_on, IN u8 type) -{ - s8 wifi_duration_adjust = 0x0; - - coex_dm->cur_ps_tdma_on = turn_on; - coex_dm->cur_ps_tdma = type; - - if (!force_exec) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], pre_ps_tdma_on = %d, cur_ps_tdma_on = %d!!\n", - coex_dm->pre_ps_tdma_on, coex_dm->cur_ps_tdma_on); - BTC_TRACE(trace_buf); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], pre_ps_tdma = %d, cur_ps_tdma = %d!!\n", - coex_dm->pre_ps_tdma, coex_dm->cur_ps_tdma); - BTC_TRACE(trace_buf); - - if ((coex_dm->pre_ps_tdma_on == coex_dm->cur_ps_tdma_on) && - (coex_dm->pre_ps_tdma == coex_dm->cur_ps_tdma)) - return; - } - - if (coex_sta->scan_ap_num >= 40) - wifi_duration_adjust = -15; - else if (coex_sta->scan_ap_num >= 20) - wifi_duration_adjust = -10; - - /* - if (!coex_sta->force_lps_on) - { - ps_tdma_byte0_val = 0x61; - ps_tdma_byte3_val = 0x11; - ps_tdma_byte4_val = 0x10; - } - - - if ( (type == 3) || (type == 13) || (type == 14) ) - { - ps_tdma_byte4_val = ps_tdma_byte4_val & 0xbf; - - if (!wifi_busy) - ps_tdma_byte4_val = ps_tdma_byte4_val | 0x1; - } - - if (bt_link_info->slave_role == true) - ps_tdma_byte4_val = ps_tdma_byte4_val | 0x1; - - */ - if (turn_on) { - switch (type) { - case 1: - default: /* d1,wb */ - halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x3c, 0x03, 0x11, 0x10); - break; - case 2: - halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x32, 0x03, 0x11, 0x10); - break; - case 3: - halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x28, 0x03, 0x11, 0x10); - break; - case 4: - halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x1e, 0x03, 0x11, 0x10); - break; - case 5: /* d1,pb,TXpause */ - halbtc8812a2ant_set_fw_pstdma(btcoexist, 0x63, - 0x3c, 0x03, 0x90, 0x10); - break; - case 6: - halbtc8812a2ant_set_fw_pstdma(btcoexist, 0x63, - 0x32, 0x03, 0x90, 0x10); - break; - case 7: - halbtc8812a2ant_set_fw_pstdma(btcoexist, 0x63, - 0x28, 0x03, 0x90, 0x10); - break; - case 8: - halbtc8812a2ant_set_fw_pstdma(btcoexist, 0x63, - 0x1e, 0x03, 0x90, 0x10); - break; - case 9: /* d1,bb */ - halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x3c, 0x03, 0x31, 0x10); - break; - case 10: - halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x32, 0x03, 0x31, 0x10); - break; - case 11: - halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x28, 0x03, 0x31, 0x10); - break; - case 12: - halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x1e, 0x03, 0x31, 0x10); - break; - case 13: /* d1,bb,TXpause */ - halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x3c, 0x03, 0x30, 0x10); - break; - case 14: - halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x32, 0x03, 0x30, 0x10); - break; - case 15: - halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x28, 0x03, 0x30, 0x10); - break; - case 16: - halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x1e, 0x03, 0x30, 0x10); - break; - case 17: - halbtc8812a2ant_set_fw_pstdma(btcoexist, 0x61, - 0x35, 0x3, 0x11, 0x11); - break; - case 18: - halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x5, 0x5, 0xe1, 0x90); - break; - case 19: - halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x25, 0x25, 0xe1, 0x90); - break; - case 20: - halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x25, 0x25, 0x60, 0x90); - break; - case 21: - halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x15, 0x3, 0x70, 0x90); - break; - case 22: - halbtc8812a2ant_set_fw_pstdma(btcoexist, 0x61, - 0x1a, 0x1a, 0x21, 0x10); - break; - case 23: - halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x1c, 0x03, 0x31, 0x10); - break; - - case 71: - halbtc8812a2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x1a, 0x1a, 0xe1, 0x90); - break; - - /* following cases is for wifi rssi low, started from 81 */ - case 80: - halbtc8812a2ant_set_fw_pstdma(btcoexist, 0x53, - 0x3c, 0x3, 0x90, 0x50); - break; - case 81: - halbtc8812a2ant_set_fw_pstdma(btcoexist, 0x53, - 0x3a + wifi_duration_adjust, 0x3, 0x90, - 0x50); - break; - case 82: - halbtc8812a2ant_set_fw_pstdma(btcoexist, 0x53, - 0x30 + wifi_duration_adjust, 0x03, 0x90, - 0x50); - break; - case 83: - halbtc8812a2ant_set_fw_pstdma(btcoexist, 0x53, - 0x21, 0x03, 0x90, 0x50); - break; - case 84: - halbtc8812a2ant_set_fw_pstdma(btcoexist, 0x53, - 0x15, 0x3, 0x90, 0x50); - break; - case 85: - halbtc8812a2ant_set_fw_pstdma(btcoexist, 0x53, - 0x1d, 0x1d, 0x80, 0x50); - break; - case 86: - halbtc8812a2ant_set_fw_pstdma(btcoexist, 0x53, - 0x15, 0x15, 0x80, 0x50); - break; - } - } else { - /* disable PS tdma */ - switch (type) { - case 0: /* ANT2PTA, 0x778=0x1 */ - halbtc8812a2ant_set_fw_pstdma(btcoexist, 0x8, - 0x0, 0x0, 0x0, 0x0); - break; - case 1: /* ANT2BT, 0x778=3 */ - halbtc8812a2ant_set_fw_pstdma(btcoexist, 0x0, - 0x0, 0x0, 0x8, 0x0); - delay_ms(5); - halbtc8812a2ant_set_ant_path(btcoexist, - BTC_ANT_WIFI_AT_CPL_AUX, false, false); - break; - case 2: /* ANT2BT, 0x778=3 */ - halbtc8812a2ant_set_fw_pstdma(btcoexist, 0x0, - 0x0, 0x0, 0x8, 0x0); - delay_ms(5); - halbtc8812a2ant_set_ant_path(btcoexist, - BTC_ANT_WIFI_AT_CPL_MAIN, false, false); - break; - default: - halbtc8812a2ant_set_fw_pstdma(btcoexist, 0x0, - 0x0, 0x0, 0x0, 0x0); - break; - } - } - - /* update pre state */ - coex_dm->pre_ps_tdma_on = coex_dm->cur_ps_tdma_on; - coex_dm->pre_ps_tdma = coex_dm->cur_ps_tdma; -} - - -void halbtc8812a2ant_ps_tdma_check_for_power_save_state( - IN struct btc_coexist *btcoexist, IN boolean new_ps_state) -{ - u8 lps_mode = 0x0; - - btcoexist->btc_get(btcoexist, BTC_GET_U1_LPS_MODE, &lps_mode); - - if (lps_mode) { /* already under LPS state */ - if (new_ps_state) { - /* keep state under LPS, do nothing. */ - } else { - /* will leave LPS state, turn off psTdma first */ - halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, - 0); - } - } else { /* NO PS state */ - if (new_ps_state) { - /* will enter LPS state, turn off psTdma first */ - halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, - 0); - } else { - /* keep state under NO PS state, do nothing. */ - } - } -} - - -void halbtc8812a2ant_power_save_state(IN struct btc_coexist *btcoexist, - IN u8 ps_type, IN u8 lps_val, IN u8 rpwm_val) -{ - boolean low_pwr_disable = false; - boolean ap_enable = false; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, - &ap_enable); - - if (ap_enable) { - ps_type = BTC_PS_WIFI_NATIVE; - lps_val = 0x0; - rpwm_val = 0x0; - } - switch (ps_type) { - case BTC_PS_WIFI_NATIVE: - /* recover to original 32k low power setting */ - low_pwr_disable = true; - btcoexist->btc_set(btcoexist, - BTC_SET_ACT_DISABLE_LOW_POWER, - &low_pwr_disable); - btcoexist->btc_set(btcoexist, BTC_SET_ACT_NORMAL_LPS, - NULL); - coex_sta->force_lps_on = false; - break; - case BTC_PS_LPS_ON: - halbtc8812a2ant_ps_tdma_check_for_power_save_state( - btcoexist, true); - halbtc8812a2ant_lps_rpwm(btcoexist, NORMAL_EXEC, - lps_val, rpwm_val); - /* when coex force to enter LPS, do not enter 32k low power. */ - low_pwr_disable = true; - btcoexist->btc_set(btcoexist, - BTC_SET_ACT_DISABLE_LOW_POWER, - &low_pwr_disable); - /* power save must executed before psTdma. */ - btcoexist->btc_set(btcoexist, BTC_SET_ACT_ENTER_LPS, - NULL); - coex_sta->force_lps_on = true; - break; - case BTC_PS_LPS_OFF: - halbtc8812a2ant_ps_tdma_check_for_power_save_state( - btcoexist, false); - btcoexist->btc_set(btcoexist, BTC_SET_ACT_LEAVE_LPS, - NULL); - coex_sta->force_lps_on = false; - break; - default: - break; - } -} - -void halbtc8812a2ant_coex_all_off(IN struct btc_coexist *btcoexist) -{ - /* fw all off */ - halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0, - 0x0); - halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1); - halbtc8812a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6); - halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - /* sw all off */ - halbtc8812a2ant_sw_mechanism1(btcoexist, false, false, false, false); - halbtc8812a2ant_sw_mechanism2(btcoexist, false, false, false, 0x18); - - /* hw all off */ - halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); -} - -void halbtc8812a2ant_init_coex_dm(IN struct btc_coexist *btcoexist) -{ - /* force to reset coex mechanism */ - halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0, - 0x0); - halbtc8812a2ant_ps_tdma(btcoexist, FORCE_EXEC, false, 1); - halbtc8812a2ant_fw_dac_swing_lvl(btcoexist, FORCE_EXEC, 6); - halbtc8812a2ant_dec_bt_pwr(btcoexist, FORCE_EXEC, 0); - - halbtc8812a2ant_coex_table_with_type(btcoexist, FORCE_EXEC, 0); - - halbtc8812a2ant_sw_mechanism1(btcoexist, false, false, false, false); - halbtc8812a2ant_sw_mechanism2(btcoexist, false, false, false, 0x18); -} - -void halbtc8812a2ant_monitor_bt_enable_disable(IN struct btc_coexist *btcoexist) -{ - struct btc_stack_info *stack_info = &btcoexist->stack_info; - static u32 bt_disable_cnt = 0; - boolean bt_active = true, bt_disabled = false; - - /* This function check if bt is disabled */ - - /* only 8812a need to consider if core stack is installed. */ - /*if (!stack_info->hci_version)*/ - /*bt_active = false;*/ - - bt_disabled = btcoexist->bt_info.bt_disabled; - - if (coex_sta->pre_bt_disabled != bt_disabled) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT is from %s to %s!!\n", - (coex_sta->pre_bt_disabled ? "disabled" : "enabled"), - (bt_disabled ? "disabled" : "enabled")); - BTC_TRACE(trace_buf); - coex_sta->pre_bt_disabled = bt_disabled; - - if (bt_disabled) { - halbtc8812a2ant_power_save_state(btcoexist, - BTC_PS_WIFI_NATIVE, 0x0, 0x0); - halbtc8812a2ant_ps_tdma(btcoexist, FORCE_EXEC, false, - 2); - halbtc8812a2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 0); - } - } -} - - -void halbtc8812a2ant_action_bt_inquiry(IN struct btc_coexist *btcoexist) -{ - halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0, - 0x0); - - halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2); - halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 3); - halbtc8812a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6); - halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - halbtc8812a2ant_sw_mechanism1(btcoexist, false, false, false, false); - halbtc8812a2ant_sw_mechanism2(btcoexist, false, false, false, 0x18); -} - - -boolean halbtc8812a2ant_is_common_action(IN struct btc_coexist *btcoexist) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - boolean common = false, wifi_connected = false, wifi_busy = false; - boolean bt_hs_on = false; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - - - if (coex_sta->c2h_bt_inquiry_page) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT is under inquiry/page scan !!\n"); - BTC_TRACE(trace_buf); - halbtc8812a2ant_action_bt_inquiry(btcoexist); - return true; - } - - if (bt_link_info->sco_exist || bt_link_info->hid_exist) - halbtc8812a2ant_limited_tx(btcoexist, NORMAL_EXEC, 1, 0, 0, 0); - else - halbtc8812a2ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0); - - if (!wifi_connected) { - halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, - 0x0, 0x0); - halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, - 0x8); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi non-connected idle!!\n"); - BTC_TRACE(trace_buf); - - if ((BT_8812A_2ANT_BT_STATUS_NON_CONNECTED_IDLE == - coex_dm->bt_status) || - (BT_8812A_2ANT_BT_STATUS_CONNECTED_IDLE == - coex_dm->bt_status)) { - halbtc8812a2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 1); - halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, - 0); - } else { - halbtc8812a2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 0); - halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, - 1); - } - - halbtc8812a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6); - halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - halbtc8812a2ant_sw_mechanism1(btcoexist, false, false, false, - false); - halbtc8812a2ant_sw_mechanism2(btcoexist, false, false, false, - 0x18); - - common = true; - } else { - if (BT_8812A_2ANT_BT_STATUS_NON_CONNECTED_IDLE == - coex_dm->bt_status) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi connected + BT non connected-idle!!\n"); - BTC_TRACE(trace_buf); - halbtc8812a2ant_power_save_state(btcoexist, - BTC_PS_WIFI_NATIVE, 0x0, 0x0); - halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, - false, false, 0x8); - - halbtc8812a2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 0); - halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, - 0); - halbtc8812a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, - 6); - halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - halbtc8812a2ant_sw_mechanism1(btcoexist, false, false, - false, false); - halbtc8812a2ant_sw_mechanism2(btcoexist, false, false, - false, 0x18); - - common = true; - } else if (BT_8812A_2ANT_BT_STATUS_CONNECTED_IDLE == - coex_dm->bt_status) { - if (bt_hs_on) - return false; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi connected + BT connected-idle!!\n"); - BTC_TRACE(trace_buf); - halbtc8812a2ant_power_save_state(btcoexist, - BTC_PS_WIFI_NATIVE, 0x0, 0x0); - halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, - false, false, 0x8); - - halbtc8812a2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 0); - halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, - 0); - halbtc8812a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, - 6); - halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - halbtc8812a2ant_sw_mechanism1(btcoexist, true, false, - false, false); - halbtc8812a2ant_sw_mechanism2(btcoexist, false, false, - false, 0x18); - - common = true; - } else { - if (wifi_busy) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi Connected-Busy + BT Busy!!\n"); - BTC_TRACE(trace_buf); - common = false; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi Connected-Idle + BT Busy!!\n"); - BTC_TRACE(trace_buf); - - halbtc8812a2ant_power_save_state(btcoexist, - BTC_PS_WIFI_NATIVE, 0x0, 0x0); - - halbtc8812a2ant_limited_rx(btcoexist, - NORMAL_EXEC, false, false, 0x8); - - halbtc8812a2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 0); - - halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 17); - - halbtc8812a2ant_fw_dac_swing_lvl(btcoexist, - NORMAL_EXEC, 6); - halbtc8812a2ant_dec_bt_pwr(btcoexist, - NORMAL_EXEC, 0); - halbtc8812a2ant_sw_mechanism1(btcoexist, false, - false, false, false); - halbtc8812a2ant_sw_mechanism2(btcoexist, false, - false, false, 0x18); - common = true; - } - } - } - - return common; -} - -void halbtc8812a2ant_tdma_duration_adjust(IN struct btc_coexist *btcoexist, - IN boolean sco_hid, IN boolean tx_pause, IN u8 max_interval) -{ - static s32 up, dn, m, n, wait_count; - s32 result; /* 0: no change, +1: increase WiFi duration, -1: decrease WiFi duration */ - u8 retry_count = 0; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], TdmaDurationAdjust()\n"); - BTC_TRACE(trace_buf); - - coex_dm->auto_tdma_adjust_low_rssi = false; - - if (!coex_dm->auto_tdma_adjust) { - coex_dm->auto_tdma_adjust = true; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], first run TdmaDurationAdjust()!!\n"); - BTC_TRACE(trace_buf); - { - if (sco_hid) { - if (tx_pause) { - if (max_interval == 1) { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 13); - coex_dm->ps_tdma_du_adj_type = - 13; - } else if (max_interval == 2) { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 14); - coex_dm->ps_tdma_du_adj_type = - 14; - } else if (max_interval == 3) { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 15); - coex_dm->ps_tdma_du_adj_type = - 15; - } else { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 15); - coex_dm->ps_tdma_du_adj_type = - 15; - } - } else { - if (max_interval == 1) { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 9); - coex_dm->ps_tdma_du_adj_type = - 9; - } else if (max_interval == 2) { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 10); - coex_dm->ps_tdma_du_adj_type = - 10; - } else if (max_interval == 3) { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 11); - coex_dm->ps_tdma_du_adj_type = - 11; - } else { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 11); - coex_dm->ps_tdma_du_adj_type = - 11; - } - } - } else { - if (tx_pause) { - if (max_interval == 1) { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 5); - coex_dm->ps_tdma_du_adj_type = - 5; - } else if (max_interval == 2) { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 6); - coex_dm->ps_tdma_du_adj_type = - 6; - } else if (max_interval == 3) { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 7); - coex_dm->ps_tdma_du_adj_type = - 7; - } else { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 7); - coex_dm->ps_tdma_du_adj_type = - 7; - } - } else { - if (max_interval == 1) { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 1); - coex_dm->ps_tdma_du_adj_type = - 1; - } else if (max_interval == 2) { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 2); - coex_dm->ps_tdma_du_adj_type = - 2; - } else if (max_interval == 3) { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 3); - coex_dm->ps_tdma_du_adj_type = - 3; - } else { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 3); - coex_dm->ps_tdma_du_adj_type = - 3; - } - } - } - } - /* ============ */ - up = 0; - dn = 0; - m = 1; - n = 3; - result = 0; - wait_count = 0; - } else { - /* acquire the BT TRx retry count from BT_Info byte2 */ - retry_count = coex_sta->bt_retry_cnt; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], retry_count = %d\n", - retry_count); - BTC_TRACE(trace_buf); - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], up=%d, dn=%d, m=%d, n=%d, wait_count=%d\n", - up, dn, m, n, wait_count); - BTC_TRACE(trace_buf); - - result = 0; - wait_count++; - - if (retry_count == - 0) { /* no retry in the last 2-second duration */ - up++; - dn--; - - if (dn <= 0) - dn = 0; - - if (up >= n) { /* if ³sÄò n ­Ó2¬í retry count¬°0, «h½Õ¼eWiFi duration */ - wait_count = 0; - n = 3; - up = 0; - dn = 0; - result = 1; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Increase wifi duration!!\n"); - BTC_TRACE(trace_buf); - } - } else if (retry_count <= - 3) { /* <=3 retry in the last 2-second duration */ - up--; - dn++; - - if (up <= 0) - up = 0; - - if (dn == 2) { /* if ³sÄò 2 ­Ó2¬í retry count< 3, «h½Õ¯¶WiFi duration */ - if (wait_count <= 2) - m++; /* ÁקK¤@ª½¦b¨â­Ólevel¤¤¨Ó¦^ */ - else - m = 1; - - if (m >= 20) /* m ³Ì¤j­È = 20 ' ³Ì¤j120¬í recheck¬O§_½Õ¾ã WiFi duration. */ - m = 20; - - n = 3 * m; - up = 0; - dn = 0; - wait_count = 0; - result = -1; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Decrease wifi duration for retry_counter<3!!\n"); - BTC_TRACE(trace_buf); - } - } else { /* retry count > 3, ¥u­n1¦¸ retry count > 3, «h½Õ¯¶WiFi duration */ - if (wait_count == 1) - m++; /* ÁקK¤@ª½¦b¨â­Ólevel¤¤¨Ó¦^ */ - else - m = 1; - - if (m >= 20) /* m ³Ì¤j­È = 20 ' ³Ì¤j120¬í recheck¬O§_½Õ¾ã WiFi duration. */ - m = 20; - - n = 3 * m; - up = 0; - dn = 0; - wait_count = 0; - result = -1; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Decrease wifi duration for retry_counter>3!!\n"); - BTC_TRACE(trace_buf); - } - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], max Interval = %d\n", - max_interval); - BTC_TRACE(trace_buf); - - if (max_interval == 1) { - if (tx_pause) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], TxPause = 1\n"); - BTC_TRACE(trace_buf); - - if (coex_dm->cur_ps_tdma == 1) { - halbtc8812a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 5); - coex_dm->ps_tdma_du_adj_type = 5; - } else if (coex_dm->cur_ps_tdma == 2) { - halbtc8812a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 6); - coex_dm->ps_tdma_du_adj_type = 6; - } else if (coex_dm->cur_ps_tdma == 3) { - halbtc8812a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 7); - coex_dm->ps_tdma_du_adj_type = 7; - } else if (coex_dm->cur_ps_tdma == 4) { - halbtc8812a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 8); - coex_dm->ps_tdma_du_adj_type = 8; - } - if (coex_dm->cur_ps_tdma == 9) { - halbtc8812a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 13); - coex_dm->ps_tdma_du_adj_type = 13; - } else if (coex_dm->cur_ps_tdma == 10) { - halbtc8812a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 14); - coex_dm->ps_tdma_du_adj_type = 14; - } else if (coex_dm->cur_ps_tdma == 11) { - halbtc8812a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 15); - coex_dm->ps_tdma_du_adj_type = 15; - } else if (coex_dm->cur_ps_tdma == 12) { - halbtc8812a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 16); - coex_dm->ps_tdma_du_adj_type = 16; - } - - if (result == -1) { - if (coex_dm->cur_ps_tdma == 5) { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 6); - coex_dm->ps_tdma_du_adj_type = - 6; - } else if (coex_dm->cur_ps_tdma == 6) { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 7); - coex_dm->ps_tdma_du_adj_type = - 7; - } else if (coex_dm->cur_ps_tdma == 7) { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 8); - coex_dm->ps_tdma_du_adj_type = - 8; - } else if (coex_dm->cur_ps_tdma == 13) { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 14); - coex_dm->ps_tdma_du_adj_type = - 14; - } else if (coex_dm->cur_ps_tdma == 14) { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 15); - coex_dm->ps_tdma_du_adj_type = - 15; - } else if (coex_dm->cur_ps_tdma == 15) { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 16); - coex_dm->ps_tdma_du_adj_type = - 16; - } - } else if (result == 1) { - if (coex_dm->cur_ps_tdma == 8) { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 7); - coex_dm->ps_tdma_du_adj_type = - 7; - } else if (coex_dm->cur_ps_tdma == 7) { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 6); - coex_dm->ps_tdma_du_adj_type = - 6; - } else if (coex_dm->cur_ps_tdma == 6) { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 5); - coex_dm->ps_tdma_du_adj_type = - 5; - } else if (coex_dm->cur_ps_tdma == 16) { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 15); - coex_dm->ps_tdma_du_adj_type = - 15; - } else if (coex_dm->cur_ps_tdma == 15) { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 14); - coex_dm->ps_tdma_du_adj_type = - 14; - } else if (coex_dm->cur_ps_tdma == 14) { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 13); - coex_dm->ps_tdma_du_adj_type = - 13; - } - } - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], TxPause = 0\n"); - BTC_TRACE(trace_buf); - - if (coex_dm->cur_ps_tdma == 5) { - halbtc8812a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 1); - coex_dm->ps_tdma_du_adj_type = 1; - } else if (coex_dm->cur_ps_tdma == 6) { - halbtc8812a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 2); - coex_dm->ps_tdma_du_adj_type = 2; - } else if (coex_dm->cur_ps_tdma == 7) { - halbtc8812a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 3); - coex_dm->ps_tdma_du_adj_type = 3; - } else if (coex_dm->cur_ps_tdma == 8) { - halbtc8812a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 4); - coex_dm->ps_tdma_du_adj_type = 4; - } - if (coex_dm->cur_ps_tdma == 13) { - halbtc8812a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 9); - coex_dm->ps_tdma_du_adj_type = 9; - } else if (coex_dm->cur_ps_tdma == 14) { - halbtc8812a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 10); - coex_dm->ps_tdma_du_adj_type = 10; - } else if (coex_dm->cur_ps_tdma == 15) { - halbtc8812a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 11); - coex_dm->ps_tdma_du_adj_type = 11; - } else if (coex_dm->cur_ps_tdma == 16) { - halbtc8812a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 12); - coex_dm->ps_tdma_du_adj_type = 12; - } - - if (result == -1) { - if (coex_dm->cur_ps_tdma == 1) { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 2); - coex_dm->ps_tdma_du_adj_type = - 2; - } else if (coex_dm->cur_ps_tdma == 2) { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 3); - coex_dm->ps_tdma_du_adj_type = - 3; - } else if (coex_dm->cur_ps_tdma == 3) { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 4); - coex_dm->ps_tdma_du_adj_type = - 4; - } else if (coex_dm->cur_ps_tdma == 9) { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 10); - coex_dm->ps_tdma_du_adj_type = - 10; - } else if (coex_dm->cur_ps_tdma == 10) { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 11); - coex_dm->ps_tdma_du_adj_type = - 11; - } else if (coex_dm->cur_ps_tdma == 11) { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 12); - coex_dm->ps_tdma_du_adj_type = - 12; - } - } else if (result == 1) { - if (coex_dm->cur_ps_tdma == 4) { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 3); - coex_dm->ps_tdma_du_adj_type = - 3; - } else if (coex_dm->cur_ps_tdma == 3) { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 2); - coex_dm->ps_tdma_du_adj_type = - 2; - } else if (coex_dm->cur_ps_tdma == 2) { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 1); - coex_dm->ps_tdma_du_adj_type = - 1; - } else if (coex_dm->cur_ps_tdma == 12) { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 11); - coex_dm->ps_tdma_du_adj_type = - 11; - } else if (coex_dm->cur_ps_tdma == 11) { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 10); - coex_dm->ps_tdma_du_adj_type = - 10; - } else if (coex_dm->cur_ps_tdma == 10) { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 9); - coex_dm->ps_tdma_du_adj_type = - 9; - } - } - } - } else if (max_interval == 2) { - if (tx_pause) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], TxPause = 1\n"); - BTC_TRACE(trace_buf); - - if (coex_dm->cur_ps_tdma == 1) { - halbtc8812a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 6); - coex_dm->ps_tdma_du_adj_type = 6; - } else if (coex_dm->cur_ps_tdma == 2) { - halbtc8812a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 6); - coex_dm->ps_tdma_du_adj_type = 6; - } else if (coex_dm->cur_ps_tdma == 3) { - halbtc8812a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 7); - coex_dm->ps_tdma_du_adj_type = 7; - } else if (coex_dm->cur_ps_tdma == 4) { - halbtc8812a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 8); - coex_dm->ps_tdma_du_adj_type = 8; - } - if (coex_dm->cur_ps_tdma == 9) { - halbtc8812a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 14); - coex_dm->ps_tdma_du_adj_type = 14; - } else if (coex_dm->cur_ps_tdma == 10) { - halbtc8812a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 14); - coex_dm->ps_tdma_du_adj_type = 14; - } else if (coex_dm->cur_ps_tdma == 11) { - halbtc8812a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 15); - coex_dm->ps_tdma_du_adj_type = 15; - } else if (coex_dm->cur_ps_tdma == 12) { - halbtc8812a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 16); - coex_dm->ps_tdma_du_adj_type = 16; - } - if (result == -1) { - if (coex_dm->cur_ps_tdma == 5) { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 6); - coex_dm->ps_tdma_du_adj_type = - 6; - } else if (coex_dm->cur_ps_tdma == 6) { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 7); - coex_dm->ps_tdma_du_adj_type = - 7; - } else if (coex_dm->cur_ps_tdma == 7) { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 8); - coex_dm->ps_tdma_du_adj_type = - 8; - } else if (coex_dm->cur_ps_tdma == 13) { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 14); - coex_dm->ps_tdma_du_adj_type = - 14; - } else if (coex_dm->cur_ps_tdma == 14) { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 15); - coex_dm->ps_tdma_du_adj_type = - 15; - } else if (coex_dm->cur_ps_tdma == 15) { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 16); - coex_dm->ps_tdma_du_adj_type = - 16; - } - } else if (result == 1) { - if (coex_dm->cur_ps_tdma == 8) { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 7); - coex_dm->ps_tdma_du_adj_type = - 7; - } else if (coex_dm->cur_ps_tdma == 7) { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 6); - coex_dm->ps_tdma_du_adj_type = - 6; - } else if (coex_dm->cur_ps_tdma == 6) { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 6); - coex_dm->ps_tdma_du_adj_type = - 6; - } else if (coex_dm->cur_ps_tdma == 16) { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 15); - coex_dm->ps_tdma_du_adj_type = - 15; - } else if (coex_dm->cur_ps_tdma == 15) { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 14); - coex_dm->ps_tdma_du_adj_type = - 14; - } else if (coex_dm->cur_ps_tdma == 14) { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 14); - coex_dm->ps_tdma_du_adj_type = - 14; - } - } - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], TxPause = 0\n"); - BTC_TRACE(trace_buf); - - if (coex_dm->cur_ps_tdma == 5) { - halbtc8812a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 2); - coex_dm->ps_tdma_du_adj_type = 2; - } else if (coex_dm->cur_ps_tdma == 6) { - halbtc8812a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 2); - coex_dm->ps_tdma_du_adj_type = 2; - } else if (coex_dm->cur_ps_tdma == 7) { - halbtc8812a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 3); - coex_dm->ps_tdma_du_adj_type = 3; - } else if (coex_dm->cur_ps_tdma == 8) { - halbtc8812a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 4); - coex_dm->ps_tdma_du_adj_type = 4; - } - if (coex_dm->cur_ps_tdma == 13) { - halbtc8812a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 10); - coex_dm->ps_tdma_du_adj_type = 10; - } else if (coex_dm->cur_ps_tdma == 14) { - halbtc8812a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 10); - coex_dm->ps_tdma_du_adj_type = 10; - } else if (coex_dm->cur_ps_tdma == 15) { - halbtc8812a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 11); - coex_dm->ps_tdma_du_adj_type = 11; - } else if (coex_dm->cur_ps_tdma == 16) { - halbtc8812a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 12); - coex_dm->ps_tdma_du_adj_type = 12; - } - if (result == -1) { - if (coex_dm->cur_ps_tdma == 1) { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 2); - coex_dm->ps_tdma_du_adj_type = - 2; - } else if (coex_dm->cur_ps_tdma == 2) { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 3); - coex_dm->ps_tdma_du_adj_type = - 3; - } else if (coex_dm->cur_ps_tdma == 3) { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 4); - coex_dm->ps_tdma_du_adj_type = - 4; - } else if (coex_dm->cur_ps_tdma == 9) { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 10); - coex_dm->ps_tdma_du_adj_type = - 10; - } else if (coex_dm->cur_ps_tdma == 10) { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 11); - coex_dm->ps_tdma_du_adj_type = - 11; - } else if (coex_dm->cur_ps_tdma == 11) { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 12); - coex_dm->ps_tdma_du_adj_type = - 12; - } - } else if (result == 1) { - if (coex_dm->cur_ps_tdma == 4) { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 3); - coex_dm->ps_tdma_du_adj_type = - 3; - } else if (coex_dm->cur_ps_tdma == 3) { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 2); - coex_dm->ps_tdma_du_adj_type = - 2; - } else if (coex_dm->cur_ps_tdma == 2) { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 2); - coex_dm->ps_tdma_du_adj_type = - 2; - } else if (coex_dm->cur_ps_tdma == 12) { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 11); - coex_dm->ps_tdma_du_adj_type = - 11; - } else if (coex_dm->cur_ps_tdma == 11) { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 10); - coex_dm->ps_tdma_du_adj_type = - 10; - } else if (coex_dm->cur_ps_tdma == 10) { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 10); - coex_dm->ps_tdma_du_adj_type = - 10; - } - } - } - } else if (max_interval == 3) { - if (tx_pause) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], TxPause = 1\n"); - BTC_TRACE(trace_buf); - - if (coex_dm->cur_ps_tdma == 1) { - halbtc8812a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 7); - coex_dm->ps_tdma_du_adj_type = 7; - } else if (coex_dm->cur_ps_tdma == 2) { - halbtc8812a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 7); - coex_dm->ps_tdma_du_adj_type = 7; - } else if (coex_dm->cur_ps_tdma == 3) { - halbtc8812a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 7); - coex_dm->ps_tdma_du_adj_type = 7; - } else if (coex_dm->cur_ps_tdma == 4) { - halbtc8812a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 8); - coex_dm->ps_tdma_du_adj_type = 8; - } - if (coex_dm->cur_ps_tdma == 9) { - halbtc8812a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 15); - coex_dm->ps_tdma_du_adj_type = 15; - } else if (coex_dm->cur_ps_tdma == 10) { - halbtc8812a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 15); - coex_dm->ps_tdma_du_adj_type = 15; - } else if (coex_dm->cur_ps_tdma == 11) { - halbtc8812a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 15); - coex_dm->ps_tdma_du_adj_type = 15; - } else if (coex_dm->cur_ps_tdma == 12) { - halbtc8812a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 16); - coex_dm->ps_tdma_du_adj_type = 16; - } - if (result == -1) { - if (coex_dm->cur_ps_tdma == 5) { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 7); - coex_dm->ps_tdma_du_adj_type = - 7; - } else if (coex_dm->cur_ps_tdma == 6) { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 7); - coex_dm->ps_tdma_du_adj_type = - 7; - } else if (coex_dm->cur_ps_tdma == 7) { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 8); - coex_dm->ps_tdma_du_adj_type = - 8; - } else if (coex_dm->cur_ps_tdma == 13) { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 15); - coex_dm->ps_tdma_du_adj_type = - 15; - } else if (coex_dm->cur_ps_tdma == 14) { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 15); - coex_dm->ps_tdma_du_adj_type = - 15; - } else if (coex_dm->cur_ps_tdma == 15) { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 16); - coex_dm->ps_tdma_du_adj_type = - 16; - } - } else if (result == 1) { - if (coex_dm->cur_ps_tdma == 8) { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 7); - coex_dm->ps_tdma_du_adj_type = - 7; - } else if (coex_dm->cur_ps_tdma == 7) { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 7); - coex_dm->ps_tdma_du_adj_type = - 7; - } else if (coex_dm->cur_ps_tdma == 6) { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 7); - coex_dm->ps_tdma_du_adj_type = - 7; - } else if (coex_dm->cur_ps_tdma == 16) { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 15); - coex_dm->ps_tdma_du_adj_type = - 15; - } else if (coex_dm->cur_ps_tdma == 15) { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 15); - coex_dm->ps_tdma_du_adj_type = - 15; - } else if (coex_dm->cur_ps_tdma == 14) { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 15); - coex_dm->ps_tdma_du_adj_type = - 15; - } - } - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], TxPause = 0\n"); - BTC_TRACE(trace_buf); - - if (coex_dm->cur_ps_tdma == 5) { - halbtc8812a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 3); - coex_dm->ps_tdma_du_adj_type = 3; - } else if (coex_dm->cur_ps_tdma == 6) { - halbtc8812a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 3); - coex_dm->ps_tdma_du_adj_type = 3; - } else if (coex_dm->cur_ps_tdma == 7) { - halbtc8812a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 3); - coex_dm->ps_tdma_du_adj_type = 3; - } else if (coex_dm->cur_ps_tdma == 8) { - halbtc8812a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 4); - coex_dm->ps_tdma_du_adj_type = 4; - } - if (coex_dm->cur_ps_tdma == 13) { - halbtc8812a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 11); - coex_dm->ps_tdma_du_adj_type = 11; - } else if (coex_dm->cur_ps_tdma == 14) { - halbtc8812a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 11); - coex_dm->ps_tdma_du_adj_type = 11; - } else if (coex_dm->cur_ps_tdma == 15) { - halbtc8812a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 11); - coex_dm->ps_tdma_du_adj_type = 11; - } else if (coex_dm->cur_ps_tdma == 16) { - halbtc8812a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 12); - coex_dm->ps_tdma_du_adj_type = 12; - } - if (result == -1) { - if (coex_dm->cur_ps_tdma == 1) { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 3); - coex_dm->ps_tdma_du_adj_type = - 3; - } else if (coex_dm->cur_ps_tdma == 2) { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 3); - coex_dm->ps_tdma_du_adj_type = - 3; - } else if (coex_dm->cur_ps_tdma == 3) { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 4); - coex_dm->ps_tdma_du_adj_type = - 4; - } else if (coex_dm->cur_ps_tdma == 9) { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 11); - coex_dm->ps_tdma_du_adj_type = - 11; - } else if (coex_dm->cur_ps_tdma == 10) { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 11); - coex_dm->ps_tdma_du_adj_type = - 11; - } else if (coex_dm->cur_ps_tdma == 11) { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 12); - coex_dm->ps_tdma_du_adj_type = - 12; - } - } else if (result == 1) { - if (coex_dm->cur_ps_tdma == 4) { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 3); - coex_dm->ps_tdma_du_adj_type = - 3; - } else if (coex_dm->cur_ps_tdma == 3) { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 3); - coex_dm->ps_tdma_du_adj_type = - 3; - } else if (coex_dm->cur_ps_tdma == 2) { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 3); - coex_dm->ps_tdma_du_adj_type = - 3; - } else if (coex_dm->cur_ps_tdma == 12) { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 11); - coex_dm->ps_tdma_du_adj_type = - 11; - } else if (coex_dm->cur_ps_tdma == 11) { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 11); - coex_dm->ps_tdma_du_adj_type = - 11; - } else if (coex_dm->cur_ps_tdma == 10) { - halbtc8812a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 11); - coex_dm->ps_tdma_du_adj_type = - 11; - } - } - } - } - } - - /* if current PsTdma not match with the recorded one (when scan, dhcp...), */ - /* then we have to adjust it back to the previous record one. */ - if (coex_dm->cur_ps_tdma != coex_dm->ps_tdma_du_adj_type) { - boolean scan = false, link = false, roam = false; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], PsTdma type dismatch!!!, cur_ps_tdma=%d, recordPsTdma=%d\n", - coex_dm->cur_ps_tdma, coex_dm->ps_tdma_du_adj_type); - BTC_TRACE(trace_buf); - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam); - - if (!scan && !link && !roam) - halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - coex_dm->ps_tdma_du_adj_type); - else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], roaming/link/scan is under progress, will adjust next time!!!\n"); - BTC_TRACE(trace_buf); - } - } -} - -/* ****************** - * pstdma for wifi rssi low - * ****************** */ -void halbtc8812a2ant_tdma_duration_adjust_for_wifi_rssi_low( - IN struct btc_coexist *btcoexist/* , */ /* IN u8 wifi_status */) -{ - static s32 up, dn, m, n, wait_count; - s32 result; /* 0: no change, +1: increase WiFi duration, -1: decrease WiFi duration */ - u8 retry_count = 0, bt_info_ext; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], halbtc8812a2ant_tdma_duration_adjust_for_wifi_rssi_low()\n"); - BTC_TRACE(trace_buf); -#if 0 - if ((BT_8812A_2ANT_WIFI_STATUS_NON_CONNECTED_ASSO_AUTH_SCAN == - wifi_status) || - (BT_8812A_2ANT_WIFI_STATUS_CONNECTED_SCAN == wifi_status) || - (BT_8812A_2ANT_WIFI_STATUS_CONNECTED_SPECIAL_PKT == - wifi_status)) { - if (coex_dm->cur_ps_tdma != 81 && - coex_dm->cur_ps_tdma != 82 && - coex_dm->cur_ps_tdma != 83 && - coex_dm->cur_ps_tdma != 84) { - halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 82); - coex_dm->ps_tdma_du_adj_type = 82; - - up = 0; - dn = 0; - m = 1; - n = 3; - result = 0; - wait_count = 0; - } - return; - } -#endif - coex_dm->auto_tdma_adjust = false; - - retry_count = coex_sta->bt_retry_cnt; - bt_info_ext = coex_sta->bt_info_ext; - - if (!coex_dm->auto_tdma_adjust_low_rssi) { - coex_dm->auto_tdma_adjust_low_rssi = true; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], first run TdmaDurationAdjustForWifiRssiLow()!!\n"); - BTC_TRACE(trace_buf); - - if (BT_INFO_8812A_2ANT_A2DP_BASIC_RATE(bt_info_ext)) { - halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 83); - coex_dm->ps_tdma_du_adj_type = 83; - } else { - halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 82); - coex_dm->ps_tdma_du_adj_type = 82; - } - /* ============ */ - up = 0; - dn = 0; - m = 1; - n = 3; - result = 0; - wait_count = 0; - } else { - /* acquire the BT TRx retry count from BT_Info byte2 - * retry_count = coex_sta->bt_retry_cnt; - * bt_info_ext = coex_sta->bt_info_ext; */ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], retry_count = %d\n", - retry_count); - BTC_TRACE(trace_buf); - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], up=%d, dn=%d, m=%d, n=%d, wait_count=%d\n", - up, dn, m, n, wait_count); - BTC_TRACE(trace_buf); - result = 0; - wait_count++; - - if ((coex_sta->low_priority_tx) > 1050 || - (coex_sta->low_priority_rx) > 1250) - retry_count++; - - if (retry_count == - 0) { /* no retry in the last 2-second duration */ - up++; - dn--; - - if (dn <= 0) - dn = 0; - - if (up >= n) { /* if ³sÄò n ­Ó2¬í retry count¬°0, «h½Õ¼eWiFi duration */ - wait_count = 0; - n = 3; - up = 0; - dn = 0; - result = 1; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Increase wifi duration!!\n"); - BTC_TRACE(trace_buf); - } - } else if (retry_count <= - 3) { /* <=3 retry in the last 2-second duration */ - up--; - dn++; - - if (up <= 0) - up = 0; - - if (dn == 2) { /* if ³sÄò 2 ­Ó2¬í retry count< 3, «h½Õ¯¶WiFi duration */ - if (wait_count <= 2) - m++; /* ÁקK¤@ª½¦b¨â­Ólevel¤¤¨Ó¦^ */ - else - m = 1; - - if (m >= 20) /* m ³Ì¤j­È = 20 ' ³Ì¤j120¬í recheck¬O§_½Õ¾ã WiFi duration. */ - m = 20; - - n = 3 * m; - up = 0; - dn = 0; - wait_count = 0; - result = -1; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Decrease wifi duration for retry_counter<3!!\n"); - BTC_TRACE(trace_buf); - } - } else { /* retry count > 3, ¥u­n1¦¸ retry count > 3, «h½Õ¯¶WiFi duration */ - if (wait_count == 1) - m++; /* ÁקK¤@ª½¦b¨â­Ólevel¤¤¨Ó¦^ */ - else - m = 1; - - if (m >= 20) /* m ³Ì¤j­È = 20 ' ³Ì¤j120¬í recheck¬O§_½Õ¾ã WiFi duration. */ - m = 20; - - n = 3 * m; - up = 0; - dn = 0; - wait_count = 0; - result = -1; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Decrease wifi duration for retry_counter>3!!\n"); - BTC_TRACE(trace_buf); - } - - if (result == -1) { - /* - if( (BT_INFO_8812A_2ANT_A2DP_BASIC_RATE(bt_info_ext)) && - ((coex_dm->cur_ps_tdma == 81) ||(coex_dm->cur_ps_tdma == 82)) ) - { - halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 84); - coex_dm->ps_tdma_du_adj_type = 84; - } - */ - if (coex_dm->cur_ps_tdma == 80) { - halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 82); - coex_dm->ps_tdma_du_adj_type = 82; - } else if (coex_dm->cur_ps_tdma == 81) { - halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 82); - coex_dm->ps_tdma_du_adj_type = 82; - } else if (coex_dm->cur_ps_tdma == 82) { - halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 83); - coex_dm->ps_tdma_du_adj_type = 83; - } else if (coex_dm->cur_ps_tdma == 83) { - halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 84); - coex_dm->ps_tdma_du_adj_type = 84; - } - } else if (result == 1) { - /* - if( (BT_INFO_8812A_2ANT_A2DP_BASIC_RATE(bt_info_ext)) && - ((coex_dm->cur_ps_tdma == 81) ||(coex_dm->cur_ps_tdma == 82)) ) - { - halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 83); - coex_dm->ps_tdma_du_adj_type = 83; - } - */ - if (coex_dm->cur_ps_tdma == 84) { - halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 83); - coex_dm->ps_tdma_du_adj_type = 83; - } else if (coex_dm->cur_ps_tdma == 83) { - halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 82); - coex_dm->ps_tdma_du_adj_type = 82; - } else if (coex_dm->cur_ps_tdma == 82) { - halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 81); - coex_dm->ps_tdma_du_adj_type = 81; - } else if ((coex_dm->cur_ps_tdma == 81) && - ((coex_sta->scan_ap_num <= 5))) { - halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 81); - coex_dm->ps_tdma_du_adj_type = 81; - } - } - - if (coex_dm->cur_ps_tdma != 80 && - coex_dm->cur_ps_tdma != 81 && - coex_dm->cur_ps_tdma != 82 && - coex_dm->cur_ps_tdma != 83 && - coex_dm->cur_ps_tdma != 84) { - /* recover to previous adjust type */ - halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - coex_dm->ps_tdma_du_adj_type); - } - } -} - -void halbtc8812a2ant_get_bt_rssi_threshold(IN struct btc_coexist *btcoexist, - IN u8 *pThres0, IN u8 *pThres1) -{ - u8 ant_type; - - btcoexist->btc_get(btcoexist, BTC_GET_U1_ANT_TYPE, &ant_type); - - - switch (ant_type) { - case BTC_ANT_TYPE_0: - *pThres0 = 100; - *pThres1 = 100; - break; - case BTC_ANT_TYPE_1: - *pThres0 = 34; - *pThres1 = 42; - break; - case BTC_ANT_TYPE_2: - *pThres0 = 34; - *pThres1 = 42; - break; - case BTC_ANT_TYPE_3: - *pThres0 = 34; - *pThres1 = 42; - break; - case BTC_ANT_TYPE_4: - *pThres0 = 34; - *pThres1 = 42; - break; - default: - break; - } -} - - - -void halbtc8812a2ant_action_sco(IN struct btc_coexist *btcoexist) -{ - u8 wifi_rssi_state = BTC_RSSI_STATE_HIGH, - bt_rssi_state = BTC_RSSI_STATE_HIGH; - u32 wifi_bw; - u8 bt_thresh0 = 0, bt_thresh1 = 0; - - - /* halbtc8812a2ant_get_bt_rssi_threshold(btcoexist, &bt_thresh0, &bt_thresh1); */ - bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, bt_thresh0, - bt_thresh1); - - wifi_rssi_state = halbtc8812a2ant_wifi_rssi_state(btcoexist, 0, 2, 34, - 0); - bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, 34, 42); - - /* power save state */ - halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0, - 0x0); - - /* coex table */ - if (BTC_RSSI_LOW(bt_rssi_state)) - halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 5); - else - halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); - - /* pstdma */ - if (BTC_RSSI_LOW(bt_rssi_state)) - halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 13); - else - halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 9); - - /* decrease BT power */ - if (BTC_RSSI_LOW(bt_rssi_state)) - halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - else if (BTC_RSSI_MEDIUM(bt_rssi_state)) - halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2); - else - halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 4); - - /* limited Rx */ - halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8); - - /* fw dac swing level */ - halbtc8812a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6); - - - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw); - /* sw mechanism */ - if (BTC_WIFI_BW_HT40 == wifi_bw) { - if (BTC_RSSI_HIGH(wifi_rssi_state)) { - halbtc8812a2ant_sw_mechanism1(btcoexist, true, true, - false, false); - halbtc8812a2ant_sw_mechanism2(btcoexist, true, false, - true, 0x6); - } else { - halbtc8812a2ant_sw_mechanism1(btcoexist, true, true, - false, false); - halbtc8812a2ant_sw_mechanism2(btcoexist, false, false, - true, 0x6); - } - } else { - if (BTC_RSSI_HIGH(wifi_rssi_state)) { - halbtc8812a2ant_sw_mechanism1(btcoexist, false, true, - false, false); - halbtc8812a2ant_sw_mechanism2(btcoexist, true, false, - true, 0x6); - } else { - halbtc8812a2ant_sw_mechanism1(btcoexist, false, true, - false, false); - halbtc8812a2ant_sw_mechanism2(btcoexist, false, false, - true, 0x6); - } - } -} - -void halbtc8812a2ant_action_sco_hid(IN struct btc_coexist *btcoexist) -{ - u8 wifi_rssi_state = BTC_RSSI_STATE_HIGH, - bt_rssi_state = BTC_RSSI_STATE_HIGH; - u32 wifi_bw; - u8 bt_thresh0 = 0, bt_thresh1 = 0; - - /* halbtc8812a2ant_get_bt_rssi_threshold(btcoexist, &bt_thresh0, &bt_thresh1); */ - bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, bt_thresh0, - bt_thresh1); - - wifi_rssi_state = halbtc8812a2ant_wifi_rssi_state(btcoexist, 0, 2, 34, - 0); - bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, 34, 42); - - /* power save state */ - halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0, - 0x0); - - /* coex table */ - halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); - - /* pstdma */ - if (BTC_RSSI_LOW(bt_rssi_state)) - halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 13); - else - halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 9); - - /* decrease BT power */ - if (BTC_RSSI_LOW(bt_rssi_state)) - halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - else if (BTC_RSSI_MEDIUM(bt_rssi_state)) - halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2); - else - halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 4); - - /* limited Rx */ - halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, true, 0x8); - - /* fw dac swing level */ - halbtc8812a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6); - - - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw); - /* sw mechanism */ - if (BTC_WIFI_BW_HT40 == wifi_bw) { - if (BTC_RSSI_HIGH(wifi_rssi_state)) { - halbtc8812a2ant_sw_mechanism1(btcoexist, true, true, - false, false); - halbtc8812a2ant_sw_mechanism2(btcoexist, true, false, - false, 0x6); - } else { - halbtc8812a2ant_sw_mechanism1(btcoexist, true, true, - false, false); - halbtc8812a2ant_sw_mechanism2(btcoexist, false, false, - false, 0x6); - } - } else { - if (BTC_RSSI_HIGH(wifi_rssi_state)) { - halbtc8812a2ant_sw_mechanism1(btcoexist, false, true, - false, false); - halbtc8812a2ant_sw_mechanism2(btcoexist, true, false, - false, 0x6); - } else { - halbtc8812a2ant_sw_mechanism1(btcoexist, false, true, - false, false); - halbtc8812a2ant_sw_mechanism2(btcoexist, false, false, - false, 0x6); - } - } -} - -void halbtc8812a2ant_action_hid(IN struct btc_coexist *btcoexist) -{ - u8 wifi_rssi_state = BTC_RSSI_STATE_HIGH, - bt_rssi_state = BTC_RSSI_STATE_HIGH; - u32 wifi_bw; - u8 anttype = 0; - - - btcoexist->btc_get(btcoexist, BTC_GET_U1_ANT_TYPE, &anttype); - - - /* halbtc8812a2ant_get_bt_rssi_threshold(btcoexist, &bt_thresh0, &bt_thresh1); - * bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, bt_thresh0, bt_thresh1); */ - - wifi_rssi_state = halbtc8812a2ant_wifi_rssi_state(btcoexist, 0, 2, 34, - 0); - bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, 34, 42); - - - if (anttype == 0) { /* ANTTYPE = 0 92E 2ant with SPDT */ - /* power save state & pstdma & coex table */ - coex_dm->auto_tdma_adjust = false; - coex_dm->auto_tdma_adjust_low_rssi = false; - halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, - 0x0, 0x0); - halbtc8812a2ant_ps_tdma(btcoexist, FORCE_EXEC, false, 0); - halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - } else if (anttype == - 1) { /* 92E 2ant with coupler and bad ant. isolation, 92E 3ant with bad ant. isolation */ - /* power save state & pstdma & coex table */ - coex_dm->auto_tdma_adjust = false; - coex_dm->auto_tdma_adjust_low_rssi = false; - halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, - 0x0, 0x0); - halbtc8812a2ant_ps_tdma(btcoexist, FORCE_EXEC, false, 0); - halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - } else if (anttype == - 2) { /* ANTTYPE = 2, 92E 2ant with coupler and normal/good ant. isolation, 92E 3ant with normal ant. isolation */ - /* power save state & pstdma & coex table */ - if (BTC_RSSI_HIGH(wifi_rssi_state) && - (!BTC_RSSI_LOW(bt_rssi_state)) && - (coex_sta->scan_ap_num < NOISY_AP_NUM_THRESH_8812A)) { - /* WIFI RSSI = high & BT RSSI = high & shielding room */ - halbtc8812a2ant_power_save_state(btcoexist, - BTC_PS_WIFI_NATIVE, 0x0, 0x0); - halbtc8812a2ant_ps_tdma(btcoexist, FORCE_EXEC, true, 9); - halbtc8812a2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 3); - } else if (BTC_RSSI_HIGH(wifi_rssi_state) && - (!BTC_RSSI_LOW(bt_rssi_state)) && - (coex_sta->scan_ap_num > NOISY_AP_NUM_THRESH_8812A)) { - /* WIFI RSSI = high & BT RSSI = high & noisy environment */ - halbtc8812a2ant_power_save_state(btcoexist, - BTC_PS_WIFI_NATIVE, 0x0, 0x0); - halbtc8812a2ant_ps_tdma(btcoexist, FORCE_EXEC, true, 9); - halbtc8812a2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 3); - } else { /* WIFI RSSI || BT RSSI == low */ - halbtc8812a2ant_power_save_state(btcoexist, - BTC_PS_WIFI_NATIVE, 0x0, 0x0); - halbtc8812a2ant_ps_tdma(btcoexist, FORCE_EXEC, true, 9); - halbtc8812a2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 3); - } - } else if (anttype == - 3) { /* ANTTYPE = 3, 92E 3ant with good ant. isolation */ - /* power save state & pstdma & coex table */ - if (BTC_RSSI_HIGH(wifi_rssi_state) && - (!BTC_RSSI_LOW(bt_rssi_state)) && - (coex_sta->scan_ap_num < NOISY_AP_NUM_THRESH_8812A)) { - /* WIFI RSSI = high & BT RSSI = high & shielding room */ - coex_dm->auto_tdma_adjust = false; - coex_dm->auto_tdma_adjust_low_rssi = false; - halbtc8812a2ant_power_save_state(btcoexist, - BTC_PS_WIFI_NATIVE, 0x0, 0x0); - halbtc8812a2ant_ps_tdma(btcoexist, FORCE_EXEC, false, - 1); - halbtc8812a2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 0); - - } else if (BTC_RSSI_HIGH(wifi_rssi_state) && - (!BTC_RSSI_LOW(bt_rssi_state)) && - (coex_sta->scan_ap_num > NOISY_AP_NUM_THRESH_8812A)) { - /* WIFI RSSI = high & BT RSSI = high & noisy environment */ - coex_dm->auto_tdma_adjust = false; - coex_dm->auto_tdma_adjust_low_rssi = false; - halbtc8812a2ant_power_save_state(btcoexist, - BTC_PS_WIFI_NATIVE, 0x0, 0x0); - halbtc8812a2ant_ps_tdma(btcoexist, FORCE_EXEC, false, - 1); - halbtc8812a2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 0); - - } else { /* WIFI RSSI || BT RSSI == low */ - coex_dm->auto_tdma_adjust = false; - coex_dm->auto_tdma_adjust_low_rssi = false; - halbtc8812a2ant_power_save_state(btcoexist, - BTC_PS_WIFI_NATIVE, 0x0, 0x0); - halbtc8812a2ant_ps_tdma(btcoexist, FORCE_EXEC, false, - 1); - halbtc8812a2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 0); - } - } else { /* ANTTYPE = 4 for test */ - /* power save state & pstdma & coex table */ - if (BTC_RSSI_HIGH(wifi_rssi_state) && - (!BTC_RSSI_LOW(bt_rssi_state)) && - (coex_sta->scan_ap_num < NOISY_AP_NUM_THRESH_8812A)) { - /* WIFI RSSI = high & BT RSSI = high & shielding room */ - halbtc8812a2ant_power_save_state(btcoexist, - BTC_PS_LPS_ON, 0x50, 0x4); - halbtc8812a2ant_tdma_duration_adjust_for_wifi_rssi_low( - btcoexist); - halbtc8812a2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 7); - } else if (BTC_RSSI_HIGH(wifi_rssi_state) && - (!BTC_RSSI_LOW(bt_rssi_state)) && - (coex_sta->scan_ap_num > NOISY_AP_NUM_THRESH_8812A)) { - /* WIFI RSSI = high & BT RSSI = high & noisy environment */ - halbtc8812a2ant_power_save_state(btcoexist, - BTC_PS_LPS_ON, 0x50, 0x4); - halbtc8812a2ant_tdma_duration_adjust_for_wifi_rssi_low( - btcoexist); - halbtc8812a2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 7); - } else { /* WIFI RSSI || BT RSSI == low */ - halbtc8812a2ant_power_save_state(btcoexist, - BTC_PS_LPS_ON, 0x50, 0x4); - halbtc8812a2ant_tdma_duration_adjust_for_wifi_rssi_low( - btcoexist); - halbtc8812a2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 7); - } - } - - - /* power save state */ - halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0, - 0x0); - - /* coex table */ - halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - - /* pstdma */ - halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); - - /* decrease BT power */ - halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - /* limited Rx */ - halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8); - - /* fw dac swing level */ - halbtc8812a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6); - - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw); - /* sw mechanism */ - if (BTC_WIFI_BW_HT40 == wifi_bw) { - if (BTC_RSSI_HIGH(wifi_rssi_state)) { - halbtc8812a2ant_sw_mechanism1(btcoexist, true, true, - false, false); - halbtc8812a2ant_sw_mechanism2(btcoexist, true, false, - false, 0x18); - } else { - halbtc8812a2ant_sw_mechanism1(btcoexist, true, true, - false, false); - halbtc8812a2ant_sw_mechanism2(btcoexist, false, false, - false, 0x18); - } - } else { - if (BTC_RSSI_HIGH(wifi_rssi_state)) { - halbtc8812a2ant_sw_mechanism1(btcoexist, false, true, - false, false); - halbtc8812a2ant_sw_mechanism2(btcoexist, true, false, - false, 0x18); - } else { - halbtc8812a2ant_sw_mechanism1(btcoexist, false, true, - false, false); - halbtc8812a2ant_sw_mechanism2(btcoexist, false, false, - false, 0x18); - } - } -} - -/* A2DP only / PAN(EDR) only/ A2DP+PAN(HS) */ -void halbtc8812a2ant_action_a2dp(IN struct btc_coexist *btcoexist) -{ - u8 wifi_rssi_state = BTC_RSSI_STATE_HIGH, - bt_rssi_state = BTC_RSSI_STATE_HIGH; - u32 wifi_bw; - u8 anttype = 0; - boolean ap_enable = false; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, - &ap_enable); - - btcoexist->btc_get(btcoexist, BTC_GET_U1_ANT_TYPE, &anttype); - - /* halbtc8812a2ant_get_bt_rssi_threshold(btcoexist, &bt_thresh0, &bt_thresh1); - * bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, bt_thresh0, bt_thresh1); */ - - wifi_rssi_state = halbtc8812a2ant_wifi_rssi_state(btcoexist, 0, 2, 34, - 0); - bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, 34, 42); - - /* anttype = 4; */ - - if (anttype == 0) { /* ANTTYPE = 0 92E 2ant with SPDT */ - - if (coex_sta->scan_ap_num > NOISY_AP_NUM_THRESH_8812A) { - coex_dm->auto_tdma_adjust = false; - coex_dm->auto_tdma_adjust_low_rssi = false; - halbtc8812a2ant_power_save_state(btcoexist, - BTC_PS_WIFI_NATIVE, 0x0, 0x0); - halbtc8812a2ant_ps_tdma(btcoexist, FORCE_EXEC, false, - 0); - halbtc8812a2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 0); - } else { - if (BTC_RSSI_HIGH(wifi_rssi_state) && - (!BTC_RSSI_LOW(bt_rssi_state))) { - /* WIFI RSSI = high & BT RSSI = high & shielding room */ - halbtc8812a2ant_power_save_state(btcoexist, - BTC_PS_LPS_ON, 0x50, 0x4); - halbtc8812a2ant_tdma_duration_adjust_for_wifi_rssi_low( - btcoexist); - halbtc8812a2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 7); - } else { /* WIFI RSSI || BT RSSI == low */ - halbtc8812a2ant_power_save_state(btcoexist, - BTC_PS_LPS_ON, 0x50, 0x4); - halbtc8812a2ant_tdma_duration_adjust_for_wifi_rssi_low( - btcoexist); - halbtc8812a2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 7); - } - } - - /* power save state & pstdma & coex table - * - if(BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state)) && (coex_sta->scan_ap_num < NOISY_AP_NUM_THRESH_8812A)) - { - halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_LPS_ON, 0x50, 0x4); - halbtc8812a2ant_tdma_duration_adjust_for_wifi_rssi_low(btcoexist); - halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7); - } - else if (BTC_RSSI_HIGH(wifi_rssi_state)&&(!BTC_RSSI_LOW(bt_rssi_state)) && (coex_sta->scan_ap_num > NOISY_AP_NUM_THRESH_8812A)) - { - coex_dm->auto_tdma_adjust = false; - coex_dm->auto_tdma_adjust_low_rssi = false; - halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0); - halbtc8812a2ant_ps_tdma(btcoexist, FORCE_EXEC, false, 0); - halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - } - else - { - halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_LPS_ON, 0x50, 0x4); - halbtc8812a2ant_tdma_duration_adjust_for_wifi_rssi_low(btcoexist); - halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7); - } - */ - } else if (anttype == - 1) { /* 92E 2ant with coupler and bad ant. isolation, 92E 3ant with bad ant. isolation */ - /* power save state & pstdma & coex table */ - if (BTC_RSSI_HIGH(wifi_rssi_state) && - (!BTC_RSSI_LOW(bt_rssi_state)) && - (coex_sta->scan_ap_num < NOISY_AP_NUM_THRESH_8812A)) { - /* WIFI RSSI = high & BT RSSI = high & shielding room */ - halbtc8812a2ant_power_save_state(btcoexist, - BTC_PS_WIFI_NATIVE, 0x0, 0x0); - halbtc8812a2ant_tdma_duration_adjust(btcoexist, false, - false, 1); /* shielding room */ - halbtc8812a2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 0); - } else if (BTC_RSSI_HIGH(wifi_rssi_state) && - (!BTC_RSSI_LOW(bt_rssi_state)) && - (coex_sta->scan_ap_num > NOISY_AP_NUM_THRESH_8812A)) { - /* WIFI RSSI = high & BT RSSI = high & noisy environment */ - coex_dm->auto_tdma_adjust = false; - coex_dm->auto_tdma_adjust_low_rssi = false; - halbtc8812a2ant_power_save_state(btcoexist, - BTC_PS_WIFI_NATIVE, 0x0, 0x0); - halbtc8812a2ant_ps_tdma(btcoexist, FORCE_EXEC, false, - 1); - halbtc8812a2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 0); - } else { /* WIFI RSSI || BT RSSI == low */ - halbtc8812a2ant_power_save_state(btcoexist, - BTC_PS_LPS_ON, 0x50, 0x4); - halbtc8812a2ant_tdma_duration_adjust_for_wifi_rssi_low( - btcoexist); - halbtc8812a2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 7); - } - - } else if (anttype == - 2) { /* ANTTYPE = 2, 92E 2ant with coupler and normal/good ant. isolation, 92E 3ant with normal ant. isolation */ - /* power save state & pstdma & coex table */ - if (BTC_RSSI_HIGH(wifi_rssi_state) && - (!BTC_RSSI_LOW(bt_rssi_state)) && - (coex_sta->scan_ap_num < NOISY_AP_NUM_THRESH_8812A)) { - /* WIFI RSSI = high & BT RSSI = high & shielding room */ - halbtc8812a2ant_power_save_state(btcoexist, - BTC_PS_WIFI_NATIVE, 0x0, 0x0); - halbtc8812a2ant_tdma_duration_adjust(btcoexist, false, - false, 1); - halbtc8812a2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 5); - } else if (BTC_RSSI_HIGH(wifi_rssi_state) && - (!BTC_RSSI_LOW(bt_rssi_state)) && - (coex_sta->scan_ap_num > NOISY_AP_NUM_THRESH_8812A)) { - /* WIFI RSSI = high & BT RSSI = high & noisy environment */ - coex_dm->auto_tdma_adjust = false; - coex_dm->auto_tdma_adjust_low_rssi = false; - halbtc8812a2ant_power_save_state(btcoexist, - BTC_PS_WIFI_NATIVE, 0x0, 0x0); - halbtc8812a2ant_ps_tdma(btcoexist, FORCE_EXEC, false, - 1); - halbtc8812a2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 0); - } else { /* WIFI RSSI || BT RSSI == low */ - halbtc8812a2ant_power_save_state(btcoexist, - BTC_PS_LPS_ON, 0x50, 0x4); - halbtc8812a2ant_tdma_duration_adjust_for_wifi_rssi_low( - btcoexist); - halbtc8812a2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 7); - } - } else if (anttype == - 3) { /* ANTTYPE = 3, 92E 3ant with good ant. isolation */ - /* power save state & pstdma & coex table */ - if (BTC_RSSI_HIGH(wifi_rssi_state) && - (!BTC_RSSI_LOW(bt_rssi_state)) && - (coex_sta->scan_ap_num < NOISY_AP_NUM_THRESH_8812A)) { - /* WIFI RSSI = high & BT RSSI = high & shielding room */ - coex_dm->auto_tdma_adjust = false; - coex_dm->auto_tdma_adjust_low_rssi = false; - halbtc8812a2ant_power_save_state(btcoexist, - BTC_PS_WIFI_NATIVE, 0x0, 0x0); - halbtc8812a2ant_ps_tdma(btcoexist, FORCE_EXEC, false, - 1); - halbtc8812a2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 0); - - } else if (BTC_RSSI_HIGH(wifi_rssi_state) && - (!BTC_RSSI_LOW(bt_rssi_state)) && - (coex_sta->scan_ap_num > NOISY_AP_NUM_THRESH_8812A)) { - /* WIFI RSSI = high & BT RSSI = high & noisy environment */ - coex_dm->auto_tdma_adjust = false; - coex_dm->auto_tdma_adjust_low_rssi = false; - halbtc8812a2ant_power_save_state(btcoexist, - BTC_PS_WIFI_NATIVE, 0x0, 0x0); - halbtc8812a2ant_ps_tdma(btcoexist, FORCE_EXEC, false, - 1); - halbtc8812a2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 0); - - } else { /* WIFI RSSI || BT RSSI == low */ - coex_dm->auto_tdma_adjust = false; - coex_dm->auto_tdma_adjust_low_rssi = false; - halbtc8812a2ant_power_save_state(btcoexist, - BTC_PS_WIFI_NATIVE, 0x0, 0x0); - halbtc8812a2ant_ps_tdma(btcoexist, FORCE_EXEC, false, - 1); - halbtc8812a2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 0); - } - } else { /* ANTTYPE = 4 for test */ - /* power save state & pstdma & coex table */ - if (BTC_RSSI_HIGH(wifi_rssi_state) && - (!BTC_RSSI_LOW(bt_rssi_state)) && - (coex_sta->scan_ap_num < NOISY_AP_NUM_THRESH_8812A)) { - /* WIFI RSSI = high & BT RSSI = high & shielding room */ - halbtc8812a2ant_power_save_state(btcoexist, - BTC_PS_LPS_ON, 0x50, 0x4); - halbtc8812a2ant_tdma_duration_adjust_for_wifi_rssi_low( - btcoexist); - halbtc8812a2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 7); - } else if (BTC_RSSI_HIGH(wifi_rssi_state) && - (!BTC_RSSI_LOW(bt_rssi_state)) && - (coex_sta->scan_ap_num > NOISY_AP_NUM_THRESH_8812A)) { - /* WIFI RSSI = high & BT RSSI = high & noisy environment */ - halbtc8812a2ant_power_save_state(btcoexist, - BTC_PS_LPS_ON, 0x50, 0x4); - halbtc8812a2ant_tdma_duration_adjust_for_wifi_rssi_low( - btcoexist); - halbtc8812a2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 7); - } else { /* WIFI RSSI || BT RSSI == low */ - halbtc8812a2ant_power_save_state(btcoexist, - BTC_PS_LPS_ON, 0x50, 0x4); - halbtc8812a2ant_tdma_duration_adjust_for_wifi_rssi_low( - btcoexist); - halbtc8812a2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 7); - } - } - - /* decrease BT power */ - halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - /* decrease BT power - * - if(BTC_RSSI_LOW(bt_rssi_state)) - halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - else if(BTC_RSSI_MEDIUM(bt_rssi_state)) - halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2); - else if (coex_sta->scan_ap_num < NOISY_AP_NUM_THRESH_8812A) - halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 4); - */ - /* limited Rx */ - halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8); - - /* fw dac swing level */ - halbtc8812a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6); - - - /* sw mechanism */ - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw); - if (BTC_WIFI_BW_HT40 == wifi_bw) { - if (BTC_RSSI_HIGH(wifi_rssi_state)) { - halbtc8812a2ant_sw_mechanism1(btcoexist, true, false, - false, false); - halbtc8812a2ant_sw_mechanism2(btcoexist, true, false, - false, 0x18); - } else { - halbtc8812a2ant_sw_mechanism1(btcoexist, true, false, - false, false); - halbtc8812a2ant_sw_mechanism2(btcoexist, false, false, - false, 0x18); - } - } else { - if (BTC_RSSI_HIGH(wifi_rssi_state)) { - halbtc8812a2ant_sw_mechanism1(btcoexist, false, false, - false, false); - halbtc8812a2ant_sw_mechanism2(btcoexist, true, false, - false, 0x18); - } else { - halbtc8812a2ant_sw_mechanism1(btcoexist, false, false, - false, false); - halbtc8812a2ant_sw_mechanism2(btcoexist, false, false, - false, 0x18); - } - } -} - -void halbtc8812a2ant_action_a2dp_pan_hs(IN struct btc_coexist *btcoexist) -{ - u8 wifi_rssi_state = BTC_RSSI_STATE_HIGH, - bt_rssi_state = BTC_RSSI_STATE_HIGH; - u32 wifi_bw; - u8 bt_thresh0 = 0, bt_thresh1 = 0; - - /* halbtc8812a2ant_get_bt_rssi_threshold(btcoexist, &bt_thresh0, &bt_thresh1); */ - bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, bt_thresh0, - bt_thresh1); - - wifi_rssi_state = halbtc8812a2ant_wifi_rssi_state(btcoexist, 0, 2, 34, - 0); - bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, 34, 42); - - /* power save state */ - halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0, - 0x0); - - /* coex table */ - if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state))) - halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2); - else - halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 5); - - /* pstdma */ - if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state))) - halbtc8812a2ant_tdma_duration_adjust(btcoexist, false, false, - 2); - else - halbtc8812a2ant_tdma_duration_adjust(btcoexist, false, true, 2); - - /* decrease BT power */ - halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - /* - - if(BTC_RSSI_LOW(bt_rssi_state)) - halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - else if(BTC_RSSI_MEDIUM(bt_rssi_state)) - halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2); - else - halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 4); - */ - /* limited Rx */ - halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8); - - /* fw dac swing level */ - halbtc8812a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6); - - - /* sw mechanism */ - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw); - if (BTC_WIFI_BW_HT40 == wifi_bw) { - if (BTC_RSSI_HIGH(wifi_rssi_state)) { - halbtc8812a2ant_sw_mechanism1(btcoexist, true, false, - false, false); - halbtc8812a2ant_sw_mechanism2(btcoexist, true, false, - true, 0x6); - } else { - halbtc8812a2ant_sw_mechanism1(btcoexist, true, false, - false, false); - halbtc8812a2ant_sw_mechanism2(btcoexist, false, false, - true, 0x6); - } - } else { - if (BTC_RSSI_HIGH(wifi_rssi_state)) { - halbtc8812a2ant_sw_mechanism1(btcoexist, false, false, - false, false); - halbtc8812a2ant_sw_mechanism2(btcoexist, true, false, - true, 0x6); - } else { - halbtc8812a2ant_sw_mechanism1(btcoexist, false, false, - false, false); - halbtc8812a2ant_sw_mechanism2(btcoexist, false, false, - true, 0x6); - } - } -} - -void halbtc8812a2ant_action_pan_edr(IN struct btc_coexist *btcoexist) -{ - u8 wifi_rssi_state = BTC_RSSI_STATE_HIGH, - bt_rssi_state = BTC_RSSI_STATE_HIGH; - u32 wifi_bw; - u8 bt_thresh0 = 0, bt_thresh1 = 0; - - - - halbtc8812a2ant_get_bt_rssi_threshold(btcoexist, &bt_thresh0, - &bt_thresh1); - bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, bt_thresh0, - bt_thresh1); - - wifi_rssi_state = halbtc8812a2ant_wifi_rssi_state(btcoexist, 0, 2, 34, - 0); - /* bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, 34, 42); */ - - /* power save state */ - if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state))) - halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, - 0x0, 0x0); - else - halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_LPS_ON, 0x50, - 0x4); - - /* coex table */ - if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state))) - halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2); - else - halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - - /* pstdma */ - if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state))) - halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 1); - else - halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 85); - - /* decrease BT power */ - halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - /* limited Rx */ - halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8); - - /* fw dac swing level */ - halbtc8812a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6); - - - /* sw mechanism */ - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw); - if (BTC_WIFI_BW_HT40 == wifi_bw) { - if (BTC_RSSI_HIGH(wifi_rssi_state)) { - halbtc8812a2ant_sw_mechanism1(btcoexist, true, false, - false, false); - halbtc8812a2ant_sw_mechanism2(btcoexist, true, false, - false, 0x18); - } else { - halbtc8812a2ant_sw_mechanism1(btcoexist, true, false, - false, false); - halbtc8812a2ant_sw_mechanism2(btcoexist, false, false, - false, 0x18); - } - } else { - if (BTC_RSSI_HIGH(wifi_rssi_state)) { - halbtc8812a2ant_sw_mechanism1(btcoexist, false, false, - false, false); - halbtc8812a2ant_sw_mechanism2(btcoexist, true, false, - false, 0x18); - } else { - halbtc8812a2ant_sw_mechanism1(btcoexist, false, false, - false, false); - halbtc8812a2ant_sw_mechanism2(btcoexist, false, false, - false, 0x18); - } - } -} - -/* PAN(HS) only */ -void halbtc8812a2ant_action_pan_hs(IN struct btc_coexist *btcoexist) -{ - u8 wifi_rssi_state = BTC_RSSI_STATE_HIGH, - bt_rssi_state = BTC_RSSI_STATE_HIGH; - u32 wifi_bw; - - wifi_rssi_state = halbtc8812a2ant_wifi_rssi_state(btcoexist, 0, 2, 34, - 0); - bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, 34, 42); - - /* power save state */ - halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0, - 0x0); - - /* coex table */ - halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2); - - /* pstdma */ - halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1); - - /* decrease BT power */ - halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - /* - - if(BTC_RSSI_LOW(bt_rssi_state)) - halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - else if(BTC_RSSI_MEDIUM(bt_rssi_state)) - halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2); - else - halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 4); - */ - /* limited Rx */ - halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8); - - /* fw dac swing level */ - halbtc8812a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6); - - - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw); - if (BTC_WIFI_BW_HT40 == wifi_bw) { - if (BTC_RSSI_HIGH(wifi_rssi_state)) { - halbtc8812a2ant_sw_mechanism1(btcoexist, true, false, - false, false); - halbtc8812a2ant_sw_mechanism2(btcoexist, true, false, - false, 0x18); - } else { - halbtc8812a2ant_sw_mechanism1(btcoexist, true, false, - false, false); - halbtc8812a2ant_sw_mechanism2(btcoexist, false, false, - false, 0x18); - } - } else { - if (BTC_RSSI_HIGH(wifi_rssi_state)) { - halbtc8812a2ant_sw_mechanism1(btcoexist, false, false, - false, false); - halbtc8812a2ant_sw_mechanism2(btcoexist, true, false, - false, 0x18); - } else { - halbtc8812a2ant_sw_mechanism1(btcoexist, false, false, - false, false); - halbtc8812a2ant_sw_mechanism2(btcoexist, false, false, - false, 0x18); - } - } -} - -/* PAN(EDR)+A2DP */ -void halbtc8812a2ant_action_pan_edr_a2dp(IN struct btc_coexist *btcoexist) -{ - u8 wifi_rssi_state = BTC_RSSI_STATE_HIGH, - bt_rssi_state = BTC_RSSI_STATE_HIGH; - u32 wifi_bw; - u8 bt_thresh0 = 0, bt_thresh1 = 0; - - halbtc8812a2ant_get_bt_rssi_threshold(btcoexist, &bt_thresh0, - &bt_thresh1); - bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, bt_thresh0, - bt_thresh1); - - wifi_rssi_state = halbtc8812a2ant_wifi_rssi_state(btcoexist, 0, 2, 34, - 0); - /* bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, 34, 42); */ - - /* power save state */ - if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state))) - halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, - 0x0, 0x0); - else - halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_LPS_ON, 0x50, - 0x4); - - /* coex table */ - if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state))) - halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2); - else - halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - - /* pstdma */ - if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state))) - halbtc8812a2ant_tdma_duration_adjust(btcoexist, false, false, - 3); - else { - coex_dm->auto_tdma_adjust = false; - coex_dm->auto_tdma_adjust_low_rssi = false; - halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 86); - } - - /* decrease BT power */ - halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - /* limited Rx */ - halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8); - - /* fw dac swing level */ - halbtc8812a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6); - - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw); - /* sw mechanism */ - if (BTC_WIFI_BW_HT40 == wifi_bw) { - if (BTC_RSSI_HIGH(wifi_rssi_state)) { - halbtc8812a2ant_sw_mechanism1(btcoexist, true, false, - false, false); - halbtc8812a2ant_sw_mechanism2(btcoexist, true, false, - false, 0x18); - } else { - halbtc8812a2ant_sw_mechanism1(btcoexist, true, false, - false, false); - halbtc8812a2ant_sw_mechanism2(btcoexist, false, false, - false, 0x18); - } - } else { - if (BTC_RSSI_HIGH(wifi_rssi_state)) { - halbtc8812a2ant_sw_mechanism1(btcoexist, false, false, - false, false); - halbtc8812a2ant_sw_mechanism2(btcoexist, true, false, - false, 0x18); - } else { - halbtc8812a2ant_sw_mechanism1(btcoexist, false, false, - false, false); - halbtc8812a2ant_sw_mechanism2(btcoexist, false, false, - false, 0x18); - } - } -} - - -void halbtc8812a2ant_action_pan_edr_hid(IN struct btc_coexist *btcoexist) -{ - u8 wifi_rssi_state = BTC_RSSI_STATE_HIGH, - bt_rssi_state = BTC_RSSI_STATE_HIGH; - u32 wifi_bw; - u8 bt_thresh0 = 0, bt_thresh1 = 0; - - - halbtc8812a2ant_get_bt_rssi_threshold(btcoexist, &bt_thresh0, - &bt_thresh1); - bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, bt_thresh0, - bt_thresh1); - - wifi_rssi_state = halbtc8812a2ant_wifi_rssi_state(btcoexist, 0, 2, 34, - 0); - /* bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, 34, 42); */ - - /* power save state */ - if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state))) - halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, - 0x0, 0x0); - else if (BTC_RSSI_LOW(wifi_rssi_state) && - (!BTC_RSSI_LOW(bt_rssi_state))) - halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, - 0x0, 0x0); - else - halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_LPS_ON, 0x50, - 0x4); - - /* coex table */ - if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state))) - halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 3); - else if (BTC_RSSI_LOW(wifi_rssi_state) && - (!BTC_RSSI_LOW(bt_rssi_state))) - halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 5); - else - halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - - /* pstdma */ - if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state))) - halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 10); - else if (BTC_RSSI_LOW(wifi_rssi_state) && - (!BTC_RSSI_LOW(bt_rssi_state))) - halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 14); - else - halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 85); - - /* decrease BT power */ - halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - /* - - if(BTC_RSSI_LOW(bt_rssi_state)) - halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - else if(BTC_RSSI_MEDIUM(bt_rssi_state)) - halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2); - else - halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 4); - */ - /* limited Rx */ - if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state))) - halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, - 0x8); - else if (BTC_RSSI_LOW(wifi_rssi_state) && - (!BTC_RSSI_LOW(bt_rssi_state))) - halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, - 0x8); - else - halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, true, - 0x8); - - /* fw dac swing level */ - halbtc8812a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6); - - - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw); - /* sw mechanism */ - if (BTC_WIFI_BW_HT40 == wifi_bw) { - if (BTC_RSSI_HIGH(wifi_rssi_state)) { - halbtc8812a2ant_sw_mechanism1(btcoexist, true, true, - false, false); - halbtc8812a2ant_sw_mechanism2(btcoexist, true, false, - false, 0x18); - } else { - halbtc8812a2ant_sw_mechanism1(btcoexist, true, true, - false, false); - halbtc8812a2ant_sw_mechanism2(btcoexist, false, false, - false, 0x18); - } - } else { - if (BTC_RSSI_HIGH(wifi_rssi_state)) { - halbtc8812a2ant_sw_mechanism1(btcoexist, false, true, - false, false); - halbtc8812a2ant_sw_mechanism2(btcoexist, true, false, - false, 0x18); - } else { - halbtc8812a2ant_sw_mechanism1(btcoexist, false, true, - false, false); - halbtc8812a2ant_sw_mechanism2(btcoexist, false, false, - false, 0x18); - } - } -} - -/* HID+A2DP+PAN(EDR) */ -void halbtc8812a2ant_action_hid_a2dp_pan_edr(IN struct btc_coexist *btcoexist) -{ - u8 wifi_rssi_state = BTC_RSSI_STATE_HIGH, - bt_rssi_state = BTC_RSSI_STATE_HIGH; - u32 wifi_bw; - u8 bt_thresh0 = 0, bt_thresh1 = 0; - - halbtc8812a2ant_get_bt_rssi_threshold(btcoexist, &bt_thresh0, - &bt_thresh1); - bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, bt_thresh0, - bt_thresh1); - - wifi_rssi_state = halbtc8812a2ant_wifi_rssi_state(btcoexist, 0, 2, 34, - 0); - /* bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, 34, 42); */ - - /* power save state */ - if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state))) - halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, - 0x0, 0x0); - else if (BTC_RSSI_LOW(wifi_rssi_state) && - (!BTC_RSSI_LOW(bt_rssi_state))) - halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, - 0x0, 0x0); - else - halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_LPS_ON, 0x50, - 0x4); - - /* coex table */ - if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state))) - halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 3); - else if (BTC_RSSI_LOW(wifi_rssi_state) && - (!BTC_RSSI_LOW(bt_rssi_state))) - halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 5); - else - halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - - /* pstdma */ - if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state))) - halbtc8812a2ant_tdma_duration_adjust(btcoexist, true, false, 3); - else if (BTC_RSSI_LOW(wifi_rssi_state) && - (!BTC_RSSI_LOW(bt_rssi_state))) - halbtc8812a2ant_tdma_duration_adjust(btcoexist, true, true, 3); - else { - coex_dm->auto_tdma_adjust = false; - halbtc8812a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 86); - } - - /* decrease BT power */ - halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - /* - - if(BTC_RSSI_LOW(bt_rssi_state)) - halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - else if(BTC_RSSI_MEDIUM(bt_rssi_state)) - halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2); - else - halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 4); - */ - /* limited Rx */ - if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state))) - halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, - 0x8); - else if (BTC_RSSI_LOW(wifi_rssi_state) && - (!BTC_RSSI_LOW(bt_rssi_state))) - halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, - 0x8); - else - halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, true, - 0x8); - - - /* fw dac swing level */ - halbtc8812a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6); - - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw); - /* sw mechanism */ - if (BTC_WIFI_BW_HT40 == wifi_bw) { - if (BTC_RSSI_HIGH(wifi_rssi_state)) { - halbtc8812a2ant_sw_mechanism1(btcoexist, true, true, - false, false); - halbtc8812a2ant_sw_mechanism2(btcoexist, true, false, - false, 0x18); - } else { - halbtc8812a2ant_sw_mechanism1(btcoexist, true, true, - false, false); - halbtc8812a2ant_sw_mechanism2(btcoexist, false, false, - false, 0x18); - } - } else { - if (BTC_RSSI_HIGH(wifi_rssi_state)) { - halbtc8812a2ant_sw_mechanism1(btcoexist, false, true, - false, false); - halbtc8812a2ant_sw_mechanism2(btcoexist, true, false, - false, 0x18); - } else { - halbtc8812a2ant_sw_mechanism1(btcoexist, false, true, - false, false); - halbtc8812a2ant_sw_mechanism2(btcoexist, false, false, - false, 0x18); - } - } -} - -void halbtc8812a2ant_action_hid_a2dp_pan_hs(IN struct btc_coexist *btcoexist) -{ - u8 wifi_rssi_state = BTC_RSSI_STATE_HIGH, - bt_rssi_state = BTC_RSSI_STATE_HIGH; - u32 wifi_bw; - u8 bt_thresh0 = 0, bt_thresh1 = 0; - - halbtc8812a2ant_get_bt_rssi_threshold(btcoexist, &bt_thresh0, - &bt_thresh1); - bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, bt_thresh0, - bt_thresh1); - - - wifi_rssi_state = halbtc8812a2ant_wifi_rssi_state(btcoexist, 0, 2, 34, - 0); - /* bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, 34, 42); */ - - /* power save state */ - halbtc8812a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0, - 0x0); - - /* coex table */ - if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state))) - halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 3); - else if (BTC_RSSI_LOW(wifi_rssi_state) && - (!BTC_RSSI_LOW(bt_rssi_state))) - halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 5); - else - halbtc8812a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - - /* pstdma */ - if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state))) - halbtc8812a2ant_tdma_duration_adjust(btcoexist, true, false, 2); - else if (BTC_RSSI_LOW(wifi_rssi_state) && - (!BTC_RSSI_LOW(bt_rssi_state))) - halbtc8812a2ant_tdma_duration_adjust(btcoexist, true, true, 2); - else - halbtc8812a2ant_tdma_duration_adjust(btcoexist, true, true, 2); - - /* decrease BT power */ - halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - /* - - if(BTC_RSSI_LOW(bt_rssi_state)) - halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - else if(BTC_RSSI_MEDIUM(bt_rssi_state)) - halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2); - else - halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 4); - */ - /* limited Rx */ - if (BTC_RSSI_HIGH(wifi_rssi_state) && (!BTC_RSSI_LOW(bt_rssi_state))) - halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, - 0x8); - else if (BTC_RSSI_LOW(wifi_rssi_state) && - (!BTC_RSSI_LOW(bt_rssi_state))) - halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, - 0x8); - else - halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, true, - 0x8); - - /* fw dac swing level */ - halbtc8812a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6); - - - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw); - /* sw mechanism */ - if (BTC_WIFI_BW_HT40 == wifi_bw) { - if (BTC_RSSI_HIGH(wifi_rssi_state)) { - halbtc8812a2ant_sw_mechanism1(btcoexist, true, true, - false, false); - halbtc8812a2ant_sw_mechanism2(btcoexist, true, false, - false, 0x18); - } else { - halbtc8812a2ant_sw_mechanism1(btcoexist, true, true, - false, false); - halbtc8812a2ant_sw_mechanism2(btcoexist, false, false, - false, 0x18); - } - } else { - if (BTC_RSSI_HIGH(wifi_rssi_state)) { - halbtc8812a2ant_sw_mechanism1(btcoexist, false, true, - false, false); - halbtc8812a2ant_sw_mechanism2(btcoexist, true, false, - false, 0x18); - } else { - halbtc8812a2ant_sw_mechanism1(btcoexist, false, true, - false, false); - halbtc8812a2ant_sw_mechanism2(btcoexist, false, false, - false, 0x18); - } - } -} - -void halbtc8812a2ant_action_hid_a2dp(IN struct btc_coexist *btcoexist) -{ - u8 wifi_rssi_state = BTC_RSSI_STATE_HIGH, - bt_rssi_state = BTC_RSSI_STATE_HIGH; - u32 wifi_bw; - u8 anttype = 0; - - btcoexist->btc_get(btcoexist, BTC_GET_U1_ANT_TYPE, &anttype); - - - /* halbtc8812a2ant_get_bt_rssi_threshold(btcoexist, &bt_thresh0, &bt_thresh1); - * bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, bt_thresh0, bt_thresh1); */ - - wifi_rssi_state = halbtc8812a2ant_wifi_rssi_state(btcoexist, 0, 2, 34, - 0); - bt_rssi_state = halbtc8812a2ant_bt_rssi_state(3, 34, 42); - - if (anttype == 0) { /* ANTTYPE = 0 92E 2ant with SPDT */ - /* power save state & pstdma & coex table */ - if (BTC_RSSI_HIGH(wifi_rssi_state) && - (!BTC_RSSI_LOW(bt_rssi_state)) && - (coex_sta->scan_ap_num < NOISY_AP_NUM_THRESH_8812A)) { - halbtc8812a2ant_power_save_state(btcoexist, - BTC_PS_LPS_ON, 0x50, 0x4); - halbtc8812a2ant_ps_tdma(btcoexist, FORCE_EXEC, true, - 83); - halbtc8812a2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 8); - - } else if (BTC_RSSI_HIGH(wifi_rssi_state) && - (!BTC_RSSI_LOW(bt_rssi_state)) && - (coex_sta->scan_ap_num > NOISY_AP_NUM_THRESH_8812A)) { - coex_dm->auto_tdma_adjust = false; - coex_dm->auto_tdma_adjust_low_rssi = false; - halbtc8812a2ant_power_save_state(btcoexist, - BTC_PS_WIFI_NATIVE, 0x0, 0x0); - halbtc8812a2ant_ps_tdma(btcoexist, FORCE_EXEC, false, - 0); - halbtc8812a2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 0); - } else { - halbtc8812a2ant_power_save_state(btcoexist, - BTC_PS_LPS_ON, 0x50, 0x4); - halbtc8812a2ant_ps_tdma(btcoexist, FORCE_EXEC, true, - 83); - halbtc8812a2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 8); - } - } else if (anttype == - 1) { /* 92E 2ant with coupler and bad ant. isolation, 92E 3ant with bad ant. isolation */ - /* power save state & pstdma & coex table */ - if (BTC_RSSI_HIGH(wifi_rssi_state) && - (!BTC_RSSI_LOW(bt_rssi_state)) && - (coex_sta->scan_ap_num < NOISY_AP_NUM_THRESH_8812A)) { - halbtc8812a2ant_power_save_state(btcoexist, - BTC_PS_WIFI_NATIVE, 0x0, 0x0); - halbtc8812a2ant_tdma_duration_adjust(btcoexist, true, - true, 2); - halbtc8812a2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 8); - } else if (BTC_RSSI_HIGH(wifi_rssi_state) && - (!BTC_RSSI_LOW(bt_rssi_state)) && - (coex_sta->scan_ap_num > NOISY_AP_NUM_THRESH_8812A)) { - coex_dm->auto_tdma_adjust = false; - coex_dm->auto_tdma_adjust_low_rssi = false; - halbtc8812a2ant_power_save_state(btcoexist, - BTC_PS_WIFI_NATIVE, 0x0, 0x0); - halbtc8812a2ant_ps_tdma(btcoexist, FORCE_EXEC, false, - 0); - halbtc8812a2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 0); - } else { - halbtc8812a2ant_power_save_state(btcoexist, - BTC_PS_LPS_ON, 0x50, 0x4); - halbtc8812a2ant_ps_tdma(btcoexist, FORCE_EXEC, true, - 83); - halbtc8812a2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 8); - } - } else if (anttype == - 2) { /* ANTTYPE = 2, 92E 2ant with coupler and normal/good ant. isolation, 92E 3ant with normal ant. isolation */ - /* power save state & pstdma & coex table */ - if (BTC_RSSI_HIGH(wifi_rssi_state) && - (!BTC_RSSI_LOW(bt_rssi_state)) && - (coex_sta->scan_ap_num < NOISY_AP_NUM_THRESH_8812A)) { - /* WIFI RSSI = high & BT RSSI = high & shielding room */ - halbtc8812a2ant_power_save_state(btcoexist, - BTC_PS_WIFI_NATIVE, 0x0, 0x0); - halbtc8812a2ant_tdma_duration_adjust(btcoexist, true, - true, 2); - halbtc8812a2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 8); - } else if (BTC_RSSI_HIGH(wifi_rssi_state) && - (!BTC_RSSI_LOW(bt_rssi_state)) && - (coex_sta->scan_ap_num > NOISY_AP_NUM_THRESH_8812A)) { - /* WIFI RSSI = high & BT RSSI = high & noisy environment */ - coex_dm->auto_tdma_adjust = false; - coex_dm->auto_tdma_adjust_low_rssi = false; - halbtc8812a2ant_power_save_state(btcoexist, - BTC_PS_WIFI_NATIVE, 0x0, 0x0); - halbtc8812a2ant_ps_tdma(btcoexist, FORCE_EXEC, false, - 0); - halbtc8812a2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 8); - } else { /* WIFI RSSI || BT RSSI == low */ - halbtc8812a2ant_power_save_state(btcoexist, - BTC_PS_LPS_ON, 0x50, 0x4); - halbtc8812a2ant_ps_tdma(btcoexist, FORCE_EXEC, true, - 83); - halbtc8812a2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 8); - } - } else if (anttype == - 3) { /* ANTTYPE = 3, 92E 3ant with good ant. isolation */ - /* power save state & pstdma & coex table */ - if (BTC_RSSI_HIGH(wifi_rssi_state) && - (!BTC_RSSI_LOW(bt_rssi_state)) && - (coex_sta->scan_ap_num < NOISY_AP_NUM_THRESH_8812A)) { - /* WIFI RSSI = high & BT RSSI = high & shielding room */ - coex_dm->auto_tdma_adjust = false; - coex_dm->auto_tdma_adjust_low_rssi = false; - halbtc8812a2ant_power_save_state(btcoexist, - BTC_PS_WIFI_NATIVE, 0x0, 0x0); - halbtc8812a2ant_ps_tdma(btcoexist, FORCE_EXEC, false, - 1); - halbtc8812a2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 0); - - } else if (BTC_RSSI_HIGH(wifi_rssi_state) && - (!BTC_RSSI_LOW(bt_rssi_state)) && - (coex_sta->scan_ap_num > NOISY_AP_NUM_THRESH_8812A)) { - /* WIFI RSSI = high & BT RSSI = high & noisy environment */ - coex_dm->auto_tdma_adjust = false; - coex_dm->auto_tdma_adjust_low_rssi = false; - halbtc8812a2ant_power_save_state(btcoexist, - BTC_PS_WIFI_NATIVE, 0x0, 0x0); - halbtc8812a2ant_ps_tdma(btcoexist, FORCE_EXEC, false, - 1); - halbtc8812a2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 0); - - } else { /* WIFI RSSI || BT RSSI == low */ - coex_dm->auto_tdma_adjust = false; - coex_dm->auto_tdma_adjust_low_rssi = false; - halbtc8812a2ant_power_save_state(btcoexist, - BTC_PS_WIFI_NATIVE, 0x0, 0x0); - halbtc8812a2ant_ps_tdma(btcoexist, FORCE_EXEC, false, - 1); - halbtc8812a2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 0); - } - } else { /* ANTTYPE = 4 for test */ - /* power save state & pstdma & coex table */ - if (BTC_RSSI_HIGH(wifi_rssi_state) && - (!BTC_RSSI_LOW(bt_rssi_state)) && - (coex_sta->scan_ap_num < NOISY_AP_NUM_THRESH_8812A)) { - /* WIFI RSSI = high & BT RSSI = high & shielding room */ - halbtc8812a2ant_power_save_state(btcoexist, - BTC_PS_LPS_ON, 0x50, 0x4); - halbtc8812a2ant_tdma_duration_adjust_for_wifi_rssi_low( - btcoexist); - halbtc8812a2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 7); - } else if (BTC_RSSI_HIGH(wifi_rssi_state) && - (!BTC_RSSI_LOW(bt_rssi_state)) && - (coex_sta->scan_ap_num > NOISY_AP_NUM_THRESH_8812A)) { - /* WIFI RSSI = high & BT RSSI = high & noisy environment */ - halbtc8812a2ant_power_save_state(btcoexist, - BTC_PS_LPS_ON, 0x50, 0x4); - halbtc8812a2ant_tdma_duration_adjust_for_wifi_rssi_low( - btcoexist); - halbtc8812a2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 7); - } else { /* WIFI RSSI || BT RSSI == low */ - halbtc8812a2ant_power_save_state(btcoexist, - BTC_PS_LPS_ON, 0x50, 0x4); - halbtc8812a2ant_tdma_duration_adjust_for_wifi_rssi_low( - btcoexist); - halbtc8812a2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 7); - } - } - - /* decrease BT power */ - halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - /* - - if(BTC_RSSI_LOW(bt_rssi_state)) - halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - else if(BTC_RSSI_MEDIUM(bt_rssi_state)) - halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2); - else if (coex_sta->scan_ap_num < NOISY_AP_NUM_THRESH_8812A) - halbtc8812a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 4); - */ - /* limited Rx */ - halbtc8812a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8); - - /* fw dac swing level */ - halbtc8812a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6); - - - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw); - /* sw mechanism */ - if (BTC_WIFI_BW_HT40 == wifi_bw) { - if (BTC_RSSI_HIGH(wifi_rssi_state)) { - halbtc8812a2ant_sw_mechanism1(btcoexist, true, true, - false, false); - halbtc8812a2ant_sw_mechanism2(btcoexist, true, false, - false, 0x18); - } else { - halbtc8812a2ant_sw_mechanism1(btcoexist, true, true, - false, false); - halbtc8812a2ant_sw_mechanism2(btcoexist, false, false, - false, 0x18); - } - } else { - if (BTC_RSSI_HIGH(wifi_rssi_state)) { - halbtc8812a2ant_sw_mechanism1(btcoexist, false, true, - false, false); - halbtc8812a2ant_sw_mechanism2(btcoexist, true, false, - false, 0x18); - } else { - halbtc8812a2ant_sw_mechanism1(btcoexist, false, true, - false, false); - halbtc8812a2ant_sw_mechanism2(btcoexist, false, false, - false, 0x18); - } - } -} - -void halbtc8812a2ant_coex_under_5g(IN struct btc_coexist *btcoexist) -{ - halbtc8812a2ant_coex_all_off(btcoexist); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Under 5G, force set BT to ignore Wlan active!!\n"); - BTC_TRACE(trace_buf); - halbtc8812a2ant_ignore_wlan_act(btcoexist, NORMAL_EXEC, true); -} -/* **************************************************** */ -void halbtc8812a2ant_run_coexist_mechanism(IN struct btc_coexist *btcoexist) -{ - boolean wifi_under_5g = false; - u8 algorithm = 0; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], RunCoexistMechanism()===>\n"); - BTC_TRACE(trace_buf); - - if (btcoexist->manual_control) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], RunCoexistMechanism(), return for Manual CTRL <===\n"); - BTC_TRACE(trace_buf); - return; - } - - if (coex_sta->under_ips) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], wifi is under IPS !!!\n"); - BTC_TRACE(trace_buf); - return; - } - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g); - if (wifi_under_5g) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], RunCoexistMechanism(), run 5G coex setting!!<===\n"); - BTC_TRACE(trace_buf); - halbtc8812a2ant_coex_under_5g(btcoexist); - return; - } - - - algorithm = halbtc8812a2ant_action_algorithm(btcoexist); - if (coex_sta->c2h_bt_inquiry_page && - (BT_8812A_2ANT_COEX_ALGO_PANHS != algorithm)) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT is under inquiry/page scan !!\n"); - BTC_TRACE(trace_buf); - halbtc8812a2ant_action_bt_inquiry(btcoexist); - return; - } - - coex_dm->cur_algorithm = algorithm; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], Algorithm = %d\n", - coex_dm->cur_algorithm); - BTC_TRACE(trace_buf); - - if (halbtc8812a2ant_is_common_action(btcoexist)) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant common.\n"); - BTC_TRACE(trace_buf); - coex_dm->auto_tdma_adjust = false; - coex_dm->auto_tdma_adjust_low_rssi = false; - } else { - if (coex_dm->cur_algorithm != coex_dm->pre_algorithm) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], pre_algorithm=%d, cur_algorithm=%d\n", - coex_dm->pre_algorithm, coex_dm->cur_algorithm); - BTC_TRACE(trace_buf); - coex_dm->auto_tdma_adjust = false; - coex_dm->auto_tdma_adjust_low_rssi = false; - } - switch (coex_dm->cur_algorithm) { - case BT_8812A_2ANT_COEX_ALGO_SCO: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, algorithm = SCO.\n"); - BTC_TRACE(trace_buf); - halbtc8812a2ant_action_sco(btcoexist); - break; - case BT_8812A_2ANT_COEX_ALGO_SCO_HID: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, algorithm = SCO+HID.\n"); - BTC_TRACE(trace_buf); - halbtc8812a2ant_action_sco_hid(btcoexist); - break; - case BT_8812A_2ANT_COEX_ALGO_HID: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, algorithm = HID.\n"); - BTC_TRACE(trace_buf); - halbtc8812a2ant_action_hid(btcoexist); - break; - case BT_8812A_2ANT_COEX_ALGO_A2DP: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, algorithm = A2DP.\n"); - BTC_TRACE(trace_buf); - halbtc8812a2ant_action_a2dp(btcoexist); - break; - case BT_8812A_2ANT_COEX_ALGO_A2DP_PANHS: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, algorithm = A2DP+PAN(HS).\n"); - BTC_TRACE(trace_buf); - halbtc8812a2ant_action_a2dp_pan_hs(btcoexist); - break; - case BT_8812A_2ANT_COEX_ALGO_PANEDR: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, algorithm = PAN(EDR).\n"); - BTC_TRACE(trace_buf); - halbtc8812a2ant_action_pan_edr(btcoexist); - break; - case BT_8812A_2ANT_COEX_ALGO_PANHS: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, algorithm = HS mode.\n"); - BTC_TRACE(trace_buf); - halbtc8812a2ant_action_pan_hs(btcoexist); - break; - case BT_8812A_2ANT_COEX_ALGO_PANEDR_A2DP: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, algorithm = PAN+A2DP.\n"); - BTC_TRACE(trace_buf); - halbtc8812a2ant_action_pan_edr_a2dp(btcoexist); - break; - case BT_8812A_2ANT_COEX_ALGO_PANEDR_HID: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, algorithm = PAN(EDR)+HID.\n"); - BTC_TRACE(trace_buf); - halbtc8812a2ant_action_pan_edr_hid(btcoexist); - break; - case BT_8812A_2ANT_COEX_ALGO_HID_A2DP_PANEDR: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, algorithm = HID+A2DP+PAN.\n"); - BTC_TRACE(trace_buf); - halbtc8812a2ant_action_hid_a2dp_pan_edr( - btcoexist); - break; - case BT_8812A_2ANT_COEX_ALGO_HID_A2DP_PANHS: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, algorithm = HID+A2DP+PAN(HS).\n"); - BTC_TRACE(trace_buf); - halbtc8812a2ant_action_hid_a2dp_pan_hs( - btcoexist); - break; - case BT_8812A_2ANT_COEX_ALGO_HID_A2DP: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, algorithm = HID+A2DP.\n"); - BTC_TRACE(trace_buf); - halbtc8812a2ant_action_hid_a2dp(btcoexist); - break; - default: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, algorithm = coexist All Off!!\n"); - BTC_TRACE(trace_buf); - halbtc8812a2ant_coex_all_off(btcoexist); - break; - } - coex_dm->pre_algorithm = coex_dm->cur_algorithm; - } - -} - -void halbtc8812a2ant_init_hw_config(IN struct btc_coexist *btcoexist, - IN boolean back_up) -{ - u8 u8tmp = 0; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], 2Ant Init HW Config!!\n"); - BTC_TRACE(trace_buf); - - if (back_up) { - /* backup rf 0x1e value */ - coex_dm->bt_rf_0x1e_backup = - btcoexist->btc_get_rf_reg(btcoexist, BTC_RF_A, 0x1e, - 0xfffff); - - coex_dm->backup_arfr_cnt1 = btcoexist->btc_read_4byte(btcoexist, - 0x430); - coex_dm->backup_arfr_cnt2 = btcoexist->btc_read_4byte(btcoexist, - 0x434); - coex_dm->backup_retry_limit = btcoexist->btc_read_2byte( - btcoexist, 0x42a); - coex_dm->backup_ampdu_max_time = btcoexist->btc_read_1byte( - btcoexist, 0x456); - } - - /* ant sw control to BT */ - halbtc8812a2ant_set_ant_path(btcoexist, BTC_ANT_WIFI_AT_CPL_AUX, true, - false); - - /* 0x790[5:0]=0x5 */ - u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x790); - u8tmp &= 0xc0; - u8tmp |= 0x5; - btcoexist->btc_write_1byte(btcoexist, 0x790, u8tmp); - - /* PTA parameter */ - btcoexist->btc_write_1byte(btcoexist, 0x6cc, 0x0); - btcoexist->btc_write_4byte(btcoexist, 0x6c8, 0xffff); - btcoexist->btc_write_4byte(btcoexist, 0x6c4, 0x55555555); - btcoexist->btc_write_4byte(btcoexist, 0x6c0, 0x55555555); - - /* coex parameters */ - btcoexist->btc_write_1byte(btcoexist, 0x778, 0x1); - - /* enable counter statistics */ - btcoexist->btc_write_1byte(btcoexist, 0x76e, 0x4); - - /* disable PTA to avoid BT insn't on */ - btcoexist->btc_write_1byte(btcoexist, 0x40, 0x00); - - /* bt clock related */ - u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x4); - u8tmp |= BIT(7); - btcoexist->btc_write_1byte(btcoexist, 0x4, u8tmp); - - /* bt clock related */ - u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x7); - u8tmp |= BIT(1); - btcoexist->btc_write_1byte(btcoexist, 0x7, u8tmp); - - /* Give bt_coex_supported_version the default value */ - coex_sta->bt_coex_supported_version = 0; - -} - -/* ************************************************************ - * work around function start with wa_halbtc8812a2ant_ - * ************************************************************ - * ************************************************************ - * extern function start with ex_halbtc8812a2ant_ - * ************************************************************ */ -void ex_halbtc8812a2ant_power_on_setting(IN struct btc_coexist *btcoexist) -{ -} - -void ex_halbtc8812a2ant_init_hw_config(IN struct btc_coexist *btcoexist, - IN boolean wifi_only) -{ - halbtc8812a2ant_init_hw_config(btcoexist, true); -} - -void ex_halbtc8812a2ant_init_coex_dm(IN struct btc_coexist *btcoexist) -{ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Coex Mechanism Init!!\n"); - BTC_TRACE(trace_buf); - - halbtc8812a2ant_init_coex_dm(btcoexist); -} - - -void ex_halbtc8812a2ant_pta_off_on_notify(IN struct btc_coexist *btcoexist, - IN u8 bt_status) -{ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], BToff/on notify\n"); - BTC_TRACE(trace_buf); - - if (BTC_BT_OFF == bt_status) { - /* PTA off */ - btcoexist->bt_info.bt_disabled = true; - halbtc8812a2ant_enable_pta(btcoexist, FORCE_EXEC, false); - - } else { - /* PTA on */ - btcoexist->bt_info.bt_disabled = false; - halbtc8812a2ant_enable_pta(btcoexist, FORCE_EXEC, true); - } - -} - - -void ex_halbtc8812a2ant_display_coex_info(IN struct btc_coexist *btcoexist) -{ - struct btc_board_info *board_info = &btcoexist->board_info; - struct btc_stack_info *stack_info = &btcoexist->stack_info; - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - u8 *cli_buf = btcoexist->cli_buf; - u8 u8tmp[4], i, bt_info_ext, ps_tdma_case = 0; - u16 u16tmp[4]; - u32 u32tmp[4]; - u32 fa_ofdm, fa_cck, cca_ofdm, cca_cck; - u32 fw_ver = 0, bt_patch_ver = 0, bt_coex_ver = 0; - u32 phyver = 0; - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n ============[BT Coexist info]============"); - CL_PRINTF(cli_buf); - - if (btcoexist->manual_control) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n ============[Under Manual Control]============"); - CL_PRINTF(cli_buf); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n =========================================="); - CL_PRINTF(cli_buf); - } - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d ", - "Ant PG number/ Ant mechanism:", - board_info->pg_ant_num, board_info->btdm_ant_num); - CL_PRINTF(cli_buf); - -#if 0 - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d", "Antenna type:", - board_info->ant_type); - CL_PRINTF(cli_buf); -#endif - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s / %d", - "BT stack/ hci ext ver", - ((stack_info->profile_notified) ? "Yes" : "No"), - stack_info->hci_version); - CL_PRINTF(cli_buf); - - bt_patch_ver = btcoexist->bt_info.bt_get_fw_ver; - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, &fw_ver); - phyver = btcoexist->btc_get_bt_phydm_version(btcoexist); - bt_coex_ver = coex_sta->bt_coex_supported_version & 0xff; - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %d_%02x/ 0x%02x/ 0x%02x (%s)", - "CoexVer WL/ BT_Desired/ BT_Report", - glcoex_ver_date_8812a_2ant, glcoex_ver_8812a_2ant, - glcoex_ver_btdesired_8812a_2ant, bt_coex_ver, - (bt_coex_ver == 0xff ? "Unknown" : (bt_coex_ver >= - glcoex_ver_btdesired_8812a_2ant ? "Match" : - "Mis-Match"))); - CL_PRINTF(cli_buf); - - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = 0x%x/ 0x%x/ v%d", - "W_FW/ B_FW/ Phy", - fw_ver, bt_patch_ver, phyver); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x ", - "Wifi channel informed to BT", - coex_dm->wifi_chnl_info[0], coex_dm->wifi_chnl_info[1], - coex_dm->wifi_chnl_info[2]); - CL_PRINTF(cli_buf); - - /* wifi status */ - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s", - "============[Wifi Status]============"); - CL_PRINTF(cli_buf); - btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_WIFI_STATUS); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s", - "============[BT Status]============"); - CL_PRINTF(cli_buf); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = [%s/ %d/ %d] ", - "BT [status/ rssi/ retryCnt]", - ((btcoexist->bt_info.bt_disabled) ? ("disabled") : (( - coex_sta->c2h_bt_inquiry_page) ? ("inquiry/page scan") - : ((BT_8812A_2ANT_BT_STATUS_NON_CONNECTED_IDLE == - coex_dm->bt_status) ? "non-connected idle" : - ((BT_8812A_2ANT_BT_STATUS_CONNECTED_IDLE == coex_dm->bt_status) - ? "connected-idle" : "busy")))), - coex_sta->bt_rssi, coex_sta->bt_retry_cnt); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d / %d / %d", - "SCO/HID/PAN/A2DP", - bt_link_info->sco_exist, bt_link_info->hid_exist, - bt_link_info->pan_exist, bt_link_info->a2dp_exist); - CL_PRINTF(cli_buf); - btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_BT_LINK_INFO); - - bt_info_ext = coex_sta->bt_info_ext; - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s", - "BT Info A2DP rate", - (bt_info_ext & BIT(0)) ? "Basic rate" : "EDR rate"); - CL_PRINTF(cli_buf); - - for (i = 0; i < BT_INFO_SRC_8812A_2ANT_MAX; i++) { - if (coex_sta->bt_info_c2h_cnt[i]) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %02x %02x %02x %02x %02x %02x %02x(%d)", - glbt_info_src_8812a_2ant[i], - coex_sta->bt_info_c2h[i][0], - coex_sta->bt_info_c2h[i][1], - coex_sta->bt_info_c2h[i][2], - coex_sta->bt_info_c2h[i][3], - coex_sta->bt_info_c2h[i][4], - coex_sta->bt_info_c2h[i][5], - coex_sta->bt_info_c2h[i][6], - coex_sta->bt_info_c2h_cnt[i]); - CL_PRINTF(cli_buf); - } - } - - /* Sw mechanism */ - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s", - "============[Sw mechanism]============"); - CL_PRINTF(cli_buf); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d ", - "SM1[ShRf/ LpRA/ LimDig]", - coex_dm->cur_rf_rx_lpf_shrink, coex_dm->cur_low_penalty_ra, - coex_dm->limited_dig); - CL_PRINTF(cli_buf); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d(0x%x) ", - "SM2[AgcT/ AdcB/ SwDacSwing(lvl)]", - coex_dm->cur_agc_table_en, coex_dm->cur_adc_back_off, - coex_dm->cur_dac_swing_on, coex_dm->cur_dac_swing_lvl); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x ", "Rate Mask", - btcoexist->bt_info.ra_mask); - CL_PRINTF(cli_buf); - - /* Fw mechanism */ - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s", - "============[Fw mechanism]============"); - CL_PRINTF(cli_buf); - - ps_tdma_case = coex_dm->cur_ps_tdma; - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %02x %02x %02x %02x %02x case-%d (auto:%d/%d)", - "PS TDMA", - coex_dm->ps_tdma_para[0], coex_dm->ps_tdma_para[1], - coex_dm->ps_tdma_para[2], coex_dm->ps_tdma_para[3], - coex_dm->ps_tdma_para[4], ps_tdma_case, - coex_dm->auto_tdma_adjust, - coex_dm->auto_tdma_adjust_low_rssi); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d ", - "DecBtPwr/ IgnWlanAct", - coex_dm->cur_bt_dec_pwr_lvl, coex_dm->cur_ignore_wlan_act); - CL_PRINTF(cli_buf); - - /* Hw setting */ - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s", - "============[Hw setting]============"); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", - "RF-A, 0x1e initVal", - coex_dm->bt_rf_0x1e_backup); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/0x%x/0x%x/0x%x", - "backup ARFR1/ARFR2/RL/AMaxTime", - coex_dm->backup_arfr_cnt1, coex_dm->backup_arfr_cnt2, - coex_dm->backup_retry_limit, - coex_dm->backup_ampdu_max_time); - CL_PRINTF(cli_buf); - - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x430); - u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x434); - u16tmp[0] = btcoexist->btc_read_2byte(btcoexist, 0x42a); - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x456); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/0x%x/0x%x/0x%x", - "0x430/0x434/0x42a/0x456", - u32tmp[0], u32tmp[1], u16tmp[0], u8tmp[0]); - CL_PRINTF(cli_buf); - - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x778); - u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0x6cc); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x ", - "0x778 (W_Act)/ 0x6cc (CoTab Sel)", - u8tmp[0], u8tmp[1]); - CL_PRINTF(cli_buf); - - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x8db); - u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0xc5b); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", - "0x8db(ADC)/0xc5b[29:25](DAC)", - ((u8tmp[0] & 0x60) >> 5), ((u8tmp[1] & 0x3e) >> 1)); - CL_PRINTF(cli_buf); - - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0xcb3); - u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0xcb7); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", - "0xcb3/ 0xcb7", - u8tmp[0], u8tmp[1]); - CL_PRINTF(cli_buf); - - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x40); - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x4c); - u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x974); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", - "0x40/ 0x4c[24:23]/ 0x974", - u8tmp[0], ((u32tmp[0] & 0x01800000) >> 23), u32tmp[1]); - CL_PRINTF(cli_buf); - - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x550); - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x522); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", - "0x550(bcn ctrl)/0x522", - u32tmp[0], u8tmp[0]); - CL_PRINTF(cli_buf); - - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xc50); - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0xa0a); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", - "0xc50(DIG)/0xa0a(CCK-TH)", - u32tmp[0], u8tmp[0]); - CL_PRINTF(cli_buf); - - fa_ofdm = btcoexist->btc_phydm_query_PHY_counter(btcoexist, - PHYDM_INFO_FA_OFDM); - fa_cck = btcoexist->btc_phydm_query_PHY_counter(btcoexist, - PHYDM_INFO_FA_CCK); - cca_ofdm = btcoexist->btc_phydm_query_PHY_counter(btcoexist, - PHYDM_INFO_CCA_OFDM); - cca_cck = btcoexist->btc_phydm_query_PHY_counter(btcoexist, - PHYDM_INFO_CCA_CCK); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", - "CCK-CCA/CCK-FA/OFDM-CCA/OFDM-FA", - cca_cck, fa_cck, cca_ofdm, fa_ofdm); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d", - "CRC_OK CCK/11g/11n/11n-agg", - coex_sta->crc_ok_cck, coex_sta->crc_ok_11g, - coex_sta->crc_ok_11n, coex_sta->crc_ok_11n_vht); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d", - "CRC_Err CCK/11g/11n/11n-agg", - coex_sta->crc_err_cck, coex_sta->crc_err_11g, - coex_sta->crc_err_11n, coex_sta->crc_err_11n_vht); - CL_PRINTF(cli_buf); - - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x6c0); - u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x6c4); - u32tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0x6c8); - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x6cc); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", - "0x6c0/0x6c4/0x6c8/0x6cc(coexTable)", - u32tmp[0], u32tmp[1], u32tmp[2], u8tmp[0]); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", - "0x770(high-pri rx/tx)", - coex_sta->high_priority_rx, coex_sta->high_priority_tx); - CL_PRINTF(cli_buf); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", - "0x774(low-pri rx/tx)", - coex_sta->low_priority_rx, coex_sta->low_priority_tx); - CL_PRINTF(cli_buf); -#if (BT_AUTO_REPORT_ONLY_8812A_2ANT == 1) - halbtc8812a2ant_monitor_bt_ctr(btcoexist); -#endif - btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_COEX_STATISTICS); -} - - -void ex_halbtc8812a2ant_ips_notify(IN struct btc_coexist *btcoexist, IN u8 type) -{ - boolean wifi_under_5g = false; - - if (BTC_IPS_ENTER == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], IPS ENTER notify\n"); - BTC_TRACE(trace_buf); - - coex_sta->under_ips = true; - halbtc8812a2ant_coex_all_off(btcoexist); - halbtc8812a2ant_set_ant_path(btcoexist, BTC_ANT_WIFI_AT_CPL_AUX, - false, true); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], IPS notify, force set BT to ignore Wlan active!!\n"); - BTC_TRACE(trace_buf); - - halbtc8812a2ant_ignore_wlan_act(btcoexist, FORCE_EXEC, true); - ex_halbtc8812a2ant_media_status_notify(btcoexist, - BTC_MEDIA_DISCONNECT); - } else if (BTC_IPS_LEAVE == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], IPS LEAVE notify\n"); - BTC_TRACE(trace_buf); - - coex_sta->under_ips = false; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, - &wifi_under_5g); - if (!wifi_under_5g) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], IPS notify, force set BT NOT to ignore Wlan active!!\n"); - BTC_TRACE(trace_buf); - - halbtc8812a2ant_ignore_wlan_act(btcoexist, FORCE_EXEC, - false); - } - } -} - -void ex_halbtc8812a2ant_lps_notify(IN struct btc_coexist *btcoexist, IN u8 type) -{ - if (BTC_LPS_ENABLE == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], LPS ENABLE notify\n"); - BTC_TRACE(trace_buf); - - coex_sta->under_lps = true; - } else if (BTC_LPS_DISABLE == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], LPS DISABLE notify\n"); - BTC_TRACE(trace_buf); - - coex_sta->under_lps = false; - } -} - -void ex_halbtc8812a2ant_scan_notify(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - if (BTC_SCAN_START == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCAN START notify\n"); - BTC_TRACE(trace_buf); - } else if (BTC_SCAN_FINISH == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCAN FINISH notify\n"); - BTC_TRACE(trace_buf); - - btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM, - &coex_sta->scan_ap_num); - } -} - -void ex_halbtc8812a2ant_connect_notify(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - if (BTC_ASSOCIATE_START == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], CONNECT START notify\n"); - BTC_TRACE(trace_buf); - } else if (BTC_ASSOCIATE_FINISH == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], CONNECT FINISH notify\n"); - BTC_TRACE(trace_buf); - } -} - -void ex_halbtc8812a2ant_media_status_notify(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - u8 data_len = 5; - u8 buf[6] = {0}; - u8 h2c_parameter[3] = {0}; - u32 wifi_bw; - u8 wifi_central_chnl; - - if (btcoexist->manual_control || - btcoexist->stop_coex_dm || - btcoexist->bt_info.bt_disabled) - return; - - if (BTC_MEDIA_CONNECT == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], MEDIA connect notify\n"); - BTC_TRACE(trace_buf); - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], MEDIA disconnect notify\n"); - BTC_TRACE(trace_buf); - } - - /* only 2.4G we need to inform bt the chnl mask */ - btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_CENTRAL_CHNL, - &wifi_central_chnl); - if ((BTC_MEDIA_CONNECT == type) && - (wifi_central_chnl <= 14)) { - h2c_parameter[0] = 0x1; - h2c_parameter[1] = wifi_central_chnl; - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw); - if (BTC_WIFI_BW_HT40 == wifi_bw) - h2c_parameter[2] = 0x30; - else - h2c_parameter[2] = 0x20; - } - - coex_dm->wifi_chnl_info[0] = h2c_parameter[0]; - coex_dm->wifi_chnl_info[1] = h2c_parameter[1]; - coex_dm->wifi_chnl_info[2] = h2c_parameter[2]; - - buf[0] = data_len; - buf[1] = 0x5; /* OP_Code */ - buf[2] = 0x3; /* OP_Code_Length */ - buf[3] = h2c_parameter[0]; /* OP_Code_Content */ - buf[4] = h2c_parameter[1]; - buf[5] = h2c_parameter[2]; - - btcoexist->btc_set(btcoexist, BTC_SET_ACT_CTRL_BT_COEX, - (void *)&buf[0]); -} - -void ex_halbtc8812a2ant_specific_packet_notify(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - if (type == BTC_PACKET_DHCP) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], DHCP Packet notify\n"); - BTC_TRACE(trace_buf); - } -} - -void ex_halbtc8812a2ant_bt_info_notify(IN struct btc_coexist *btcoexist, - IN u8 *tmp_buf, IN u8 length) -{ - u8 bt_info = 0; - u8 i, rsp_source = 0; - boolean bt_busy = false, limited_dig = false; - boolean wifi_connected = false, wifi_under_5g = false; - - coex_sta->c2h_bt_info_req_sent = false; - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g); - - rsp_source = tmp_buf[0] & 0xf; - if (rsp_source >= BT_INFO_SRC_8812A_2ANT_MAX) - rsp_source = BT_INFO_SRC_8812A_2ANT_WIFI_FW; - coex_sta->bt_info_c2h_cnt[rsp_source]++; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Bt info[%d], length=%d, hex data=[", rsp_source, - length); - BTC_TRACE(trace_buf); - - for (i = 0; i < length; i++) { - coex_sta->bt_info_c2h[rsp_source][i] = tmp_buf[i]; - if (i == 1) - bt_info = tmp_buf[i]; - if (i == length - 1) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "0x%02x]\n", - tmp_buf[i]); - BTC_TRACE(trace_buf); - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "0x%02x, ", - tmp_buf[i]); - BTC_TRACE(trace_buf); - } - } - - if (BT_INFO_SRC_8812A_2ANT_WIFI_FW != rsp_source) { - coex_sta->bt_retry_cnt = /* [3:0] */ - coex_sta->bt_info_c2h[rsp_source][2] & 0xf; - - coex_sta->bt_rssi = - coex_sta->bt_info_c2h[rsp_source][3] * 2 + 10; - - coex_sta->bt_info_ext = - coex_sta->bt_info_c2h[rsp_source][4]; - - /* Here we need to resend some wifi info to BT */ - /* because bt is reset and loss of the info. */ - if ((coex_sta->bt_info_ext & BIT(1))) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT ext info bit1 check, send wifi BW&Chnl to BT!!\n"); - BTC_TRACE(trace_buf); - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - if (wifi_connected) - ex_halbtc8812a2ant_media_status_notify( - btcoexist, BTC_MEDIA_CONNECT); - else - ex_halbtc8812a2ant_media_status_notify( - btcoexist, BTC_MEDIA_DISCONNECT); - } - - if ((coex_sta->bt_info_ext & BIT(3)) && !wifi_under_5g) { - /* BT already ignored WlanAct */ - if (!btcoexist->manual_control && - !btcoexist->stop_coex_dm) { - if (!coex_sta->under_ips) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT ext info bit3 check, set BT NOT to ignore Wlan active!!\n"); - BTC_TRACE(trace_buf); - halbtc8812a2ant_ignore_wlan_act( - btcoexist, FORCE_EXEC, false); - } - } - } else { - /* BT already NOT ignore Wlan active, do nothing here. */ - - if (coex_sta->under_ips) { - /* work around for 8812a combo hw bug => when IPS, wlanAct is always high. */ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], wifi is under IPS, set BT to ignore Wlan active!!\n"); - BTC_TRACE(trace_buf); - halbtc8812a2ant_ignore_wlan_act(btcoexist, - FORCE_EXEC, true); - } - } - } - - /* check BIT2 first ==> check if bt is under inquiry or page scan */ - if (bt_info & BT_INFO_8812A_2ANT_B_INQ_PAGE) - coex_sta->c2h_bt_inquiry_page = true; - else - coex_sta->c2h_bt_inquiry_page = false; - - /* set link exist status */ - if (!(bt_info & BT_INFO_8812A_2ANT_B_CONNECTION)) { - coex_sta->bt_link_exist = false; - coex_sta->pan_exist = false; - coex_sta->a2dp_exist = false; - coex_sta->hid_exist = false; - coex_sta->sco_exist = false; - coex_sta->acl_busy = false; - } else { /* connection exists */ - coex_sta->bt_link_exist = true; - if (bt_info & BT_INFO_8812A_2ANT_B_FTP) - coex_sta->pan_exist = true; - else - coex_sta->pan_exist = false; - if (bt_info & BT_INFO_8812A_2ANT_B_A2DP) - coex_sta->a2dp_exist = true; - else - coex_sta->a2dp_exist = false; - if (bt_info & BT_INFO_8812A_2ANT_B_HID) - coex_sta->hid_exist = true; - else - coex_sta->hid_exist = false; - if (bt_info & BT_INFO_8812A_2ANT_B_SCO_ESCO) - coex_sta->sco_exist = true; - else - coex_sta->sco_exist = false; - if (bt_info & BT_INFO_8812A_2ANT_B_ACL_BUSY) - coex_sta->acl_busy = true; - else - coex_sta->acl_busy = false; - - } - - halbtc8812a2ant_update_bt_link_info(btcoexist); - - if (!(bt_info & BT_INFO_8812A_2ANT_B_CONNECTION)) { - coex_dm->bt_status = BT_8812A_2ANT_BT_STATUS_NON_CONNECTED_IDLE; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), BT Non-Connected idle!!!\n"); - BTC_TRACE(trace_buf); - } else if (bt_info == - BT_INFO_8812A_2ANT_B_CONNECTION) { /* connection exists but no busy */ - coex_dm->bt_status = BT_8812A_2ANT_BT_STATUS_CONNECTED_IDLE; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), BT Connected-idle!!!\n"); - BTC_TRACE(trace_buf); - } else if ((bt_info & BT_INFO_8812A_2ANT_B_SCO_ESCO) || - (bt_info & BT_INFO_8812A_2ANT_B_SCO_BUSY)) { - coex_dm->bt_status = BT_8812A_2ANT_BT_STATUS_SCO_BUSY; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), BT SCO busy!!!\n"); - BTC_TRACE(trace_buf); - } else if (bt_info & BT_INFO_8812A_2ANT_B_ACL_BUSY) { - coex_dm->bt_status = BT_8812A_2ANT_BT_STATUS_ACL_BUSY; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), BT ACL busy!!!\n"); - BTC_TRACE(trace_buf); - } else { - coex_dm->bt_status = BT_8812A_2ANT_BT_STATUS_MAX; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), BT Non-Defined state!!!\n"); - BTC_TRACE(trace_buf); - } - - if ((BT_8812A_2ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) || - (BT_8812A_2ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) || - (BT_8812A_2ANT_BT_STATUS_ACL_SCO_BUSY == coex_dm->bt_status)) { - bt_busy = true; - if (!wifi_under_5g) - limited_dig = true; - } else { - bt_busy = false; - limited_dig = false; - } - - btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bt_busy); - - coex_dm->limited_dig = limited_dig; - btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_LIMITED_DIG, &limited_dig); - - halbtc8812a2ant_run_coexist_mechanism(btcoexist); -} - -void ex_halbtc8812a2ant_halt_notify(IN struct btc_coexist *btcoexist) -{ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], Halt notify\n"); - BTC_TRACE(trace_buf); - - halbtc8812a2ant_set_ant_path(btcoexist, BTC_ANT_WIFI_AT_CPL_AUX, false, - true); - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Halt notify, force set BT to ignore Wlan active!!\n"); - BTC_TRACE(trace_buf); - - halbtc8812a2ant_ignore_wlan_act(btcoexist, FORCE_EXEC, true); - ex_halbtc8812a2ant_media_status_notify(btcoexist, BTC_MEDIA_DISCONNECT); - - /* 0x522=0xff, pause tx */ - btcoexist->btc_write_1byte(btcoexist, 0x522, 0xff); - /* 0x40[7:6]=2'b01, modify BT mode. */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x40, 0xc0, 0x2); - /* PTA off. */ -#ifndef CONFIG_PCI_HCI - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x40, 0x20, 0x0); -#endif -} - -void ex_halbtc8812a2ant_periodical(IN struct btc_coexist *btcoexist) -{ - static u8 dis_ver_info_cnt = 0; - u32 fw_ver = 0, bt_patch_ver = 0; - struct btc_board_info *board_info = &btcoexist->board_info; - struct btc_stack_info *stack_info = &btcoexist->stack_info; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ==========================Periodical===========================\n"); - BTC_TRACE(trace_buf); - - if (dis_ver_info_cnt <= 5) { - dis_ver_info_cnt += 1; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ****************************************************************\n"); - BTC_TRACE(trace_buf); - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Ant PG Num/ Ant Mech/ Ant Pos = %d/ %d/ %d\n", - board_info->pg_ant_num, board_info->btdm_ant_num, - board_info->btdm_ant_pos); - BTC_TRACE(trace_buf); - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT stack/ hci ext ver = %s / %d\n", - ((stack_info->profile_notified) ? "Yes" : "No"), - stack_info->hci_version); - BTC_TRACE(trace_buf); - - btcoexist->btc_get(btcoexist, BTC_GET_U4_BT_PATCH_VER, - &bt_patch_ver); - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, &fw_ver); - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], CoexVer/ FwVer/ PatchVer = %d_%x/ 0x%x/ 0x%x(%d)\n", - glcoex_ver_date_8812a_2ant, glcoex_ver_8812a_2ant, - fw_ver, bt_patch_ver, bt_patch_ver); - BTC_TRACE(trace_buf); - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ****************************************************************\n"); - BTC_TRACE(trace_buf); - } - - if ((coex_sta->bt_coex_supported_version == 0) || - (coex_sta->bt_coex_supported_version == 0xffff)) - coex_sta->bt_coex_supported_version = - btcoexist->btc_get_bt_coex_supported_version(btcoexist); - -#if (BT_AUTO_REPORT_ONLY_8812A_2ANT == 0) - halbtc8812a2ant_query_bt_info(btcoexist); - halbtc8812a2ant_monitor_bt_ctr(btcoexist); - halbtc8812a2ant_monitor_wifi_ctr(btcoexist); - halbtc8812a2ant_monitor_bt_enable_disable(btcoexist); -#else - halbtc8812a2ant_monitor_wifi_ctr(btcoexist); - - if (halbtc8812a2ant_is_wifi_status_changed(btcoexist) || - coex_dm->auto_tdma_adjust || - coex_dm->auto_tdma_adjust_low_rssi) - halbtc8812a2ant_run_coexist_mechanism(btcoexist); -#endif -} - -void ex_halbtc8812a2ant_dbg_control(IN struct btc_coexist *btcoexist, - IN u8 op_code, IN u8 op_len, IN u8 *pdata) -{ - switch (op_code) { - case BTC_DBG_SET_COEX_DEC_BT_PWR: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Set Dec BT power\n"); - BTC_TRACE(trace_buf); - - { - u8 data_len = 4; - u8 buf[6] = {0}; - u8 dec_bt_pwr = 0, pwr_level = 0; - - if (op_len == 2) { - dec_bt_pwr = pdata[0]; - pwr_level = pdata[1]; - - buf[0] = data_len; - buf[1] = 0x3; /* OP_Code */ - buf[2] = 0x2; /* OP_Code_Length */ - - buf[3] = dec_bt_pwr; /* OP_Code_Content */ - buf[4] = pwr_level; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Set Dec BT power=%d, pwr_level=%d\n", - dec_bt_pwr, pwr_level); - BTC_TRACE(trace_buf); - - btcoexist->btc_set(btcoexist, - BTC_SET_ACT_CTRL_BT_COEX, - (void *)&buf[0]); - } - } - break; - - case BTC_DBG_SET_COEX_BT_AFH_MAP: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Set BT AFH Map\n"); - BTC_TRACE(trace_buf); - { - u8 data_len = 5; - u8 buf[6] = {0}; - - if (op_len == 3) { - buf[0] = data_len; - buf[1] = 0x5; /* OP_Code */ - buf[2] = 0x3; /* OP_Code_Length */ - - buf[3] = pdata[0]; /* OP_Code_Content */ - buf[4] = pdata[1]; - buf[5] = pdata[2]; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Set BT AFH Map = %02x %02x %02x\n", - pdata[0], pdata[1], pdata[2]); - BTC_TRACE(trace_buf); - btcoexist->btc_set(btcoexist, - BTC_SET_ACT_CTRL_BT_COEX, - (void *)&buf[0]); - } - } - break; - - case BTC_DBG_SET_COEX_BT_IGNORE_WLAN_ACT: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Set BT Ignore Wlan Active\n"); - BTC_TRACE(trace_buf); - { - u8 data_len = 3; - u8 buf[6] = {0}; - - if (op_len == 1) { - buf[0] = data_len; - buf[1] = 0x1; /* OP_Code */ - buf[2] = 0x1; /* OP_Code_Length */ - - buf[3] = pdata[0]; /* OP_Code_Content */ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Set BT Ignore Wlan Active = 0x%x\n", - pdata[0]); - BTC_TRACE(trace_buf); - - btcoexist->btc_set(btcoexist, - BTC_SET_ACT_CTRL_BT_COEX, - (void *)&buf[0]); - } - } - break; - - default: - break; - } -} - -#endif - -#endif /* #if (BT_SUPPORT == 1 && COEX_SUPPORT == 1) */ - diff --git a/hal/btc/halbtc8812a2ant.h b/hal/btc/halbtc8812a2ant.h deleted file mode 100644 index fa19aaf..0000000 --- a/hal/btc/halbtc8812a2ant.h +++ /dev/null @@ -1,227 +0,0 @@ - -#if (BT_SUPPORT == 1 && COEX_SUPPORT == 1) - -#if (RTL8812A_SUPPORT == 1) - -/* ******************************************* - * The following is for 8812A 2Ant BT Co-exist definition - * ******************************************* */ -#define BT_AUTO_REPORT_ONLY_8812A_2ANT 0 - -#define BT_INFO_8812A_2ANT_B_FTP BIT(7) -#define BT_INFO_8812A_2ANT_B_A2DP BIT(6) -#define BT_INFO_8812A_2ANT_B_HID BIT(5) -#define BT_INFO_8812A_2ANT_B_SCO_BUSY BIT(4) -#define BT_INFO_8812A_2ANT_B_ACL_BUSY BIT(3) -#define BT_INFO_8812A_2ANT_B_INQ_PAGE BIT(2) -#define BT_INFO_8812A_2ANT_B_SCO_ESCO BIT(1) -#define BT_INFO_8812A_2ANT_B_CONNECTION BIT(0) - -#define BT_INFO_8812A_2ANT_A2DP_BASIC_RATE(_BT_INFO_EXT_) \ - (((_BT_INFO_EXT_&BIT(0))) ? true : false) - -#define BTC_RSSI_COEX_THRESH_TOL_8812A_2ANT 2 -#define NOISY_AP_NUM_THRESH_8812A 50 - -enum bt_info_src_8812a_2ant { - BT_INFO_SRC_8812A_2ANT_WIFI_FW = 0x0, - BT_INFO_SRC_8812A_2ANT_BT_RSP = 0x1, - BT_INFO_SRC_8812A_2ANT_BT_ACTIVE_SEND = 0x2, - BT_INFO_SRC_8812A_2ANT_MAX -}; - -enum bt_8812a_2ant_bt_status { - BT_8812A_2ANT_BT_STATUS_NON_CONNECTED_IDLE = 0x0, - BT_8812A_2ANT_BT_STATUS_CONNECTED_IDLE = 0x1, - BT_8812A_2ANT_BT_STATUS_INQ_PAGE = 0x2, - BT_8812A_2ANT_BT_STATUS_ACL_BUSY = 0x3, - BT_8812A_2ANT_BT_STATUS_SCO_BUSY = 0x4, - BT_8812A_2ANT_BT_STATUS_ACL_SCO_BUSY = 0x5, - BT_8812A_2ANT_BT_STATUS_MAX -}; - -enum bt_8812a_2ant_coex_algo { - BT_8812A_2ANT_COEX_ALGO_UNDEFINED = 0x0, - BT_8812A_2ANT_COEX_ALGO_SCO = 0x1, - BT_8812A_2ANT_COEX_ALGO_SCO_HID = 0x2, - BT_8812A_2ANT_COEX_ALGO_HID = 0x3, - BT_8812A_2ANT_COEX_ALGO_A2DP = 0x4, - BT_8812A_2ANT_COEX_ALGO_A2DP_PANHS = 0x5, - BT_8812A_2ANT_COEX_ALGO_PANEDR = 0x6, - BT_8812A_2ANT_COEX_ALGO_PANHS = 0x7, - BT_8812A_2ANT_COEX_ALGO_PANEDR_A2DP = 0x8, - BT_8812A_2ANT_COEX_ALGO_PANEDR_HID = 0x9, - BT_8812A_2ANT_COEX_ALGO_HID_A2DP_PANEDR = 0xa, - BT_8812A_2ANT_COEX_ALGO_HID_A2DP_PANHS = 0xb, - BT_8812A_2ANT_COEX_ALGO_HID_A2DP = 0xc, - BT_8812A_2ANT_COEX_ALGO_MAX = 0xd -}; - -struct coex_dm_8812a_2ant { - /* fw mechanism */ - u8 pre_bt_dec_pwr_lvl; - u8 cur_bt_dec_pwr_lvl; - u8 pre_fw_dac_swing_lvl; - u8 cur_fw_dac_swing_lvl; - boolean cur_ignore_wlan_act; - boolean pre_ignore_wlan_act; - u8 pre_ps_tdma; - u8 cur_ps_tdma; - u8 ps_tdma_para[5]; - u8 ps_tdma_du_adj_type; - boolean auto_tdma_adjust; - boolean auto_tdma_adjust_low_rssi; - boolean pre_ps_tdma_on; - boolean cur_ps_tdma_on; - boolean pre_bt_auto_report; - boolean cur_bt_auto_report; - u8 pre_lps; - u8 cur_lps; - u8 pre_rpwm; - u8 cur_rpwm; - - /* sw mechanism */ - boolean pre_rf_rx_lpf_shrink; - boolean cur_rf_rx_lpf_shrink; - u32 bt_rf_0x1e_backup; - boolean pre_low_penalty_ra; - boolean cur_low_penalty_ra; - boolean pre_dac_swing_on; - u32 pre_dac_swing_lvl; - boolean cur_dac_swing_on; - u32 cur_dac_swing_lvl; - boolean pre_adc_back_off; - boolean cur_adc_back_off; - boolean pre_agc_table_en; - boolean cur_agc_table_en; - u32 pre_val0x6c0; - u32 cur_val0x6c0; - u32 pre_val0x6c4; - u32 cur_val0x6c4; - u32 pre_val0x6c8; - u32 cur_val0x6c8; - u8 pre_val0x6cc; - u8 cur_val0x6cc; - boolean limited_dig; - u32 backup_arfr_cnt1; /* Auto Rate Fallback Retry cnt */ - u32 backup_arfr_cnt2; /* Auto Rate Fallback Retry cnt */ - u16 backup_retry_limit; - u8 backup_ampdu_max_time; - - /* algorithm related */ - u8 pre_algorithm; - u8 cur_algorithm; - u8 bt_status; - u8 wifi_chnl_info[3]; - - u32 pre_ra_mask; - u32 cur_ra_mask; - u8 cur_ra_mask_type; - u8 pre_arfr_type; - u8 cur_arfr_type; - u8 pre_retry_limit_type; - u8 cur_retry_limit_type; - u8 pre_ampdu_time_type; - u8 cur_ampdu_time_type; - - boolean cur_enable_pta; - boolean pre_enable_pta; -}; - -struct coex_sta_8812a_2ant { - boolean bt_disabled; - boolean bt_link_exist; - boolean sco_exist; - boolean a2dp_exist; - boolean hid_exist; - boolean pan_exist; - boolean acl_busy; - - boolean under_lps; - boolean under_ips; - u32 high_priority_tx; - u32 high_priority_rx; - u32 low_priority_tx; - u32 low_priority_rx; - u8 bt_rssi; - u8 pre_bt_rssi_state; - u8 pre_wifi_rssi_state[4]; - boolean c2h_bt_info_req_sent; - u8 bt_info_c2h[BT_INFO_SRC_8812A_2ANT_MAX][10]; - u32 bt_info_c2h_cnt[BT_INFO_SRC_8812A_2ANT_MAX]; - u32 bt_info_query_cnt; - boolean c2h_bt_inquiry_page; - u8 bt_retry_cnt; - u8 bt_info_ext; - u8 scan_ap_num; - boolean pre_bt_disabled; - u32 pre_bt_info_c2h_cnt_bt_rsp; - u32 pre_bt_info_c2h_cnt_bt_send; - boolean force_lps_on; - u32 bt_coex_supported_version; - - u32 crc_ok_cck; - u32 crc_ok_11g; - u32 crc_ok_11n; - u32 crc_ok_11n_vht; - - u32 crc_err_cck; - u32 crc_err_11g; - u32 crc_err_11n; - u32 crc_err_11n_vht; -}; - -/* ******************************************* - * The following is interface which will notify coex module. - * ******************************************* */ -void ex_halbtc8812a2ant_power_on_setting(IN struct btc_coexist *btcoexist); -void ex_halbtc8812a2ant_init_hw_config(IN struct btc_coexist *btcoexist, - IN boolean wifi_only); -void ex_halbtc8812a2ant_init_coex_dm(IN struct btc_coexist *btcoexist); -void ex_halbtc8812a2ant_ips_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8812a2ant_lps_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8812a2ant_scan_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8812a2ant_connect_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8812a2ant_media_status_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8812a2ant_specific_packet_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8812a2ant_bt_info_notify(IN struct btc_coexist *btcoexist, - IN u8 *tmp_buf, IN u8 length); -void ex_halbtc8812a2ant_rf_status_notify(IN struct btc_coexist *btcoexist, - IN u8 type); - -void ex_halbtc8812a2ant_halt_notify(IN struct btc_coexist *btcoexist); -void ex_halbtc8812a2ant_periodical(IN struct btc_coexist *btcoexist); -void ex_halbtc8812a2ant_display_coex_info(IN struct btc_coexist *btcoexist); -void ex_halbtc8812a2ant_dbg_control(IN struct btc_coexist *btcoexist, - IN u8 op_code, IN u8 op_len, IN u8 *pdata); -void ex_halbtc8812a2ant_pta_off_on_notify(IN struct btc_coexist *btcoexist, - IN u8 bt_status); - -#else -#define ex_halbtc8812a2ant_power_on_setting(btcoexist) -#define ex_halbtc8812a2ant_init_hw_config(btcoexist, wifi_only) -#define ex_halbtc8812a2ant_init_coex_dm(btcoexist) -#define ex_halbtc8812a2ant_ips_notify(btcoexist, type) -#define ex_halbtc8812a2ant_lps_notify(btcoexist, type) -#define ex_halbtc8812a2ant_scan_notify(btcoexist, type) -#define ex_halbtc8812a2ant_connect_notify(btcoexist, type) -#define ex_halbtc8812a2ant_media_status_notify(btcoexist, type) -#define ex_halbtc8812a2ant_specific_packet_notify(btcoexist, type) -#define ex_halbtc8812a2ant_bt_info_notify(btcoexist, tmp_buf, length) -#define ex_halbtc8812a2ant_rf_status_notify(btcoexist, type) -#define ex_halbtc8812a2ant_halt_notify(btcoexist) -#define ex_halbtc8812a2ant_periodical(btcoexist) -#define ex_halbtc8812a2ant_display_coex_info(btcoexist) -#define ex_halbtc8812a2ant_dbg_control(btcoexist, op_code, op_len, pdata) -#define ex_halbtc8812a2ant_pta_off_on_notify(btcoexist, bt_status) - -#endif - -#endif - diff --git a/hal/btc/halbtc8821a1ant.c b/hal/btc/halbtc8821a1ant.c deleted file mode 100644 index bba78ae..0000000 --- a/hal/btc/halbtc8821a1ant.c +++ /dev/null @@ -1,3289 +0,0 @@ -/* ************************************************************ - * Description: - * - * This file is for 8821A_1ANT Co-exist mechanism - * - * History - * 2012/11/15 Cosa first check in. - * - * ************************************************************ - * SY modify 2015/04/27 - * ************************************************************ - * include files - * ************************************************************ */ -#include "mp_precomp.h" - -#if (BT_SUPPORT == 1 && COEX_SUPPORT == 1) - -#if (RTL8821A_SUPPORT == 1) -/* ************************************************************ - * Global variables, these are static variables - * ************************************************************ */ -static u8 *trace_buf = &gl_btc_trace_buf[0]; -static struct coex_dm_8821a_1ant glcoex_dm_8821a_1ant; -static struct coex_dm_8821a_1ant *coex_dm = &glcoex_dm_8821a_1ant; -static struct coex_sta_8821a_1ant glcoex_sta_8821a_1ant; -static struct coex_sta_8821a_1ant *coex_sta = &glcoex_sta_8821a_1ant; - -const char *const glbt_info_src_8821a_1ant[] = { - "BT Info[wifi fw]", - "BT Info[bt rsp]", - "BT Info[bt auto report]", -}; - -u32 glcoex_ver_date_8821a_1ant = 20160816; -u32 glcoex_ver_8821a_1ant = 0x63; -u32 glcoex_ver_btdesired_8821a_1ant = 0x62; - -/* ************************************************************ - * local function proto type if needed - * ************************************************************ - * ************************************************************ - * local function start with halbtc8821a1ant_ - * ************************************************************ */ -u8 halbtc8821a1ant_bt_rssi_state(u8 level_num, u8 rssi_thresh, u8 rssi_thresh1) -{ - s32 bt_rssi = 0; - u8 bt_rssi_state = coex_sta->pre_bt_rssi_state; - - bt_rssi = coex_sta->bt_rssi; - - if (level_num == 2) { - if ((coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_LOW) || - (coex_sta->pre_bt_rssi_state == - BTC_RSSI_STATE_STAY_LOW)) { - if (bt_rssi >= (rssi_thresh + - BTC_RSSI_COEX_THRESH_TOL_8821A_1ANT)) - bt_rssi_state = BTC_RSSI_STATE_HIGH; - else - bt_rssi_state = BTC_RSSI_STATE_STAY_LOW; - } else { - if (bt_rssi < rssi_thresh) - bt_rssi_state = BTC_RSSI_STATE_LOW; - else - bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH; - } - } else if (level_num == 3) { - if (rssi_thresh > rssi_thresh1) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Rssi thresh error!!\n"); - BTC_TRACE(trace_buf); - return coex_sta->pre_bt_rssi_state; - } - - if ((coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_LOW) || - (coex_sta->pre_bt_rssi_state == - BTC_RSSI_STATE_STAY_LOW)) { - if (bt_rssi >= (rssi_thresh + - BTC_RSSI_COEX_THRESH_TOL_8821A_1ANT)) - bt_rssi_state = BTC_RSSI_STATE_MEDIUM; - else - bt_rssi_state = BTC_RSSI_STATE_STAY_LOW; - } else if ((coex_sta->pre_bt_rssi_state == - BTC_RSSI_STATE_MEDIUM) || - (coex_sta->pre_bt_rssi_state == - BTC_RSSI_STATE_STAY_MEDIUM)) { - if (bt_rssi >= (rssi_thresh1 + - BTC_RSSI_COEX_THRESH_TOL_8821A_1ANT)) - bt_rssi_state = BTC_RSSI_STATE_HIGH; - else if (bt_rssi < rssi_thresh) - bt_rssi_state = BTC_RSSI_STATE_LOW; - else - bt_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM; - } else { - if (bt_rssi < rssi_thresh1) - bt_rssi_state = BTC_RSSI_STATE_MEDIUM; - else - bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH; - } - } - - coex_sta->pre_bt_rssi_state = bt_rssi_state; - - return bt_rssi_state; -} - -u8 halbtc8821a1ant_wifi_rssi_state(IN struct btc_coexist *btcoexist, - IN u8 index, IN u8 level_num, IN u8 rssi_thresh, IN u8 rssi_thresh1) -{ - s32 wifi_rssi = 0; - u8 wifi_rssi_state = coex_sta->pre_wifi_rssi_state[index]; - - btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi); - - if (level_num == 2) { - if ((coex_sta->pre_wifi_rssi_state[index] == BTC_RSSI_STATE_LOW) - || - (coex_sta->pre_wifi_rssi_state[index] == - BTC_RSSI_STATE_STAY_LOW)) { - if (wifi_rssi >= (rssi_thresh + - BTC_RSSI_COEX_THRESH_TOL_8821A_1ANT)) - wifi_rssi_state = BTC_RSSI_STATE_HIGH; - else - wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW; - } else { - if (wifi_rssi < rssi_thresh) - wifi_rssi_state = BTC_RSSI_STATE_LOW; - else - wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH; - } - } else if (level_num == 3) { - if (rssi_thresh > rssi_thresh1) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], wifi RSSI thresh error!!\n"); - BTC_TRACE(trace_buf); - return coex_sta->pre_wifi_rssi_state[index]; - } - - if ((coex_sta->pre_wifi_rssi_state[index] == BTC_RSSI_STATE_LOW) - || - (coex_sta->pre_wifi_rssi_state[index] == - BTC_RSSI_STATE_STAY_LOW)) { - if (wifi_rssi >= (rssi_thresh + - BTC_RSSI_COEX_THRESH_TOL_8821A_1ANT)) - wifi_rssi_state = BTC_RSSI_STATE_MEDIUM; - else - wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW; - } else if ((coex_sta->pre_wifi_rssi_state[index] == - BTC_RSSI_STATE_MEDIUM) || - (coex_sta->pre_wifi_rssi_state[index] == - BTC_RSSI_STATE_STAY_MEDIUM)) { - if (wifi_rssi >= (rssi_thresh1 + - BTC_RSSI_COEX_THRESH_TOL_8821A_1ANT)) - wifi_rssi_state = BTC_RSSI_STATE_HIGH; - else if (wifi_rssi < rssi_thresh) - wifi_rssi_state = BTC_RSSI_STATE_LOW; - else - wifi_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM; - } else { - if (wifi_rssi < rssi_thresh1) - wifi_rssi_state = BTC_RSSI_STATE_MEDIUM; - else - wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH; - } - } - - coex_sta->pre_wifi_rssi_state[index] = wifi_rssi_state; - - return wifi_rssi_state; -} - -void halbtc8821a1ant_update_ra_mask(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u32 dis_rate_mask) -{ - coex_dm->cur_ra_mask = dis_rate_mask; - - if (force_exec || (coex_dm->pre_ra_mask != coex_dm->cur_ra_mask)) - btcoexist->btc_set(btcoexist, BTC_SET_ACT_UPDATE_RAMASK, - &coex_dm->cur_ra_mask); - coex_dm->pre_ra_mask = coex_dm->cur_ra_mask; -} - -void halbtc8821a1ant_auto_rate_fallback_retry(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 type) -{ - boolean wifi_under_b_mode = false; - - coex_dm->cur_arfr_type = type; - - if (force_exec || (coex_dm->pre_arfr_type != coex_dm->cur_arfr_type)) { - switch (coex_dm->cur_arfr_type) { - case 0: /* normal mode */ - btcoexist->btc_write_4byte(btcoexist, 0x430, - coex_dm->backup_arfr_cnt1); - btcoexist->btc_write_4byte(btcoexist, 0x434, - coex_dm->backup_arfr_cnt2); - break; - case 1: - btcoexist->btc_get(btcoexist, - BTC_GET_BL_WIFI_UNDER_B_MODE, - &wifi_under_b_mode); - if (wifi_under_b_mode) { - btcoexist->btc_write_4byte(btcoexist, - 0x430, 0x0); - btcoexist->btc_write_4byte(btcoexist, - 0x434, 0x01010101); - } else { - btcoexist->btc_write_4byte(btcoexist, - 0x430, 0x0); - btcoexist->btc_write_4byte(btcoexist, - 0x434, 0x04030201); - } - break; - default: - break; - } - } - - coex_dm->pre_arfr_type = coex_dm->cur_arfr_type; -} - -void halbtc8821a1ant_retry_limit(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 type) -{ - coex_dm->cur_retry_limit_type = type; - - if (force_exec || - (coex_dm->pre_retry_limit_type != - coex_dm->cur_retry_limit_type)) { - switch (coex_dm->cur_retry_limit_type) { - case 0: /* normal mode */ - btcoexist->btc_write_2byte(btcoexist, 0x42a, - coex_dm->backup_retry_limit); - break; - case 1: /* retry limit=8 */ - btcoexist->btc_write_2byte(btcoexist, 0x42a, - 0x0808); - break; - default: - break; - } - } - - coex_dm->pre_retry_limit_type = coex_dm->cur_retry_limit_type; -} - -void halbtc8821a1ant_ampdu_max_time(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 type) -{ - coex_dm->cur_ampdu_time_type = type; - - if (force_exec || - (coex_dm->pre_ampdu_time_type != coex_dm->cur_ampdu_time_type)) { - switch (coex_dm->cur_ampdu_time_type) { - case 0: /* normal mode */ - btcoexist->btc_write_1byte(btcoexist, 0x456, - coex_dm->backup_ampdu_max_time); - break; - case 1: /* AMPDU timw = 0x38 * 32us */ - btcoexist->btc_write_1byte(btcoexist, 0x456, - 0x38); - break; - default: - break; - } - } - - coex_dm->pre_ampdu_time_type = coex_dm->cur_ampdu_time_type; -} - -void halbtc8821a1ant_limited_tx(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 ra_mask_type, IN u8 arfr_type, - IN u8 retry_limit_type, IN u8 ampdu_time_type) -{ - switch (ra_mask_type) { - case 0: /* normal mode */ - halbtc8821a1ant_update_ra_mask(btcoexist, force_exec, - 0x0); - break; - case 1: /* disable cck 1/2 */ - halbtc8821a1ant_update_ra_mask(btcoexist, force_exec, - 0x00000003); - break; - case 2: /* disable cck 1/2/5.5, ofdm 6/9/12/18/24, mcs 0/1/2/3/4 */ - halbtc8821a1ant_update_ra_mask(btcoexist, force_exec, - 0x0001f1f7); - break; - default: - break; - } - - halbtc8821a1ant_auto_rate_fallback_retry(btcoexist, force_exec, - arfr_type); - halbtc8821a1ant_retry_limit(btcoexist, force_exec, retry_limit_type); - halbtc8821a1ant_ampdu_max_time(btcoexist, force_exec, ampdu_time_type); -} - - -/* true/xxxx/x:1 - * false/false/x: 64 - * false/true/x:x */ -void halbtc8821a1ant_limited_rx(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean rej_ap_agg_pkt, - IN boolean bt_ctrl_agg_buf_size, IN u8 agg_buf_size) -{ - boolean reject_rx_agg = rej_ap_agg_pkt; - boolean bt_ctrl_rx_agg_size = bt_ctrl_agg_buf_size; - u8 rx_agg_size = agg_buf_size; - - /* ============================================ */ - /* Rx Aggregation related setting */ - /* ============================================ */ - btcoexist->btc_set(btcoexist, BTC_SET_BL_TO_REJ_AP_AGG_PKT, - &reject_rx_agg); - /* decide BT control aggregation buf size or not */ - btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_CTRL_AGG_SIZE, - &bt_ctrl_rx_agg_size); - /* aggregation buf size, only work when BT control Rx aggregation size. */ - btcoexist->btc_set(btcoexist, BTC_SET_U1_AGG_BUF_SIZE, &rx_agg_size); - /* real update aggregation setting */ - btcoexist->btc_set(btcoexist, BTC_SET_ACT_AGGREGATE_CTRL, NULL); - - -} - -void halbtc8821a1ant_monitor_bt_ctr(IN struct btc_coexist *btcoexist) -{ - u32 reg_hp_txrx, reg_lp_txrx, u32tmp; - u32 reg_hp_tx = 0, reg_hp_rx = 0, reg_lp_tx = 0, reg_lp_rx = 0; -#if 0 - /* to avoid 0x76e[3] = 1 (WLAN_Act control by PTA) during IPS */ - if (!(btcoexist->btc_read_1byte(btcoexist, 0x76e) & 0x8)) { - coex_sta->high_priority_tx = 65535; - coex_sta->high_priority_rx = 65535; - coex_sta->low_priority_tx = 65535; - coex_sta->low_priority_rx = 65535; - return; - } -#endif - reg_hp_txrx = 0x770; - reg_lp_txrx = 0x774; - - u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_hp_txrx); - reg_hp_tx = u32tmp & MASKLWORD; - reg_hp_rx = (u32tmp & MASKHWORD) >> 16; - - u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_lp_txrx); - reg_lp_tx = u32tmp & MASKLWORD; - reg_lp_rx = (u32tmp & MASKHWORD) >> 16; - - coex_sta->high_priority_tx = reg_hp_tx; - coex_sta->high_priority_rx = reg_hp_rx; - coex_sta->low_priority_tx = reg_lp_tx; - coex_sta->low_priority_rx = reg_lp_rx; - - /* reset counter */ - btcoexist->btc_write_1byte(btcoexist, 0x76e, 0xc); -} - -void halbtc8821a1ant_monitor_wifi_ctr(IN struct btc_coexist *btcoexist) -{ -#if 1 - - coex_sta->crc_ok_cck = btcoexist->btc_phydm_query_PHY_counter( - btcoexist, - PHYDM_INFO_CRC32_OK_CCK); - coex_sta->crc_ok_11g = btcoexist->btc_phydm_query_PHY_counter( - btcoexist, - PHYDM_INFO_CRC32_OK_LEGACY); - coex_sta->crc_ok_11n = btcoexist->btc_phydm_query_PHY_counter( - btcoexist, - PHYDM_INFO_CRC32_OK_HT); - coex_sta->crc_ok_11n_vht = - btcoexist->btc_phydm_query_PHY_counter( - btcoexist, - PHYDM_INFO_CRC32_OK_VHT); - - coex_sta->crc_err_cck = btcoexist->btc_phydm_query_PHY_counter( - btcoexist, - PHYDM_INFO_CRC32_ERROR_CCK); - coex_sta->crc_err_11g = btcoexist->btc_phydm_query_PHY_counter( - btcoexist, - PHYDM_INFO_CRC32_ERROR_LEGACY); - coex_sta->crc_err_11n = btcoexist->btc_phydm_query_PHY_counter( - btcoexist, - PHYDM_INFO_CRC32_ERROR_HT); - coex_sta->crc_err_11n_vht = - btcoexist->btc_phydm_query_PHY_counter( - btcoexist, - PHYDM_INFO_CRC32_ERROR_VHT); - -#endif -} - - -void halbtc8821a1ant_query_bt_info(IN struct btc_coexist *btcoexist) -{ - u8 h2c_parameter[1] = {0}; - - coex_sta->c2h_bt_info_req_sent = true; - - h2c_parameter[0] |= BIT(0); /* trigger */ - - btcoexist->btc_fill_h2c(btcoexist, 0x61, 1, h2c_parameter); -} - -boolean halbtc8821a1ant_is_wifi_status_changed(IN struct btc_coexist *btcoexist) -{ - static boolean pre_wifi_busy = false, pre_under_4way = false, - pre_bt_hs_on = false; - boolean wifi_busy = false, under_4way = false, bt_hs_on = false; - boolean wifi_connected = false; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS, - &under_4way); - - if (wifi_connected) { - if (wifi_busy != pre_wifi_busy) { - pre_wifi_busy = wifi_busy; - return true; - } - if (under_4way != pre_under_4way) { - pre_under_4way = under_4way; - return true; - } - if (bt_hs_on != pre_bt_hs_on) { - pre_bt_hs_on = bt_hs_on; - return true; - } - } - - return false; -} - -void halbtc8821a1ant_update_bt_link_info(IN struct btc_coexist *btcoexist) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - boolean bt_hs_on = false; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); - - bt_link_info->bt_link_exist = coex_sta->bt_link_exist; - bt_link_info->sco_exist = coex_sta->sco_exist; - bt_link_info->a2dp_exist = coex_sta->a2dp_exist; - bt_link_info->pan_exist = coex_sta->pan_exist; - bt_link_info->hid_exist = coex_sta->hid_exist; - - /* work around for HS mode. */ - if (bt_hs_on) { - bt_link_info->pan_exist = true; - bt_link_info->bt_link_exist = true; - } - - /* check if Sco only */ - if (bt_link_info->sco_exist && - !bt_link_info->a2dp_exist && - !bt_link_info->pan_exist && - !bt_link_info->hid_exist) - bt_link_info->sco_only = true; - else - bt_link_info->sco_only = false; - - /* check if A2dp only */ - if (!bt_link_info->sco_exist && - bt_link_info->a2dp_exist && - !bt_link_info->pan_exist && - !bt_link_info->hid_exist) - bt_link_info->a2dp_only = true; - else - bt_link_info->a2dp_only = false; - - /* check if Pan only */ - if (!bt_link_info->sco_exist && - !bt_link_info->a2dp_exist && - bt_link_info->pan_exist && - !bt_link_info->hid_exist) - bt_link_info->pan_only = true; - else - bt_link_info->pan_only = false; - - /* check if Hid only */ - if (!bt_link_info->sco_exist && - !bt_link_info->a2dp_exist && - !bt_link_info->pan_exist && - bt_link_info->hid_exist) - bt_link_info->hid_only = true; - else - bt_link_info->hid_only = false; -} - -u8 halbtc8821a1ant_action_algorithm(IN struct btc_coexist *btcoexist) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - boolean bt_hs_on = false; - u8 algorithm = BT_8821A_1ANT_COEX_ALGO_UNDEFINED; - u8 num_of_diff_profile = 0; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); - - if (!bt_link_info->bt_link_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], No BT link exists!!!\n"); - BTC_TRACE(trace_buf); - return algorithm; - } - - if (bt_link_info->sco_exist) - num_of_diff_profile++; - if (bt_link_info->hid_exist) - num_of_diff_profile++; - if (bt_link_info->pan_exist) - num_of_diff_profile++; - if (bt_link_info->a2dp_exist) - num_of_diff_profile++; - - if (num_of_diff_profile == 1) { - if (bt_link_info->sco_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = SCO only\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8821A_1ANT_COEX_ALGO_SCO; - } else { - if (bt_link_info->hid_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = HID only\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8821A_1ANT_COEX_ALGO_HID; - } else if (bt_link_info->a2dp_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = A2DP only\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8821A_1ANT_COEX_ALGO_A2DP; - } else if (bt_link_info->pan_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = PAN(HS) only\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8821A_1ANT_COEX_ALGO_PANHS; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = PAN(EDR) only\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8821A_1ANT_COEX_ALGO_PANEDR; - } - } - } - } else if (num_of_diff_profile == 2) { - if (bt_link_info->sco_exist) { - if (bt_link_info->hid_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = SCO + HID\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8821A_1ANT_COEX_ALGO_HID; - } else if (bt_link_info->a2dp_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = SCO + A2DP ==> SCO\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8821A_1ANT_COEX_ALGO_SCO; - } else if (bt_link_info->pan_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = SCO + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8821A_1ANT_COEX_ALGO_SCO; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = SCO + PAN(EDR)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8821A_1ANT_COEX_ALGO_PANEDR_HID; - } - } - } else { - if (bt_link_info->hid_exist && - bt_link_info->a2dp_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = HID + A2DP\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8821A_1ANT_COEX_ALGO_HID_A2DP; - } else if (bt_link_info->hid_exist && - bt_link_info->pan_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = HID + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8821A_1ANT_COEX_ALGO_HID_A2DP; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = HID + PAN(EDR)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8821A_1ANT_COEX_ALGO_PANEDR_HID; - } - } else if (bt_link_info->pan_exist && - bt_link_info->a2dp_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = A2DP + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8821A_1ANT_COEX_ALGO_A2DP_PANHS; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = A2DP + PAN(EDR)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8821A_1ANT_COEX_ALGO_PANEDR_A2DP; - } - } - } - } else if (num_of_diff_profile == 3) { - if (bt_link_info->sco_exist) { - if (bt_link_info->hid_exist && - bt_link_info->a2dp_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = SCO + HID + A2DP ==> HID\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8821A_1ANT_COEX_ALGO_HID; - } else if (bt_link_info->hid_exist && - bt_link_info->pan_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = SCO + HID + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8821A_1ANT_COEX_ALGO_HID_A2DP; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = SCO + HID + PAN(EDR)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8821A_1ANT_COEX_ALGO_PANEDR_HID; - } - } else if (bt_link_info->pan_exist && - bt_link_info->a2dp_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = SCO + A2DP + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8821A_1ANT_COEX_ALGO_SCO; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = SCO + A2DP + PAN(EDR) ==> HID\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8821A_1ANT_COEX_ALGO_PANEDR_HID; - } - } - } else { - if (bt_link_info->hid_exist && - bt_link_info->pan_exist && - bt_link_info->a2dp_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = HID + A2DP + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8821A_1ANT_COEX_ALGO_HID_A2DP; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = HID + A2DP + PAN(EDR)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8821A_1ANT_COEX_ALGO_HID_A2DP_PANEDR; - } - } - } - } else if (num_of_diff_profile >= 3) { - if (bt_link_info->sco_exist) { - if (bt_link_info->hid_exist && - bt_link_info->pan_exist && - bt_link_info->a2dp_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Error!!! BT Profile = SCO + HID + A2DP + PAN(HS)\n"); - BTC_TRACE(trace_buf); - - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = SCO + HID + A2DP + PAN(EDR)==>PAN(EDR)+HID\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8821A_1ANT_COEX_ALGO_PANEDR_HID; - } - } - } - } - - return algorithm; -} - -void halbtc8821a1ant_set_bt_auto_report(IN struct btc_coexist *btcoexist, - IN boolean enable_auto_report) -{ - u8 h2c_parameter[1] = {0}; - - h2c_parameter[0] = 0; - - if (enable_auto_report) - h2c_parameter[0] |= BIT(0); - - btcoexist->btc_fill_h2c(btcoexist, 0x68, 1, h2c_parameter); -} - -void halbtc8821a1ant_bt_auto_report(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean enable_auto_report) -{ - coex_dm->cur_bt_auto_report = enable_auto_report; - - if (!force_exec) { - if (coex_dm->pre_bt_auto_report == coex_dm->cur_bt_auto_report) - return; - } - halbtc8821a1ant_set_bt_auto_report(btcoexist, - coex_dm->cur_bt_auto_report); - - coex_dm->pre_bt_auto_report = coex_dm->cur_bt_auto_report; -} - -void halbtc8821a1ant_set_sw_penalty_tx_rate_adaptive(IN struct btc_coexist - *btcoexist, IN boolean low_penalty_ra) -{ - u8 h2c_parameter[6] = {0}; - - h2c_parameter[0] = 0x6; /* op_code, 0x6= Retry_Penalty */ - - if (low_penalty_ra) { - h2c_parameter[1] |= BIT(0); - h2c_parameter[2] = - 0x00; /* normal rate except MCS7/6/5, OFDM54/48/36 */ - h2c_parameter[3] = 0xf5; /* MCS7 or OFDM54 */ - h2c_parameter[4] = 0xa0; /* MCS6 or OFDM48 */ - h2c_parameter[5] = 0xa0; /* MCS5 or OFDM36 */ - } - - btcoexist->btc_fill_h2c(btcoexist, 0x69, 6, h2c_parameter); -} - -void halbtc8821a1ant_low_penalty_ra(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean low_penalty_ra) -{ - coex_dm->cur_low_penalty_ra = low_penalty_ra; - - if (!force_exec) { - if (coex_dm->pre_low_penalty_ra == coex_dm->cur_low_penalty_ra) - return; - } - halbtc8821a1ant_set_sw_penalty_tx_rate_adaptive(btcoexist, - coex_dm->cur_low_penalty_ra); - - coex_dm->pre_low_penalty_ra = coex_dm->cur_low_penalty_ra; -} - -void halbtc8821a1ant_set_coex_table(IN struct btc_coexist *btcoexist, - IN u32 val0x6c0, IN u32 val0x6c4, IN u32 val0x6c8, IN u8 val0x6cc) -{ - btcoexist->btc_write_4byte(btcoexist, 0x6c0, val0x6c0); - - btcoexist->btc_write_4byte(btcoexist, 0x6c4, val0x6c4); - - btcoexist->btc_write_4byte(btcoexist, 0x6c8, val0x6c8); - - btcoexist->btc_write_1byte(btcoexist, 0x6cc, val0x6cc); -} - -void halbtc8821a1ant_coex_table(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u32 val0x6c0, IN u32 val0x6c4, - IN u32 val0x6c8, IN u8 val0x6cc) -{ - coex_dm->cur_val0x6c0 = val0x6c0; - coex_dm->cur_val0x6c4 = val0x6c4; - coex_dm->cur_val0x6c8 = val0x6c8; - coex_dm->cur_val0x6cc = val0x6cc; - - if (!force_exec) { - if ((coex_dm->pre_val0x6c0 == coex_dm->cur_val0x6c0) && - (coex_dm->pre_val0x6c4 == coex_dm->cur_val0x6c4) && - (coex_dm->pre_val0x6c8 == coex_dm->cur_val0x6c8) && - (coex_dm->pre_val0x6cc == coex_dm->cur_val0x6cc)) - return; - } - halbtc8821a1ant_set_coex_table(btcoexist, val0x6c0, val0x6c4, val0x6c8, - val0x6cc); - - coex_dm->pre_val0x6c0 = coex_dm->cur_val0x6c0; - coex_dm->pre_val0x6c4 = coex_dm->cur_val0x6c4; - coex_dm->pre_val0x6c8 = coex_dm->cur_val0x6c8; - coex_dm->pre_val0x6cc = coex_dm->cur_val0x6cc; -} - -void halbtc8821a1ant_coex_table_with_type(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 type) -{ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** CoexTable(%d) **********\n", type); - BTC_TRACE(trace_buf); - - switch (type) { - case 0: - halbtc8821a1ant_coex_table(btcoexist, force_exec, - 0x55555555, 0x55555555, 0xffffff, 0x3); - break; - case 1: - halbtc8821a1ant_coex_table(btcoexist, force_exec, - 0x55555555, 0x5a5a5a5a, 0xffffff, 0x3); - break; - case 2: - halbtc8821a1ant_coex_table(btcoexist, force_exec, - 0x5a5a5a5a, 0x5a5a5a5a, 0xffffff, 0x3); - break; - case 3: - halbtc8821a1ant_coex_table(btcoexist, force_exec, - 0x5a5a5a5a, 0xaaaaaaaa, 0xffffff, 0x3); - break; - case 4: - halbtc8821a1ant_coex_table(btcoexist, force_exec, - 0x55555555, 0x5a5a5a5a, 0xffffff, 0x3); - break; - case 5: - halbtc8821a1ant_coex_table(btcoexist, force_exec, - 0x5a5a5a5a, 0xaaaa5a5a, 0xffffff, 0x3); - break; - case 6: - halbtc8821a1ant_coex_table(btcoexist, force_exec, - 0x55555555, 0xaaaa5a5a, 0xffffff, 0x3); - break; - case 7: - halbtc8821a1ant_coex_table(btcoexist, force_exec, - 0xaaaaaaaa, 0xaaaaaaaa, 0xffffff, 0x3); - break; - default: - break; - } -} - -void halbtc8821a1ant_set_fw_ignore_wlan_act(IN struct btc_coexist *btcoexist, - IN boolean enable) -{ - u8 h2c_parameter[1] = {0}; - - if (enable) - h2c_parameter[0] |= BIT(0); /* function enable */ - - btcoexist->btc_fill_h2c(btcoexist, 0x63, 1, h2c_parameter); -} - -void halbtc8821a1ant_ignore_wlan_act(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean enable) -{ - coex_dm->cur_ignore_wlan_act = enable; - - if (!force_exec) { - if (coex_dm->pre_ignore_wlan_act == - coex_dm->cur_ignore_wlan_act) - return; - } - halbtc8821a1ant_set_fw_ignore_wlan_act(btcoexist, enable); - - coex_dm->pre_ignore_wlan_act = coex_dm->cur_ignore_wlan_act; -} - -void halbtc8821a1ant_set_fw_pstdma(IN struct btc_coexist *btcoexist, - IN u8 byte1, IN u8 byte2, IN u8 byte3, IN u8 byte4, IN u8 byte5) -{ - u8 h2c_parameter[5] = {0}; - u8 real_byte1 = byte1, real_byte5 = byte5; - boolean ap_enable = false; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, - &ap_enable); - - if (ap_enable) { - if (byte1 & BIT(4) && !(byte1 & BIT(5))) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], FW for 1Ant AP mode\n"); - BTC_TRACE(trace_buf); - real_byte1 &= ~BIT(4); - real_byte1 |= BIT(5); - - real_byte5 |= BIT(5); - real_byte5 &= ~BIT(6); - } - } - - h2c_parameter[0] = real_byte1; - h2c_parameter[1] = byte2; - h2c_parameter[2] = byte3; - h2c_parameter[3] = byte4; - h2c_parameter[4] = real_byte5; - - coex_dm->ps_tdma_para[0] = real_byte1; - coex_dm->ps_tdma_para[1] = byte2; - coex_dm->ps_tdma_para[2] = byte3; - coex_dm->ps_tdma_para[3] = byte4; - coex_dm->ps_tdma_para[4] = real_byte5; - - btcoexist->btc_fill_h2c(btcoexist, 0x60, 5, h2c_parameter); -} - -void halbtc8821a1ant_set_lps_rpwm(IN struct btc_coexist *btcoexist, - IN u8 lps_val, IN u8 rpwm_val) -{ - u8 lps = lps_val; - u8 rpwm = rpwm_val; - - btcoexist->btc_set(btcoexist, BTC_SET_U1_LPS_VAL, &lps); - btcoexist->btc_set(btcoexist, BTC_SET_U1_RPWM_VAL, &rpwm); -} - -void halbtc8821a1ant_lps_rpwm(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 lps_val, IN u8 rpwm_val) -{ - coex_dm->cur_lps = lps_val; - coex_dm->cur_rpwm = rpwm_val; - - if (!force_exec) { - if ((coex_dm->pre_lps == coex_dm->cur_lps) && - (coex_dm->pre_rpwm == coex_dm->cur_rpwm)) - return; - } - halbtc8821a1ant_set_lps_rpwm(btcoexist, lps_val, rpwm_val); - - coex_dm->pre_lps = coex_dm->cur_lps; - coex_dm->pre_rpwm = coex_dm->cur_rpwm; -} - -void halbtc8821a1ant_sw_mechanism(IN struct btc_coexist *btcoexist, - IN boolean low_penalty_ra) -{ - halbtc8821a1ant_low_penalty_ra(btcoexist, NORMAL_EXEC, low_penalty_ra); -} - -void halbtc8821a1ant_set_ant_path(IN struct btc_coexist *btcoexist, - IN u8 ant_pos_type, IN boolean init_hwcfg, IN boolean wifi_off) -{ - struct btc_board_info *board_info = &btcoexist->board_info; - u32 u32tmp = 0; - u8 h2c_parameter[2] = {0}; - - if (init_hwcfg) { - /* 0x4c[23]=0, 0x4c[24]=1 Antenna control by WL/BT */ - u32tmp = btcoexist->btc_read_4byte(btcoexist, 0x4c); - u32tmp &= ~BIT(23); - u32tmp |= BIT(24); - btcoexist->btc_write_4byte(btcoexist, 0x4c, u32tmp); - - /* 0x765 = 0x18 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x765, 0x18, 0x3); - - if (board_info->btdm_ant_pos == BTC_ANTENNA_AT_MAIN_PORT) { - /* tell firmware "antenna inverse" ==> WRONG firmware antenna control code.==>need fw to fix */ - h2c_parameter[0] = 1; - h2c_parameter[1] = 1; - btcoexist->btc_fill_h2c(btcoexist, 0x65, 2, - h2c_parameter); - - /* btcoexist->btc_write_1byte_bitmask(btcoexist, 0x64, 0x1, 0x1); */ /*Main Ant to BT for IPS case 0x4c[23]=1 */ - } else { - /* tell firmware "no antenna inverse" ==> WRONG firmware antenna control code.==>need fw to fix */ - h2c_parameter[0] = 0; - h2c_parameter[1] = 1; - btcoexist->btc_fill_h2c(btcoexist, 0x65, 2, - h2c_parameter); - - /* btcoexist->btc_write_1byte_bitmask(btcoexist, 0x64, 0x1, 0x0); */ /*Aux Ant to BT for IPS case 0x4c[23]=1 */ - } - } else if (wifi_off) { - /* 0x4c[24:23]=00, Set Antenna control by BT_RFE_CTRL BT Vendor 0xac=0xf002 */ - u32tmp = btcoexist->btc_read_4byte(btcoexist, 0x4c); - u32tmp &= ~BIT(23); - u32tmp &= ~BIT(24); - btcoexist->btc_write_4byte(btcoexist, 0x4c, u32tmp); - - /* 0x765 = 0x18 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x765, 0x18, 0x3); - } else { - /* 0x765 = 0x0 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x765, 0x18, 0x0); - } - - /* ext switch setting */ - switch (ant_pos_type) { - case BTC_ANT_PATH_WIFI: - btcoexist->btc_write_1byte(btcoexist, 0xcb4, 0x77); - if (board_info->btdm_ant_pos == - BTC_ANTENNA_AT_MAIN_PORT) - btcoexist->btc_write_1byte_bitmask(btcoexist, - 0xcb7, 0x30, 0x1); - else - btcoexist->btc_write_1byte_bitmask(btcoexist, - 0xcb7, 0x30, 0x2); - break; - case BTC_ANT_PATH_BT: - btcoexist->btc_write_1byte(btcoexist, 0xcb4, 0x77); - if (board_info->btdm_ant_pos == - BTC_ANTENNA_AT_MAIN_PORT) - btcoexist->btc_write_1byte_bitmask(btcoexist, - 0xcb7, 0x30, 0x2); - else - btcoexist->btc_write_1byte_bitmask(btcoexist, - 0xcb7, 0x30, 0x1); - break; - default: - case BTC_ANT_PATH_PTA: - btcoexist->btc_write_1byte(btcoexist, 0xcb4, 0x66); - if (board_info->btdm_ant_pos == - BTC_ANTENNA_AT_MAIN_PORT) - btcoexist->btc_write_1byte_bitmask(btcoexist, - 0xcb7, 0x30, 0x1); - else - btcoexist->btc_write_1byte_bitmask(btcoexist, - 0xcb7, 0x30, 0x2); - break; - } -} - -void halbtc8821a1ant_ps_tdma(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean turn_on, IN u8 type) -{ - u8 rssi_adjust_val = 0; - /* u32 fw_ver=0; */ - - coex_dm->cur_ps_tdma_on = turn_on; - coex_dm->cur_ps_tdma = type; - - if (coex_dm->cur_ps_tdma_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** TDMA(on, %d) **********\n", - coex_dm->cur_ps_tdma); - BTC_TRACE(trace_buf); - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** TDMA(off, %d) **********\n", - coex_dm->cur_ps_tdma); - BTC_TRACE(trace_buf); - } - - if (!force_exec) { - if ((coex_dm->pre_ps_tdma_on == coex_dm->cur_ps_tdma_on) && - (coex_dm->pre_ps_tdma == coex_dm->cur_ps_tdma)) - return; - } - if (turn_on) { - switch (type) { - default: - halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51, - 0x1a, 0x1a, 0x0, 0x50); - break; - case 1: - halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51, - 0x3a, 0x03, 0x10, 0x50); - rssi_adjust_val = 11; - break; - case 2: - halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51, - 0x2b, 0x03, 0x10, 0x50); - rssi_adjust_val = 14; - break; - case 3: - halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51, - 0x1d, 0x1d, 0x0, 0x52); - break; - case 4: - halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x93, - 0x15, 0x3, 0x14, 0x0); - rssi_adjust_val = 17; - break; - case 5: - halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x61, - 0x15, 0x3, 0x11, 0x10); - break; - case 6: - halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x61, - 0x20, 0x3, 0x11, 0x13); - break; - case 7: - halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x13, - 0xc, 0x5, 0x0, 0x0); - break; - case 8: - halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x93, - 0x25, 0x3, 0x10, 0x0); - break; - case 9: - halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51, - 0x21, 0x3, 0x10, 0x50); - rssi_adjust_val = 18; - break; - case 10: - halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x13, - 0xa, 0xa, 0x0, 0x40); - break; - case 11: - halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51, - 0x15, 0x03, 0x10, 0x50); - rssi_adjust_val = 20; - break; - case 12: - halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51, - 0x0a, 0x0a, 0x0, 0x50); - break; - case 13: - if (coex_sta->scan_ap_num <= 5) - halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51, - 0x40, 0x3, 0x10, 0x50); - else - halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51, - 0x12, 0x12, 0x0, 0x50); - break; - case 14: - if (coex_sta->scan_ap_num <= 5) - halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51, - 0x30, 0x3, 0x10, 0x50); - else - halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51, - 0x1e, 0x3, 0x10, 0x14); - break; - case 15: - halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x13, - 0xa, 0x3, 0x8, 0x0); - break; - case 16: - halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x93, - 0x15, 0x3, 0x10, 0x0); - rssi_adjust_val = 18; - break; - case 18: - halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x93, - 0x25, 0x3, 0x10, 0x0); - rssi_adjust_val = 14; - break; - case 20: - halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x61, - 0x35, 0x03, 0x11, 0x10); - break; - case 21: - halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x61, - 0x25, 0x03, 0x11, 0x11); - break; - case 22: - halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x61, - 0x25, 0x03, 0x11, 0x10); - break; - case 23: - halbtc8821a1ant_set_fw_pstdma(btcoexist, 0xe3, - 0x25, 0x3, 0x31, 0x18); - rssi_adjust_val = 22; - break; - case 24: - halbtc8821a1ant_set_fw_pstdma(btcoexist, 0xe3, - 0x15, 0x3, 0x31, 0x18); - rssi_adjust_val = 22; - break; - case 25: - halbtc8821a1ant_set_fw_pstdma(btcoexist, 0xe3, - 0xa, 0x3, 0x31, 0x18); - rssi_adjust_val = 22; - break; - case 26: - halbtc8821a1ant_set_fw_pstdma(btcoexist, 0xe3, - 0xa, 0x3, 0x31, 0x18); - rssi_adjust_val = 22; - break; - case 27: - halbtc8821a1ant_set_fw_pstdma(btcoexist, 0xe3, - 0x25, 0x3, 0x31, 0x98); - rssi_adjust_val = 22; - break; - case 28: - halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x69, - 0x25, 0x3, 0x31, 0x0); - break; - case 29: - halbtc8821a1ant_set_fw_pstdma(btcoexist, 0xab, - 0x1a, 0x1a, 0x1, 0x10); - break; - case 30: - halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51, - 0x30, 0x3, 0x10, 0x10); - break; - case 31: - halbtc8821a1ant_set_fw_pstdma(btcoexist, 0xd3, - 0x1a, 0x1a, 0, 0x58); - break; - case 32: - halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x61, - 0x35, 0x3, 0x11, 0x11); - break; - case 33: - halbtc8821a1ant_set_fw_pstdma(btcoexist, 0xa3, - 0x25, 0x3, 0x30, 0x90); - break; - case 34: - halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x53, - 0x1a, 0x1a, 0x0, 0x10); - break; - case 35: - halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x63, - 0x1a, 0x1a, 0x0, 0x10); - break; - case 36: - halbtc8821a1ant_set_fw_pstdma(btcoexist, 0xd3, - 0x12, 0x3, 0x14, 0x50); - break; - case 40: /* SoftAP only with no sta associated,BT disable ,TDMA mode for power saving */ - /* here softap mode screen off will cost 70-80mA for phone */ - halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x23, - 0x18, 0x00, 0x10, 0x24); - break; - case 41: - halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51, - 0x15, 0x3, 0x11, 0x11); - break; - case 42: - halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51, - 0x20, 0x3, 0x11, 0x11); - break; - case 43: - halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51, - 0x30, 0x3, 0x10, 0x11); - break; - } - } else { - /* disable PS tdma */ - switch (type) { - case 8: /* PTA Control */ - halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x8, - 0x0, 0x0, 0x0, 0x0); - halbtc8821a1ant_set_ant_path(btcoexist, - BTC_ANT_PATH_PTA, false, false); - break; - case 0: - default: /* Software control, Antenna at BT side */ - halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x0, - 0x0, 0x0, 0x0, 0x0); - halbtc8821a1ant_set_ant_path(btcoexist, - BTC_ANT_PATH_BT, false, false); - break; - case 9: /* Software control, Antenna at WiFi side */ - halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x0, - 0x0, 0x0, 0x0, 0x0); - halbtc8821a1ant_set_ant_path(btcoexist, - BTC_ANT_PATH_WIFI, false, false); - break; - case 10: /* under 5G */ - halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x0, - 0x0, 0x0, 0x8, 0x0); - halbtc8821a1ant_set_ant_path(btcoexist, - BTC_ANT_PATH_BT, false, false); - break; - } - } - rssi_adjust_val = 0; - btcoexist->btc_set(btcoexist, - BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE, &rssi_adjust_val); - - /* update pre state */ - coex_dm->pre_ps_tdma_on = coex_dm->cur_ps_tdma_on; - coex_dm->pre_ps_tdma = coex_dm->cur_ps_tdma; -} - -void halbtc8821a1ant_coex_all_off(IN struct btc_coexist *btcoexist) -{ - /* sw all off */ - halbtc8821a1ant_sw_mechanism(btcoexist, false); - - /* hw all off */ - halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); -} - -boolean halbtc8821a1ant_is_common_action(IN struct btc_coexist *btcoexist) -{ - boolean common = false, wifi_connected = false, wifi_busy = false; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - - if (!wifi_connected && - BT_8821A_1ANT_BT_STATUS_NON_CONNECTED_IDLE == - coex_dm->bt_status) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi non connected-idle + BT non connected-idle!!\n"); - BTC_TRACE(trace_buf); - halbtc8821a1ant_sw_mechanism(btcoexist, false); - - common = true; - } else if (wifi_connected && - (BT_8821A_1ANT_BT_STATUS_NON_CONNECTED_IDLE == - coex_dm->bt_status)) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi connected + BT non connected-idle!!\n"); - BTC_TRACE(trace_buf); - halbtc8821a1ant_sw_mechanism(btcoexist, false); - - common = true; - } else if (!wifi_connected && - (BT_8821A_1ANT_BT_STATUS_CONNECTED_IDLE == - coex_dm->bt_status)) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi non connected-idle + BT connected-idle!!\n"); - BTC_TRACE(trace_buf); - halbtc8821a1ant_sw_mechanism(btcoexist, false); - - common = true; - } else if (wifi_connected && - (BT_8821A_1ANT_BT_STATUS_CONNECTED_IDLE == - coex_dm->bt_status)) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi connected + BT connected-idle!!\n"); - BTC_TRACE(trace_buf); - halbtc8821a1ant_sw_mechanism(btcoexist, false); - - common = true; - } else if (!wifi_connected && - (BT_8821A_1ANT_BT_STATUS_CONNECTED_IDLE != - coex_dm->bt_status)) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi non connected-idle + BT Busy!!\n"); - BTC_TRACE(trace_buf); - halbtc8821a1ant_sw_mechanism(btcoexist, false); - - common = true; - } else { - if (wifi_busy) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi Connected-Busy + BT Busy!!\n"); - BTC_TRACE(trace_buf); - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi Connected-Idle + BT Busy!!\n"); - BTC_TRACE(trace_buf); - } - - common = false; - } - - return common; -} - -void halbtc8821a1ant_ps_tdma_check_for_power_save_state( - IN struct btc_coexist *btcoexist, IN boolean new_ps_state) -{ - u8 lps_mode = 0x0; - - btcoexist->btc_get(btcoexist, BTC_GET_U1_LPS_MODE, &lps_mode); - - if (lps_mode) { /* already under LPS state */ - if (new_ps_state) { - /* keep state under LPS, do nothing. */ - } else { - /* will leave LPS state, turn off psTdma first */ - halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, - 1); - } - } else { /* NO PS state */ - if (new_ps_state) { - /* will enter LPS state, turn off psTdma first */ - halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, - 0); - } else { - /* keep state under NO PS state, do nothing. */ - } - } -} - -void halbtc8821a1ant_power_save_state(IN struct btc_coexist *btcoexist, - IN u8 ps_type, IN u8 lps_val, IN u8 rpwm_val) -{ - boolean low_pwr_disable = false; - - switch (ps_type) { - case BTC_PS_WIFI_NATIVE: - /* recover to original 32k low power setting */ - low_pwr_disable = false; - btcoexist->btc_set(btcoexist, - BTC_SET_ACT_DISABLE_LOW_POWER, - &low_pwr_disable); - btcoexist->btc_set(btcoexist, BTC_SET_ACT_NORMAL_LPS, - NULL); - break; - case BTC_PS_LPS_ON: - halbtc8821a1ant_ps_tdma_check_for_power_save_state( - btcoexist, true); - halbtc8821a1ant_lps_rpwm(btcoexist, NORMAL_EXEC, - lps_val, rpwm_val); - /* when coex force to enter LPS, do not enter 32k low power. */ - low_pwr_disable = true; - btcoexist->btc_set(btcoexist, - BTC_SET_ACT_DISABLE_LOW_POWER, - &low_pwr_disable); - /* power save must executed before psTdma. */ - btcoexist->btc_set(btcoexist, BTC_SET_ACT_ENTER_LPS, - NULL); - break; - case BTC_PS_LPS_OFF: - halbtc8821a1ant_ps_tdma_check_for_power_save_state( - btcoexist, false); - btcoexist->btc_set(btcoexist, BTC_SET_ACT_LEAVE_LPS, - NULL); - break; - default: - break; - } -} - -void halbtc8821a1ant_coex_under_5g(IN struct btc_coexist *btcoexist) -{ - halbtc8821a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0, - 0x0); - - halbtc8821a1ant_ignore_wlan_act(btcoexist, NORMAL_EXEC, true); - - halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 10); - - halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - - halbtc8821a1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0); - - halbtc8821a1ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 5); -} - -void halbtc8821a1ant_action_wifi_only(IN struct btc_coexist *btcoexist) -{ - halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 9); -} - -void halbtc8821a1ant_monitor_bt_enable_disable(IN struct btc_coexist *btcoexist) -{ - static u32 bt_disable_cnt = 0; - boolean bt_active = true, bt_disabled = false; - - /* This function check if bt is disabled */ - - if (coex_sta->high_priority_tx == 0 && - coex_sta->high_priority_rx == 0 && - coex_sta->low_priority_tx == 0 && - coex_sta->low_priority_rx == 0) - bt_active = false; - if (coex_sta->high_priority_tx == 0xffff && - coex_sta->high_priority_rx == 0xffff && - coex_sta->low_priority_tx == 0xffff && - coex_sta->low_priority_rx == 0xffff) - bt_active = false; - if (bt_active) { - bt_disable_cnt = 0; - bt_disabled = false; - btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_DISABLE, - &bt_disabled); - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT is enabled !!\n"); - BTC_TRACE(trace_buf); - } else { - bt_disable_cnt++; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], bt all counters=0, %d times!!\n", - bt_disable_cnt); - BTC_TRACE(trace_buf); - if (bt_disable_cnt >= 10) { - bt_disabled = true; - btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_DISABLE, - &bt_disabled); - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT is disabled !!\n"); - BTC_TRACE(trace_buf); - halbtc8821a1ant_action_wifi_only(btcoexist); - } - } - if (coex_sta->bt_disabled != bt_disabled) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT is from %s to %s!!\n", - (coex_sta->bt_disabled ? "disabled" : "enabled"), - (bt_disabled ? "disabled" : "enabled")); - BTC_TRACE(trace_buf); - coex_sta->bt_disabled = bt_disabled; - if (!bt_disabled) { - } else { - btcoexist->btc_set(btcoexist, BTC_SET_ACT_LEAVE_LPS, - NULL); - btcoexist->btc_set(btcoexist, BTC_SET_ACT_NORMAL_LPS, - NULL); - } - } -} - -/* ********************************************* - * - * Software Coex Mechanism start - * - * ********************************************* */ - -void halbtc8821a1ant_action_bt_whck_test(IN struct btc_coexist *btcoexist) -{ - halbtc8821a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0, - 0x0); - - halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8); - /* halbtc8821a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA, NORMAL_EXEC, false, false); */ - halbtc8821a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA, false, false); - halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); -} -/* SCO only or SCO+PAN(HS) */ -void halbtc8821a1ant_action_sco(IN struct btc_coexist *btcoexist) -{ - halbtc8821a1ant_sw_mechanism(btcoexist, true); -} - -void halbtc8821a1ant_action_hid(IN struct btc_coexist *btcoexist) -{ - halbtc8821a1ant_sw_mechanism(btcoexist, true); -} - -/* A2DP only / PAN(EDR) only/ A2DP+PAN(HS) */ -void halbtc8821a1ant_action_a2dp(IN struct btc_coexist *btcoexist) -{ - halbtc8821a1ant_sw_mechanism(btcoexist, false); -} - -void halbtc8821a1ant_action_a2dp_pan_hs(IN struct btc_coexist *btcoexist) -{ - halbtc8821a1ant_sw_mechanism(btcoexist, false); -} - -void halbtc8821a1ant_action_pan_edr(IN struct btc_coexist *btcoexist) -{ - halbtc8821a1ant_sw_mechanism(btcoexist, false); -} - -/* PAN(HS) only */ -void halbtc8821a1ant_action_pan_hs(IN struct btc_coexist *btcoexist) -{ - halbtc8821a1ant_sw_mechanism(btcoexist, false); -} - -/* PAN(EDR)+A2DP */ -void halbtc8821a1ant_action_pan_edr_a2dp(IN struct btc_coexist *btcoexist) -{ - halbtc8821a1ant_sw_mechanism(btcoexist, false); -} - -void halbtc8821a1ant_action_pan_edr_hid(IN struct btc_coexist *btcoexist) -{ - halbtc8821a1ant_sw_mechanism(btcoexist, true); -} - -/* HID+A2DP+PAN(EDR) */ -void halbtc8821a1ant_action_hid_a2dp_pan_edr(IN struct btc_coexist *btcoexist) -{ - halbtc8821a1ant_sw_mechanism(btcoexist, true); -} - -void halbtc8821a1ant_action_hid_a2dp(IN struct btc_coexist *btcoexist) -{ - halbtc8821a1ant_sw_mechanism(btcoexist, true); -} - -/* ********************************************* - * - * Non-Software Coex Mechanism start - * - * ********************************************* */ -void halbtc8821a1ant_action_wifi_multi_port(IN struct btc_coexist *btcoexist) -{ - halbtc8821a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0, - 0x0); - - halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8); - halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2); -} - -void halbtc8821a1ant_action_hs(IN struct btc_coexist *btcoexist) -{ - halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 5); - halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2); -} - -void halbtc8821a1ant_action_bt_inquiry(IN struct btc_coexist *btcoexist) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - boolean wifi_connected = false, ap_enable = false, wifi_busy = false, - bt_busy = false; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, - &ap_enable); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bt_busy); - - if ((!wifi_connected) && (!coex_sta->wifi_is_high_pri_task)) { - halbtc8821a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, - 0x0, 0x0); - halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8); - - halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - } - - /* sy modify */ - else if ((bt_link_info->sco_exist) || (bt_link_info->hid_exist) || - (bt_link_info->a2dp_exist)) { - /* SCO/HID/A2DP busy */ - halbtc8821a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, - 0x0, 0x0); - halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32); - - halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); - } - - /* sy modify */ - - else if ((bt_link_info->a2dp_exist) && - (bt_link_info->hid_exist)) { - /* A2DP+HID busy */ - halbtc8821a1ant_power_save_state(btcoexist, - BTC_PS_WIFI_NATIVE, 0x0, 0x0); - halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 14); - - halbtc8821a1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 1); - } - - - else if ((bt_link_info->pan_exist) || (wifi_busy)) { - halbtc8821a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, - 0x0, 0x0); - halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20); - - halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); - } else { - halbtc8821a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, - 0x0, 0x0); - halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8); - - halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7); - } -} - -void halbtc8821a1ant_action_bt_sco_hid_only_busy(IN struct btc_coexist - *btcoexist, IN u8 wifi_status) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - boolean wifi_connected = false; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - - /* tdma and coex table */ - - if (bt_link_info->sco_exist) { - halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 41); - halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2); - } else { /* HID */ - halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 42); - halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2); - } -} - -void halbtc8821a1ant_action_wifi_connected_bt_acl_busy(IN struct btc_coexist - *btcoexist, IN u8 wifi_status) -{ - u8 bt_rssi_state; - - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - - bt_rssi_state = halbtc8821a1ant_bt_rssi_state(2, 28, 0); - - if (bt_link_info->hid_only) { /* HID */ - halbtc8821a1ant_action_bt_sco_hid_only_busy(btcoexist, - wifi_status); - coex_dm->auto_tdma_adjust = false; - return; - } else if (bt_link_info->a2dp_only) { /* A2DP */ - if (BT_8821A_1ANT_WIFI_STATUS_CONNECTED_IDLE == wifi_status) { - /* halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8); */ - /* halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2); */ - halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 32); - halbtc8821a1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 1); - coex_dm->auto_tdma_adjust = false; - } else if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) || - (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) { - /* halbtc8821a1ant_tdma_duration_adjust_for_acl(btcoexist, wifi_status); */ - halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 14); - halbtc8821a1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 1); - } else { /* for low BT RSSI */ - halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 14); - halbtc8821a1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 1); - coex_dm->auto_tdma_adjust = false; - } - } else if (bt_link_info->hid_exist && - bt_link_info->a2dp_exist) { /* HID+A2DP */ - if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) || - (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) { - halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 14); - coex_dm->auto_tdma_adjust = false; - } else { /* for low BT RSSI */ - halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 14); - coex_dm->auto_tdma_adjust = false; - } - - halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1); - } else if ((bt_link_info->pan_only) || (bt_link_info->hid_exist && - bt_link_info->pan_exist)) { /* PAN(OPP,FTP), HID+PAN(OPP,FTP) */ - halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 3); - halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 6); - coex_dm->auto_tdma_adjust = false; - } else if (((bt_link_info->a2dp_exist) && (bt_link_info->pan_exist)) || - (bt_link_info->hid_exist && bt_link_info->a2dp_exist && - bt_link_info->pan_exist)) { /* A2DP+PAN(OPP,FTP), HID+A2DP+PAN(OPP,FTP) */ - halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 43); - halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1); - coex_dm->auto_tdma_adjust = false; - } else { - halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 11); - halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1); - coex_dm->auto_tdma_adjust = false; - } -} - -void halbtc8821a1ant_action_wifi_not_connected(IN struct btc_coexist *btcoexist) -{ - /* power save state */ - halbtc8821a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0, - 0x0); - - /* tdma and coex table */ - halbtc8821a1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 8); - halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); -} - -void halbtc8821a1ant_action_wifi_not_connected_scan(IN struct btc_coexist - *btcoexist) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - - halbtc8821a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0, - 0x0); - - /* tdma and coex table */ - if (BT_8821A_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) { - if (bt_link_info->a2dp_exist) { - /* sy modify */ - halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 14); - halbtc8821a1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 1); - } else if (bt_link_info->a2dp_exist && - bt_link_info->pan_exist) { - halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 22); - halbtc8821a1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 4); - } else { - halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 20); - halbtc8821a1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 4); - } - } else if ((BT_8821A_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) || - (BT_8821A_1ANT_BT_STATUS_ACL_SCO_BUSY == - coex_dm->bt_status)) { - halbtc8821a1ant_action_bt_sco_hid_only_busy(btcoexist, - BT_8821A_1ANT_WIFI_STATUS_CONNECTED_SCAN); - } else { - /* halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20); */ - /* halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1); */ - - /* Bryant Add */ - halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8); - halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2); - } -} - -void halbtc8821a1ant_action_wifi_not_connected_asso_auth( - IN struct btc_coexist *btcoexist) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - - halbtc8821a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0, - 0x0); - - /* tdma and coex table */ - if ((bt_link_info->sco_exist) || (bt_link_info->hid_exist)) { - /* sy modify */ - halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 14); - halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1); - } else if ((bt_link_info->a2dp_exist) || (bt_link_info->pan_exist)) { - halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20); - halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); - } else { - halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8); - halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2); - } -} - -void halbtc8821a1ant_action_wifi_connected_scan(IN struct btc_coexist - *btcoexist) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - - halbtc8821a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0, - 0x0); - - /* tdma and coex table */ - if (BT_8821A_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) { - if (bt_link_info->a2dp_exist) { - /* sy modify */ - halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 14); - halbtc8821a1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 1); - } else if (bt_link_info->a2dp_exist && - bt_link_info->pan_exist) { - halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 22); - halbtc8821a1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 4); - } else { - halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 20); - halbtc8821a1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 4); - } - } else if ((BT_8821A_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) || - (BT_8821A_1ANT_BT_STATUS_ACL_SCO_BUSY == - coex_dm->bt_status)) { - halbtc8821a1ant_action_bt_sco_hid_only_busy(btcoexist, - BT_8821A_1ANT_WIFI_STATUS_CONNECTED_SCAN); - } else { - /* halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20); */ - /* halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1); */ - - /* Bryant Add */ - halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8); - halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2); - } -} - -void halbtc8821a1ant_action_wifi_connected_specific_packet( - IN struct btc_coexist *btcoexist) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - - halbtc8821a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0, - 0x0); - - /* tdma and coex table */ - /* sy modify */ - if ((bt_link_info->sco_exist) || (bt_link_info->hid_exist) || - (bt_link_info->a2dp_exist)) { - halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32); - halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); - } - - if ((bt_link_info->hid_exist) && (bt_link_info->a2dp_exist)) { - halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 14); - halbtc8821a1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 1); - } - - - else if (bt_link_info->pan_exist) { - halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20); - halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); - } else { - halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8); - halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2); - } -} - -void halbtc8821a1ant_action_wifi_connected(IN struct btc_coexist *btcoexist) -{ - boolean wifi_busy = false; - boolean scan = false, link = false, roam = false; - boolean under_4way = false, ap_enable = false; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], CoexForWifiConnect()===>\n"); - BTC_TRACE(trace_buf); - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS, - &under_4way); - if (under_4way) { - halbtc8821a1ant_action_wifi_connected_specific_packet( - btcoexist); - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], CoexForWifiConnect(), return for wifi is under 4way<===\n"); - BTC_TRACE(trace_buf); - return; - } - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam); - if (scan || link || roam) { - if (scan) - halbtc8821a1ant_action_wifi_connected_scan(btcoexist); - else - halbtc8821a1ant_action_wifi_connected_specific_packet( - btcoexist); - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], CoexForWifiConnect(), return for wifi is under scan<===\n"); - BTC_TRACE(trace_buf); - return; - } - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, - &ap_enable); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - /* power save state */ - if (!ap_enable && - BT_8821A_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status && - !btcoexist->bt_link_info.hid_only) { - if (!wifi_busy && btcoexist->bt_link_info.a2dp_only) /* A2DP */ - halbtc8821a1ant_power_save_state(btcoexist, - BTC_PS_WIFI_NATIVE, 0x0, 0x0); - else - halbtc8821a1ant_power_save_state(btcoexist, - BTC_PS_LPS_ON, 0x50, 0x4); - } else - halbtc8821a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, - 0x0, 0x0); - - /* tdma and coex table */ - if (!wifi_busy) { - if (BT_8821A_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) { - halbtc8821a1ant_action_wifi_connected_bt_acl_busy( - btcoexist, - BT_8821A_1ANT_WIFI_STATUS_CONNECTED_IDLE); - } else if ((BT_8821A_1ANT_BT_STATUS_SCO_BUSY == - coex_dm->bt_status) || - (BT_8821A_1ANT_BT_STATUS_ACL_SCO_BUSY == - coex_dm->bt_status)) { - halbtc8821a1ant_action_bt_sco_hid_only_busy(btcoexist, - BT_8821A_1ANT_WIFI_STATUS_CONNECTED_IDLE); - } else { - halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, - 8); - halbtc8821a1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 2); - } - } else { - if (BT_8821A_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) { - halbtc8821a1ant_action_wifi_connected_bt_acl_busy( - btcoexist, - BT_8821A_1ANT_WIFI_STATUS_CONNECTED_BUSY); - } else if ((BT_8821A_1ANT_BT_STATUS_SCO_BUSY == - coex_dm->bt_status) || - (BT_8821A_1ANT_BT_STATUS_ACL_SCO_BUSY == - coex_dm->bt_status)) { - halbtc8821a1ant_action_bt_sco_hid_only_busy(btcoexist, - BT_8821A_1ANT_WIFI_STATUS_CONNECTED_BUSY); - } else { - halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, - 8); - halbtc8821a1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 2); - } - } -} - -void halbtc8821a1ant_run_sw_coexist_mechanism(IN struct btc_coexist *btcoexist) -{ - u8 algorithm = 0; - - algorithm = halbtc8821a1ant_action_algorithm(btcoexist); - coex_dm->cur_algorithm = algorithm; - - if (halbtc8821a1ant_is_common_action(btcoexist)) { - - } else { - switch (coex_dm->cur_algorithm) { - case BT_8821A_1ANT_COEX_ALGO_SCO: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action algorithm = SCO.\n"); - BTC_TRACE(trace_buf); - halbtc8821a1ant_action_sco(btcoexist); - break; - case BT_8821A_1ANT_COEX_ALGO_HID: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action algorithm = HID.\n"); - BTC_TRACE(trace_buf); - halbtc8821a1ant_action_hid(btcoexist); - break; - case BT_8821A_1ANT_COEX_ALGO_A2DP: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action algorithm = A2DP.\n"); - BTC_TRACE(trace_buf); - halbtc8821a1ant_action_a2dp(btcoexist); - break; - case BT_8821A_1ANT_COEX_ALGO_A2DP_PANHS: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action algorithm = A2DP+PAN(HS).\n"); - BTC_TRACE(trace_buf); - halbtc8821a1ant_action_a2dp_pan_hs(btcoexist); - break; - case BT_8821A_1ANT_COEX_ALGO_PANEDR: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action algorithm = PAN(EDR).\n"); - BTC_TRACE(trace_buf); - halbtc8821a1ant_action_pan_edr(btcoexist); - break; - case BT_8821A_1ANT_COEX_ALGO_PANHS: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action algorithm = HS mode.\n"); - BTC_TRACE(trace_buf); - halbtc8821a1ant_action_pan_hs(btcoexist); - break; - case BT_8821A_1ANT_COEX_ALGO_PANEDR_A2DP: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action algorithm = PAN+A2DP.\n"); - BTC_TRACE(trace_buf); - halbtc8821a1ant_action_pan_edr_a2dp(btcoexist); - break; - case BT_8821A_1ANT_COEX_ALGO_PANEDR_HID: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action algorithm = PAN(EDR)+HID.\n"); - BTC_TRACE(trace_buf); - halbtc8821a1ant_action_pan_edr_hid(btcoexist); - break; - case BT_8821A_1ANT_COEX_ALGO_HID_A2DP_PANEDR: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action algorithm = HID+A2DP+PAN.\n"); - BTC_TRACE(trace_buf); - halbtc8821a1ant_action_hid_a2dp_pan_edr( - btcoexist); - break; - case BT_8821A_1ANT_COEX_ALGO_HID_A2DP: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action algorithm = HID+A2DP.\n"); - BTC_TRACE(trace_buf); - halbtc8821a1ant_action_hid_a2dp(btcoexist); - break; - default: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action algorithm = coexist All Off!!\n"); - BTC_TRACE(trace_buf); - /* halbtc8821a1ant_coex_all_off(btcoexist); */ - break; - } - coex_dm->pre_algorithm = coex_dm->cur_algorithm; - } -} - -void halbtc8821a1ant_run_coexist_mechanism(IN struct btc_coexist *btcoexist) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - boolean wifi_connected = false, bt_hs_on = false; - boolean increase_scan_dev_num = false; - boolean bt_ctrl_agg_buf_size = false; - u8 agg_buf_size = 5; - u8 wifi_rssi_state = BTC_RSSI_STATE_HIGH; - u32 wifi_link_status = 0; - u32 num_of_wifi_link = 0; - boolean wifi_under_5g = false; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], RunCoexistMechanism()===>\n"); - BTC_TRACE(trace_buf); - - if (btcoexist->manual_control) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], RunCoexistMechanism(), return for Manual CTRL <===\n"); - BTC_TRACE(trace_buf); - return; - } - - if (btcoexist->stop_coex_dm) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], RunCoexistMechanism(), return for Stop Coex DM <===\n"); - BTC_TRACE(trace_buf); - return; - } - - if (coex_sta->under_ips) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], wifi is under IPS !!!\n"); - BTC_TRACE(trace_buf); - return; - } - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g); - if (wifi_under_5g) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], RunCoexistMechanism(), return for 5G <===\n"); - BTC_TRACE(trace_buf); - halbtc8821a1ant_coex_under_5g(btcoexist); - return; - } - if (coex_sta->bt_whck_test) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT is under WHCK TEST!!!\n"); - BTC_TRACE(trace_buf); - halbtc8821a1ant_action_bt_whck_test(btcoexist); - return; - } - - if ((BT_8821A_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) || - (BT_8821A_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) || - (BT_8821A_1ANT_BT_STATUS_ACL_SCO_BUSY == coex_dm->bt_status)) - increase_scan_dev_num = true; - - btcoexist->btc_set(btcoexist, BTC_SET_BL_INC_SCAN_DEV_NUM, - &increase_scan_dev_num); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS, - &wifi_link_status); - num_of_wifi_link = wifi_link_status >> 16; - if ((num_of_wifi_link >= 2) || - (wifi_link_status & WIFI_P2P_GO_CONNECTED)) { - halbtc8821a1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0); - halbtc8821a1ant_limited_rx(btcoexist, NORMAL_EXEC, false, - bt_ctrl_agg_buf_size, agg_buf_size); - halbtc8821a1ant_action_wifi_multi_port(btcoexist); - return; - } - - if (!bt_link_info->sco_exist && !bt_link_info->hid_exist) - halbtc8821a1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0); - else { - if (wifi_connected) { - wifi_rssi_state = halbtc8821a1ant_wifi_rssi_state( - btcoexist, 1, 2, 30, 0); - if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) || - (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) { - /* halbtc8821a1ant_limited_tx(btcoexist, NORMAL_EXEC, 1, 1, 1, 1); */ - halbtc8821a1ant_limited_tx(btcoexist, - NORMAL_EXEC, 1, 1, 0, 1); - } else { - /* halbtc8821a1ant_limited_tx(btcoexist, NORMAL_EXEC, 1, 1, 1, 1); */ - halbtc8821a1ant_limited_tx(btcoexist, - NORMAL_EXEC, 1, 1, 0, 1); - } - } else - halbtc8821a1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, - 0, 0); - - } - - if (bt_link_info->sco_exist) { - bt_ctrl_agg_buf_size = true; - agg_buf_size = 0x3; - } else if (bt_link_info->hid_exist) { - bt_ctrl_agg_buf_size = true; - agg_buf_size = 0x5; - } else if (bt_link_info->a2dp_exist || bt_link_info->pan_exist) { - bt_ctrl_agg_buf_size = true; - agg_buf_size = 0x8; - } - halbtc8821a1ant_limited_rx(btcoexist, NORMAL_EXEC, false, - bt_ctrl_agg_buf_size, agg_buf_size); - - halbtc8821a1ant_run_sw_coexist_mechanism(btcoexist); - - /* low pelnaty ra in pcr ra */ - btcoexist->btc_phydm_modify_RA_PCR_threshold(btcoexist, 0, 25); - - btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); - if (coex_sta->c2h_bt_inquiry_page) { - halbtc8821a1ant_action_bt_inquiry(btcoexist); - return; - } else if (bt_hs_on) { - halbtc8821a1ant_action_hs(btcoexist); - return; - } - - - if (!wifi_connected) { - boolean scan = false, link = false, roam = false; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], wifi is non connected-idle !!!\n"); - BTC_TRACE(trace_buf); - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam); - - if (scan || link || roam) { - if (scan) - halbtc8821a1ant_action_wifi_not_connected_scan( - btcoexist); - else - halbtc8821a1ant_action_wifi_not_connected_asso_auth( - btcoexist); - } else - halbtc8821a1ant_action_wifi_not_connected(btcoexist); - } else /* wifi LPS/Busy */ - halbtc8821a1ant_action_wifi_connected(btcoexist); -} - -void halbtc8821a1ant_init_coex_dm(IN struct btc_coexist *btcoexist) -{ - /* force to reset coex mechanism */ - /* sw all off */ - halbtc8821a1ant_sw_mechanism(btcoexist, false); - - /* halbtc8821a1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 8); */ - halbtc8821a1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 0); -} - -void halbtc8821a1ant_init_hw_config(IN struct btc_coexist *btcoexist, - IN boolean back_up, IN boolean wifi_only) -{ - u8 u8tmp = 0; - boolean wifi_under_5g = false; - - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], 1Ant Init HW Config!!\n"); - BTC_TRACE(trace_buf); - - if (wifi_only) - return; - - if (back_up) { - coex_dm->backup_arfr_cnt1 = btcoexist->btc_read_4byte(btcoexist, - 0x430); - coex_dm->backup_arfr_cnt2 = btcoexist->btc_read_4byte(btcoexist, - 0x434); - coex_dm->backup_retry_limit = btcoexist->btc_read_2byte( - btcoexist, 0x42a); - coex_dm->backup_ampdu_max_time = btcoexist->btc_read_1byte( - btcoexist, 0x456); - } - - /* 0x790[5:0]=0x5 */ - u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x790); - u8tmp &= 0xc0; - u8tmp |= 0x5; - btcoexist->btc_write_1byte(btcoexist, 0x790, u8tmp); - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g); - - /* Give bt_coex_supported_version the default value */ - coex_sta->bt_coex_supported_version = 0; - - /* 0xf0[15:12] --> Chip Cut information */ - coex_sta->cut_version = (btcoexist->btc_read_1byte(btcoexist, - 0xf1) & 0xf0) >> 4; - - /* Antenna config */ - if (wifi_under_5g) - halbtc8821a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT, true, - false); - else - halbtc8821a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA, true, - false); - - /* PTA parameter */ - halbtc8821a1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 0); - - /* Enable counter statistics */ - btcoexist->btc_write_1byte(btcoexist, 0x76e, - 0xc); /* 0x76e[3] =1, WLAN_Act control by PTA */ - btcoexist->btc_write_1byte(btcoexist, 0x778, 0x3); - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x40, 0x20, 0x1); -} - -/* ************************************************************ - * work around function start with wa_halbtc8821a1ant_ - * ************************************************************ - * ************************************************************ - * extern function start with ex_halbtc8821a1ant_ - * ************************************************************ */ -void ex_halbtc8821a1ant_power_on_setting(IN struct btc_coexist *btcoexist) -{ -} - -void ex_halbtc8821a1ant_init_hw_config(IN struct btc_coexist *btcoexist, - IN boolean wifi_only) -{ - halbtc8821a1ant_init_hw_config(btcoexist, true, wifi_only); -} - -void ex_halbtc8821a1ant_init_coex_dm(IN struct btc_coexist *btcoexist) -{ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Coex Mechanism Init!!\n"); - BTC_TRACE(trace_buf); - - btcoexist->stop_coex_dm = false; - - halbtc8821a1ant_init_coex_dm(btcoexist); - - halbtc8821a1ant_query_bt_info(btcoexist); -} - -void ex_halbtc8821a1ant_display_coex_info(IN struct btc_coexist *btcoexist) -{ - struct btc_board_info *board_info = &btcoexist->board_info; - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - u8 *cli_buf = btcoexist->cli_buf; - u8 u8tmp[4], i, bt_info_ext, ps_tdma_case = 0; - u16 u16tmp[4]; - u32 u32tmp[4]; - u32 fw_ver = 0, bt_patch_ver = 0; - u32 bt_coex_ver = 0; - u32 fa_ofdm, fa_cck, cca_ofdm, cca_cck; - u32 phyver = 0; - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n ============[BT Coexist info]============"); - CL_PRINTF(cli_buf); - - if (btcoexist->manual_control) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n ============[Under Manual Control]============"); - CL_PRINTF(cli_buf); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n =========================================="); - CL_PRINTF(cli_buf); - } - if (btcoexist->stop_coex_dm) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n ============[Coex is STOPPED]============"); - CL_PRINTF(cli_buf); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n =========================================="); - CL_PRINTF(cli_buf); - } - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d", - "Ant PG Num/ Ant Mech/ Ant Pos:", - board_info->pg_ant_num, board_info->btdm_ant_num, - board_info->btdm_ant_pos); - CL_PRINTF(cli_buf); - - /* btcoexist->btc_get(btcoexist, BTC_GET_U4_BT_PATCH_VER, &bt_patch_ver); */ - bt_patch_ver = btcoexist->bt_info.bt_get_fw_ver; - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, &fw_ver); - phyver = btcoexist->btc_get_bt_phydm_version(btcoexist); - bt_coex_ver = ((coex_sta->bt_coex_supported_version & 0xff00) >> 8); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %d_%02x/ 0x%02x/ 0x%02x (%s)", - "CoexVer WL/ BT_Desired/ BT_Report", - glcoex_ver_date_8821a_1ant, glcoex_ver_8821a_1ant, - glcoex_ver_btdesired_8821a_1ant, - bt_coex_ver, - (bt_coex_ver == 0xff ? "Unknown" : - (bt_coex_ver >= glcoex_ver_btdesired_8821a_1ant ? - "Match" : "Mis-Match"))); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = 0x%x/ 0x%x/ v%d/ %c", - "W_FW/ B_FW/ Phy/ Kt", - fw_ver, bt_patch_ver, phyver, - coex_sta->cut_version + 65); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x ", - "Wifi channel informed to BT", - coex_dm->wifi_chnl_info[0], coex_dm->wifi_chnl_info[1], - coex_dm->wifi_chnl_info[2]); - CL_PRINTF(cli_buf); - - /* wifi status */ - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s", - "============[Wifi Status]============"); - CL_PRINTF(cli_buf); - btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_WIFI_STATUS); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s", - "============[BT Status]============"); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = [%s/ %d/ %d] ", - "BT [status/ rssi/ retryCnt]", - ((coex_sta->bt_disabled) ? ("disabled") : (( - coex_sta->c2h_bt_inquiry_page) ? ("inquiry/page scan") - : ((BT_8821A_1ANT_BT_STATUS_NON_CONNECTED_IDLE == - coex_dm->bt_status) ? "non-connected idle" : - ((BT_8821A_1ANT_BT_STATUS_CONNECTED_IDLE == coex_dm->bt_status) - ? "connected-idle" : "busy")))), - coex_sta->bt_rssi, coex_sta->bt_retry_cnt); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d / %d / %d", - "SCO/HID/PAN/A2DP", - bt_link_info->sco_exist, bt_link_info->hid_exist, - bt_link_info->pan_exist, bt_link_info->a2dp_exist); - CL_PRINTF(cli_buf); - btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_BT_LINK_INFO); - - bt_info_ext = coex_sta->bt_info_ext; - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s", - "BT Info A2DP rate", - (bt_info_ext & BIT(0)) ? "Basic rate" : "EDR rate"); - CL_PRINTF(cli_buf); - - for (i = 0; i < BT_INFO_SRC_8821A_1ANT_MAX; i++) { - if (coex_sta->bt_info_c2h_cnt[i]) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %02x %02x %02x %02x %02x %02x %02x(%d)", - glbt_info_src_8821a_1ant[i], - coex_sta->bt_info_c2h[i][0], - coex_sta->bt_info_c2h[i][1], - coex_sta->bt_info_c2h[i][2], - coex_sta->bt_info_c2h[i][3], - coex_sta->bt_info_c2h[i][4], - coex_sta->bt_info_c2h[i][5], - coex_sta->bt_info_c2h[i][6], - coex_sta->bt_info_c2h_cnt[i]); - CL_PRINTF(cli_buf); - } - } - - if (!btcoexist->manual_control) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d", - "SM[LowPenaltyRA]", - coex_dm->cur_low_penalty_ra); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s", - "============[mechanisms]============"); - CL_PRINTF(cli_buf); - - ps_tdma_case = coex_dm->cur_ps_tdma; - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %02x %02x %02x %02x %02x case-%d (auto:%d)", - "PS TDMA", - coex_dm->ps_tdma_para[0], coex_dm->ps_tdma_para[1], - coex_dm->ps_tdma_para[2], coex_dm->ps_tdma_para[3], - coex_dm->ps_tdma_para[4], ps_tdma_case, - coex_dm->auto_tdma_adjust); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d ", - "IgnWlanAct", - coex_dm->cur_ignore_wlan_act); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x ", - "Latest error condition(should be 0)", - coex_dm->error_condition); - CL_PRINTF(cli_buf); - } - - /* Hw setting */ - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s", - "============[Hw setting]============"); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/0x%x/0x%x/0x%x", - "backup ARFR1/ARFR2/RL/AMaxTime", - coex_dm->backup_arfr_cnt1, coex_dm->backup_arfr_cnt2, - coex_dm->backup_retry_limit, - coex_dm->backup_ampdu_max_time); - CL_PRINTF(cli_buf); - - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x430); - u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x434); - u16tmp[0] = btcoexist->btc_read_2byte(btcoexist, 0x42a); - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x456); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/0x%x/0x%x/0x%x", - "0x430/0x434/0x42a/0x456", - u32tmp[0], u32tmp[1], u16tmp[0], u8tmp[0]); - CL_PRINTF(cli_buf); - - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x778); - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xc58); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", - "0x778/ 0xc58[29:25]", - u8tmp[0], (u32tmp[0] & 0x3e000000) >> 25); - CL_PRINTF(cli_buf); - - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x8db); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0x8db[6:5]", - ((u8tmp[0] & 0x60) >> 5)); - CL_PRINTF(cli_buf); - - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x975); - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xcb4); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", - "0xcb4[29:28]/0xcb4[7:0]/0x974[9:8]", - (u32tmp[0] & 0x30000000) >> 28, u32tmp[0] & 0xff, - u8tmp[0] & 0x3); - CL_PRINTF(cli_buf); - - - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x40); - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x4c); - u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0x64); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", - "0x40/0x4c[24:23]/0x64[0]", - u8tmp[0], ((u32tmp[0] & 0x01800000) >> 23), u8tmp[1] & 0x1); - CL_PRINTF(cli_buf); - - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x550); - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x522); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", - "0x550(bcn ctrl)/0x522", - u32tmp[0], u8tmp[0]); - CL_PRINTF(cli_buf); - - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xc50); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0xc50(dig)", - u32tmp[0] & 0xff); - CL_PRINTF(cli_buf); - - fa_ofdm = btcoexist->btc_phydm_query_PHY_counter(btcoexist, - PHYDM_INFO_FA_OFDM); - fa_cck = btcoexist->btc_phydm_query_PHY_counter(btcoexist, - PHYDM_INFO_FA_CCK); - cca_ofdm = btcoexist->btc_phydm_query_PHY_counter(btcoexist, - PHYDM_INFO_CCA_OFDM); - cca_cck = btcoexist->btc_phydm_query_PHY_counter(btcoexist, - PHYDM_INFO_CCA_CCK); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", - "CCK-CCA/CCK-FA/OFDM-CCA/OFDM-FA", - cca_cck, fa_cck, cca_ofdm, fa_ofdm); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d", - "CRC_OK CCK/11g/11n/11n-agg", - coex_sta->crc_ok_cck, coex_sta->crc_ok_11g, - coex_sta->crc_ok_11n, coex_sta->crc_ok_11n_vht); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d", - "CRC_Err CCK/11g/11n/11n-agg", - coex_sta->crc_err_cck, coex_sta->crc_err_11g, - coex_sta->crc_err_11n, coex_sta->crc_err_11n_vht); - CL_PRINTF(cli_buf); - - - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x6c0); - u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x6c4); - u32tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0x6c8); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", - "0x6c0/0x6c4/0x6c8(coexTable)", - u32tmp[0], u32tmp[1], u32tmp[2]); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", - "0x770(high-pri rx/tx)", - coex_sta->high_priority_rx, coex_sta->high_priority_tx); - CL_PRINTF(cli_buf); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", - "0x774(low-pri rx/tx)", - coex_sta->low_priority_rx, coex_sta->low_priority_tx); - CL_PRINTF(cli_buf); -#if (BT_AUTO_REPORT_ONLY_8821A_1ANT == 1) - halbtc8821a1ant_monitor_bt_ctr(btcoexist); -#endif - btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_COEX_STATISTICS); -} - - -void ex_halbtc8821a1ant_ips_notify(IN struct btc_coexist *btcoexist, IN u8 type) -{ - boolean wifi_under_5g = false; - - if (btcoexist->manual_control || btcoexist->stop_coex_dm) - return; - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, - &wifi_under_5g); - if (wifi_under_5g) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], RunCoexistMechanism(), return for 5G <===\n"); - BTC_TRACE(trace_buf); - halbtc8821a1ant_coex_under_5g(btcoexist); - return; - } - - if (BTC_IPS_ENTER == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], IPS ENTER notify\n"); - BTC_TRACE(trace_buf); - coex_sta->under_ips = true; - - halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); - halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - halbtc8821a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT, false, - true); - /* halbtc8821a1ant_set_ant_path_d_cut(btcoexist, false, false, false, BTC_ANT_PATH_BT, BTC_WIFI_STAT_NORMAL_OFF); */ - } else if (BTC_IPS_LEAVE == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], IPS LEAVE notify\n"); - BTC_TRACE(trace_buf); - coex_sta->under_ips = false; - - halbtc8821a1ant_init_hw_config(btcoexist, false, false); - halbtc8821a1ant_init_coex_dm(btcoexist); - halbtc8821a1ant_query_bt_info(btcoexist); - } -} - -void ex_halbtc8821a1ant_lps_notify(IN struct btc_coexist *btcoexist, IN u8 type) -{ - - - if (BTC_LPS_ENABLE == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], LPS ENABLE notify\n"); - BTC_TRACE(trace_buf); - coex_sta->under_lps = true; - } else if (BTC_LPS_DISABLE == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], LPS DISABLE notify\n"); - BTC_TRACE(trace_buf); - coex_sta->under_lps = false; - } -} - -void ex_halbtc8821a1ant_scan_notify(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - boolean wifi_connected = false, bt_hs_on = false; - u32 wifi_link_status = 0; - u32 num_of_wifi_link = 0; - boolean bt_ctrl_agg_buf_size = false; - u8 agg_buf_size = 5; - boolean wifi_under_5g = false; - - if (btcoexist->manual_control || - btcoexist->stop_coex_dm) - return; - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g); - if (wifi_under_5g) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], RunCoexistMechanism(), return for 5G <===\n"); - BTC_TRACE(trace_buf); - halbtc8821a1ant_coex_under_5g(btcoexist); - return; - } - - if (BTC_SCAN_START == type) { - coex_sta->wifi_is_high_pri_task = true; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCAN START notify\n"); - BTC_TRACE(trace_buf); - - halbtc8821a1ant_ps_tdma(btcoexist, FORCE_EXEC, false, - 8); /* Force antenna setup for no scan result issue */ - } else { - coex_sta->wifi_is_high_pri_task = false; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCAN FINISH notify\n"); - BTC_TRACE(trace_buf); - } - - if (coex_sta->bt_disabled) - return; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - - halbtc8821a1ant_query_bt_info(btcoexist); - - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS, - &wifi_link_status); - num_of_wifi_link = wifi_link_status >> 16; - if (num_of_wifi_link >= 2) { - halbtc8821a1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0); - halbtc8821a1ant_limited_rx(btcoexist, NORMAL_EXEC, false, - bt_ctrl_agg_buf_size, agg_buf_size); - halbtc8821a1ant_action_wifi_multi_port(btcoexist); - return; - } - - if (coex_sta->c2h_bt_inquiry_page) { - halbtc8821a1ant_action_bt_inquiry(btcoexist); - return; - } else if (bt_hs_on) { - halbtc8821a1ant_action_hs(btcoexist); - return; - } - - if (BTC_SCAN_START == type) { - if (!wifi_connected) /* non-connected scan */ - halbtc8821a1ant_action_wifi_not_connected_scan( - btcoexist); - else /* wifi is connected */ - halbtc8821a1ant_action_wifi_connected_scan(btcoexist); - } else if (BTC_SCAN_FINISH == type) { - if (!wifi_connected) /* non-connected scan */ - halbtc8821a1ant_action_wifi_not_connected(btcoexist); - else - halbtc8821a1ant_action_wifi_connected(btcoexist); - } -} - -/* copy scan notify content to switch band notify */ -void ex_halbtc8821a1ant_switchband_notify(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - boolean wifi_connected = false, bt_hs_on = false; - u32 wifi_link_status = 0; - u32 num_of_wifi_link = 0; - boolean bt_ctrl_agg_buf_size = false; - u8 agg_buf_size = 5; - boolean wifi_under_5g = false; - - if (btcoexist->manual_control || - btcoexist->stop_coex_dm) - return; - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g); - if (wifi_under_5g) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], RunCoexistMechanism(), return for 5G <===\n"); - BTC_TRACE(trace_buf); - halbtc8821a1ant_coex_under_5g(btcoexist); - return; - } - - if (BTC_SCAN_START == type) { - coex_sta->wifi_is_high_pri_task = true; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCAN START notify\n"); - BTC_TRACE(trace_buf); - - halbtc8821a1ant_ps_tdma(btcoexist, FORCE_EXEC, false, - 8); /* Force antenna setup for no scan result issue */ - } else { - coex_sta->wifi_is_high_pri_task = false; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCAN FINISH notify\n"); - BTC_TRACE(trace_buf); - } - - if (coex_sta->bt_disabled) - return; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - - halbtc8821a1ant_query_bt_info(btcoexist); - - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS, - &wifi_link_status); - num_of_wifi_link = wifi_link_status >> 16; - if (num_of_wifi_link >= 2) { - halbtc8821a1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0); - halbtc8821a1ant_limited_rx(btcoexist, NORMAL_EXEC, false, - bt_ctrl_agg_buf_size, agg_buf_size); - halbtc8821a1ant_action_wifi_multi_port(btcoexist); - return; - } - - if (coex_sta->c2h_bt_inquiry_page) { - halbtc8821a1ant_action_bt_inquiry(btcoexist); - return; - } else if (bt_hs_on) { - halbtc8821a1ant_action_hs(btcoexist); - return; - } - - if (BTC_SCAN_START == type) { - if (!wifi_connected) /* non-connected scan */ - halbtc8821a1ant_action_wifi_not_connected_scan( - btcoexist); - else /* wifi is connected */ - halbtc8821a1ant_action_wifi_connected_scan(btcoexist); - } else if (BTC_SCAN_FINISH == type) { - if (!wifi_connected) /* non-connected scan */ - halbtc8821a1ant_action_wifi_not_connected(btcoexist); - else - halbtc8821a1ant_action_wifi_connected(btcoexist); - } -} -void ex_halbtc8821a1ant_connect_notify(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - boolean wifi_connected = false, bt_hs_on = false; - u32 wifi_link_status = 0; - u32 num_of_wifi_link = 0; - boolean bt_ctrl_agg_buf_size = false; - u8 agg_buf_size = 5; - boolean wifi_under_5g = false; - - if (btcoexist->manual_control || - btcoexist->stop_coex_dm || - coex_sta->bt_disabled) - return; - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g); - if (wifi_under_5g) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], RunCoexistMechanism(), return for 5G <===\n"); - BTC_TRACE(trace_buf); - halbtc8821a1ant_coex_under_5g(btcoexist); - return; - } - - if (BTC_ASSOCIATE_START == type) { - coex_sta->wifi_is_high_pri_task = true; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], CONNECT START notify\n"); - BTC_TRACE(trace_buf); - coex_dm->arp_cnt = 0; - } else { - coex_sta->wifi_is_high_pri_task = false; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], CONNECT FINISH notify\n"); - BTC_TRACE(trace_buf); - coex_dm->arp_cnt = 0; - } - - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS, - &wifi_link_status); - num_of_wifi_link = wifi_link_status >> 16; - if (num_of_wifi_link >= 2) { - halbtc8821a1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0); - halbtc8821a1ant_limited_rx(btcoexist, NORMAL_EXEC, false, - bt_ctrl_agg_buf_size, agg_buf_size); - halbtc8821a1ant_action_wifi_multi_port(btcoexist); - return; - } - - btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); - if (coex_sta->c2h_bt_inquiry_page) { - halbtc8821a1ant_action_bt_inquiry(btcoexist); - return; - } else if (bt_hs_on) { - halbtc8821a1ant_action_hs(btcoexist); - return; - } - - if (BTC_ASSOCIATE_START == type) - halbtc8821a1ant_action_wifi_not_connected_asso_auth(btcoexist); - else if (BTC_ASSOCIATE_FINISH == type) { - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - if (!wifi_connected) /* non-connected scan */ - halbtc8821a1ant_action_wifi_not_connected(btcoexist); - else - halbtc8821a1ant_action_wifi_connected(btcoexist); - } -} - -void ex_halbtc8821a1ant_media_status_notify(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - u8 h2c_parameter[3] = {0}; - u32 wifi_bw; - u8 wifi_central_chnl; - boolean wifi_under_5g = false; - - if (btcoexist->manual_control || - btcoexist->stop_coex_dm || - coex_sta->bt_disabled) - return; - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g); - if (wifi_under_5g) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], RunCoexistMechanism(), return for 5G <===\n"); - BTC_TRACE(trace_buf); - halbtc8821a1ant_coex_under_5g(btcoexist); - return; - } - - if (BTC_MEDIA_CONNECT == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], MEDIA connect notify\n"); - BTC_TRACE(trace_buf); - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], MEDIA disconnect notify\n"); - BTC_TRACE(trace_buf); - coex_dm->arp_cnt = 0; - } - - /* only 2.4G we need to inform bt the chnl mask */ - btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_CENTRAL_CHNL, - &wifi_central_chnl); - if ((BTC_MEDIA_CONNECT == type) && - (wifi_central_chnl <= 14)) { - /* h2c_parameter[0] = 0x1; */ - h2c_parameter[0] = 0x0; - h2c_parameter[1] = wifi_central_chnl; - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw); - if (BTC_WIFI_BW_HT40 == wifi_bw) - h2c_parameter[2] = 0x30; - else - h2c_parameter[2] = 0x20; - } - - coex_dm->wifi_chnl_info[0] = h2c_parameter[0]; - coex_dm->wifi_chnl_info[1] = h2c_parameter[1]; - coex_dm->wifi_chnl_info[2] = h2c_parameter[2]; - - btcoexist->btc_fill_h2c(btcoexist, 0x66, 3, h2c_parameter); -} - -void ex_halbtc8821a1ant_specific_packet_notify(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - boolean bt_hs_on = false; - u32 wifi_link_status = 0; - u32 num_of_wifi_link = 0; - boolean bt_ctrl_agg_buf_size = false; - u8 agg_buf_size = 5; - boolean wifi_under_5g = false; - - if (btcoexist->manual_control || - btcoexist->stop_coex_dm || - coex_sta->bt_disabled) - return; - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g); - if (wifi_under_5g) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], RunCoexistMechanism(), return for 5G <===\n"); - BTC_TRACE(trace_buf); - halbtc8821a1ant_coex_under_5g(btcoexist); - return; - } - - if (BTC_PACKET_DHCP == type || - BTC_PACKET_EAPOL == type || - BTC_PACKET_ARP == type) { - coex_sta->wifi_is_high_pri_task = true; - - if (BTC_PACKET_ARP == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], specific Packet ARP notify\n"); - BTC_TRACE(trace_buf); - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], specific Packet DHCP or EAPOL notify\n"); - BTC_TRACE(trace_buf); - } - } else { - coex_sta->wifi_is_high_pri_task = false; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], specific Packet [Type = %d] notify\n", type); - BTC_TRACE(trace_buf); - } - - coex_sta->specific_pkt_period_cnt = 0; - - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS, - &wifi_link_status); - num_of_wifi_link = wifi_link_status >> 16; - if (num_of_wifi_link >= 2) { - halbtc8821a1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0); - halbtc8821a1ant_limited_rx(btcoexist, NORMAL_EXEC, false, - bt_ctrl_agg_buf_size, agg_buf_size); - halbtc8821a1ant_action_wifi_multi_port(btcoexist); - return; - } - - btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); - if (coex_sta->c2h_bt_inquiry_page) { - halbtc8821a1ant_action_bt_inquiry(btcoexist); - return; - } else if (bt_hs_on) { - halbtc8821a1ant_action_hs(btcoexist); - return; - } - - if (BTC_PACKET_DHCP == type || - BTC_PACKET_EAPOL == type || - BTC_PACKET_ARP == type) { - if (BTC_PACKET_ARP == type) { - coex_dm->arp_cnt++; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ARP Packet Count = %d\n", - coex_dm->arp_cnt); - BTC_TRACE(trace_buf); - if (coex_dm->arp_cnt >= - 10) /* if APR PKT > 10 after connect, do not go to ActionWifiConnectedSpecificPacket(btcoexist) */ - return; - } - - halbtc8821a1ant_action_wifi_connected_specific_packet( - btcoexist); - } -} - -void ex_halbtc8821a1ant_bt_info_notify(IN struct btc_coexist *btcoexist, - IN u8 *tmp_buf, IN u8 length) -{ - u8 bt_info = 0; - u8 i, rsp_source = 0; - boolean wifi_connected = false; - boolean bt_busy = false; - boolean wifi_under_5g = false; - - - coex_sta->c2h_bt_info_req_sent = false; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g); - - rsp_source = tmp_buf[0] & 0xf; - if (rsp_source >= BT_INFO_SRC_8821A_1ANT_MAX) - rsp_source = BT_INFO_SRC_8821A_1ANT_WIFI_FW; - coex_sta->bt_info_c2h_cnt[rsp_source]++; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Bt info[%d], length=%d, hex data=[", rsp_source, - length); - BTC_TRACE(trace_buf); - for (i = 0; i < length; i++) { - coex_sta->bt_info_c2h[rsp_source][i] = tmp_buf[i]; - if (i == 1) - bt_info = tmp_buf[i]; - if (i == length - 1) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "0x%02x]\n", - tmp_buf[i]); - BTC_TRACE(trace_buf); - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "0x%02x, ", - tmp_buf[i]); - BTC_TRACE(trace_buf); - } - } - /* if 0xff, it means BT is under WHCK test */ - if (bt_info == 0xff) - coex_sta->bt_whck_test = true; - else - coex_sta->bt_whck_test = false; - - if (BT_INFO_SRC_8821A_1ANT_WIFI_FW != rsp_source) { - coex_sta->bt_retry_cnt = /* [3:0] */ - coex_sta->bt_info_c2h[rsp_source][2] & 0xf; - - if (coex_sta->bt_info_c2h[rsp_source][2] & 0x20) - coex_sta->c2h_bt_page = true; - else - coex_sta->c2h_bt_page = false; - - coex_sta->bt_rssi = - coex_sta->bt_info_c2h[rsp_source][3] * 2 + 10; - - coex_sta->bt_info_ext = - coex_sta->bt_info_c2h[rsp_source][4]; - - coex_sta->bt_tx_rx_mask = (coex_sta->bt_info_c2h[rsp_source][2] - & 0x40); - btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TX_RX_MASK, - &coex_sta->bt_tx_rx_mask); - if (!coex_sta->bt_tx_rx_mask) { - /* BT into is responded by BT FW and BT RF REG 0x3C != 0x15 => Need to switch BT TRx Mask */ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Switch BT TRx Mask since BT RF REG 0x3C != 0x15\n"); - BTC_TRACE(trace_buf); - btcoexist->btc_set_bt_reg(btcoexist, BTC_BT_REG_RF, - 0x3c, 0x15); - } - - /* Here we need to resend some wifi info to BT */ - /* because bt is reset and loss of the info. */ - if (coex_sta->bt_info_ext & BIT(1)) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT ext info bit1 check, send wifi BW&Chnl to BT!!\n"); - BTC_TRACE(trace_buf); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - if (wifi_connected) - ex_halbtc8821a1ant_media_status_notify( - btcoexist, BTC_MEDIA_CONNECT); - else - ex_halbtc8821a1ant_media_status_notify( - btcoexist, BTC_MEDIA_DISCONNECT); - } - - if ((coex_sta->bt_info_ext & BIT(3)) && !wifi_under_5g) { - if (!btcoexist->manual_control && - !btcoexist->stop_coex_dm) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT ext info bit3 check, set BT NOT to ignore Wlan active!!\n"); - BTC_TRACE(trace_buf); - halbtc8821a1ant_ignore_wlan_act(btcoexist, - FORCE_EXEC, false); - } - } else { - /* BT already NOT ignore Wlan active, do nothing here. */ - } -#if (BT_AUTO_REPORT_ONLY_8821A_1ANT == 0) - if ((coex_sta->bt_info_ext & BIT(4))) { - /* BT auto report already enabled, do nothing */ - } else - halbtc8821a1ant_bt_auto_report(btcoexist, FORCE_EXEC, - true); -#endif - } - - /* check BIT2 first ==> check if bt is under inquiry or page scan */ - if (bt_info & BT_INFO_8821A_1ANT_B_INQ_PAGE) - coex_sta->c2h_bt_inquiry_page = true; - else - coex_sta->c2h_bt_inquiry_page = false; - - /* set link exist status */ - if (!(bt_info & BT_INFO_8821A_1ANT_B_CONNECTION)) { - coex_sta->bt_link_exist = false; - coex_sta->pan_exist = false; - coex_sta->a2dp_exist = false; - coex_sta->hid_exist = false; - coex_sta->sco_exist = false; - } else { /* connection exists */ - coex_sta->bt_link_exist = true; - if (bt_info & BT_INFO_8821A_1ANT_B_FTP) - coex_sta->pan_exist = true; - else - coex_sta->pan_exist = false; - if (bt_info & BT_INFO_8821A_1ANT_B_A2DP) - coex_sta->a2dp_exist = true; - else - coex_sta->a2dp_exist = false; - if (bt_info & BT_INFO_8821A_1ANT_B_HID) - coex_sta->hid_exist = true; - else - coex_sta->hid_exist = false; - if (bt_info & BT_INFO_8821A_1ANT_B_SCO_ESCO) - coex_sta->sco_exist = true; - else - coex_sta->sco_exist = false; - } - - halbtc8821a1ant_update_bt_link_info(btcoexist); - - bt_info = bt_info & - 0x1f; /* mask profile bit for connect-ilde identification ( for CSR case: A2DP idle --> 0x41) */ - - if (!(bt_info & BT_INFO_8821A_1ANT_B_CONNECTION)) { - coex_dm->bt_status = BT_8821A_1ANT_BT_STATUS_NON_CONNECTED_IDLE; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), BT Non-Connected idle!!!\n"); - BTC_TRACE(trace_buf); - } else if (bt_info == - BT_INFO_8821A_1ANT_B_CONNECTION) { /* connection exists but no busy */ - coex_dm->bt_status = BT_8821A_1ANT_BT_STATUS_CONNECTED_IDLE; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), BT Connected-idle!!!\n"); - BTC_TRACE(trace_buf); - } else if ((bt_info & BT_INFO_8821A_1ANT_B_SCO_ESCO) || - (bt_info & BT_INFO_8821A_1ANT_B_SCO_BUSY)) { - coex_dm->bt_status = BT_8821A_1ANT_BT_STATUS_SCO_BUSY; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), BT SCO busy!!!\n"); - BTC_TRACE(trace_buf); - } else if (bt_info & BT_INFO_8821A_1ANT_B_ACL_BUSY) { - if (BT_8821A_1ANT_BT_STATUS_ACL_BUSY != coex_dm->bt_status) - coex_dm->auto_tdma_adjust = false; - coex_dm->bt_status = BT_8821A_1ANT_BT_STATUS_ACL_BUSY; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), BT ACL busy!!!\n"); - BTC_TRACE(trace_buf); - } else { - coex_dm->bt_status = BT_8821A_1ANT_BT_STATUS_MAX; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), BT Non-Defined state!!!\n"); - BTC_TRACE(trace_buf); - } - - if ((BT_8821A_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) || - (BT_8821A_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) || - (BT_8821A_1ANT_BT_STATUS_ACL_SCO_BUSY == coex_dm->bt_status)) - bt_busy = true; - else - bt_busy = false; - btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bt_busy); - - halbtc8821a1ant_run_coexist_mechanism(btcoexist); -} - -void ex_halbtc8821a1ant_halt_notify(IN struct btc_coexist *btcoexist) -{ - boolean wifi_under_5g = false; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g); - if (wifi_under_5g) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], RunCoexistMechanism(), return for 5G <===\n"); - BTC_TRACE(trace_buf); - halbtc8821a1ant_coex_under_5g(btcoexist); - return; - } - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], Halt notify\n"); - BTC_TRACE(trace_buf); - - halbtc8821a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0, - 0x0); - halbtc8821a1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 0); - halbtc8821a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT, false, true); - /* halbtc8821a1ant_set_ant_path_d_cut(btcoexist, false, false, false, BTC_ANT_PATH_BT, BTC_WIFI_STAT_NORMAL_OFF); */ - - halbtc8821a1ant_ignore_wlan_act(btcoexist, FORCE_EXEC, true); - - ex_halbtc8821a1ant_media_status_notify(btcoexist, BTC_MEDIA_DISCONNECT); - - btcoexist->stop_coex_dm = true; -} - -void ex_halbtc8821a1ant_pnp_notify(IN struct btc_coexist *btcoexist, - IN u8 pnp_state) -{ - boolean wifi_under_5g = false; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g); - if (wifi_under_5g) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], RunCoexistMechanism(), return for 5G <===\n"); - BTC_TRACE(trace_buf); - halbtc8821a1ant_coex_under_5g(btcoexist); - return; - } - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], Pnp notify\n"); - BTC_TRACE(trace_buf); - - if (BTC_WIFI_PNP_SLEEP == pnp_state) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Pnp notify to SLEEP\n"); - BTC_TRACE(trace_buf); - - halbtc8821a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, - 0x0, 0x0); - halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); - halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2); - halbtc8821a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT, false, - true); - /* halbtc8821a1ant_set_ant_path_d_cut(btcoexist, false, false, false, BTC_ANT_PATH_BT, BTC_WIFI_STAT_NORMAL_OFF); */ - - /* Sinda 20150819, workaround for driver skip leave IPS/LPS to speed up sleep time. */ - /* Driver do not leave IPS/LPS when driver is going to sleep, so BTCoexistence think wifi is still under IPS/LPS */ - /* BT should clear UnderIPS/UnderLPS state to avoid mismatch state after wakeup. */ - coex_sta->under_ips = false; - coex_sta->under_lps = false; - btcoexist->stop_coex_dm = true; - } else if (BTC_WIFI_PNP_WAKE_UP == pnp_state) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Pnp notify to WAKE UP\n"); - BTC_TRACE(trace_buf); - btcoexist->stop_coex_dm = false; - halbtc8821a1ant_init_hw_config(btcoexist, false, false); - halbtc8821a1ant_init_coex_dm(btcoexist); - halbtc8821a1ant_query_bt_info(btcoexist); - } -} - -void ex_halbtc8821a1ant_periodical(IN struct btc_coexist *btcoexist) -{ - - if (((coex_sta->bt_coex_supported_version == 0) || - (coex_sta->bt_coex_supported_version == 0xffff)) && - (!coex_sta->bt_disabled)) - coex_sta->bt_coex_supported_version = - btcoexist->btc_get_bt_coex_supported_version(btcoexist); - -#if (BT_AUTO_REPORT_ONLY_8821A_1ANT == 0) - halbtc8821a1ant_query_bt_info(btcoexist); - halbtc8821a1ant_monitor_bt_enable_disable(btcoexist); -#else - halbtc8821a1ant_monitor_bt_ctr(btcoexist); - halbtc8821a1ant_monitor_wifi_ctr(btcoexist); - halbtc8821a1ant_monitor_bt_enable_disable(btcoexist); - if (halbtc8821a1ant_is_wifi_status_changed(btcoexist) || - coex_dm->auto_tdma_adjust) { - /* if(coex_sta->specific_pkt_period_cnt > 2) */ - /* { */ - halbtc8821a1ant_run_coexist_mechanism(btcoexist); - /* } */ - } - - coex_sta->specific_pkt_period_cnt++; -#endif -} - -#endif - -#endif /* #if (BT_SUPPORT == 1 && COEX_SUPPORT == 1) */ - - diff --git a/hal/btc/halbtc8821a1ant.h b/hal/btc/halbtc8821a1ant.h deleted file mode 100644 index 53a5313..0000000 --- a/hal/btc/halbtc8821a1ant.h +++ /dev/null @@ -1,214 +0,0 @@ - -#if (BT_SUPPORT == 1 && COEX_SUPPORT == 1) - -#if (RTL8821A_SUPPORT == 1) - -/* ******************************************* - * The following is for 8821A 1ANT BT Co-exist definition - * ******************************************* */ -#define BT_AUTO_REPORT_ONLY_8821A_1ANT 1 - -#define BT_INFO_8821A_1ANT_B_FTP BIT(7) -#define BT_INFO_8821A_1ANT_B_A2DP BIT(6) -#define BT_INFO_8821A_1ANT_B_HID BIT(5) -#define BT_INFO_8821A_1ANT_B_SCO_BUSY BIT(4) -#define BT_INFO_8821A_1ANT_B_ACL_BUSY BIT(3) -#define BT_INFO_8821A_1ANT_B_INQ_PAGE BIT(2) -#define BT_INFO_8821A_1ANT_B_SCO_ESCO BIT(1) -#define BT_INFO_8821A_1ANT_B_CONNECTION BIT(0) - -#define BT_INFO_8821A_1ANT_A2DP_BASIC_RATE(_BT_INFO_EXT_) \ - (((_BT_INFO_EXT_&BIT(0))) ? true : false) - -#define BTC_RSSI_COEX_THRESH_TOL_8821A_1ANT 2 - -enum bt_info_src_8821a_1ant { - BT_INFO_SRC_8821A_1ANT_WIFI_FW = 0x0, - BT_INFO_SRC_8821A_1ANT_BT_RSP = 0x1, - BT_INFO_SRC_8821A_1ANT_BT_ACTIVE_SEND = 0x2, - BT_INFO_SRC_8821A_1ANT_MAX -}; - -enum bt_8821a_1ant_bt_status { - BT_8821A_1ANT_BT_STATUS_NON_CONNECTED_IDLE = 0x0, - BT_8821A_1ANT_BT_STATUS_CONNECTED_IDLE = 0x1, - BT_8821A_1ANT_BT_STATUS_INQ_PAGE = 0x2, - BT_8821A_1ANT_BT_STATUS_ACL_BUSY = 0x3, - BT_8821A_1ANT_BT_STATUS_SCO_BUSY = 0x4, - BT_8821A_1ANT_BT_STATUS_ACL_SCO_BUSY = 0x5, - BT_8821A_1ANT_BT_STATUS_MAX -}; - -enum bt_8821a_1ant_wifi_status { - BT_8821A_1ANT_WIFI_STATUS_NON_CONNECTED_IDLE = 0x0, - BT_8821A_1ANT_WIFI_STATUS_NON_CONNECTED_ASSO_AUTH_SCAN = 0x1, - BT_8821A_1ANT_WIFI_STATUS_CONNECTED_SCAN = 0x2, - BT_8821A_1ANT_WIFI_STATUS_CONNECTED_SPECIFIC_PKT = 0x3, - BT_8821A_1ANT_WIFI_STATUS_CONNECTED_IDLE = 0x4, - BT_8821A_1ANT_WIFI_STATUS_CONNECTED_BUSY = 0x5, - BT_8821A_1ANT_WIFI_STATUS_MAX -}; - -enum bt_8821a_1ant_coex_algo { - BT_8821A_1ANT_COEX_ALGO_UNDEFINED = 0x0, - BT_8821A_1ANT_COEX_ALGO_SCO = 0x1, - BT_8821A_1ANT_COEX_ALGO_HID = 0x2, - BT_8821A_1ANT_COEX_ALGO_A2DP = 0x3, - BT_8821A_1ANT_COEX_ALGO_A2DP_PANHS = 0x4, - BT_8821A_1ANT_COEX_ALGO_PANEDR = 0x5, - BT_8821A_1ANT_COEX_ALGO_PANHS = 0x6, - BT_8821A_1ANT_COEX_ALGO_PANEDR_A2DP = 0x7, - BT_8821A_1ANT_COEX_ALGO_PANEDR_HID = 0x8, - BT_8821A_1ANT_COEX_ALGO_HID_A2DP_PANEDR = 0x9, - BT_8821A_1ANT_COEX_ALGO_HID_A2DP = 0xa, - BT_8821A_1ANT_COEX_ALGO_MAX = 0xb, -}; - -struct coex_dm_8821a_1ant { - /* fw mechanism */ - boolean cur_ignore_wlan_act; - boolean pre_ignore_wlan_act; - u8 pre_ps_tdma; - u8 cur_ps_tdma; - u8 ps_tdma_para[5]; - u8 ps_tdma_du_adj_type; - boolean auto_tdma_adjust; - boolean pre_ps_tdma_on; - boolean cur_ps_tdma_on; - boolean pre_bt_auto_report; - boolean cur_bt_auto_report; - u8 pre_lps; - u8 cur_lps; - u8 pre_rpwm; - u8 cur_rpwm; - - /* sw mechanism */ - boolean pre_low_penalty_ra; - boolean cur_low_penalty_ra; - u32 pre_val0x6c0; - u32 cur_val0x6c0; - u32 pre_val0x6c4; - u32 cur_val0x6c4; - u32 pre_val0x6c8; - u32 cur_val0x6c8; - u8 pre_val0x6cc; - u8 cur_val0x6cc; - - u32 backup_arfr_cnt1; /* Auto Rate Fallback Retry cnt */ - u32 backup_arfr_cnt2; /* Auto Rate Fallback Retry cnt */ - u16 backup_retry_limit; - u8 backup_ampdu_max_time; - - /* algorithm related */ - u8 pre_algorithm; - u8 cur_algorithm; - u8 bt_status; - u8 wifi_chnl_info[3]; - - u32 pre_ra_mask; - u32 cur_ra_mask; - u8 pre_arfr_type; - u8 cur_arfr_type; - u8 pre_retry_limit_type; - u8 cur_retry_limit_type; - u8 pre_ampdu_time_type; - u8 cur_ampdu_time_type; - u32 arp_cnt; - - u8 error_condition; -}; - -struct coex_sta_8821a_1ant { - boolean bt_disabled; - boolean bt_link_exist; - boolean sco_exist; - boolean a2dp_exist; - boolean hid_exist; - boolean pan_exist; - - boolean under_lps; - boolean under_ips; - u32 specific_pkt_period_cnt; - u32 high_priority_tx; - u32 high_priority_rx; - u32 low_priority_tx; - u32 low_priority_rx; - - u32 crc_ok_cck; - u32 crc_ok_11g; - u32 crc_ok_11n; - u32 crc_ok_11n_vht; - - u32 crc_err_cck; - u32 crc_err_11g; - u32 crc_err_11n; - u32 crc_err_11n_vht; - - u32 bt_coex_supported_version; - u8 cut_version; - u8 bt_rssi; - u8 scan_ap_num; - boolean bt_tx_rx_mask; - u8 pre_bt_rssi_state; - u8 pre_wifi_rssi_state[4]; - boolean c2h_bt_info_req_sent; - u8 bt_info_c2h[BT_INFO_SRC_8821A_1ANT_MAX][10]; - u32 bt_info_c2h_cnt[BT_INFO_SRC_8821A_1ANT_MAX]; - boolean c2h_bt_inquiry_page; - boolean c2h_bt_page; /* Add for win8.1 page out issue */ - boolean wifi_is_high_pri_task; /* Add for win8.1 page out issue */ - u8 bt_retry_cnt; - u8 bt_info_ext; - boolean bt_whck_test; /* Add for ASUS WHQL TEST that enable wifi test bt */ -}; - -/* ******************************************* - * The following is interface which will notify coex module. - * ******************************************* */ -void ex_halbtc8821a1ant_power_on_setting(IN struct btc_coexist *btcoexist); -void ex_halbtc8821a1ant_init_hw_config(IN struct btc_coexist *btcoexist, - IN boolean wifi_only); -void ex_halbtc8821a1ant_init_coex_dm(IN struct btc_coexist *btcoexist); -void ex_halbtc8821a1ant_ips_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8821a1ant_lps_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8821a1ant_scan_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8821a1ant_switchband_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8821a1ant_connect_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8821a1ant_media_status_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8821a1ant_specific_packet_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8821a1ant_bt_info_notify(IN struct btc_coexist *btcoexist, - IN u8 *tmp_buf, IN u8 length); -void ex_halbtc8821a1ant_halt_notify(IN struct btc_coexist *btcoexist); -void ex_halbtc8821a1ant_pnp_notify(IN struct btc_coexist *btcoexist, - IN u8 pnp_state); -void ex_halbtc8821a1ant_periodical(IN struct btc_coexist *btcoexist); -void ex_halbtc8821a1ant_display_coex_info(IN struct btc_coexist *btcoexist); - -#else -#define ex_halbtc8821a1ant_power_on_setting(btcoexist) -#define ex_halbtc8821a1ant_init_hw_config(btcoexist, wifi_only) -#define ex_halbtc8821a1ant_init_coex_dm(btcoexist) -#define ex_halbtc8821a1ant_ips_notify(btcoexist, type) -#define ex_halbtc8821a1ant_lps_notify(btcoexist, type) -#define ex_halbtc8821a1ant_scan_notify(btcoexist, type) -#define ex_halbtc8821a1ant_switchband_notify(btcoexist, type) -#define ex_halbtc8821a1ant_connect_notify(btcoexist, type) -#define ex_halbtc8821a1ant_media_status_notify(btcoexist, type) -#define ex_halbtc8821a1ant_specific_packet_notify(btcoexist, type) -#define ex_halbtc8821a1ant_bt_info_notify(btcoexist, tmp_buf, length) -#define ex_halbtc8821a1ant_halt_notify(btcoexist) -#define ex_halbtc8821a1ant_pnp_notify(btcoexist, pnp_state) -#define ex_halbtc8821a1ant_periodical(btcoexist) -#define ex_halbtc8821a1ant_display_coex_info(btcoexist) - -#endif - -#endif - diff --git a/hal/btc/halbtc8821a2ant.c b/hal/btc/halbtc8821a2ant.c deleted file mode 100644 index 80efc33..0000000 --- a/hal/btc/halbtc8821a2ant.c +++ /dev/null @@ -1,4637 +0,0 @@ -/* ************************************************************ - * Description: - * - * This file is for RTL8821A Co-exist mechanism - * - * History - * 2012/11/15 Cosa first check in. - * - * ************************************************************ */ - -/* ************************************************************ - * include files - * ************************************************************ */ -#include "mp_precomp.h" - -#if (BT_SUPPORT == 1 && COEX_SUPPORT == 1) - -#if (RTL8821A_SUPPORT == 1) -/* ************************************************************ - * Global variables, these are static variables - * ************************************************************ */ -static u8 *trace_buf = &gl_btc_trace_buf[0]; -static struct coex_dm_8821a_2ant glcoex_dm_8821a_2ant; -static struct coex_dm_8821a_2ant *coex_dm = &glcoex_dm_8821a_2ant; -static struct coex_sta_8821a_2ant glcoex_sta_8821a_2ant; -static struct coex_sta_8821a_2ant *coex_sta = &glcoex_sta_8821a_2ant; - -const char *const glbt_info_src_8821a_2ant[] = { - "BT Info[wifi fw]", - "BT Info[bt rsp]", - "BT Info[bt auto report]", -}; - -u32 glcoex_ver_date_8821a_2ant = 20160816; -u32 glcoex_ver_8821a_2ant = 0x5d; -u32 glcoex_ver_btdesired_8821a_2ant = 0x5c; - -/* modify 20140903v43 a2dpandhid tdmaonoff a2dp glitch _ tdma off 778=3(case1)->778=1(case0) - * and to improve tp while a2dphid case23->case25 , case123->case125 for asus spec - * and modify for asus bt WHQL test _ tdma off_ 778=3->1_ - * ************************************************************ - * local function proto type if needed - * ************************************************************ - * ************************************************************ - * local function start with halbtc8821a2ant_ - * ************************************************************ */ -u8 halbtc8821a2ant_bt_rssi_state(u8 level_num, u8 rssi_thresh, u8 rssi_thresh1) -{ - s32 bt_rssi = 0; - u8 bt_rssi_state = coex_sta->pre_bt_rssi_state; - - bt_rssi = coex_sta->bt_rssi; - - if (level_num == 2) { - if ((coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_LOW) || - (coex_sta->pre_bt_rssi_state == - BTC_RSSI_STATE_STAY_LOW)) { - if (bt_rssi >= (rssi_thresh + - BTC_RSSI_COEX_THRESH_TOL_8821A_2ANT)) - bt_rssi_state = BTC_RSSI_STATE_HIGH; - else - bt_rssi_state = BTC_RSSI_STATE_STAY_LOW; - } else { - if (bt_rssi < rssi_thresh) - bt_rssi_state = BTC_RSSI_STATE_LOW; - else - bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH; - } - } else if (level_num == 3) { - if (rssi_thresh > rssi_thresh1) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Rssi thresh error!!\n"); - BTC_TRACE(trace_buf); - return coex_sta->pre_bt_rssi_state; - } - - if ((coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_LOW) || - (coex_sta->pre_bt_rssi_state == - BTC_RSSI_STATE_STAY_LOW)) { - if (bt_rssi >= (rssi_thresh + - BTC_RSSI_COEX_THRESH_TOL_8821A_2ANT)) - bt_rssi_state = BTC_RSSI_STATE_MEDIUM; - else - bt_rssi_state = BTC_RSSI_STATE_STAY_LOW; - } else if ((coex_sta->pre_bt_rssi_state == - BTC_RSSI_STATE_MEDIUM) || - (coex_sta->pre_bt_rssi_state == - BTC_RSSI_STATE_STAY_MEDIUM)) { - if (bt_rssi >= (rssi_thresh1 + - BTC_RSSI_COEX_THRESH_TOL_8821A_2ANT)) - bt_rssi_state = BTC_RSSI_STATE_HIGH; - else if (bt_rssi < rssi_thresh) - bt_rssi_state = BTC_RSSI_STATE_LOW; - else - bt_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM; - } else { - if (bt_rssi < rssi_thresh1) - bt_rssi_state = BTC_RSSI_STATE_MEDIUM; - else - bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH; - } - } - - coex_sta->pre_bt_rssi_state = bt_rssi_state; - - return bt_rssi_state; -} - -u8 halbtc8821a2ant_wifi_rssi_state(IN struct btc_coexist *btcoexist, - IN u8 index, IN u8 level_num, IN u8 rssi_thresh, IN u8 rssi_thresh1) -{ - s32 wifi_rssi = 0; - u8 wifi_rssi_state = coex_sta->pre_wifi_rssi_state[index]; - - btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi); - - if (level_num == 2) { - if ((coex_sta->pre_wifi_rssi_state[index] == BTC_RSSI_STATE_LOW) - || - (coex_sta->pre_wifi_rssi_state[index] == - BTC_RSSI_STATE_STAY_LOW)) { - if (wifi_rssi >= (rssi_thresh + - BTC_RSSI_COEX_THRESH_TOL_8821A_2ANT)) - wifi_rssi_state = BTC_RSSI_STATE_HIGH; - else - wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW; - } else { - if (wifi_rssi < rssi_thresh) - wifi_rssi_state = BTC_RSSI_STATE_LOW; - else - wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH; - } - } else if (level_num == 3) { - if (rssi_thresh > rssi_thresh1) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], wifi RSSI thresh error!!\n"); - BTC_TRACE(trace_buf); - return coex_sta->pre_wifi_rssi_state[index]; - } - - if ((coex_sta->pre_wifi_rssi_state[index] == BTC_RSSI_STATE_LOW) - || - (coex_sta->pre_wifi_rssi_state[index] == - BTC_RSSI_STATE_STAY_LOW)) { - if (wifi_rssi >= (rssi_thresh + - BTC_RSSI_COEX_THRESH_TOL_8821A_2ANT)) - wifi_rssi_state = BTC_RSSI_STATE_MEDIUM; - else - wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW; - } else if ((coex_sta->pre_wifi_rssi_state[index] == - BTC_RSSI_STATE_MEDIUM) || - (coex_sta->pre_wifi_rssi_state[index] == - BTC_RSSI_STATE_STAY_MEDIUM)) { - if (wifi_rssi >= (rssi_thresh1 + - BTC_RSSI_COEX_THRESH_TOL_8821A_2ANT)) - wifi_rssi_state = BTC_RSSI_STATE_HIGH; - else if (wifi_rssi < rssi_thresh) - wifi_rssi_state = BTC_RSSI_STATE_LOW; - else - wifi_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM; - } else { - if (wifi_rssi < rssi_thresh1) - wifi_rssi_state = BTC_RSSI_STATE_MEDIUM; - else - wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH; - } - } - - coex_sta->pre_wifi_rssi_state[index] = wifi_rssi_state; - - return wifi_rssi_state; -} - -void halbtc8821a2ant_monitor_bt_enable_disable(IN struct btc_coexist *btcoexist) -{ - static u32 bt_disable_cnt = 0; - boolean bt_active = true, bt_disabled = false; - - /* This function check if bt is disabled */ - - if (coex_sta->high_priority_tx == 0 && - coex_sta->high_priority_rx == 0 && - coex_sta->low_priority_tx == 0 && - coex_sta->low_priority_rx == 0) - bt_active = false; - if (coex_sta->high_priority_tx == 0xffff && - coex_sta->high_priority_rx == 0xffff && - coex_sta->low_priority_tx == 0xffff && - coex_sta->low_priority_rx == 0xffff) - bt_active = false; - if (bt_active) { - bt_disable_cnt = 0; - bt_disabled = false; - btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_DISABLE, - &bt_disabled); - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT is enabled !!\n"); - BTC_TRACE(trace_buf); - } else { - bt_disable_cnt++; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], bt all counters=0, %d times!!\n", - bt_disable_cnt); - BTC_TRACE(trace_buf); - if (bt_disable_cnt >= 10) { - bt_disabled = true; - btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_DISABLE, - &bt_disabled); - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT is disabled !!\n"); - BTC_TRACE(trace_buf); - } - } - if (coex_sta->bt_disabled != bt_disabled) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT is from %s to %s!!\n", - (coex_sta->bt_disabled ? "disabled" : "enabled"), - (bt_disabled ? "disabled" : "enabled")); - BTC_TRACE(trace_buf); - coex_sta->bt_disabled = bt_disabled; - /* if (!bt_disabled) { - } else { - } */ - } -} - -void halbtc8821a2ant_limited_rx(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean rej_ap_agg_pkt, - IN boolean bt_ctrl_agg_buf_size, IN u8 agg_buf_size) -{ - boolean reject_rx_agg = rej_ap_agg_pkt; - boolean bt_ctrl_rx_agg_size = bt_ctrl_agg_buf_size; - u8 rx_agg_size = agg_buf_size; - - /* ============================================ */ - /* Rx Aggregation related setting */ - /* ============================================ */ - btcoexist->btc_set(btcoexist, BTC_SET_BL_TO_REJ_AP_AGG_PKT, - &reject_rx_agg); - /* decide BT control aggregation buf size or not */ - btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_CTRL_AGG_SIZE, - &bt_ctrl_rx_agg_size); - /* aggregation buf size, only work when BT control Rx aggregation size. */ - btcoexist->btc_set(btcoexist, BTC_SET_U1_AGG_BUF_SIZE, &rx_agg_size); - /* real update aggregation setting */ - btcoexist->btc_set(btcoexist, BTC_SET_ACT_AGGREGATE_CTRL, NULL); -} - -void halbtc8821a2ant_monitor_bt_ctr(IN struct btc_coexist *btcoexist) -{ - u32 reg_hp_txrx, reg_lp_txrx, u32tmp; - u32 reg_hp_tx = 0, reg_hp_rx = 0, reg_lp_tx = 0, reg_lp_rx = 0; - - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - - reg_hp_txrx = 0x770; - reg_lp_txrx = 0x774; - - u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_hp_txrx); - reg_hp_tx = u32tmp & MASKLWORD; - reg_hp_rx = (u32tmp & MASKHWORD) >> 16; - - u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_lp_txrx); - reg_lp_tx = u32tmp & MASKLWORD; - reg_lp_rx = (u32tmp & MASKHWORD) >> 16; - - coex_sta->high_priority_tx = reg_hp_tx; - coex_sta->high_priority_rx = reg_hp_rx; - coex_sta->low_priority_tx = reg_lp_tx; - coex_sta->low_priority_rx = reg_lp_rx; - - if ((coex_sta->low_priority_rx >= 950) && - (coex_sta->low_priority_rx >= coex_sta->low_priority_tx) && - (!coex_sta->under_ips)) - bt_link_info->slave_role = true; - else - bt_link_info->slave_role = false; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], High Priority Tx/Rx (reg 0x%x)=0x%x(%d)/0x%x(%d)\n", - reg_hp_txrx, reg_hp_tx, reg_hp_tx, reg_hp_rx, reg_hp_rx); - BTC_TRACE(trace_buf); - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Low Priority Tx/Rx (reg 0x%x)=0x%x(%d)/0x%x(%d)\n", - reg_lp_txrx, reg_lp_tx, reg_lp_tx, reg_lp_rx, reg_lp_rx); - BTC_TRACE(trace_buf); - - /* reset counter */ - btcoexist->btc_write_1byte(btcoexist, 0x76e, 0xc); -} - -void halbtc8821a2ant_monitor_wifi_ctr(IN struct btc_coexist *btcoexist) -{ -#if 1 - - coex_sta->crc_ok_cck = btcoexist->btc_phydm_query_PHY_counter( - btcoexist, - PHYDM_INFO_CRC32_OK_CCK); - coex_sta->crc_ok_11g = btcoexist->btc_phydm_query_PHY_counter( - btcoexist, - PHYDM_INFO_CRC32_OK_LEGACY); - coex_sta->crc_ok_11n = btcoexist->btc_phydm_query_PHY_counter( - btcoexist, - PHYDM_INFO_CRC32_OK_HT); - coex_sta->crc_ok_11n_vht = - btcoexist->btc_phydm_query_PHY_counter( - btcoexist, - PHYDM_INFO_CRC32_OK_VHT); - - coex_sta->crc_err_cck = btcoexist->btc_phydm_query_PHY_counter( - btcoexist, - PHYDM_INFO_CRC32_ERROR_CCK); - coex_sta->crc_err_11g = btcoexist->btc_phydm_query_PHY_counter( - btcoexist, - PHYDM_INFO_CRC32_ERROR_LEGACY); - coex_sta->crc_err_11n = btcoexist->btc_phydm_query_PHY_counter( - btcoexist, - PHYDM_INFO_CRC32_ERROR_HT); - coex_sta->crc_err_11n_vht = - btcoexist->btc_phydm_query_PHY_counter( - btcoexist, - PHYDM_INFO_CRC32_ERROR_VHT); - -#endif -} - -void halbtc8821a2ant_query_bt_info(IN struct btc_coexist *btcoexist) -{ - u8 h2c_parameter[1] = {0}; - - coex_sta->c2h_bt_info_req_sent = true; - - h2c_parameter[0] |= BIT(0); /* trigger */ - - btcoexist->btc_fill_h2c(btcoexist, 0x61, 1, h2c_parameter); -} - -boolean halbtc8821a2ant_is_wifi_status_changed(IN struct btc_coexist *btcoexist) -{ - static boolean pre_wifi_busy = false, pre_under_4way = false, - pre_bt_hs_on = false; - boolean wifi_busy = false, under_4way = false, bt_hs_on = false; - boolean wifi_connected = false; - u8 wifi_rssi_state = BTC_RSSI_STATE_HIGH; - - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS, - &under_4way); - - if (wifi_connected) { - if (wifi_busy != pre_wifi_busy) { - pre_wifi_busy = wifi_busy; - return true; - } - if (under_4way != pre_under_4way) { - pre_under_4way = under_4way; - return true; - } - if (bt_hs_on != pre_bt_hs_on) { - pre_bt_hs_on = bt_hs_on; - return true; - } - - - wifi_rssi_state = halbtc8821a2ant_wifi_rssi_state(btcoexist, 3, - 2, BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0); - - if ((BTC_RSSI_STATE_HIGH == wifi_rssi_state) || - (BTC_RSSI_STATE_LOW == wifi_rssi_state)) - return true; - - } - - return false; -} - -void halbtc8821a2ant_update_bt_link_info(IN struct btc_coexist *btcoexist) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - boolean bt_hs_on = false; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); - - bt_link_info->bt_link_exist = coex_sta->bt_link_exist; - bt_link_info->sco_exist = coex_sta->sco_exist; - bt_link_info->a2dp_exist = coex_sta->a2dp_exist; - bt_link_info->pan_exist = coex_sta->pan_exist; - bt_link_info->hid_exist = coex_sta->hid_exist; - - /* work around for HS mode. */ - if (bt_hs_on) { - bt_link_info->pan_exist = true; - bt_link_info->bt_link_exist = true; - } - - /* check if Sco only */ - if (bt_link_info->sco_exist && - !bt_link_info->a2dp_exist && - !bt_link_info->pan_exist && - !bt_link_info->hid_exist) - bt_link_info->sco_only = true; - else - bt_link_info->sco_only = false; - - /* check if A2dp only */ - if (!bt_link_info->sco_exist && - bt_link_info->a2dp_exist && - !bt_link_info->pan_exist && - !bt_link_info->hid_exist) - bt_link_info->a2dp_only = true; - else - bt_link_info->a2dp_only = false; - - /* check if Pan only */ - if (!bt_link_info->sco_exist && - !bt_link_info->a2dp_exist && - bt_link_info->pan_exist && - !bt_link_info->hid_exist) - bt_link_info->pan_only = true; - else - bt_link_info->pan_only = false; - - /* check if Hid only */ - if (!bt_link_info->sco_exist && - !bt_link_info->a2dp_exist && - !bt_link_info->pan_exist && - bt_link_info->hid_exist) - bt_link_info->hid_only = true; - else - bt_link_info->hid_only = false; -} - -u8 halbtc8821a2ant_action_algorithm(IN struct btc_coexist *btcoexist) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - boolean bt_hs_on = false; - u8 algorithm = BT_8821A_2ANT_COEX_ALGO_UNDEFINED; - u8 num_of_diff_profile = 0; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); - - if (!bt_link_info->bt_link_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], No BT link exists!!!\n"); - BTC_TRACE(trace_buf); - return algorithm; - } - - if (bt_link_info->sco_exist) - num_of_diff_profile++; - if (bt_link_info->hid_exist) - num_of_diff_profile++; - if (bt_link_info->pan_exist) - num_of_diff_profile++; - if (bt_link_info->a2dp_exist) - num_of_diff_profile++; - - if (num_of_diff_profile == 1) { - if (bt_link_info->sco_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCO only\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8821A_2ANT_COEX_ALGO_SCO; - } else { - if (bt_link_info->hid_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], HID only\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8821A_2ANT_COEX_ALGO_HID; - } else if (bt_link_info->a2dp_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], A2DP only\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8821A_2ANT_COEX_ALGO_A2DP; - } else if (bt_link_info->pan_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], PAN(HS) only\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8821A_2ANT_COEX_ALGO_PANHS; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], PAN(EDR) only\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8821A_2ANT_COEX_ALGO_PANEDR; - } - } - } - } else if (num_of_diff_profile == 2) { - if (bt_link_info->sco_exist) { - if (bt_link_info->hid_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCO + HID\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8821A_2ANT_COEX_ALGO_SCO; - } else if (bt_link_info->a2dp_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCO + A2DP ==> SCO\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8821A_2ANT_COEX_ALGO_SCO; - } else if (bt_link_info->pan_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCO + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8821A_2ANT_COEX_ALGO_SCO; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCO + PAN(EDR)\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8821A_2ANT_COEX_ALGO_SCO; - } - } - } else { - if (bt_link_info->hid_exist && - bt_link_info->a2dp_exist) { - { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], HID + A2DP\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8821A_2ANT_COEX_ALGO_HID_A2DP; - } - } else if (bt_link_info->hid_exist && - bt_link_info->pan_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], HID + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8821A_2ANT_COEX_ALGO_HID; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], HID + PAN(EDR)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8821A_2ANT_COEX_ALGO_PANEDR_HID; - } - } else if (bt_link_info->pan_exist && - bt_link_info->a2dp_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], A2DP + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8821A_2ANT_COEX_ALGO_A2DP_PANHS; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], A2DP + PAN(EDR)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8821A_2ANT_COEX_ALGO_PANEDR_A2DP; - } - } - } - } else if (num_of_diff_profile == 3) { - if (bt_link_info->sco_exist) { - if (bt_link_info->hid_exist && - bt_link_info->a2dp_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCO + HID + A2DP ==> SCO\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8821A_2ANT_COEX_ALGO_SCO; - } else if (bt_link_info->hid_exist && - bt_link_info->pan_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCO + HID + PAN(HS) ==> SCO\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8821A_2ANT_COEX_ALGO_SCO; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCO + HID + PAN(EDR) ==> SCO\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8821A_2ANT_COEX_ALGO_SCO; - } - } else if (bt_link_info->pan_exist && - bt_link_info->a2dp_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCO + A2DP + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8821A_2ANT_COEX_ALGO_SCO; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCO + A2DP + PAN(EDR) ==> HID\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8821A_2ANT_COEX_ALGO_SCO; - } - } - } else { - if (bt_link_info->hid_exist && - bt_link_info->pan_exist && - bt_link_info->a2dp_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], HID + A2DP + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8821A_2ANT_COEX_ALGO_HID_A2DP; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], HID + A2DP + PAN(EDR)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8821A_2ANT_COEX_ALGO_HID_A2DP_PANEDR; - } - } - } - } else if (num_of_diff_profile >= 3) { - if (bt_link_info->sco_exist) { - if (bt_link_info->hid_exist && - bt_link_info->pan_exist && - bt_link_info->a2dp_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Error!!! SCO + HID + A2DP + PAN(HS)\n"); - BTC_TRACE(trace_buf); - - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCO + HID + A2DP + PAN(EDR)==>PAN(EDR)+HID\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8821A_2ANT_COEX_ALGO_SCO; - } - } - } - } - - return algorithm; -} - -void halbtc8821a2ant_set_fw_dac_swing_level(IN struct btc_coexist *btcoexist, - IN u8 dac_swing_lvl) -{ - u8 h2c_parameter[1] = {0}; - - /* There are several type of dacswing */ - /* 0x18/ 0x10/ 0xc/ 0x8/ 0x4/ 0x6 */ - h2c_parameter[0] = dac_swing_lvl; - - btcoexist->btc_fill_h2c(btcoexist, 0x64, 1, h2c_parameter); -} - -void halbtc8821a2ant_set_fw_dec_bt_pwr(IN struct btc_coexist *btcoexist, - IN u8 dec_bt_pwr_lvl) -{ - u8 h2c_parameter[1] = {0}; - - h2c_parameter[0] = dec_bt_pwr_lvl; - - btcoexist->btc_fill_h2c(btcoexist, 0x62, 1, h2c_parameter); -} - -void halbtc8821a2ant_dec_bt_pwr(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 dec_bt_pwr_lvl) -{ - coex_dm->cur_bt_dec_pwr_lvl = dec_bt_pwr_lvl; - - if (!force_exec) { - if (coex_dm->pre_bt_dec_pwr_lvl == coex_dm->cur_bt_dec_pwr_lvl) - return; - } - halbtc8821a2ant_set_fw_dec_bt_pwr(btcoexist, - coex_dm->cur_bt_dec_pwr_lvl); - - coex_dm->pre_bt_dec_pwr_lvl = coex_dm->cur_bt_dec_pwr_lvl; -} - -void halbtc8821a2ant_set_bt_auto_report(IN struct btc_coexist *btcoexist, - IN boolean enable_auto_report) -{ - u8 h2c_parameter[1] = {0}; - - h2c_parameter[0] = 0; - - if (enable_auto_report) - h2c_parameter[0] |= BIT(0); - - btcoexist->btc_fill_h2c(btcoexist, 0x68, 1, h2c_parameter); -} - -void halbtc8821a2ant_bt_auto_report(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean enable_auto_report) -{ - coex_dm->cur_bt_auto_report = enable_auto_report; - - if (!force_exec) { - if (coex_dm->pre_bt_auto_report == coex_dm->cur_bt_auto_report) - return; - } - halbtc8821a2ant_set_bt_auto_report(btcoexist, - coex_dm->cur_bt_auto_report); - - coex_dm->pre_bt_auto_report = coex_dm->cur_bt_auto_report; -} - -void halbtc8821a2ant_fw_dac_swing_lvl(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 fw_dac_swing_lvl) -{ - coex_dm->cur_fw_dac_swing_lvl = fw_dac_swing_lvl; - - if (!force_exec) { - if (coex_dm->pre_fw_dac_swing_lvl == - coex_dm->cur_fw_dac_swing_lvl) - return; - } - - halbtc8821a2ant_set_fw_dac_swing_level(btcoexist, - coex_dm->cur_fw_dac_swing_lvl); - - coex_dm->pre_fw_dac_swing_lvl = coex_dm->cur_fw_dac_swing_lvl; -} - -void halbtc8821a2ant_set_sw_rf_rx_lpf_corner(IN struct btc_coexist *btcoexist, - IN boolean rx_rf_shrink_on) -{ - if (rx_rf_shrink_on) { - /* Shrink RF Rx LPF corner */ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Shrink RF Rx LPF corner!!\n"); - BTC_TRACE(trace_buf); - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1e, 0xfffff, - 0xffffc); - } else { - /* Resume RF Rx LPF corner */ - /* After initialized, we can use coex_dm->bt_rf_0x1e_backup */ - if (btcoexist->initilized) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Resume RF Rx LPF corner!!\n"); - BTC_TRACE(trace_buf); - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1e, - 0xfffff, coex_dm->bt_rf_0x1e_backup); - } - } -} - -void halbtc8821a2ant_rf_shrink(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean rx_rf_shrink_on) -{ - coex_dm->cur_rf_rx_lpf_shrink = rx_rf_shrink_on; - - if (!force_exec) { - if (coex_dm->pre_rf_rx_lpf_shrink == - coex_dm->cur_rf_rx_lpf_shrink) - return; - } - halbtc8821a2ant_set_sw_rf_rx_lpf_corner(btcoexist, - coex_dm->cur_rf_rx_lpf_shrink); - - coex_dm->pre_rf_rx_lpf_shrink = coex_dm->cur_rf_rx_lpf_shrink; -} - -void halbtc8821a2ant_set_sw_penalty_tx_rate_adaptive(IN struct btc_coexist - *btcoexist, IN boolean low_penalty_ra) -{ - u8 h2c_parameter[6] = {0}; - - h2c_parameter[0] = 0x6; /* op_code, 0x6= Retry_Penalty */ - - if (low_penalty_ra) { - h2c_parameter[1] |= BIT(0); - h2c_parameter[2] = - 0x00; /* normal rate except MCS7/6/5, OFDM54/48/36 */ - h2c_parameter[3] = 0xf3; /* MCS7 or OFDM54 */ - h2c_parameter[4] = 0xa0; /* MCS6 or OFDM48 */ - h2c_parameter[5] = 0xa0; /* MCS5 or OFDM36 */ - /* h2c_parameter[3] = 0xf7; */ /*MCS7 or OFDM54 */ - /* h2c_parameter[4] = 0xf8; */ /*MCS6 or OFDM48 */ - /* h2c_parameter[5] = 0xf9; /MCS5 or OFDM36 */ - } - - btcoexist->btc_fill_h2c(btcoexist, 0x69, 6, h2c_parameter); -} - -void halbtc8821a2ant_low_penalty_ra(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean low_penalty_ra) -{ - coex_dm->cur_low_penalty_ra = low_penalty_ra; - - if (!force_exec) { - if (coex_dm->pre_low_penalty_ra == coex_dm->cur_low_penalty_ra) - return; - } - halbtc8821a2ant_set_sw_penalty_tx_rate_adaptive(btcoexist, - coex_dm->cur_low_penalty_ra); - - coex_dm->pre_low_penalty_ra = coex_dm->cur_low_penalty_ra; -} - -void halbtc8821a2ant_set_dac_swing_reg(IN struct btc_coexist *btcoexist, - IN u32 level) -{ - u8 val = (u8)level; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Write SwDacSwing = 0x%x\n", level); - BTC_TRACE(trace_buf); - btcoexist->btc_write_1byte_bitmask(btcoexist, 0xc5b, 0x3e, val); -} - -void halbtc8821a2ant_set_sw_full_time_dac_swing(IN struct btc_coexist - *btcoexist, IN boolean sw_dac_swing_on, IN u32 sw_dac_swing_lvl) -{ - if (sw_dac_swing_on) - halbtc8821a2ant_set_dac_swing_reg(btcoexist, sw_dac_swing_lvl); - else - halbtc8821a2ant_set_dac_swing_reg(btcoexist, 0x18); -} - - -void halbtc8821a2ant_dac_swing(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean dac_swing_on, IN u32 dac_swing_lvl) -{ - coex_dm->cur_dac_swing_on = dac_swing_on; - coex_dm->cur_dac_swing_lvl = dac_swing_lvl; - - if (!force_exec) { - if ((coex_dm->pre_dac_swing_on == coex_dm->cur_dac_swing_on) && - (coex_dm->pre_dac_swing_lvl == - coex_dm->cur_dac_swing_lvl)) - return; - } - delay_ms(30); - halbtc8821a2ant_set_sw_full_time_dac_swing(btcoexist, dac_swing_on, - dac_swing_lvl); - - coex_dm->pre_dac_swing_on = coex_dm->cur_dac_swing_on; - coex_dm->pre_dac_swing_lvl = coex_dm->cur_dac_swing_lvl; -} - -void halbtc8821a2ant_set_adc_back_off(IN struct btc_coexist *btcoexist, - IN boolean adc_back_off) -{ - if (adc_back_off) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BB BackOff Level On!\n"); - BTC_TRACE(trace_buf); - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x8db, 0x60, 0x3); - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BB BackOff Level Off!\n"); - BTC_TRACE(trace_buf); - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x8db, 0x60, 0x1); - } -} - -void halbtc8821a2ant_adc_back_off(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean adc_back_off) -{ - coex_dm->cur_adc_back_off = adc_back_off; - - if (!force_exec) { - if (coex_dm->pre_adc_back_off == coex_dm->cur_adc_back_off) - return; - } - halbtc8821a2ant_set_adc_back_off(btcoexist, coex_dm->cur_adc_back_off); - - coex_dm->pre_adc_back_off = coex_dm->cur_adc_back_off; -} - -void halbtc8821a2ant_set_agc_table(IN struct btc_coexist *btcoexist, - IN boolean agc_table_en) -{ - u8 rssi_adjust_val = 0; - - /* =================BB AGC Gain Table */ - if (agc_table_en) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BB Agc Table On!\n"); - BTC_TRACE(trace_buf); - btcoexist->btc_write_4byte(btcoexist, 0xc78, 0x6e1A0001); - btcoexist->btc_write_4byte(btcoexist, 0xc78, 0x6d1B0001); - btcoexist->btc_write_4byte(btcoexist, 0xc78, 0x6c1C0001); - btcoexist->btc_write_4byte(btcoexist, 0xc78, 0x6b1D0001); - btcoexist->btc_write_4byte(btcoexist, 0xc78, 0x6a1E0001); - btcoexist->btc_write_4byte(btcoexist, 0xc78, 0x691F0001); - btcoexist->btc_write_4byte(btcoexist, 0xc78, 0x68200001); - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BB Agc Table Off!\n"); - BTC_TRACE(trace_buf); - btcoexist->btc_write_4byte(btcoexist, 0xc78, 0xaa1A0001); - btcoexist->btc_write_4byte(btcoexist, 0xc78, 0xa91B0001); - btcoexist->btc_write_4byte(btcoexist, 0xc78, 0xa81C0001); - btcoexist->btc_write_4byte(btcoexist, 0xc78, 0xa71D0001); - btcoexist->btc_write_4byte(btcoexist, 0xc78, 0xa61E0001); - btcoexist->btc_write_4byte(btcoexist, 0xc78, 0xa51F0001); - btcoexist->btc_write_4byte(btcoexist, 0xc78, 0xa4200001); - } - - - /* =================RF Gain */ - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0xef, 0xfffff, 0x02000); - if (agc_table_en) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Agc Table On!\n"); - BTC_TRACE(trace_buf); - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x3b, 0xfffff, - 0x38fff); - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x3b, 0xfffff, - 0x38ffe); - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Agc Table Off!\n"); - BTC_TRACE(trace_buf); - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x3b, 0xfffff, - 0x380c3); - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x3b, 0xfffff, - 0x28ce6); - } - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0xef, 0xfffff, 0x0); - - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0xed, 0xfffff, 0x1); - if (agc_table_en) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Agc Table On!\n"); - BTC_TRACE(trace_buf); - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x40, 0xfffff, - 0x38fff); - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x40, 0xfffff, - 0x38ffe); - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Agc Table Off!\n"); - BTC_TRACE(trace_buf); - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x40, 0xfffff, - 0x380c3); - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x40, 0xfffff, - 0x28ce6); - } - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0xed, 0xfffff, 0x0); - - /* set rssi_adjust_val for wifi module. */ - if (agc_table_en) - rssi_adjust_val = 8; - btcoexist->btc_set(btcoexist, BTC_SET_U1_RSSI_ADJ_VAL_FOR_AGC_TABLE_ON, - &rssi_adjust_val); -} - -void halbtc8821a2ant_agc_table(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean agc_table_en) -{ - coex_dm->cur_agc_table_en = agc_table_en; - - if (!force_exec) { - if (coex_dm->pre_agc_table_en == coex_dm->cur_agc_table_en) - return; - } - halbtc8821a2ant_set_agc_table(btcoexist, agc_table_en); - - coex_dm->pre_agc_table_en = coex_dm->cur_agc_table_en; -} - -void halbtc8821a2ant_set_coex_table(IN struct btc_coexist *btcoexist, - IN u32 val0x6c0, IN u32 val0x6c4, IN u32 val0x6c8, IN u8 val0x6cc) -{ - btcoexist->btc_write_4byte(btcoexist, 0x6c0, val0x6c0); - - btcoexist->btc_write_4byte(btcoexist, 0x6c4, val0x6c4); - - btcoexist->btc_write_4byte(btcoexist, 0x6c8, val0x6c8); - - btcoexist->btc_write_1byte(btcoexist, 0x6cc, val0x6cc); -} - -void halbtc8821a2ant_coex_table(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u32 val0x6c0, IN u32 val0x6c4, - IN u32 val0x6c8, IN u8 val0x6cc) -{ - coex_dm->cur_val0x6c0 = val0x6c0; - coex_dm->cur_val0x6c4 = val0x6c4; - coex_dm->cur_val0x6c8 = val0x6c8; - coex_dm->cur_val0x6cc = val0x6cc; - - if (!force_exec) { - if ((coex_dm->pre_val0x6c0 == coex_dm->cur_val0x6c0) && - (coex_dm->pre_val0x6c4 == coex_dm->cur_val0x6c4) && - (coex_dm->pre_val0x6c8 == coex_dm->cur_val0x6c8) && - (coex_dm->pre_val0x6cc == coex_dm->cur_val0x6cc)) - return; - } - halbtc8821a2ant_set_coex_table(btcoexist, val0x6c0, val0x6c4, val0x6c8, - val0x6cc); - - coex_dm->pre_val0x6c0 = coex_dm->cur_val0x6c0; - coex_dm->pre_val0x6c4 = coex_dm->cur_val0x6c4; - coex_dm->pre_val0x6c8 = coex_dm->cur_val0x6c8; - coex_dm->pre_val0x6cc = coex_dm->cur_val0x6cc; -} - -void halbtc8821a2ant_coex_table_with_type(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 type) -{ - coex_sta->coex_table_type = type; - - switch (type) { - case 0: - halbtc8821a2ant_coex_table(btcoexist, force_exec, - 0x55555555, 0x55555555, 0xffffff, 0x3); - break; - case 1: - halbtc8821a2ant_coex_table(btcoexist, force_exec, - 0x55555555, 0x5afa5afa, 0xffffff, 0x3); - break; - case 2: - halbtc8821a2ant_coex_table(btcoexist, force_exec, - 0x5ada5ada, 0x5ada5ada, 0xffffff, 0x3); - break; - case 3: - halbtc8821a2ant_coex_table(btcoexist, force_exec, - 0xaaaaaaaa, 0xaaaaaaaa, 0xffffff, 0x3); - break; - case 4: - halbtc8821a2ant_coex_table(btcoexist, force_exec, - 0xffffffff, 0xffffffff, 0xffffff, 0x3); - break; - case 5: - halbtc8821a2ant_coex_table(btcoexist, force_exec, - 0x5fff5fff, 0x5fff5fff, 0xffffff, 0x3); - break; - case 6: - halbtc8821a2ant_coex_table(btcoexist, force_exec, - 0x55ff55ff, 0x5a5a5a5a, 0xffffff, 0x3); - break; - case 7: - halbtc8821a2ant_coex_table(btcoexist, force_exec, - 0x55dd55dd, 0x5ada5ada, 0xffffff, 0x3); - break; - case 8: - halbtc8821a2ant_coex_table(btcoexist, force_exec, - 0x55dd55dd, 0x5ada5ada, 0xffffff, 0x3); - break; - case 9: - halbtc8821a2ant_coex_table(btcoexist, force_exec, - 0x55dd55dd, 0x5ada5ada, 0xffffff, 0x3); - break; - case 10: - halbtc8821a2ant_coex_table(btcoexist, force_exec, - 0x55dd55dd, 0x5ada5ada, 0xffffff, 0x3); - break; - case 11: - halbtc8821a2ant_coex_table(btcoexist, force_exec, - 0x55dd55dd, 0x5ada5ada, 0xffffff, 0x3); - break; - case 12: - halbtc8821a2ant_coex_table(btcoexist, force_exec, - 0x55dd55dd, 0x5ada5ada, 0xffffff, 0x3); - break; - case 13: - halbtc8821a2ant_coex_table(btcoexist, force_exec, - 0x5fff5fff, 0xaaaaaaaa, 0xffffff, 0x3); - break; - case 14: - halbtc8821a2ant_coex_table(btcoexist, force_exec, - 0x5fff5fff, 0x5ada5ada, 0xffffff, 0x3); - break; - case 15: - halbtc8821a2ant_coex_table(btcoexist, force_exec, - 0x55dd55dd, 0xaaaaaaaa, 0xffffff, 0x3); - break; - case 16: - halbtc8821a2ant_coex_table(btcoexist, force_exec, - 0x5fdf5fdf, 0x5fdb5fdb, 0xffffff, 0x3); - break; - case 17: - halbtc8821a2ant_coex_table(btcoexist, force_exec, - 0xfafafafa, 0xfafafafa, 0xffffff, 0x3); - break; - case 18: - halbtc8821a2ant_coex_table(btcoexist, force_exec, - 0x5555555f, 0x5ada5ada, 0xffffff, 0x3); - break; - default: - break; - } -} - -void halbtc8821a2ant_set_fw_ignore_wlan_act(IN struct btc_coexist *btcoexist, - IN boolean enable) -{ - u8 h2c_parameter[1] = {0}; - - if (enable) - h2c_parameter[0] |= BIT(0); /* function enable */ - - btcoexist->btc_fill_h2c(btcoexist, 0x63, 1, h2c_parameter); -} - -void halbtc8821a2ant_set_lps_rpwm(IN struct btc_coexist *btcoexist, - IN u8 lps_val, IN u8 rpwm_val) -{ - u8 lps = lps_val; - u8 rpwm = rpwm_val; - - btcoexist->btc_set(btcoexist, BTC_SET_U1_LPS_VAL, &lps); - btcoexist->btc_set(btcoexist, BTC_SET_U1_RPWM_VAL, &rpwm); -} - -void halbtc8821a2ant_lps_rpwm(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 lps_val, IN u8 rpwm_val) -{ - coex_dm->cur_lps = lps_val; - coex_dm->cur_rpwm = rpwm_val; - - if (!force_exec) { - if ((coex_dm->pre_lps == coex_dm->cur_lps) && - (coex_dm->pre_rpwm == coex_dm->cur_rpwm)) - return; - } - halbtc8821a2ant_set_lps_rpwm(btcoexist, lps_val, rpwm_val); - - coex_dm->pre_lps = coex_dm->cur_lps; - coex_dm->pre_rpwm = coex_dm->cur_rpwm; -} - -void halbtc8821a2ant_ignore_wlan_act(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean enable) -{ - coex_dm->cur_ignore_wlan_act = enable; - - if (!force_exec) { - if (coex_dm->pre_ignore_wlan_act == - coex_dm->cur_ignore_wlan_act) - return; - } - halbtc8821a2ant_set_fw_ignore_wlan_act(btcoexist, enable); - - coex_dm->pre_ignore_wlan_act = coex_dm->cur_ignore_wlan_act; -} - -void halbtc8821a2ant_set_fw_pstdma(IN struct btc_coexist *btcoexist, - IN u8 byte1, IN u8 byte2, IN u8 byte3, IN u8 byte4, IN u8 byte5) -{ - u8 h2c_parameter[5] = {0}; - - h2c_parameter[0] = byte1; - h2c_parameter[1] = byte2; - h2c_parameter[2] = byte3; - h2c_parameter[3] = byte4; - h2c_parameter[4] = byte5; - - coex_dm->ps_tdma_para[0] = byte1; - coex_dm->ps_tdma_para[1] = byte2; - coex_dm->ps_tdma_para[2] = byte3; - coex_dm->ps_tdma_para[3] = byte4; - coex_dm->ps_tdma_para[4] = byte5; - - btcoexist->btc_fill_h2c(btcoexist, 0x60, 5, h2c_parameter); -} - -void halbtc8821a2ant_sw_mechanism1(IN struct btc_coexist *btcoexist, - IN boolean shrink_rx_lpf, IN boolean low_penalty_ra, - IN boolean limited_dig, IN boolean bt_lna_constrain) -{ - /* - u32 wifi_bw; - - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw); - - if(BTC_WIFI_BW_HT40 != wifi_bw) - { - if (shrink_rx_lpf) - shrink_rx_lpf = false; - } - */ - - /* halbtc8821a2ant_rf_shrink(btcoexist, NORMAL_EXEC, shrink_rx_lpf); */ - halbtc8821a2ant_low_penalty_ra(btcoexist, NORMAL_EXEC, low_penalty_ra); -} - -void halbtc8821a2ant_sw_mechanism2(IN struct btc_coexist *btcoexist, - IN boolean agc_table_shift, IN boolean adc_back_off, - IN boolean sw_dac_swing, IN u32 dac_swing_lvl) -{ - /* halbtc8821a2ant_agc_table(btcoexist, NORMAL_EXEC, agc_table_shift); */ - /* halbtc8821a2ant_adc_back_off(btcoexist, NORMAL_EXEC, adc_back_off); */ - halbtc8821a2ant_dac_swing(btcoexist, NORMAL_EXEC, sw_dac_swing, - dac_swing_lvl); -} - -void halbtc8821a2ant_set_ant_path(IN struct btc_coexist *btcoexist, - IN u8 ant_pos_type, IN boolean init_hwcfg, IN boolean wifi_off) -{ - struct btc_board_info *board_info = &btcoexist->board_info; - u32 u32tmp = 0; - u8 h2c_parameter[2] = {0}; - - if (init_hwcfg) { - /* 0x4c[23]=0, 0x4c[24]=1 Antenna control by WL/BT */ - u32tmp = btcoexist->btc_read_4byte(btcoexist, 0x4c); - u32tmp &= ~BIT(23); - u32tmp |= BIT(24); - btcoexist->btc_write_4byte(btcoexist, 0x4c, u32tmp); - - btcoexist->btc_write_4byte(btcoexist, 0x974, 0x3ff); - /* btcoexist->btc_write_1byte(btcoexist, 0xcb4, 0x77); */ - - if (board_info->btdm_ant_pos == BTC_ANTENNA_AT_MAIN_PORT) { - /* tell firmware "antenna inverse" ==> WRONG firmware antenna control code.==>need fw to fix */ - h2c_parameter[0] = 1; - h2c_parameter[1] = 1; - btcoexist->btc_fill_h2c(btcoexist, 0x65, 2, - h2c_parameter); - } else { - /* tell firmware "no antenna inverse" ==> WRONG firmware antenna control code.==>need fw to fix */ - h2c_parameter[0] = 0; - h2c_parameter[1] = 1; - btcoexist->btc_fill_h2c(btcoexist, 0x65, 2, - h2c_parameter); - } - } - - /* ext switch setting */ - switch (ant_pos_type) { - case BTC_ANT_WIFI_AT_MAIN: - btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb7, - 0x30, 0x1); - break; - case BTC_ANT_WIFI_AT_AUX: - btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb7, - 0x30, 0x2); - break; - } -} - -void halbtc8821a2ant_ps_tdma(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean turn_on, IN u8 type) -{ - u8 wifi_rssi_state1, bt_rssi_state; - - - wifi_rssi_state1 = halbtc8821a2ant_wifi_rssi_state(btcoexist, 1, 2, - BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0); - bt_rssi_state = halbtc8821a2ant_bt_rssi_state(2, - BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 0); - - if (!(BTC_RSSI_HIGH(wifi_rssi_state1) && - BTC_RSSI_HIGH(bt_rssi_state)) && turn_on) { - type = type + 100; /* for WiFi RSSI low or BT RSSI low */ - } - - coex_dm->cur_ps_tdma_on = turn_on; - coex_dm->cur_ps_tdma = type; - - if (!force_exec) { - if ((coex_dm->pre_ps_tdma_on == coex_dm->cur_ps_tdma_on) && - (coex_dm->pre_ps_tdma == coex_dm->cur_ps_tdma)) - return; - } - if (turn_on) { - switch (type) { - case 1: - default: - /* halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, 0x1a, 0x1a, 0xe1, 0x90); */ - halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x3c, 0x03, 0xf1, 0x90); - break; - case 2: - /* halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, 0x12, 0x12, 0xe1, 0x90); */ - halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x2d, 0x03, 0xf1, 0x90); - break; - case 3: - halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x1c, 0x3, 0xf1, 0x90); - break; - case 4: - halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x10, 0x03, 0xf1, 0x90); - break; - case 5: - /* halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, 0x1a, 0x1a, 0x60, 0x90); */ - halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x3c, 0x3, 0x70, 0x90); - break; - case 6: - /* halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, 0x12, 0x12, 0x60, 0x90); */ - halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x2d, 0x3, 0x70, 0x90); - break; - case 7: - halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x1c, 0x3, 0x70, 0x90); - break; - case 8: - halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xa3, - 0x10, 0x3, 0x70, 0x90); - break; - case 9: - /* halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, 0x1a, 0x1a, 0xe1, 0x90); */ - halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x3c, 0x03, 0xf1, 0x90); - break; - case 10: - /* halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, 0x12, 0x12, 0xe1, 0x90); */ - halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x2d, 0x03, 0xf1, 0x90); - break; - case 11: - /* halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, 0xa, 0xa, 0xe1, 0x90); */ - halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x1c, 0x3, 0xf1, 0x90); - break; - case 12: - /* halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, 0x5, 0x5, 0xe1, 0x90); */ - halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x10, 0x3, 0xf1, 0x90); - break; - case 13: - /* halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, 0x1a, 0x1a, 0x60, 0x90); */ - halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x3c, 0x3, 0x70, 0x90); - break; - case 14: - /* halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, 0x12, 0x12, 0x60, 0x90); */ - halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x2d, 0x3, 0x70, 0x90); - break; - case 15: - /* halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, 0xa, 0xa, 0x60, 0x90); */ - halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x1c, 0x3, 0x70, 0x90); - break; - case 16: - /* halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, 0x5, 0x5, 0x60, 0x90); */ - halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x10, 0x3, 0x70, 0x90); - break; - case 17: - halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xa3, - 0x2f, 0x2f, 0x60, 0x90); - break; - case 18: - halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x5, 0x5, 0xe1, 0x90); - break; - case 19: - halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x25, 0x25, 0xe1, 0x90); - break; - case 20: - halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x25, 0x25, 0x60, 0x90); - break; - case 21: - halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x15, 0x03, 0x70, 0x90); - break; - case 23: - halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x1e, 0x03, 0xf0, 0x14); - break; - case 24: - case 124: - halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xd3, - 0x3c, 0x03, 0x70, 0x50); - break; - /* case25/case125 : for lenovo bt pan tp degrade<30% while wifi downlink */ - case 25: - halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x14, 0x03, 0xf1, 0x90); - break; - case 26: - halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x30, 0x03, 0xf1, 0x90); - break; - case 27: - halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xd3, - 0x23, 0x03, 0x70, 0x50); - break; - case 28: - halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xd3, - 0x1e, 0x03, 0x70, 0x50); - break; - case 71: - /* halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, 0x1a, 0x1a, 0xe1, 0x90); */ - - halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x3c, 0x03, 0xf1, 0x90); - break; - case 101: - case 105: - case 171: - halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xd3, - 0x3a, 0x03, 0x70, 0x50); - break; - case 102: - case 106: - case 110: - case 114: - halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xd3, - 0x2d, 0x03, 0x70, 0x50); - break; - case 103: - case 107: - case 111: - case 115: - halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xd3, - 0x1c, 0x03, 0x70, 0x50); - break; - case 104: - case 108: - case 112: - case 116: - halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xd3, - 0x10, 0x03, 0x70, 0x50); - break; - case 109: - halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x3c, 0x03, 0xf1, 0x90); - break; - case 113: - halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x3c, 0x03, 0x70, 0x90); - break; - case 121: - halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x15, 0x03, 0x70, 0x90); - break; - case 22: - case 122: - halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x35, 0x03, 0x71, 0x11); - break; - case 123: - halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xd3, - 0x1c, 0x03, 0x70, 0x54); - break; - /* case25/case125 : for lenovo bt pan tp degrade<30% while wifi downlink */ - case 125: - halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xd3, - 0x14, 0x03, 0x70, 0x50); - break; - case 126: - halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xd3, - 0x30, 0x03, 0x70, 0x50); - break; - case 127: - halbtc8821a2ant_set_fw_pstdma(btcoexist, 0xd3, - 0x28, 0x03, 0x70, 0x50); - break; - } - } else { - /* disable PS tdma */ - switch (type) { - case 0: - halbtc8821a2ant_set_fw_pstdma(btcoexist, 0x0, - 0x0, 0x0, 0x40, 0x0); - break; - case 1: - halbtc8821a2ant_set_fw_pstdma(btcoexist, 0x0, - 0x0, 0x0, 0x48, 0x0); - break; - default: - halbtc8821a2ant_set_fw_pstdma(btcoexist, 0x0, - 0x0, 0x0, 0x40, 0x0); - break; - } - } - - /* update pre state */ - coex_dm->pre_ps_tdma_on = coex_dm->cur_ps_tdma_on; - coex_dm->pre_ps_tdma = coex_dm->cur_ps_tdma; -} - -void halbtc8821a2ant_ps_tdma_check_for_power_save_state( - IN struct btc_coexist *btcoexist, IN boolean new_ps_state) -{ - u8 lps_mode = 0x0; - - btcoexist->btc_get(btcoexist, BTC_GET_U1_LPS_MODE, &lps_mode); - - if (lps_mode) { /* already under LPS state */ - if (new_ps_state) { - /* keep state under LPS, do nothing. */ - } else { - /* will leave LPS state, turn off psTdma first */ - halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, - 1); - } - } else { /* NO PS state */ - if (new_ps_state) { - /* will enter LPS state, turn off psTdma first */ - halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, - 1); - } else { - /* keep state under NO PS state, do nothing. */ - } - } -} - -void halbtc8821a2ant_power_save_state(IN struct btc_coexist *btcoexist, - IN u8 ps_type, IN u8 lps_val, IN u8 rpwm_val) -{ - boolean low_pwr_disable = false; - - switch (ps_type) { - case BTC_PS_WIFI_NATIVE: - /* recover to original 32k low power setting */ - low_pwr_disable = false; - btcoexist->btc_set(btcoexist, - BTC_SET_ACT_DISABLE_LOW_POWER, - &low_pwr_disable); - btcoexist->btc_set(btcoexist, BTC_SET_ACT_NORMAL_LPS, - NULL); - coex_sta->force_lps_on = false; - break; - case BTC_PS_LPS_ON: - halbtc8821a2ant_ps_tdma_check_for_power_save_state( - btcoexist, true); - halbtc8821a2ant_lps_rpwm(btcoexist, NORMAL_EXEC, - lps_val, rpwm_val); - /* when coex force to enter LPS, do not enter 32k low power. */ - low_pwr_disable = true; - btcoexist->btc_set(btcoexist, - BTC_SET_ACT_DISABLE_LOW_POWER, - &low_pwr_disable); - /* power save must executed before psTdma. */ - btcoexist->btc_set(btcoexist, BTC_SET_ACT_ENTER_LPS, - NULL); - coex_sta->force_lps_on = true; - break; - case BTC_PS_LPS_OFF: - halbtc8821a2ant_ps_tdma_check_for_power_save_state( - btcoexist, false); - btcoexist->btc_set(btcoexist, BTC_SET_ACT_LEAVE_LPS, - NULL); - coex_sta->force_lps_on = false; - break; - default: - break; - } -} - - -void halbtc8821a2ant_coex_all_off(IN struct btc_coexist *btcoexist) -{ - /* fw all off */ - halbtc8821a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0, - 0x0); - halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1); - halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6); - halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - /* sw all off */ - halbtc8821a2ant_sw_mechanism1(btcoexist, false, false, false, false); - halbtc8821a2ant_sw_mechanism2(btcoexist, false, false, false, 0x18); - - /* hw all off */ - /* btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0); */ - halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); -} - -void halbtc8821a2ant_coex_under_5g(IN struct btc_coexist *btcoexist) -{ - halbtc8821a2ant_coex_all_off(btcoexist); - - halbtc8821a2ant_ignore_wlan_act(btcoexist, NORMAL_EXEC, true); -} - -void halbtc8821a2ant_init_coex_dm(IN struct btc_coexist *btcoexist) -{ - /* force to reset coex mechanism */ - halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - - halbtc8821a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0, - 0x0); - halbtc8821a2ant_ps_tdma(btcoexist, FORCE_EXEC, false, 1); - halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, FORCE_EXEC, 6); - halbtc8821a2ant_dec_bt_pwr(btcoexist, FORCE_EXEC, 0); - - halbtc8821a2ant_sw_mechanism1(btcoexist, false, false, false, false); - halbtc8821a2ant_sw_mechanism2(btcoexist, false, false, false, 0x18); -} - -void halbtc8821a2ant_action_bt_inquiry(IN struct btc_coexist *btcoexist) -{ - u8 wifi_rssi_state, wifi_rssi_state1, bt_rssi_state; - boolean wifi_connected = false; - boolean low_pwr_disable = true; - boolean scan = false, link = false, roam = false; - - - wifi_rssi_state = halbtc8821a2ant_wifi_rssi_state(btcoexist, 0, 2, 15, - 0); - wifi_rssi_state1 = halbtc8821a2ant_wifi_rssi_state(btcoexist, 1, 2, - BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0); - bt_rssi_state = halbtc8821a2ant_bt_rssi_state(2, - BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 0); - - btcoexist->btc_set(btcoexist, BTC_SET_ACT_DISABLE_LOW_POWER, - &low_pwr_disable); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam); - - - halbtc8821a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0, - 0x0); - - if (scan || link || roam) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi link process + BT Inq/Page!!\n"); - BTC_TRACE(trace_buf); - halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, - 7); - halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 22); - } else if (wifi_connected) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi connected + BT Inq/Page!!\n"); - BTC_TRACE(trace_buf); - halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, - 7); - halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 22); - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi no-link + BT Inq/Page!!\n"); - BTC_TRACE(trace_buf); - halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1); - } - - halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, FORCE_EXEC, 6); - halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - halbtc8821a2ant_sw_mechanism1(btcoexist, false, false, false, false); - halbtc8821a2ant_sw_mechanism2(btcoexist, false, false, false, 0x18); - -} - - -void halbtc8821a2ant_action_wifi_link_process(IN struct btc_coexist *btcoexist) -{ - u8 u8tmpa, u8tmpb; - - halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7); - halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 22); - - halbtc8821a2ant_sw_mechanism1(btcoexist, false, false, false, false); - halbtc8821a2ant_sw_mechanism2(btcoexist, false, false, false, 0x18); - - - - u8tmpa = btcoexist->btc_read_1byte(btcoexist, 0x765); - u8tmpb = btcoexist->btc_read_1byte(btcoexist, 0x76e); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "############# [BTCoex], 0x765=0x%x, 0x76e=0x%x\n", u8tmpa, - u8tmpb); - BTC_TRACE(trace_buf); -} - -boolean halbtc8821a2ant_action_wifi_idle_process(IN struct btc_coexist - *btcoexist) -{ - u8 wifi_rssi_state, wifi_rssi_state1, bt_rssi_state; - u8 ap_num = 0; - - wifi_rssi_state = halbtc8821a2ant_wifi_rssi_state(btcoexist, 0, 2, 15, - 0); - /* wifi_rssi_state1 = halbtc8821a2ant_wifi_rssi_state(btcoexist, 1, 2, BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0); */ - wifi_rssi_state1 = halbtc8821a2ant_wifi_rssi_state(btcoexist, 1, 2, - BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES - 20, 0); - bt_rssi_state = halbtc8821a2ant_bt_rssi_state(2, - BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 0); - - btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM, &ap_num); - - /* define the office environment */ - if (BTC_RSSI_HIGH(wifi_rssi_state1) && - (coex_sta->hid_exist == true) && - (coex_sta->a2dp_exist == true)) { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi idle process for BT HID+A2DP exist!!\n"); - BTC_TRACE(trace_buf); - - halbtc8821a2ant_dac_swing(btcoexist, NORMAL_EXEC, true, 0x6); - halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - /* sw all off */ - halbtc8821a2ant_sw_mechanism1(btcoexist, false, false, false, - false); - halbtc8821a2ant_sw_mechanism2(btcoexist, false, false, false, - 0x18); - - halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - - halbtc8821a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, - 0x0, 0x0); - halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1); - - return true; - } - - /* */ - else if (coex_sta->pan_exist == true) { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi idle process for BT PAN exist!!\n"); - BTC_TRACE(trace_buf); - - halbtc8821a2ant_dac_swing(btcoexist, NORMAL_EXEC, true, 0x6); - halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - /* sw all off */ - halbtc8821a2ant_sw_mechanism1(btcoexist, false, false, false, - false); - halbtc8821a2ant_sw_mechanism2(btcoexist, false, false, false, - 0x18); - - halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - - halbtc8821a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, - 0x0, 0x0); - halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1); - - return true; - } - - else { - halbtc8821a2ant_dac_swing(btcoexist, NORMAL_EXEC, true, 0x18); - return false; - } - - -} - - - -boolean halbtc8821a2ant_is_common_action(IN struct btc_coexist *btcoexist) -{ - boolean common = false, wifi_connected = false, wifi_busy = false; - boolean bt_hs_on = false, low_pwr_disable = false; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - - if (!wifi_connected) { - low_pwr_disable = false; - btcoexist->btc_set(btcoexist, BTC_SET_ACT_DISABLE_LOW_POWER, - &low_pwr_disable); - halbtc8821a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, - 0x8); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi non-connected idle!!\n"); - BTC_TRACE(trace_buf); - - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, - 0x0); - halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - - halbtc8821a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, - 0x0, 0x0); - halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1); - halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6); - halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - halbtc8821a2ant_sw_mechanism1(btcoexist, false, false, false, - false); - halbtc8821a2ant_sw_mechanism2(btcoexist, false, false, false, - 0x18); - - common = true; - } else { - if (BT_8821A_2ANT_BT_STATUS_NON_CONNECTED_IDLE == - coex_dm->bt_status) { - low_pwr_disable = false; - btcoexist->btc_set(btcoexist, - BTC_SET_ACT_DISABLE_LOW_POWER, - &low_pwr_disable); - halbtc8821a2ant_limited_rx(btcoexist, NORMAL_EXEC, - false, false, 0x8); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi connected + BT non connected-idle!!\n"); - BTC_TRACE(trace_buf); - - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, - 0xfffff, 0x0); - halbtc8821a2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 0); - - halbtc8821a2ant_power_save_state(btcoexist, - BTC_PS_WIFI_NATIVE, 0x0, 0x0); - halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, - 1); - halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, - 0xb); - halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - halbtc8821a2ant_sw_mechanism1(btcoexist, false, false, - false, - false); - halbtc8821a2ant_sw_mechanism2(btcoexist, false, false, - false, 0x18); - - common = true; - } else if (BT_8821A_2ANT_BT_STATUS_CONNECTED_IDLE == - coex_dm->bt_status) { - low_pwr_disable = true; - btcoexist->btc_set(btcoexist, - BTC_SET_ACT_DISABLE_LOW_POWER, - &low_pwr_disable); - - if (bt_hs_on) - return false; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi connected + BT connected-idle!!\n"); - BTC_TRACE(trace_buf); - halbtc8821a2ant_limited_rx(btcoexist, NORMAL_EXEC, - false, false, 0x8); - - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, - 0xfffff, 0x0); - halbtc8821a2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 0); - - halbtc8821a2ant_power_save_state(btcoexist, - BTC_PS_WIFI_NATIVE, 0x0, 0x0); - halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, - 1); - halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, - 0xb); - halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - halbtc8821a2ant_sw_mechanism1(btcoexist, true, false, - false, false); - halbtc8821a2ant_sw_mechanism2(btcoexist, false, false, - false, 0x18); - - common = true; - } else { - low_pwr_disable = true; - btcoexist->btc_set(btcoexist, - BTC_SET_ACT_DISABLE_LOW_POWER, - &low_pwr_disable); - - if (wifi_busy) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi Connected-Busy + BT Busy!!\n"); - BTC_TRACE(trace_buf); - common = false; - /* common = halbtc8821a2ant_action_wifi_idle_process(btcoexist); */ - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi Connected-Idle + BT Busy!!\n"); - BTC_TRACE(trace_buf); - /* common = false; */ - common = halbtc8821a2ant_action_wifi_idle_process( - btcoexist); - } - } - } - - return common; -} -void halbtc8821a2ant_tdma_duration_adjust(IN struct btc_coexist *btcoexist, - IN boolean sco_hid, IN boolean tx_pause, IN u8 max_interval) -{ - static s32 up, dn, m, n, wait_count; - s32 result; /* 0: no change, +1: increase WiFi duration, -1: decrease WiFi duration */ - u8 retry_count = 0; - - if (!coex_dm->auto_tdma_adjust) { - coex_dm->auto_tdma_adjust = true; - { - if (sco_hid) { - if (tx_pause) { - if (max_interval == 1) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 13); - coex_dm->ps_tdma_du_adj_type = - 13; - } else if (max_interval == 2) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 14); - coex_dm->ps_tdma_du_adj_type = - 14; - } else if (max_interval == 3) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 15); - coex_dm->ps_tdma_du_adj_type = - 15; - } else { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 15); - coex_dm->ps_tdma_du_adj_type = - 15; - } - } else { - if (max_interval == 1) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 9); - coex_dm->ps_tdma_du_adj_type = - 9; - } else if (max_interval == 2) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 10); - coex_dm->ps_tdma_du_adj_type = - 10; - } else if (max_interval == 3) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 11); - coex_dm->ps_tdma_du_adj_type = - 11; - } else { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 11); - coex_dm->ps_tdma_du_adj_type = - 11; - } - } - } else { - if (tx_pause) { - if (max_interval == 1) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 5); - coex_dm->ps_tdma_du_adj_type = - 5; - } else if (max_interval == 2) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 6); - coex_dm->ps_tdma_du_adj_type = - 6; - } else if (max_interval == 3) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 7); - coex_dm->ps_tdma_du_adj_type = - 7; - } else { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 7); - coex_dm->ps_tdma_du_adj_type = - 7; - } - } else { - if (max_interval == 1) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 1); - coex_dm->ps_tdma_du_adj_type = - 1; - } else if (max_interval == 2) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 2); - coex_dm->ps_tdma_du_adj_type = - 2; - } else if (max_interval == 3) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 3); - coex_dm->ps_tdma_du_adj_type = - 3; - } else { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 3); - coex_dm->ps_tdma_du_adj_type = - 3; - } - } - } - } - /* ============ */ - up = 0; - dn = 0; - m = 1; - n = 3; - result = 0; - wait_count = 0; - } else { - /* acquire the BT TRx retry count from BT_Info byte2 */ - retry_count = coex_sta->bt_retry_cnt; - result = 0; - wait_count++; - - if (retry_count == - 0) { /* no retry in the last 2-second duration */ - up++; - dn--; - - if (dn <= 0) - dn = 0; - - if (up >= n) { /* if ³sÄò n ­Ó2¬í retry count¬°0, «h½Õ¼eWiFi duration */ - wait_count = 0; - n = 3; - up = 0; - dn = 0; - result = 1; - } - } else if (retry_count <= - 3) { /* <=3 retry in the last 2-second duration */ - up--; - dn++; - - if (up <= 0) - up = 0; - - if (dn == 2) { /* if ³sÄò 2 ­Ó2¬í retry count< 3, «h½Õ¯¶WiFi duration */ - if (wait_count <= 2) - m++; /* ÁקK¤@ª½¦b¨â­Ólevel¤¤¨Ó¦^ */ - else - m = 1; - - if (m >= 20) /* m ³Ì¤j­È = 20 ' ³Ì¤j120¬í recheck¬O§_½Õ¾ã WiFi duration. */ - m = 20; - - n = 3 * m; - up = 0; - dn = 0; - wait_count = 0; - result = -1; - } - } else { /* retry count > 3, ¥u­n1¦¸ retry count > 3, «h½Õ¯¶WiFi duration */ - if (wait_count == 1) - m++; /* ÁקK¤@ª½¦b¨â­Ólevel¤¤¨Ó¦^ */ - else - m = 1; - - if (m >= 20) /* m ³Ì¤j­È = 20 ' ³Ì¤j120¬í recheck¬O§_½Õ¾ã WiFi duration. */ - m = 20; - - n = 3 * m; - up = 0; - dn = 0; - wait_count = 0; - result = -1; - } - - if (max_interval == 1) { - if (tx_pause) { - if (coex_dm->cur_ps_tdma == 71) { - halbtc8821a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 5); - coex_dm->ps_tdma_du_adj_type = 5; - } else if (coex_dm->cur_ps_tdma == 1) { - halbtc8821a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 5); - coex_dm->ps_tdma_du_adj_type = 5; - } else if (coex_dm->cur_ps_tdma == 2) { - halbtc8821a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 6); - coex_dm->ps_tdma_du_adj_type = 6; - } else if (coex_dm->cur_ps_tdma == 3) { - halbtc8821a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 7); - coex_dm->ps_tdma_du_adj_type = 7; - } else if (coex_dm->cur_ps_tdma == 4) { - halbtc8821a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 8); - coex_dm->ps_tdma_du_adj_type = 8; - } - if (coex_dm->cur_ps_tdma == 9) { - halbtc8821a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 13); - coex_dm->ps_tdma_du_adj_type = 13; - } else if (coex_dm->cur_ps_tdma == 10) { - halbtc8821a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 14); - coex_dm->ps_tdma_du_adj_type = 14; - } else if (coex_dm->cur_ps_tdma == 11) { - halbtc8821a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 15); - coex_dm->ps_tdma_du_adj_type = 15; - } else if (coex_dm->cur_ps_tdma == 12) { - halbtc8821a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 16); - coex_dm->ps_tdma_du_adj_type = 16; - } - - if (result == -1) { - if (coex_dm->cur_ps_tdma == 5) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 6); - coex_dm->ps_tdma_du_adj_type = - 6; - } else if (coex_dm->cur_ps_tdma == 6) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 7); - coex_dm->ps_tdma_du_adj_type = - 7; - } else if (coex_dm->cur_ps_tdma == 7) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 8); - coex_dm->ps_tdma_du_adj_type = - 8; - } else if (coex_dm->cur_ps_tdma == 13) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 14); - coex_dm->ps_tdma_du_adj_type = - 14; - } else if (coex_dm->cur_ps_tdma == 14) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 15); - coex_dm->ps_tdma_du_adj_type = - 15; - } else if (coex_dm->cur_ps_tdma == 15) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 16); - coex_dm->ps_tdma_du_adj_type = - 16; - } - } else if (result == 1) { - if (coex_dm->cur_ps_tdma == 8) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 7); - coex_dm->ps_tdma_du_adj_type = - 7; - } else if (coex_dm->cur_ps_tdma == 7) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 6); - coex_dm->ps_tdma_du_adj_type = - 6; - } else if (coex_dm->cur_ps_tdma == 6) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 5); - coex_dm->ps_tdma_du_adj_type = - 5; - } else if (coex_dm->cur_ps_tdma == 16) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 15); - coex_dm->ps_tdma_du_adj_type = - 15; - } else if (coex_dm->cur_ps_tdma == 15) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 14); - coex_dm->ps_tdma_du_adj_type = - 14; - } else if (coex_dm->cur_ps_tdma == 14) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 13); - coex_dm->ps_tdma_du_adj_type = - 13; - } - } - } else { - if (coex_dm->cur_ps_tdma == 5) { - halbtc8821a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 71); - coex_dm->ps_tdma_du_adj_type = 71; - } else if (coex_dm->cur_ps_tdma == 6) { - halbtc8821a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 2); - coex_dm->ps_tdma_du_adj_type = 2; - } else if (coex_dm->cur_ps_tdma == 7) { - halbtc8821a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 3); - coex_dm->ps_tdma_du_adj_type = 3; - } else if (coex_dm->cur_ps_tdma == 8) { - halbtc8821a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 4); - coex_dm->ps_tdma_du_adj_type = 4; - } - if (coex_dm->cur_ps_tdma == 13) { - halbtc8821a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 9); - coex_dm->ps_tdma_du_adj_type = 9; - } else if (coex_dm->cur_ps_tdma == 14) { - halbtc8821a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 10); - coex_dm->ps_tdma_du_adj_type = 10; - } else if (coex_dm->cur_ps_tdma == 15) { - halbtc8821a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 11); - coex_dm->ps_tdma_du_adj_type = 11; - } else if (coex_dm->cur_ps_tdma == 16) { - halbtc8821a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 12); - coex_dm->ps_tdma_du_adj_type = 12; - } - - if (result == -1) { - if (coex_dm->cur_ps_tdma == 71) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 1); - coex_dm->ps_tdma_du_adj_type = - 1; - } else if (coex_dm->cur_ps_tdma == 1) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 2); - coex_dm->ps_tdma_du_adj_type = - 2; - } else if (coex_dm->cur_ps_tdma == 2) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 3); - coex_dm->ps_tdma_du_adj_type = - 3; - } else if (coex_dm->cur_ps_tdma == 3) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 4); - coex_dm->ps_tdma_du_adj_type = - 4; - } else if (coex_dm->cur_ps_tdma == 9) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 10); - coex_dm->ps_tdma_du_adj_type = - 10; - } else if (coex_dm->cur_ps_tdma == 10) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 11); - coex_dm->ps_tdma_du_adj_type = - 11; - } else if (coex_dm->cur_ps_tdma == 11) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 12); - coex_dm->ps_tdma_du_adj_type = - 12; - } - } else if (result == 1) { - if (coex_dm->cur_ps_tdma == 4) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 3); - coex_dm->ps_tdma_du_adj_type = - 3; - } else if (coex_dm->cur_ps_tdma == 3) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 2); - coex_dm->ps_tdma_du_adj_type = - 2; - } else if (coex_dm->cur_ps_tdma == 2) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 1); - coex_dm->ps_tdma_du_adj_type = - 1; - } else if (coex_dm->cur_ps_tdma == 1) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 71); - coex_dm->ps_tdma_du_adj_type = - 71; - } else if (coex_dm->cur_ps_tdma == 12) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 11); - coex_dm->ps_tdma_du_adj_type = - 11; - } else if (coex_dm->cur_ps_tdma == 11) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 10); - coex_dm->ps_tdma_du_adj_type = - 10; - } else if (coex_dm->cur_ps_tdma == 10) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 9); - coex_dm->ps_tdma_du_adj_type = - 9; - } - } - } - } else if (max_interval == 2) { - if (tx_pause) { - if (coex_dm->cur_ps_tdma == 1) { - halbtc8821a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 6); - coex_dm->ps_tdma_du_adj_type = 6; - } else if (coex_dm->cur_ps_tdma == 2) { - halbtc8821a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 6); - coex_dm->ps_tdma_du_adj_type = 6; - } else if (coex_dm->cur_ps_tdma == 3) { - halbtc8821a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 7); - coex_dm->ps_tdma_du_adj_type = 7; - } else if (coex_dm->cur_ps_tdma == 4) { - halbtc8821a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 8); - coex_dm->ps_tdma_du_adj_type = 8; - } - if (coex_dm->cur_ps_tdma == 9) { - halbtc8821a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 14); - coex_dm->ps_tdma_du_adj_type = 14; - } else if (coex_dm->cur_ps_tdma == 10) { - halbtc8821a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 14); - coex_dm->ps_tdma_du_adj_type = 14; - } else if (coex_dm->cur_ps_tdma == 11) { - halbtc8821a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 15); - coex_dm->ps_tdma_du_adj_type = 15; - } else if (coex_dm->cur_ps_tdma == 12) { - halbtc8821a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 16); - coex_dm->ps_tdma_du_adj_type = 16; - } - if (result == -1) { - if (coex_dm->cur_ps_tdma == 5) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 6); - coex_dm->ps_tdma_du_adj_type = - 6; - } else if (coex_dm->cur_ps_tdma == 6) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 7); - coex_dm->ps_tdma_du_adj_type = - 7; - } else if (coex_dm->cur_ps_tdma == 7) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 8); - coex_dm->ps_tdma_du_adj_type = - 8; - } else if (coex_dm->cur_ps_tdma == 13) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 14); - coex_dm->ps_tdma_du_adj_type = - 14; - } else if (coex_dm->cur_ps_tdma == 14) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 15); - coex_dm->ps_tdma_du_adj_type = - 15; - } else if (coex_dm->cur_ps_tdma == 15) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 16); - coex_dm->ps_tdma_du_adj_type = - 16; - } - } else if (result == 1) { - if (coex_dm->cur_ps_tdma == 8) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 7); - coex_dm->ps_tdma_du_adj_type = - 7; - } else if (coex_dm->cur_ps_tdma == 7) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 6); - coex_dm->ps_tdma_du_adj_type = - 6; - } else if (coex_dm->cur_ps_tdma == 6) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 6); - coex_dm->ps_tdma_du_adj_type = - 6; - } else if (coex_dm->cur_ps_tdma == 16) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 15); - coex_dm->ps_tdma_du_adj_type = - 15; - } else if (coex_dm->cur_ps_tdma == 15) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 14); - coex_dm->ps_tdma_du_adj_type = - 14; - } else if (coex_dm->cur_ps_tdma == 14) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 14); - coex_dm->ps_tdma_du_adj_type = - 14; - } - } - } else { - if (coex_dm->cur_ps_tdma == 5) { - halbtc8821a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 2); - coex_dm->ps_tdma_du_adj_type = 2; - } else if (coex_dm->cur_ps_tdma == 6) { - halbtc8821a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 2); - coex_dm->ps_tdma_du_adj_type = 2; - } else if (coex_dm->cur_ps_tdma == 7) { - halbtc8821a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 3); - coex_dm->ps_tdma_du_adj_type = 3; - } else if (coex_dm->cur_ps_tdma == 8) { - halbtc8821a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 4); - coex_dm->ps_tdma_du_adj_type = 4; - } - if (coex_dm->cur_ps_tdma == 13) { - halbtc8821a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 10); - coex_dm->ps_tdma_du_adj_type = 10; - } else if (coex_dm->cur_ps_tdma == 14) { - halbtc8821a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 10); - coex_dm->ps_tdma_du_adj_type = 10; - } else if (coex_dm->cur_ps_tdma == 15) { - halbtc8821a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 11); - coex_dm->ps_tdma_du_adj_type = 11; - } else if (coex_dm->cur_ps_tdma == 16) { - halbtc8821a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 12); - coex_dm->ps_tdma_du_adj_type = 12; - } - if (result == -1) { - if (coex_dm->cur_ps_tdma == 1) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 2); - coex_dm->ps_tdma_du_adj_type = - 2; - } else if (coex_dm->cur_ps_tdma == 2) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 3); - coex_dm->ps_tdma_du_adj_type = - 3; - } else if (coex_dm->cur_ps_tdma == 3) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 4); - coex_dm->ps_tdma_du_adj_type = - 4; - } else if (coex_dm->cur_ps_tdma == 9) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 10); - coex_dm->ps_tdma_du_adj_type = - 10; - } else if (coex_dm->cur_ps_tdma == 10) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 11); - coex_dm->ps_tdma_du_adj_type = - 11; - } else if (coex_dm->cur_ps_tdma == 11) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 12); - coex_dm->ps_tdma_du_adj_type = - 12; - } - } else if (result == 1) { - if (coex_dm->cur_ps_tdma == 4) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 3); - coex_dm->ps_tdma_du_adj_type = - 3; - } else if (coex_dm->cur_ps_tdma == 3) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 2); - coex_dm->ps_tdma_du_adj_type = - 2; - } else if (coex_dm->cur_ps_tdma == 2) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 2); - coex_dm->ps_tdma_du_adj_type = - 2; - } else if (coex_dm->cur_ps_tdma == 12) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 11); - coex_dm->ps_tdma_du_adj_type = - 11; - } else if (coex_dm->cur_ps_tdma == 11) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 10); - coex_dm->ps_tdma_du_adj_type = - 10; - } else if (coex_dm->cur_ps_tdma == 10) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 10); - coex_dm->ps_tdma_du_adj_type = - 10; - } - } - } - } else if (max_interval == 3) { - if (tx_pause) { - if (coex_dm->cur_ps_tdma == 1) { - halbtc8821a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 7); - coex_dm->ps_tdma_du_adj_type = 7; - } else if (coex_dm->cur_ps_tdma == 2) { - halbtc8821a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 7); - coex_dm->ps_tdma_du_adj_type = 7; - } else if (coex_dm->cur_ps_tdma == 3) { - halbtc8821a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 7); - coex_dm->ps_tdma_du_adj_type = 7; - } else if (coex_dm->cur_ps_tdma == 4) { - halbtc8821a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 8); - coex_dm->ps_tdma_du_adj_type = 8; - } - if (coex_dm->cur_ps_tdma == 9) { - halbtc8821a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 15); - coex_dm->ps_tdma_du_adj_type = 15; - } else if (coex_dm->cur_ps_tdma == 10) { - halbtc8821a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 15); - coex_dm->ps_tdma_du_adj_type = 15; - } else if (coex_dm->cur_ps_tdma == 11) { - halbtc8821a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 15); - coex_dm->ps_tdma_du_adj_type = 15; - } else if (coex_dm->cur_ps_tdma == 12) { - halbtc8821a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 16); - coex_dm->ps_tdma_du_adj_type = 16; - } - if (result == -1) { - if (coex_dm->cur_ps_tdma == 5) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 7); - coex_dm->ps_tdma_du_adj_type = - 7; - } else if (coex_dm->cur_ps_tdma == 6) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 7); - coex_dm->ps_tdma_du_adj_type = - 7; - } else if (coex_dm->cur_ps_tdma == 7) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 8); - coex_dm->ps_tdma_du_adj_type = - 8; - } else if (coex_dm->cur_ps_tdma == 13) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 15); - coex_dm->ps_tdma_du_adj_type = - 15; - } else if (coex_dm->cur_ps_tdma == 14) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 15); - coex_dm->ps_tdma_du_adj_type = - 15; - } else if (coex_dm->cur_ps_tdma == 15) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 16); - coex_dm->ps_tdma_du_adj_type = - 16; - } - } else if (result == 1) { - if (coex_dm->cur_ps_tdma == 8) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 7); - coex_dm->ps_tdma_du_adj_type = - 7; - } else if (coex_dm->cur_ps_tdma == 7) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 7); - coex_dm->ps_tdma_du_adj_type = - 7; - } else if (coex_dm->cur_ps_tdma == 6) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 7); - coex_dm->ps_tdma_du_adj_type = - 7; - } else if (coex_dm->cur_ps_tdma == 16) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 15); - coex_dm->ps_tdma_du_adj_type = - 15; - } else if (coex_dm->cur_ps_tdma == 15) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 15); - coex_dm->ps_tdma_du_adj_type = - 15; - } else if (coex_dm->cur_ps_tdma == 14) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 15); - coex_dm->ps_tdma_du_adj_type = - 15; - } - } - } else { - if (coex_dm->cur_ps_tdma == 5) { - halbtc8821a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 3); - coex_dm->ps_tdma_du_adj_type = 3; - } else if (coex_dm->cur_ps_tdma == 6) { - halbtc8821a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 3); - coex_dm->ps_tdma_du_adj_type = 3; - } else if (coex_dm->cur_ps_tdma == 7) { - halbtc8821a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 3); - coex_dm->ps_tdma_du_adj_type = 3; - } else if (coex_dm->cur_ps_tdma == 8) { - halbtc8821a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 4); - coex_dm->ps_tdma_du_adj_type = 4; - } - if (coex_dm->cur_ps_tdma == 13) { - halbtc8821a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 11); - coex_dm->ps_tdma_du_adj_type = 11; - } else if (coex_dm->cur_ps_tdma == 14) { - halbtc8821a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 11); - coex_dm->ps_tdma_du_adj_type = 11; - } else if (coex_dm->cur_ps_tdma == 15) { - halbtc8821a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 11); - coex_dm->ps_tdma_du_adj_type = 11; - } else if (coex_dm->cur_ps_tdma == 16) { - halbtc8821a2ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 12); - coex_dm->ps_tdma_du_adj_type = 12; - } - if (result == -1) { - if (coex_dm->cur_ps_tdma == 1) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 3); - coex_dm->ps_tdma_du_adj_type = - 3; - } else if (coex_dm->cur_ps_tdma == 2) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 3); - coex_dm->ps_tdma_du_adj_type = - 3; - } else if (coex_dm->cur_ps_tdma == 3) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 4); - coex_dm->ps_tdma_du_adj_type = - 4; - } else if (coex_dm->cur_ps_tdma == 9) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 11); - coex_dm->ps_tdma_du_adj_type = - 11; - } else if (coex_dm->cur_ps_tdma == 10) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 11); - coex_dm->ps_tdma_du_adj_type = - 11; - } else if (coex_dm->cur_ps_tdma == 11) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 12); - coex_dm->ps_tdma_du_adj_type = - 12; - } - } else if (result == 1) { - if (coex_dm->cur_ps_tdma == 4) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 3); - coex_dm->ps_tdma_du_adj_type = - 3; - } else if (coex_dm->cur_ps_tdma == 3) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 3); - coex_dm->ps_tdma_du_adj_type = - 3; - } else if (coex_dm->cur_ps_tdma == 2) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 3); - coex_dm->ps_tdma_du_adj_type = - 3; - } else if (coex_dm->cur_ps_tdma == 12) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 11); - coex_dm->ps_tdma_du_adj_type = - 11; - } else if (coex_dm->cur_ps_tdma == 11) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 11); - coex_dm->ps_tdma_du_adj_type = - 11; - } else if (coex_dm->cur_ps_tdma == 10) { - halbtc8821a2ant_ps_tdma( - btcoexist, NORMAL_EXEC, - true, 11); - coex_dm->ps_tdma_du_adj_type = - 11; - } - } - } - } - } - - /* if current PsTdma not match with the recorded one (when scan, dhcp...), */ - /* then we have to adjust it back to the previous record one. */ - if (coex_dm->cur_ps_tdma != coex_dm->ps_tdma_du_adj_type) { - boolean scan = false, link = false, roam = false; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], PsTdma type dismatch!!!, cur_ps_tdma=%d, recordPsTdma=%d\n", - coex_dm->cur_ps_tdma, coex_dm->ps_tdma_du_adj_type); - BTC_TRACE(trace_buf); - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam); - - if (!scan && !link && !roam) - halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - coex_dm->ps_tdma_du_adj_type); - else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], roaming/link/scan is under progress, will adjust next time!!!\n"); - BTC_TRACE(trace_buf); - } - } -} - -/* SCO only or SCO+PAN(HS) */ -void halbtc8821a2ant_action_sco(IN struct btc_coexist *btcoexist) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - u8 wifi_rssi_state, bt_rssi_state; - u32 wifi_bw; - - wifi_rssi_state = halbtc8821a2ant_wifi_rssi_state(btcoexist, 0, 2, 15, - 0); - bt_rssi_state = halbtc8821a2ant_bt_rssi_state(2, - BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 0); - - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0); - - halbtc8821a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8); - - halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 4); - - if (BTC_RSSI_HIGH(bt_rssi_state)) - halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2); - else - halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw); - - if (BTC_WIFI_BW_LEGACY == wifi_bw) /* for SCO quality at 11b/g mode */ - halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2); - else { /* for SCO quality & wifi performance balance at 11n mode */ - if (BTC_WIFI_BW_HT40 == wifi_bw) - halbtc8821a2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 8); - else { - if (bt_link_info->sco_only) - halbtc8821a2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 17); - else - halbtc8821a2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 12); - } - } - - halbtc8821a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0, - 0x0); - halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, - 0); /* for voice quality */ - - /* sw mechanism */ - if (BTC_WIFI_BW_HT40 == wifi_bw) { - if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) || - (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) { - halbtc8821a2ant_sw_mechanism1(btcoexist, true, true, - false, false); - halbtc8821a2ant_sw_mechanism2(btcoexist, true, false, - true, 0x18); - } else { - halbtc8821a2ant_sw_mechanism1(btcoexist, true, true, - false, false); - halbtc8821a2ant_sw_mechanism2(btcoexist, false, false, - true, 0x18); - } - } else { - if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) || - (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) { - halbtc8821a2ant_sw_mechanism1(btcoexist, false, true, - false, false); - halbtc8821a2ant_sw_mechanism2(btcoexist, true, false, - true, 0x18); - } else { - halbtc8821a2ant_sw_mechanism1(btcoexist, false, true, - false, false); - halbtc8821a2ant_sw_mechanism2(btcoexist, false, false, - true, 0x18); - } - } -} - - -void halbtc8821a2ant_action_hid(IN struct btc_coexist *btcoexist) -{ - u8 wifi_rssi_state, bt_rssi_state; - u32 wifi_bw; - - btcoexist->btc_phydm_modify_RA_PCR_threshold(btcoexist, 0, 25); - - wifi_rssi_state = halbtc8821a2ant_wifi_rssi_state(btcoexist, 0, 2, 15, - 0); - bt_rssi_state = halbtc8821a2ant_bt_rssi_state(2, - BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 0); - - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0); - - halbtc8821a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8); - - halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6); - - if (BTC_RSSI_HIGH(bt_rssi_state)) - halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2); - else - halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw); - - if (BTC_WIFI_BW_LEGACY == wifi_bw) /* for HID at 11b/g mode */ - halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7); - else /* for HID quality & wifi performance balance at 11n mode */ - halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2); - - halbtc8821a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0, - 0x0); - - halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 24); - - /* sw mechanism */ - if (BTC_WIFI_BW_HT40 == wifi_bw) { - if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) || - (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) { - halbtc8821a2ant_sw_mechanism1(btcoexist, true, true, - false, false); - halbtc8821a2ant_sw_mechanism2(btcoexist, true, false, - false, 0x18); - } else { - halbtc8821a2ant_sw_mechanism1(btcoexist, true, true, - false, false); - halbtc8821a2ant_sw_mechanism2(btcoexist, false, false, - false, 0x18); - } - } else { - if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) || - (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) { - halbtc8821a2ant_sw_mechanism1(btcoexist, false, true, - false, false); - halbtc8821a2ant_sw_mechanism2(btcoexist, true, false, - false, 0x18); - } else { - halbtc8821a2ant_sw_mechanism1(btcoexist, false, true, - false, false); - halbtc8821a2ant_sw_mechanism2(btcoexist, false, false, - false, 0x18); - } - } -} - -/* A2DP only / PAN(EDR) only/ A2DP+PAN(HS) */ -void halbtc8821a2ant_action_a2dp(IN struct btc_coexist *btcoexist) -{ - u8 wifi_rssi_state, wifi_rssi_state1, bt_rssi_state; - u32 wifi_bw; - u8 ap_num = 0; - - wifi_rssi_state = halbtc8821a2ant_wifi_rssi_state(btcoexist, 0, 2, 15, - 0); - wifi_rssi_state1 = halbtc8821a2ant_wifi_rssi_state(btcoexist, 1, 2, - BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0); - bt_rssi_state = halbtc8821a2ant_bt_rssi_state(2, - BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 0); - - btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM, &ap_num); - - /* define the office environment */ - if ((ap_num >= 10) && BTC_RSSI_HIGH(wifi_rssi_state1) && - BTC_RSSI_HIGH(bt_rssi_state)) { - /* dbg_print(" AP#>10(%d)\n", ap_num); */ - halbtc8821a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, - 0x0, 0x0); - - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, - 0x0); - halbtc8821a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, - 0x8); - halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6); - halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2); - - halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - - halbtc8821a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, - 0x0, 0x0); - /* halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1); */ - halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 23); - - /* sw mechanism */ - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw); - if (BTC_WIFI_BW_HT40 == wifi_bw) { - halbtc8821a2ant_sw_mechanism1(btcoexist, true, false, - false, false); - halbtc8821a2ant_sw_mechanism2(btcoexist, true, false, - true, 0x6); - } else { - halbtc8821a2ant_sw_mechanism1(btcoexist, false, false, - false, false); - halbtc8821a2ant_sw_mechanism2(btcoexist, true, false, - true, 0x6); - } - return; - - } - - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0); - halbtc8821a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8); - - halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6); - - if (BTC_RSSI_HIGH(bt_rssi_state)) - halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2); - else - halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - - if (BTC_RSSI_HIGH(wifi_rssi_state1) && BTC_RSSI_HIGH(bt_rssi_state)) { - halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7); - halbtc8821a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, - 0x0, 0x0); - } else { - halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, - 13); - halbtc8821a2ant_power_save_state(btcoexist, BTC_PS_LPS_ON, 0x50, - 0x4); - } - - - if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) || - (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) { - /* halbtc8821a2ant_tdma_duration_adjust(btcoexist, false, false, 1); */ - halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 23); - } else { - /* halbtc8821a2ant_tdma_duration_adjust(btcoexist, false, true, 1); */ - halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 23); - } - - /* sw mechanism */ - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw); - if (BTC_WIFI_BW_HT40 == wifi_bw) { - if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) || - (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) { - halbtc8821a2ant_sw_mechanism1(btcoexist, true, false, - false, false); - halbtc8821a2ant_sw_mechanism2(btcoexist, true, false, - false, 0x18); - } else { - halbtc8821a2ant_sw_mechanism1(btcoexist, true, false, - false, false); - halbtc8821a2ant_sw_mechanism2(btcoexist, false, false, - false, 0x18); - } - } else { - if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) || - (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) { - halbtc8821a2ant_sw_mechanism1(btcoexist, false, false, - false, false); - halbtc8821a2ant_sw_mechanism2(btcoexist, true, false, - false, 0x18); - } else { - halbtc8821a2ant_sw_mechanism1(btcoexist, false, false, - false, false); - halbtc8821a2ant_sw_mechanism2(btcoexist, false, false, - false, 0x18); - } - } -} - -void halbtc8821a2ant_action_a2dp_pan_hs(IN struct btc_coexist *btcoexist) -{ - u8 wifi_rssi_state, wifi_rssi_state1, bt_rssi_state; - u32 wifi_bw; - - wifi_rssi_state = halbtc8821a2ant_wifi_rssi_state(btcoexist, 0, 2, 15, - 0); - wifi_rssi_state1 = halbtc8821a2ant_wifi_rssi_state(btcoexist, 1, 2, - BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0); - bt_rssi_state = halbtc8821a2ant_bt_rssi_state(2, - BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 0); - - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0); - - halbtc8821a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8); - - halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6); - - if (BTC_RSSI_HIGH(bt_rssi_state)) - halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2); - else - halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - if (BTC_RSSI_HIGH(wifi_rssi_state1) && BTC_RSSI_HIGH(bt_rssi_state)) { - halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7); - halbtc8821a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, - 0x0, 0x0); - } else { - halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, - 13); - halbtc8821a2ant_power_save_state(btcoexist, BTC_PS_LPS_ON, 0x50, - 0x4); - } - - halbtc8821a2ant_tdma_duration_adjust(btcoexist, false, true, 2); - - /* sw mechanism */ - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw); - if (BTC_WIFI_BW_HT40 == wifi_bw) { - if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) || - (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) { - halbtc8821a2ant_sw_mechanism1(btcoexist, true, false, - false, false); - halbtc8821a2ant_sw_mechanism2(btcoexist, true, false, - false, 0x18); - } else { - halbtc8821a2ant_sw_mechanism1(btcoexist, true, false, - false, false); - halbtc8821a2ant_sw_mechanism2(btcoexist, false, false, - false, 0x18); - } - } else { - if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) || - (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) { - halbtc8821a2ant_sw_mechanism1(btcoexist, false, false, - false, false); - halbtc8821a2ant_sw_mechanism2(btcoexist, true, false, - false, 0x18); - } else { - halbtc8821a2ant_sw_mechanism1(btcoexist, false, false, - false, false); - halbtc8821a2ant_sw_mechanism2(btcoexist, false, false, - false, 0x18); - } - } -} - -void halbtc8821a2ant_action_pan_edr(IN struct btc_coexist *btcoexist) -{ - u8 wifi_rssi_state, wifi_rssi_state1, bt_rssi_state; - u32 wifi_bw; - - wifi_rssi_state = halbtc8821a2ant_wifi_rssi_state(btcoexist, 0, 2, 15, - 0); - wifi_rssi_state1 = halbtc8821a2ant_wifi_rssi_state(btcoexist, 1, 2, - BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0); - bt_rssi_state = halbtc8821a2ant_bt_rssi_state(2, - BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 0); - - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0); - - halbtc8821a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8); - - halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6); - - if (BTC_RSSI_HIGH(bt_rssi_state)) - halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2); - else - halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - if (BTC_RSSI_HIGH(wifi_rssi_state1) && BTC_RSSI_HIGH(bt_rssi_state)) { - halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, - 10); - halbtc8821a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, - 0x0, 0x0); - } else { - halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, - 13); - halbtc8821a2ant_power_save_state(btcoexist, BTC_PS_LPS_ON, 0x50, - 0x4); - } - - if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) || - (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) - halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 26); - else - halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 26); - - /* sw mechanism */ - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw); - if (BTC_WIFI_BW_HT40 == wifi_bw) { - if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) || - (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) { - halbtc8821a2ant_sw_mechanism1(btcoexist, true, false, - false, false); - halbtc8821a2ant_sw_mechanism2(btcoexist, true, false, - false, 0x18); - } else { - halbtc8821a2ant_sw_mechanism1(btcoexist, true, false, - false, false); - halbtc8821a2ant_sw_mechanism2(btcoexist, false, false, - false, 0x18); - } - } else { - if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) || - (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) { - halbtc8821a2ant_sw_mechanism1(btcoexist, false, false, - false, false); - halbtc8821a2ant_sw_mechanism2(btcoexist, true, false, - false, 0x18); - } else { - halbtc8821a2ant_sw_mechanism1(btcoexist, false, false, - false, false); - halbtc8821a2ant_sw_mechanism2(btcoexist, false, false, - false, 0x18); - } - } -} - - -/* PAN(HS) only */ -void halbtc8821a2ant_action_pan_hs(IN struct btc_coexist *btcoexist) -{ - u8 wifi_rssi_state, wifi_rssi_state1, bt_rssi_state; - u32 wifi_bw; - - wifi_rssi_state = halbtc8821a2ant_wifi_rssi_state(btcoexist, 0, 2, 15, - 0); - wifi_rssi_state1 = halbtc8821a2ant_wifi_rssi_state(btcoexist, 1, 2, - BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0); - bt_rssi_state = halbtc8821a2ant_bt_rssi_state(2, - BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 0); - - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0); - - halbtc8821a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8); - - halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6); - - if (BTC_RSSI_HIGH(bt_rssi_state)) - halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2); - else - halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7); - - halbtc8821a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0, - 0x0); - halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1); - - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw); - if (BTC_WIFI_BW_HT40 == wifi_bw) { - if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) || - (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) { - halbtc8821a2ant_sw_mechanism1(btcoexist, true, false, - false, false); - halbtc8821a2ant_sw_mechanism2(btcoexist, true, false, - false, 0x18); - } else { - halbtc8821a2ant_sw_mechanism1(btcoexist, true, false, - false, false); - halbtc8821a2ant_sw_mechanism2(btcoexist, false, false, - false, 0x18); - } - } else { - if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) || - (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) { - halbtc8821a2ant_sw_mechanism1(btcoexist, false, false, - false, false); - halbtc8821a2ant_sw_mechanism2(btcoexist, true, false, - false, 0x18); - } else { - halbtc8821a2ant_sw_mechanism1(btcoexist, false, false, - false, false); - halbtc8821a2ant_sw_mechanism2(btcoexist, false, false, - false, 0x18); - } - } -} - -/* PAN(EDR)+A2DP */ -void halbtc8821a2ant_action_pan_edr_a2dp(IN struct btc_coexist *btcoexist) -{ - u8 wifi_rssi_state, wifi_rssi_state1, bt_rssi_state; - u32 wifi_bw; - - wifi_rssi_state = halbtc8821a2ant_wifi_rssi_state(btcoexist, 0, 2, 15, - 0); - wifi_rssi_state1 = halbtc8821a2ant_wifi_rssi_state(btcoexist, 1, 2, - BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0); - bt_rssi_state = halbtc8821a2ant_bt_rssi_state(2, - BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 0); - - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0); - - halbtc8821a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8); - - halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6); - - if (BTC_RSSI_HIGH(bt_rssi_state)) - halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2); - else - halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - if (BTC_RSSI_HIGH(wifi_rssi_state1) && BTC_RSSI_HIGH(bt_rssi_state)) - halbtc8821a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, - 0x0, 0x0); - else - halbtc8821a2ant_power_save_state(btcoexist, BTC_PS_LPS_ON, 0x50, - 0x4); - - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw); - - if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) || - (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) { - halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, - 12); - - if (BTC_WIFI_BW_HT40 == wifi_bw) - halbtc8821a2ant_tdma_duration_adjust(btcoexist, false, - true, 3); - else - halbtc8821a2ant_tdma_duration_adjust(btcoexist, false, - false, 3); - } else { - halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, - 13); - halbtc8821a2ant_tdma_duration_adjust(btcoexist, false, true, 3); - } - - /* sw mechanism */ - if (BTC_WIFI_BW_HT40 == wifi_bw) { - if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) || - (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) { - halbtc8821a2ant_sw_mechanism1(btcoexist, true, false, - false, false); - halbtc8821a2ant_sw_mechanism2(btcoexist, true, false, - false, 0x18); - } else { - halbtc8821a2ant_sw_mechanism1(btcoexist, true, false, - false, false); - halbtc8821a2ant_sw_mechanism2(btcoexist, false, false, - false, 0x18); - } - } else { - if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) || - (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) { - halbtc8821a2ant_sw_mechanism1(btcoexist, false, false, - false, false); - halbtc8821a2ant_sw_mechanism2(btcoexist, true, false, - false, 0x18); - } else { - halbtc8821a2ant_sw_mechanism1(btcoexist, false, false, - false, false); - halbtc8821a2ant_sw_mechanism2(btcoexist, false, false, - false, 0x18); - } - } -} - -void halbtc8821a2ant_action_pan_edr_hid(IN struct btc_coexist *btcoexist) -{ - u8 wifi_rssi_state, wifi_rssi_state1, bt_rssi_state; - u32 wifi_bw; - - btcoexist->btc_phydm_modify_RA_PCR_threshold(btcoexist, 0, 25); - - wifi_rssi_state = halbtc8821a2ant_wifi_rssi_state(btcoexist, 0, 2, 15, - 0); - wifi_rssi_state1 = halbtc8821a2ant_wifi_rssi_state(btcoexist, 1, 2, - BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0); - bt_rssi_state = halbtc8821a2ant_bt_rssi_state(2, - BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 0); - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw); - - halbtc8821a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8); - - if (BTC_RSSI_HIGH(bt_rssi_state)) - halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2); - else - halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - if (BTC_RSSI_HIGH(wifi_rssi_state1) && BTC_RSSI_HIGH(bt_rssi_state)) { - halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7); - halbtc8821a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, - 0x0, 0x0); - } else { - halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, - 14); - halbtc8821a2ant_power_save_state(btcoexist, BTC_PS_LPS_ON, 0x50, - 0x4); - } - - if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) || - (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) { - if (BTC_WIFI_BW_HT40 == wifi_bw) { - halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, - 3); - /* halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 11); */ - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, - 0xfffff, 0x780); - } else { - halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, - 6); - /* halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7); */ - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, - 0xfffff, 0x0); - } - halbtc8821a2ant_tdma_duration_adjust(btcoexist, true, false, 2); - } else { - halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6); - /* halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 14); */ - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, - 0x0); - halbtc8821a2ant_tdma_duration_adjust(btcoexist, true, true, 2); - } - - /* sw mechanism */ - if (BTC_WIFI_BW_HT40 == wifi_bw) { - if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) || - (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) { - halbtc8821a2ant_sw_mechanism1(btcoexist, true, true, - false, false); - halbtc8821a2ant_sw_mechanism2(btcoexist, true, false, - false, 0x18); - } else { - halbtc8821a2ant_sw_mechanism1(btcoexist, true, true, - false, false); - halbtc8821a2ant_sw_mechanism2(btcoexist, false, false, - false, 0x18); - } - } else { - if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) || - (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) { - halbtc8821a2ant_sw_mechanism1(btcoexist, false, true, - false, false); - halbtc8821a2ant_sw_mechanism2(btcoexist, true, false, - false, 0x18); - } else { - halbtc8821a2ant_sw_mechanism1(btcoexist, false, true, - false, false); - halbtc8821a2ant_sw_mechanism2(btcoexist, false, false, - false, 0x18); - } - } -} - -/* HID+A2DP+PAN(EDR) */ -void halbtc8821a2ant_action_hid_a2dp_pan_edr(IN struct btc_coexist *btcoexist) -{ - u8 wifi_rssi_state, wifi_rssi_state1, bt_rssi_state; - u32 wifi_bw; - - btcoexist->btc_phydm_modify_RA_PCR_threshold(btcoexist, 0, 25); - - wifi_rssi_state = halbtc8821a2ant_wifi_rssi_state(btcoexist, 0, 2, 15, - 0); - wifi_rssi_state1 = halbtc8821a2ant_wifi_rssi_state(btcoexist, 1, 2, - BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0); - bt_rssi_state = halbtc8821a2ant_bt_rssi_state(2, - BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 0); - - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0); - - halbtc8821a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8); - - halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6); - - if (BTC_RSSI_HIGH(bt_rssi_state)) - halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2); - else - halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - if (BTC_RSSI_HIGH(wifi_rssi_state1) && BTC_RSSI_HIGH(bt_rssi_state)) { - halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7); - halbtc8821a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, - 0x0, 0x0); - } else { - halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, - 14); - halbtc8821a2ant_power_save_state(btcoexist, BTC_PS_LPS_ON, 0x50, - 0x4); - } - - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw); - - if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) || - (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) { - if (BTC_WIFI_BW_HT40 == wifi_bw) - halbtc8821a2ant_tdma_duration_adjust(btcoexist, true, - true, 3); - else - halbtc8821a2ant_tdma_duration_adjust(btcoexist, true, - false, 3); - } else - halbtc8821a2ant_tdma_duration_adjust(btcoexist, true, true, 3); - - /* sw mechanism */ - if (BTC_WIFI_BW_HT40 == wifi_bw) { - if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) || - (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) { - halbtc8821a2ant_sw_mechanism1(btcoexist, true, true, - false, false); - halbtc8821a2ant_sw_mechanism2(btcoexist, true, false, - false, 0x18); - } else { - halbtc8821a2ant_sw_mechanism1(btcoexist, true, true, - false, false); - halbtc8821a2ant_sw_mechanism2(btcoexist, false, false, - false, 0x18); - } - } else { - if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) || - (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) { - halbtc8821a2ant_sw_mechanism1(btcoexist, false, true, - false, false); - halbtc8821a2ant_sw_mechanism2(btcoexist, true, false, - false, 0x18); - } else { - halbtc8821a2ant_sw_mechanism1(btcoexist, false, true, - false, false); - halbtc8821a2ant_sw_mechanism2(btcoexist, false, false, - false, 0x18); - } - } -} - -void halbtc8821a2ant_action_hid_a2dp(IN struct btc_coexist *btcoexist) -{ - u8 wifi_rssi_state, wifi_rssi_state1, bt_rssi_state; - u32 wifi_bw; - u8 ap_num = 0; - - btcoexist->btc_phydm_modify_RA_PCR_threshold(btcoexist, 0, 25); - - wifi_rssi_state = halbtc8821a2ant_wifi_rssi_state(btcoexist, 0, 2, 15, - 0); - /* bt_rssi_state = halbtc8821a2ant_bt_rssi_state(2, 29, 0); */ - wifi_rssi_state1 = halbtc8821a2ant_wifi_rssi_state(btcoexist, 1, 2, - BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0); - bt_rssi_state = halbtc8821a2ant_bt_rssi_state(3, - BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 37); - - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0); - - halbtc8821a2ant_limited_rx(btcoexist, NORMAL_EXEC, false, true, 0x6); - - halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6); - - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw); - if (BTC_WIFI_BW_LEGACY == wifi_bw) { - if (BTC_RSSI_HIGH(bt_rssi_state)) - halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2); - else if (BTC_RSSI_MEDIUM(bt_rssi_state)) - halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2); - else - halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - } else { - /* only 802.11N mode we have to dec bt power to 4 degree */ - if (BTC_RSSI_HIGH(bt_rssi_state)) { - btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM, - &ap_num); - /* need to check ap Number of Not */ - if (ap_num < 10) - halbtc8821a2ant_dec_bt_pwr(btcoexist, - NORMAL_EXEC, 4); - else - halbtc8821a2ant_dec_bt_pwr(btcoexist, - NORMAL_EXEC, 2); - } else if (BTC_RSSI_MEDIUM(bt_rssi_state)) - halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2); - else - halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - } - - if (BTC_RSSI_HIGH(wifi_rssi_state1) && BTC_RSSI_HIGH(bt_rssi_state)) { - halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, - 18); - halbtc8821a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, - 0x0, 0x0); - } else { - halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, - 18); - halbtc8821a2ant_power_save_state(btcoexist, BTC_PS_LPS_ON, 0x50, - 0x4); - } - - if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) || - (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) { - /* halbtc8821a2ant_tdma_duration_adjust(btcoexist, true, false, 3); */ - halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 28); - } else { - /* halbtc8821a2ant_tdma_duration_adjust(btcoexist, true, true, 3); */ - halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 28); - } - - /* sw mechanism */ - if (BTC_WIFI_BW_HT40 == wifi_bw) { - if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) || - (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) { - halbtc8821a2ant_sw_mechanism1(btcoexist, true, true, - false, false); - halbtc8821a2ant_sw_mechanism2(btcoexist, true, false, - false, 0x18); - } else { - halbtc8821a2ant_sw_mechanism1(btcoexist, true, true, - false, false); - halbtc8821a2ant_sw_mechanism2(btcoexist, false, false, - false, 0x18); - } - } else { - if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) || - (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) { - halbtc8821a2ant_sw_mechanism1(btcoexist, false, true, - false, false); - halbtc8821a2ant_sw_mechanism2(btcoexist, true, false, - false, 0x18); - } else { - halbtc8821a2ant_sw_mechanism1(btcoexist, false, true, - false, false); - halbtc8821a2ant_sw_mechanism2(btcoexist, false, false, - false, 0x18); - } - } -} - -void halbtc8821a2ant_action_bt_whck_test(IN struct btc_coexist *btcoexist) -{ - halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - /* sw all off */ - halbtc8821a2ant_sw_mechanism1(btcoexist, false, false, false, false); - halbtc8821a2ant_sw_mechanism2(btcoexist, false, false, false, 0x18); - - halbtc8821a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0, - 0x0); - - halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1); - halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); -} - -void halbtc8821a2ant_action_wifi_multi_port(IN struct btc_coexist *btcoexist) -{ - halbtc8821a2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6); - halbtc8821a2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - /* sw all off */ - halbtc8821a2ant_sw_mechanism1(btcoexist, false, false, false, false); - halbtc8821a2ant_sw_mechanism2(btcoexist, false, false, false, 0x18); - - /* hw all off */ - /* btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0); */ - halbtc8821a2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - - halbtc8821a2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0, - 0x0); - halbtc8821a2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1); -} - -void halbtc8821a2ant_run_coexist_mechanism(IN struct btc_coexist *btcoexist) -{ - boolean wifi_under_5g = false; - u8 algorithm = 0; - u32 num_of_wifi_link = 0; - u32 wifi_link_status = 0; - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - boolean miracast_plus_bt = false; - boolean scan = false, link = false, roam = false; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], RunCoexistMechanism()===>\n"); - BTC_TRACE(trace_buf); - - if (btcoexist->manual_control) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], RunCoexistMechanism(), return for Manual CTRL <===\n"); - BTC_TRACE(trace_buf); - return; - } - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g); - if (wifi_under_5g) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], RunCoexistMechanism(), run 5G coex setting!!<===\n"); - BTC_TRACE(trace_buf); - halbtc8821a2ant_coex_under_5g(btcoexist); - return; - } - - if (coex_sta->under_ips) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], wifi is under IPS !!!\n"); - BTC_TRACE(trace_buf); - return; - } - - if (coex_sta->bt_whck_test) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT is under WHCK TEST!!!\n"); - BTC_TRACE(trace_buf); - halbtc8821a2ant_action_bt_whck_test(btcoexist); - return; - } - - algorithm = halbtc8821a2ant_action_algorithm(btcoexist); - if (coex_sta->c2h_bt_inquiry_page && - (BT_8821A_2ANT_COEX_ALGO_PANHS != algorithm)) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT is under inquiry/page scan !!\n"); - BTC_TRACE(trace_buf); - halbtc8821a2ant_action_bt_inquiry(btcoexist); - return; - } - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam); - - if (scan || link || roam) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], WiFi is under Link Process !!\n"); - BTC_TRACE(trace_buf); - halbtc8821a2ant_action_wifi_link_process(btcoexist); - return; - } - - /* for P2P */ - - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS, - &wifi_link_status); - num_of_wifi_link = wifi_link_status >> 16; - - if ((num_of_wifi_link >= 2) || - (wifi_link_status & WIFI_P2P_GO_CONNECTED)) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "############# [BTCoex], Multi-Port num_of_wifi_link = %d, wifi_link_status = 0x%x\n", - num_of_wifi_link, wifi_link_status); - BTC_TRACE(trace_buf); - - if (bt_link_info->bt_link_exist) - miracast_plus_bt = true; - else - miracast_plus_bt = false; - - btcoexist->btc_set(btcoexist, BTC_SET_BL_MIRACAST_PLUS_BT, - &miracast_plus_bt); - halbtc8821a2ant_action_wifi_multi_port(btcoexist); - - return; - } - - miracast_plus_bt = false; - btcoexist->btc_set(btcoexist, BTC_SET_BL_MIRACAST_PLUS_BT, - &miracast_plus_bt); - - coex_dm->cur_algorithm = algorithm; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], Algorithm = %d\n", - coex_dm->cur_algorithm); - BTC_TRACE(trace_buf); - - if (halbtc8821a2ant_is_common_action(btcoexist)) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant common.\n"); - BTC_TRACE(trace_buf); - coex_dm->auto_tdma_adjust = false; - } else { - if (coex_dm->cur_algorithm != coex_dm->pre_algorithm) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], pre_algorithm=%d, cur_algorithm=%d\n", - coex_dm->pre_algorithm, coex_dm->cur_algorithm); - BTC_TRACE(trace_buf); - coex_dm->auto_tdma_adjust = false; - } - switch (coex_dm->cur_algorithm) { - case BT_8821A_2ANT_COEX_ALGO_SCO: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, algorithm = SCO.\n"); - BTC_TRACE(trace_buf); - halbtc8821a2ant_action_sco(btcoexist); - break; - case BT_8821A_2ANT_COEX_ALGO_HID: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, algorithm = HID.\n"); - BTC_TRACE(trace_buf); - halbtc8821a2ant_action_hid(btcoexist); - break; - case BT_8821A_2ANT_COEX_ALGO_A2DP: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, algorithm = A2DP.\n"); - BTC_TRACE(trace_buf); - halbtc8821a2ant_action_a2dp(btcoexist); - break; - case BT_8821A_2ANT_COEX_ALGO_A2DP_PANHS: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, algorithm = A2DP+PAN(HS).\n"); - BTC_TRACE(trace_buf); - halbtc8821a2ant_action_a2dp_pan_hs(btcoexist); - break; - case BT_8821A_2ANT_COEX_ALGO_PANEDR: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, algorithm = PAN(EDR).\n"); - BTC_TRACE(trace_buf); - halbtc8821a2ant_action_pan_edr(btcoexist); - break; - case BT_8821A_2ANT_COEX_ALGO_PANHS: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, algorithm = HS mode.\n"); - BTC_TRACE(trace_buf); - halbtc8821a2ant_action_pan_hs(btcoexist); - break; - case BT_8821A_2ANT_COEX_ALGO_PANEDR_A2DP: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, algorithm = PAN+A2DP.\n"); - BTC_TRACE(trace_buf); - halbtc8821a2ant_action_pan_edr_a2dp(btcoexist); - break; - case BT_8821A_2ANT_COEX_ALGO_PANEDR_HID: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, algorithm = PAN(EDR)+HID.\n"); - BTC_TRACE(trace_buf); - halbtc8821a2ant_action_pan_edr_hid(btcoexist); - break; - case BT_8821A_2ANT_COEX_ALGO_HID_A2DP_PANEDR: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, algorithm = HID+A2DP+PAN.\n"); - BTC_TRACE(trace_buf); - halbtc8821a2ant_action_hid_a2dp_pan_edr( - btcoexist); - break; - case BT_8821A_2ANT_COEX_ALGO_HID_A2DP: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, algorithm = HID+A2DP.\n"); - BTC_TRACE(trace_buf); - halbtc8821a2ant_action_hid_a2dp(btcoexist); - break; - default: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, algorithm = coexist All Off!!\n"); - BTC_TRACE(trace_buf); - halbtc8821a2ant_coex_all_off(btcoexist); - break; - } - coex_dm->pre_algorithm = coex_dm->cur_algorithm; - } -} - -void halbtc8821a2ant_wifi_off_hw_cfg(IN struct btc_coexist *btcoexist) -{ - u8 h2c_parameter[2] = {0}; - u32 fw_ver = 0; - - /* set wlan_act to low */ - btcoexist->btc_write_1byte(btcoexist, 0x76e, 0x4); - - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, - 0x780); /* WiFi goto standby while GNT_BT 0-->1 */ - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, &fw_ver); - if (fw_ver >= 0x180000) { - /* Use H2C to set GNT_BT to HIGH */ - h2c_parameter[0] = 1; - btcoexist->btc_fill_h2c(btcoexist, 0x6E, 1, h2c_parameter); - } else - btcoexist->btc_write_1byte(btcoexist, 0x765, 0x18); -} - -void halbtc8821a2ant_init_hw_config(IN struct btc_coexist *btcoexist, - IN boolean back_up) -{ - u8 u8tmp = 0; - - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], 2Ant Init HW Config!!\n"); - BTC_TRACE(trace_buf); - - /* Give bt_coex_supported_version the default value */ - coex_sta->bt_coex_supported_version = 0; - - /* 0xf0[15:12] --> Chip Cut information */ - coex_sta->cut_version = (btcoexist->btc_read_1byte(btcoexist, - 0xf1) & 0xf0) >> 4; - - /* backup rf 0x1e value */ - coex_dm->bt_rf_0x1e_backup = - btcoexist->btc_get_rf_reg(btcoexist, BTC_RF_A, 0x1e, 0xfffff); - - /* 0x790[5:0]=0x5 */ - u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x790); - u8tmp &= 0xc0; - u8tmp |= 0x5; - btcoexist->btc_write_1byte(btcoexist, 0x790, u8tmp); - - /* Antenna config */ - halbtc8821a2ant_set_ant_path(btcoexist, BTC_ANT_WIFI_AT_MAIN, true, - false); - coex_sta->dis_ver_info_cnt = 0; - - /* PTA parameter */ - halbtc8821a2ant_coex_table_with_type(btcoexist, FORCE_EXEC, 0); - - /* Enable counter statistics */ - btcoexist->btc_write_1byte(btcoexist, 0x76e, - 0x4); /* 0x76e[3] =1, WLAN_Act control by PTA */ - btcoexist->btc_write_1byte(btcoexist, 0x778, 0x3); - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x40, 0x20, 0x1); -} - -/* ************************************************************ - * work around function start with wa_halbtc8821a2ant_ - * ************************************************************ - * ************************************************************ - * extern function start with ex_halbtc8821a2ant_ - * ************************************************************ */ -void ex_halbtc8821a2ant_power_on_setting(IN struct btc_coexist *btcoexist) -{ - -} - -void ex_halbtc8821a2ant_pre_load_firmware(IN struct btc_coexist *btcoexist) -{ - struct btc_board_info *board_info = &btcoexist->board_info; - u8 u8tmp = 0x4; /* Set BIT2 by default since it's 2ant case */ - - /* */ - /* S0 or S1 setting and Local register setting(By the setting fw can get ant number, S0/S1, ... info) */ - /* Local setting bit define */ - /* BIT0: "0" for no antenna inverse; "1" for antenna inverse */ - /* BIT1: "0" for internal switch; "1" for external switch */ - /* BIT2: "0" for one antenna; "1" for two antenna */ - /* NOTE: here default all internal switch and 1-antenna ==> BIT1=0 and BIT2=0 */ - if (btcoexist->chip_interface == BTC_INTF_USB) { - /* fixed at S0 for USB interface */ - u8tmp |= 0x1; /* antenna inverse */ - btcoexist->btc_write_local_reg_1byte(btcoexist, 0xfe08, u8tmp); - } else { - /* for PCIE and SDIO interface, we check efuse 0xc3[6] */ - if (board_info->single_ant_path == 0) { - } else if (board_info->single_ant_path == 1) { - /* set to S0 */ - u8tmp |= 0x1; /* antenna inverse */ - } - - if (btcoexist->chip_interface == BTC_INTF_PCI) - btcoexist->btc_write_local_reg_1byte(btcoexist, 0x384, - u8tmp); - else if (btcoexist->chip_interface == BTC_INTF_SDIO) - btcoexist->btc_write_local_reg_1byte(btcoexist, 0x60, - u8tmp); - } -} - -void ex_halbtc8821a2ant_init_hw_config(IN struct btc_coexist *btcoexist, - IN boolean wifi_only) -{ - halbtc8821a2ant_init_hw_config(btcoexist, true); -} - -void ex_halbtc8821a2ant_init_coex_dm(IN struct btc_coexist *btcoexist) -{ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Coex Mechanism Init!!\n"); - BTC_TRACE(trace_buf); - - halbtc8821a2ant_init_coex_dm(btcoexist); -} - -void ex_halbtc8821a2ant_display_coex_info(IN struct btc_coexist *btcoexist) -{ - struct btc_board_info *board_info = &btcoexist->board_info; - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - u8 *cli_buf = btcoexist->cli_buf; - u8 u8tmp[4], i, bt_info_ext, ps_tdma_case = 0; - u32 u32tmp[4]; - u32 fw_ver = 0, bt_patch_ver = 0; - u32 bt_coex_ver = 0; - u32 phyver = 0; - u32 fa_ofdm, fa_cck, cca_ofdm, cca_cck; - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n ============[BT Coexist info]============"); - CL_PRINTF(cli_buf); - - if (btcoexist->manual_control) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n ============[Under Manual Control]============"); - CL_PRINTF(cli_buf); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n =========================================="); - CL_PRINTF(cli_buf); - } - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d ", - "Ant PG number/ Ant mechanism:", - board_info->pg_ant_num, board_info->btdm_ant_num); - CL_PRINTF(cli_buf); - - /* btcoexist->btc_get(btcoexist, BTC_GET_U4_BT_PATCH_VER, &bt_patch_ver); */ - bt_patch_ver = btcoexist->bt_info.bt_get_fw_ver; - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, &fw_ver); - phyver = btcoexist->btc_get_bt_phydm_version(btcoexist); - bt_coex_ver = coex_sta->bt_coex_supported_version & 0xff; - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %d_%02x/ 0x%02x/ 0x%02x (%s)", - "CoexVer WL/ BT_Desired/ BT_Report", - glcoex_ver_date_8821a_2ant, glcoex_ver_8821a_2ant, - glcoex_ver_btdesired_8821a_2ant, - bt_coex_ver, - (bt_coex_ver == 0xff ? "Unknown" : - (bt_coex_ver >= glcoex_ver_btdesired_8821a_2ant ? - "Match" : "Mis-Match"))); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = 0x%x/ 0x%x/ v%d/ %c", - "W_FW/ B_FW/ Phy/ Kt", - fw_ver, bt_patch_ver, phyver, - coex_sta->cut_version + 65); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x ", - "Wifi channel informed to BT", - coex_dm->wifi_chnl_info[0], coex_dm->wifi_chnl_info[1], - coex_dm->wifi_chnl_info[2]); - CL_PRINTF(cli_buf); - - /* wifi status */ - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s", - "============[Wifi Status]============"); - CL_PRINTF(cli_buf); - btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_WIFI_STATUS); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s", - "============[BT Status]============"); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = [%s/ %ddBm/ %d] ", - "BT [status/ rssi/ retryCnt]", - ((coex_sta->bt_disabled) ? ("disabled") : (( - coex_sta->c2h_bt_inquiry_page) ? ("inquiry/page scan") - : ((BT_8821A_2ANT_BT_STATUS_NON_CONNECTED_IDLE == - coex_dm->bt_status) ? "non-connected idle" : - ((BT_8821A_2ANT_BT_STATUS_CONNECTED_IDLE == coex_dm->bt_status) - ? "connected-idle" : "busy")))), - coex_sta->bt_rssi - 100, coex_sta->bt_retry_cnt); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d / %d / %d", - "SCO/HID/PAN/A2DP", - bt_link_info->sco_exist, bt_link_info->hid_exist, - bt_link_info->pan_exist, bt_link_info->a2dp_exist); - CL_PRINTF(cli_buf); - - { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s", - "BT Role", - (bt_link_info->slave_role) ? "Slave" : "Master"); - CL_PRINTF(cli_buf); - } - - bt_info_ext = coex_sta->bt_info_ext; - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s", - "BT Info A2DP rate", - (bt_info_ext & BIT(0)) ? "Basic rate" : "EDR rate"); - CL_PRINTF(cli_buf); - - for (i = 0; i < BT_INFO_SRC_8821A_2ANT_MAX; i++) { - if (coex_sta->bt_info_c2h_cnt[i]) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %02x %02x %02x %02x %02x %02x %02x(%d)", - glbt_info_src_8821a_2ant[i], - coex_sta->bt_info_c2h[i][0], - coex_sta->bt_info_c2h[i][1], - coex_sta->bt_info_c2h[i][2], - coex_sta->bt_info_c2h[i][3], - coex_sta->bt_info_c2h[i][4], - coex_sta->bt_info_c2h[i][5], - coex_sta->bt_info_c2h[i][6], - coex_sta->bt_info_c2h_cnt[i]); - CL_PRINTF(cli_buf); - } - } - - /* Sw mechanism */ - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s", - "============[Sw mechanism]============"); - CL_PRINTF(cli_buf); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d ", - "SM1[ShRf/ LpRA/ LimDig]", - coex_dm->cur_rf_rx_lpf_shrink, coex_dm->cur_low_penalty_ra, - coex_dm->limited_dig); - CL_PRINTF(cli_buf); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d(0x%x) ", - "SM2[AgcT/ AdcB/ SwDacSwing(lvl)]", - coex_dm->cur_agc_table_en, coex_dm->cur_adc_back_off, - coex_dm->cur_dac_swing_on, coex_dm->cur_dac_swing_lvl); - CL_PRINTF(cli_buf); - - /* Fw mechanism */ - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s", - "============[Fw mechanism]============"); - CL_PRINTF(cli_buf); - - ps_tdma_case = coex_dm->cur_ps_tdma; - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %02x %02x %02x %02x %02x case-%d (auto:%d)", - "PS TDMA", - coex_dm->ps_tdma_para[0], coex_dm->ps_tdma_para[1], - coex_dm->ps_tdma_para[2], coex_dm->ps_tdma_para[3], - coex_dm->ps_tdma_para[4], ps_tdma_case, - coex_dm->auto_tdma_adjust); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d", - "Coex Table Type", - coex_sta->coex_table_type); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d ", - "DecBtPwr/ IgnWlanAct", - coex_dm->cur_bt_dec_pwr_lvl, coex_dm->cur_ignore_wlan_act); - CL_PRINTF(cli_buf); - - /* Hw setting */ - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s", - "============[Hw setting]============"); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", - "RF-A, 0x1e initVal", - coex_dm->bt_rf_0x1e_backup); - CL_PRINTF(cli_buf); - - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x778); - u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0xc5b); - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x880); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", - "0x778/0x880[29:25]/0xc58[29:25]", - u8tmp[0], (u32tmp[0] & 0x3e000000) >> 25, - ((u8tmp[1] & 0x3e) >> 1)); - CL_PRINTF(cli_buf); - - u32tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x764); - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x76e); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", - "0x764/ 0x765/ 0x76e", - (u32tmp[0] & 0xff), (u32tmp[0] & 0xff00) >> 8, u8tmp[0]); - CL_PRINTF(cli_buf); - - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xcb4); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", - "0xcb4[7:0](ctrl)/ 0xcb4[29:28](val)", - u32tmp[0] & 0xff, ((u32tmp[0] & 0x30000000) >> 28)); - CL_PRINTF(cli_buf); - - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x40); - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x4c); - u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x974); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", - "0x40/ 0x4c[24:23]/ 0x974", - u8tmp[0], ((u32tmp[0] & 0x01800000) >> 23), u32tmp[1]); - CL_PRINTF(cli_buf); - - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x550); - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x522); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", - "0x550(bcn ctrl)/0x522", - u32tmp[0], u8tmp[0]); - CL_PRINTF(cli_buf); - - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xc50); - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x49c); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", - "0xc50(dig)/0x49c(null-drop)", - u32tmp[0] & 0xff, u8tmp[0]); - CL_PRINTF(cli_buf); - - fa_ofdm = btcoexist->btc_phydm_query_PHY_counter(btcoexist, - PHYDM_INFO_FA_OFDM); - fa_cck = btcoexist->btc_phydm_query_PHY_counter(btcoexist, - PHYDM_INFO_FA_CCK); - cca_ofdm = btcoexist->btc_phydm_query_PHY_counter(btcoexist, - PHYDM_INFO_CCA_OFDM); - cca_cck = btcoexist->btc_phydm_query_PHY_counter(btcoexist, - PHYDM_INFO_CCA_CCK); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", - "CCK-CCA/CCK-FA/OFDM-CCA/OFDM-FA", - cca_cck, fa_cck, cca_ofdm, fa_ofdm); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d", - "CRC_OK CCK/11g/11n/11n-agg", - coex_sta->crc_ok_cck, coex_sta->crc_ok_11g, - coex_sta->crc_ok_11n, coex_sta->crc_ok_11n_vht); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d", - "CRC_Err CCK/11g/11n/11n-agg", - coex_sta->crc_err_cck, coex_sta->crc_err_11g, - coex_sta->crc_err_11n, coex_sta->crc_err_11n_vht); - CL_PRINTF(cli_buf); - - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x6c0); - u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x6c4); - u32tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0x6c8); - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x6cc); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", - "0x6c0/0x6c4/0x6c8/0x6cc(coexTable)", - u32tmp[0], u32tmp[1], u32tmp[2], u8tmp[0]); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", - "0x770(high-pri rx/tx)", - coex_sta->high_priority_rx, coex_sta->high_priority_tx); - CL_PRINTF(cli_buf); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", - "0x774(low-pri rx/tx)", - coex_sta->low_priority_rx, coex_sta->low_priority_tx); - CL_PRINTF(cli_buf); -#if (BT_AUTO_REPORT_ONLY_8821A_2ANT == 1) - /* halbtc8821a2ant_monitor_bt_ctr(btcoexist); */ -#endif - btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_COEX_STATISTICS); -} - - -void ex_halbtc8821a2ant_ips_notify(IN struct btc_coexist *btcoexist, IN u8 type) -{ - if (BTC_IPS_ENTER == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], IPS ENTER notify\n"); - BTC_TRACE(trace_buf); - coex_sta->under_ips = true; - halbtc8821a2ant_wifi_off_hw_cfg(btcoexist); - halbtc8821a2ant_ignore_wlan_act(btcoexist, FORCE_EXEC, true); - halbtc8821a2ant_coex_all_off(btcoexist); - } else if (BTC_IPS_LEAVE == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], IPS LEAVE notify\n"); - BTC_TRACE(trace_buf); - coex_sta->under_ips = false; - halbtc8821a2ant_init_hw_config(btcoexist, false); - halbtc8821a2ant_init_coex_dm(btcoexist); - halbtc8821a2ant_query_bt_info(btcoexist); - } -} - -void ex_halbtc8821a2ant_lps_notify(IN struct btc_coexist *btcoexist, IN u8 type) -{ - if (BTC_LPS_ENABLE == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], LPS ENABLE notify\n"); - BTC_TRACE(trace_buf); - coex_sta->under_lps = true; - } else if (BTC_LPS_DISABLE == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], LPS DISABLE notify\n"); - BTC_TRACE(trace_buf); - coex_sta->under_lps = false; - } -} - -void ex_halbtc8821a2ant_scan_notify(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - u8 u8tmpa, u8tmpb; - - u8tmpa = btcoexist->btc_read_1byte(btcoexist, 0x765); - u8tmpb = btcoexist->btc_read_1byte(btcoexist, 0x76e); - - if (BTC_SCAN_START == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCAN START notify\n"); - BTC_TRACE(trace_buf); - } else if (BTC_SCAN_FINISH == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCAN FINISH notify\n"); - BTC_TRACE(trace_buf); - } - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "############# [BTCoex], 0x765=0x%x, 0x76e=0x%x\n", u8tmpa, - u8tmpb); - BTC_TRACE(trace_buf); -} - -/* copy scan notify content to switch band notify */ -void ex_halbtc8821a2ant_switchband_notify(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - u8 u8tmpa, u8tmpb; - - u8tmpa = btcoexist->btc_read_1byte(btcoexist, 0x765); - u8tmpb = btcoexist->btc_read_1byte(btcoexist, 0x76e); - - if (BTC_SCAN_START == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCAN START notify\n"); - BTC_TRACE(trace_buf); - } else if (BTC_SCAN_FINISH == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCAN FINISH notify\n"); - BTC_TRACE(trace_buf); - } - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "############# [BTCoex], 0x765=0x%x, 0x76e=0x%x\n", u8tmpa, - u8tmpb); - BTC_TRACE(trace_buf); -} - -void ex_halbtc8821a2ant_connect_notify(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - if (BTC_ASSOCIATE_START == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], CONNECT START notify\n"); - BTC_TRACE(trace_buf); - } else if (BTC_ASSOCIATE_FINISH == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], CONNECT FINISH notify\n"); - BTC_TRACE(trace_buf); - } -} - -void ex_halbtc8821a2ant_media_status_notify(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - u8 h2c_parameter[3] = {0}; - u32 wifi_bw; - u8 wifi_central_chnl; - u8 ap_num = 0; - - if (BTC_MEDIA_CONNECT == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], MEDIA connect notify\n"); - BTC_TRACE(trace_buf); - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], MEDIA disconnect notify\n"); - BTC_TRACE(trace_buf); - } - - /* only 2.4G we need to inform bt the chnl mask */ - btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_CENTRAL_CHNL, - &wifi_central_chnl); - if ((BTC_MEDIA_CONNECT == type) && - (wifi_central_chnl <= 14)) { - h2c_parameter[0] = 0x1; - h2c_parameter[1] = wifi_central_chnl; - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw); - if (BTC_WIFI_BW_HT40 == wifi_bw) - h2c_parameter[2] = 0x30; - else { - btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM, - &ap_num); - if (ap_num < 10) - h2c_parameter[2] = 0x30; - else - h2c_parameter[2] = 0x20; - } - } - - coex_dm->wifi_chnl_info[0] = h2c_parameter[0]; - coex_dm->wifi_chnl_info[1] = h2c_parameter[1]; - coex_dm->wifi_chnl_info[2] = h2c_parameter[2]; - - btcoexist->btc_fill_h2c(btcoexist, 0x66, 3, h2c_parameter); -} - -void ex_halbtc8821a2ant_specific_packet_notify(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - if (type == BTC_PACKET_DHCP) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], DHCP Packet notify\n"); - BTC_TRACE(trace_buf); - } -} - -void ex_halbtc8821a2ant_bt_info_notify(IN struct btc_coexist *btcoexist, - IN u8 *tmp_buf, IN u8 length) -{ - u8 bt_info = 0; - u8 i, rsp_source = 0; - boolean bt_busy = false, limited_dig = false; - boolean wifi_connected = false, wifi_under_5g = false; - - coex_sta->c2h_bt_info_req_sent = false; - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - - rsp_source = tmp_buf[0] & 0xf; - if (rsp_source >= BT_INFO_SRC_8821A_2ANT_MAX) - rsp_source = BT_INFO_SRC_8821A_2ANT_WIFI_FW; - coex_sta->bt_info_c2h_cnt[rsp_source]++; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Bt info[%d], length=%d, hex data=[", rsp_source, - length); - BTC_TRACE(trace_buf); - for (i = 0; i < length; i++) { - coex_sta->bt_info_c2h[rsp_source][i] = tmp_buf[i]; - if (i == 1) - bt_info = tmp_buf[i]; - if (i == length - 1) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "0x%02x]\n", - tmp_buf[i]); - BTC_TRACE(trace_buf); - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "0x%02x, ", - tmp_buf[i]); - BTC_TRACE(trace_buf); - } - } - - if (btcoexist->manual_control) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), return for Manual CTRL<===\n"); - BTC_TRACE(trace_buf); - return; - } - - /* if 0xff, it means BT is under WHCK test */ - if (bt_info == 0xff) - coex_sta->bt_whck_test = true; - else - coex_sta->bt_whck_test = false; - - if (BT_INFO_SRC_8821A_2ANT_WIFI_FW != rsp_source) { - coex_sta->bt_retry_cnt = /* [3:0] */ - coex_sta->bt_info_c2h[rsp_source][2] & 0xf; - - coex_sta->bt_rssi = - coex_sta->bt_info_c2h[rsp_source][3] * 2 + 10; - - coex_sta->bt_info_ext = - coex_sta->bt_info_c2h[rsp_source][4]; - - coex_sta->bt_tx_rx_mask = (coex_sta->bt_info_c2h[rsp_source][2] - & 0x40); - btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TX_RX_MASK, - &coex_sta->bt_tx_rx_mask); - if (coex_sta->bt_tx_rx_mask) { - /* BT into is responded by BT FW and BT RF REG 0x3C != 0x01 => Need to switch BT TRx Mask */ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Switch BT TRx Mask since BT RF REG 0x3C != 0x01\n"); - BTC_TRACE(trace_buf); - btcoexist->btc_set_bt_reg(btcoexist, BTC_BT_REG_RF, - 0x3c, 0x01); - } - - /* Here we need to resend some wifi info to BT */ - /* because bt is reset and loss of the info. */ - if ((coex_sta->bt_info_ext & BIT(1))) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT ext info bit1 check, send wifi BW&Chnl to BT!!\n"); - BTC_TRACE(trace_buf); - if (wifi_connected) - ex_halbtc8821a2ant_media_status_notify( - btcoexist, BTC_MEDIA_CONNECT); - else - ex_halbtc8821a2ant_media_status_notify( - btcoexist, BTC_MEDIA_DISCONNECT); - } - - - if (!btcoexist->manual_control && !wifi_under_5g) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT ext info = 0x%x!!\n", - coex_sta->bt_info_ext); - BTC_TRACE(trace_buf); - if ((coex_sta->bt_info_ext & BIT(3))) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT ext info bit3=1, wifi_connected=%d\n", - wifi_connected); - BTC_TRACE(trace_buf); - if (wifi_connected) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT ext info bit3 check, set BT NOT to ignore Wlan active!!\n"); - BTC_TRACE(trace_buf); - halbtc8821a2ant_ignore_wlan_act( - btcoexist, FORCE_EXEC, false); - } - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT ext info bit3=0, wifi_connected=%d\n", - wifi_connected); - BTC_TRACE(trace_buf); - /* BT already NOT ignore Wlan active, do nothing here. */ - if (!wifi_connected) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT ext info bit3 check, set BT to ignore Wlan active!!\n"); - BTC_TRACE(trace_buf); - halbtc8821a2ant_ignore_wlan_act( - btcoexist, FORCE_EXEC, true); - } - } - } - -#if (BT_AUTO_REPORT_ONLY_8821A_2ANT == 0) - if ((coex_sta->bt_info_ext & BIT(4))) { - /* BT auto report already enabled, do nothing */ - } else - halbtc8821a2ant_bt_auto_report(btcoexist, FORCE_EXEC, - true); -#endif - } - - /* check BIT2 first ==> check if bt is under inquiry or page scan */ - if (bt_info & BT_INFO_8821A_2ANT_B_INQ_PAGE) - coex_sta->c2h_bt_inquiry_page = true; - else - coex_sta->c2h_bt_inquiry_page = false; - - /* set link exist status */ - if (!(bt_info & BT_INFO_8821A_2ANT_B_CONNECTION)) { - coex_sta->bt_link_exist = false; - coex_sta->pan_exist = false; - coex_sta->a2dp_exist = false; - coex_sta->hid_exist = false; - coex_sta->sco_exist = false; - } else { /* connection exists */ - coex_sta->bt_link_exist = true; - if (bt_info & BT_INFO_8821A_2ANT_B_FTP) - coex_sta->pan_exist = true; - else - coex_sta->pan_exist = false; - if (bt_info & BT_INFO_8821A_2ANT_B_A2DP) - coex_sta->a2dp_exist = true; - else - coex_sta->a2dp_exist = false; - if (bt_info & BT_INFO_8821A_2ANT_B_HID) - coex_sta->hid_exist = true; - else - coex_sta->hid_exist = false; - if (bt_info & BT_INFO_8821A_2ANT_B_SCO_ESCO) - coex_sta->sco_exist = true; - else - coex_sta->sco_exist = false; - - if ((coex_sta->hid_exist == false) && - (coex_sta->c2h_bt_inquiry_page == false) && - (coex_sta->sco_exist == false)) { - if (coex_sta->high_priority_tx + - coex_sta->high_priority_rx >= 160) - coex_sta->hid_exist = true; - } - } - - halbtc8821a2ant_update_bt_link_info(btcoexist); - - if (!(bt_info & BT_INFO_8821A_2ANT_B_CONNECTION)) { - coex_dm->bt_status = BT_8821A_2ANT_BT_STATUS_NON_CONNECTED_IDLE; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), BT Non-Connected idle!!!\n"); - BTC_TRACE(trace_buf); - } else if (bt_info == - BT_INFO_8821A_2ANT_B_CONNECTION) { /* connection exists but no busy */ - coex_dm->bt_status = BT_8821A_2ANT_BT_STATUS_CONNECTED_IDLE; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), BT Connected-idle!!!\n"); - BTC_TRACE(trace_buf); - } else if ((bt_info & BT_INFO_8821A_2ANT_B_SCO_ESCO) || - (bt_info & BT_INFO_8821A_2ANT_B_SCO_BUSY)) { - coex_dm->bt_status = BT_8821A_2ANT_BT_STATUS_SCO_BUSY; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), BT SCO busy!!!\n"); - BTC_TRACE(trace_buf); - } else if (bt_info & BT_INFO_8821A_2ANT_B_ACL_BUSY) { - coex_dm->bt_status = BT_8821A_2ANT_BT_STATUS_ACL_BUSY; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), BT ACL busy!!!\n"); - BTC_TRACE(trace_buf); - } else { - coex_dm->bt_status = BT_8821A_2ANT_BT_STATUS_MAX; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), BT Non-Defined state!!!\n"); - BTC_TRACE(trace_buf); - } - - if ((BT_8821A_2ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) || - (BT_8821A_2ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) || - (BT_8821A_2ANT_BT_STATUS_ACL_SCO_BUSY == coex_dm->bt_status)) { - bt_busy = true; - limited_dig = true; - } else { - bt_busy = false; - limited_dig = false; - } - - btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bt_busy); - - coex_dm->limited_dig = limited_dig; - btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_LIMITED_DIG, &limited_dig); - - halbtc8821a2ant_run_coexist_mechanism(btcoexist); -} - -void ex_halbtc8821a2ant_halt_notify(IN struct btc_coexist *btcoexist) -{ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], Halt notify\n"); - BTC_TRACE(trace_buf); - - halbtc8821a2ant_wifi_off_hw_cfg(btcoexist); - /* remove due to interrupt is disabled that polling c2h will fail and delay 100ms. */ - /* btcoexist->btc_set_bt_reg(btcoexist, BTC_BT_REG_RF, 0x3c, 0x15); */ /*BT goto standby while GNT_BT 1-->0 */ - halbtc8821a2ant_ignore_wlan_act(btcoexist, FORCE_EXEC, true); - - ex_halbtc8821a2ant_media_status_notify(btcoexist, BTC_MEDIA_DISCONNECT); -} - -void ex_halbtc8821a2ant_pnp_notify(IN struct btc_coexist *btcoexist, - IN u8 pnp_state) -{ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], Pnp notify\n"); - BTC_TRACE(trace_buf); - - if (BTC_WIFI_PNP_SLEEP == pnp_state) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Pnp notify to SLEEP\n"); - BTC_TRACE(trace_buf); - } else if (BTC_WIFI_PNP_WAKE_UP == pnp_state) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Pnp notify to WAKE UP\n"); - BTC_TRACE(trace_buf); - halbtc8821a2ant_init_hw_config(btcoexist, false); - halbtc8821a2ant_init_coex_dm(btcoexist); - halbtc8821a2ant_query_bt_info(btcoexist); - } -} - -void ex_halbtc8821a2ant_periodical(IN struct btc_coexist *btcoexist) -{ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ==========================Periodical===========================\n"); - BTC_TRACE(trace_buf); - - if (coex_sta->dis_ver_info_cnt <= 5) { - coex_sta->dis_ver_info_cnt += 1; - if (coex_sta->dis_ver_info_cnt == 3) { - /* Antenna config to set 0x765 = 0x0 (GNT_BT control by PTA) after initial */ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Set GNT_BT control by PTA\n"); - BTC_TRACE(trace_buf); - halbtc8821a2ant_set_ant_path(btcoexist, - BTC_ANT_WIFI_AT_MAIN, false, false); - } - } - - if (((coex_sta->bt_coex_supported_version == 0) || - (coex_sta->bt_coex_supported_version == 0xffff)) && - (!coex_sta->bt_disabled)) - coex_sta->bt_coex_supported_version = - btcoexist->btc_get_bt_coex_supported_version(btcoexist); - - -#if (BT_AUTO_REPORT_ONLY_8821A_2ANT == 0) - halbtc8821a2ant_query_bt_info(btcoexist); - halbtc8821a2ant_monitor_bt_enable_disable(btcoexist); -#else - halbtc8821a2ant_monitor_bt_ctr(btcoexist); - halbtc8821a2ant_monitor_wifi_ctr(btcoexist); - halbtc8821a2ant_monitor_bt_enable_disable(btcoexist); - - if (halbtc8821a2ant_is_wifi_status_changed(btcoexist) || - coex_dm->auto_tdma_adjust) - halbtc8821a2ant_run_coexist_mechanism(btcoexist); -#endif -} - -#endif - -#endif /* #if (BT_SUPPORT == 1 && COEX_SUPPORT == 1) */ diff --git a/hal/btc/halbtc8821a2ant.h b/hal/btc/halbtc8821a2ant.h deleted file mode 100644 index 8151397..0000000 --- a/hal/btc/halbtc8821a2ant.h +++ /dev/null @@ -1,211 +0,0 @@ - -#if (BT_SUPPORT == 1 && COEX_SUPPORT == 1) - -#if (RTL8821A_SUPPORT == 1) - -/* ******************************************* - * The following is for 8821A 2Ant BT Co-exist definition - * ******************************************* */ -#define BT_AUTO_REPORT_ONLY_8821A_2ANT 1 - - -#define BT_INFO_8821A_2ANT_B_FTP BIT(7) -#define BT_INFO_8821A_2ANT_B_A2DP BIT(6) -#define BT_INFO_8821A_2ANT_B_HID BIT(5) -#define BT_INFO_8821A_2ANT_B_SCO_BUSY BIT(4) -#define BT_INFO_8821A_2ANT_B_ACL_BUSY BIT(3) -#define BT_INFO_8821A_2ANT_B_INQ_PAGE BIT(2) -#define BT_INFO_8821A_2ANT_B_SCO_ESCO BIT(1) -#define BT_INFO_8821A_2ANT_B_CONNECTION BIT(0) - -#define BTC_RSSI_COEX_THRESH_TOL_8821A_2ANT 2 - - -#define BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES 42 /* WiFi RSSI Threshold for 2-Ant TDMA/1-Ant PS-TDMA translation */ -#define BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES 46 /* BT RSSI Threshold for 2-Ant TDMA/1-Ant PS-TDMA translation */ - -enum bt_info_src_8821a_2ant { - BT_INFO_SRC_8821A_2ANT_WIFI_FW = 0x0, - BT_INFO_SRC_8821A_2ANT_BT_RSP = 0x1, - BT_INFO_SRC_8821A_2ANT_BT_ACTIVE_SEND = 0x2, - BT_INFO_SRC_8821A_2ANT_MAX -}; - -enum bt_8821a_2ant_bt_status { - BT_8821A_2ANT_BT_STATUS_NON_CONNECTED_IDLE = 0x0, - BT_8821A_2ANT_BT_STATUS_CONNECTED_IDLE = 0x1, - BT_8821A_2ANT_BT_STATUS_INQ_PAGE = 0x2, - BT_8821A_2ANT_BT_STATUS_ACL_BUSY = 0x3, - BT_8821A_2ANT_BT_STATUS_SCO_BUSY = 0x4, - BT_8821A_2ANT_BT_STATUS_ACL_SCO_BUSY = 0x5, - BT_8821A_2ANT_BT_STATUS_MAX -}; - -enum bt_8821a_2ant_coex_algo { - BT_8821A_2ANT_COEX_ALGO_UNDEFINED = 0x0, - BT_8821A_2ANT_COEX_ALGO_SCO = 0x1, - BT_8821A_2ANT_COEX_ALGO_HID = 0x2, - BT_8821A_2ANT_COEX_ALGO_A2DP = 0x3, - BT_8821A_2ANT_COEX_ALGO_A2DP_PANHS = 0x4, - BT_8821A_2ANT_COEX_ALGO_PANEDR = 0x5, - BT_8821A_2ANT_COEX_ALGO_PANHS = 0x6, - BT_8821A_2ANT_COEX_ALGO_PANEDR_A2DP = 0x7, - BT_8821A_2ANT_COEX_ALGO_PANEDR_HID = 0x8, - BT_8821A_2ANT_COEX_ALGO_HID_A2DP_PANEDR = 0x9, - BT_8821A_2ANT_COEX_ALGO_HID_A2DP = 0xa, - BT_8821A_2ANT_COEX_ALGO_MAX = 0xb, -}; - -struct coex_dm_8821a_2ant { - /* fw mechanism */ - u8 pre_bt_dec_pwr_lvl; - u8 cur_bt_dec_pwr_lvl; - u8 pre_fw_dac_swing_lvl; - u8 cur_fw_dac_swing_lvl; - boolean cur_ignore_wlan_act; - boolean pre_ignore_wlan_act; - u8 pre_ps_tdma; - u8 cur_ps_tdma; - u8 ps_tdma_para[5]; - u8 ps_tdma_du_adj_type; - boolean reset_tdma_adjust; - boolean auto_tdma_adjust; - boolean pre_ps_tdma_on; - boolean cur_ps_tdma_on; - boolean pre_bt_auto_report; - boolean cur_bt_auto_report; - - /* sw mechanism */ - boolean pre_rf_rx_lpf_shrink; - boolean cur_rf_rx_lpf_shrink; - u32 bt_rf_0x1e_backup; - boolean pre_low_penalty_ra; - boolean cur_low_penalty_ra; - boolean pre_dac_swing_on; - u32 pre_dac_swing_lvl; - boolean cur_dac_swing_on; - u32 cur_dac_swing_lvl; - boolean pre_adc_back_off; - boolean cur_adc_back_off; - boolean pre_agc_table_en; - boolean cur_agc_table_en; - u32 pre_val0x6c0; - u32 cur_val0x6c0; - u32 pre_val0x6c4; - u32 cur_val0x6c4; - u32 pre_val0x6c8; - u32 cur_val0x6c8; - u8 pre_val0x6cc; - u8 cur_val0x6cc; - boolean limited_dig; - - /* algorithm related */ - u8 pre_algorithm; - u8 cur_algorithm; - u8 bt_status; - u8 wifi_chnl_info[3]; - - boolean need_recover0x948; - u32 backup0x948; - - u8 pre_lps; - u8 cur_lps; - u8 pre_rpwm; - u8 cur_rpwm; -}; - -struct coex_sta_8821a_2ant { - boolean bt_disabled; - boolean bt_link_exist; - boolean sco_exist; - boolean a2dp_exist; - boolean hid_exist; - boolean pan_exist; - - boolean under_lps; - boolean under_ips; - u32 high_priority_tx; - u32 high_priority_rx; - u32 low_priority_tx; - u32 low_priority_rx; - u8 bt_rssi; - boolean bt_tx_rx_mask; - u8 pre_bt_rssi_state; - u8 pre_wifi_rssi_state[4]; - boolean c2h_bt_info_req_sent; - u8 bt_info_c2h[BT_INFO_SRC_8821A_2ANT_MAX][10]; - u32 bt_info_c2h_cnt[BT_INFO_SRC_8821A_2ANT_MAX]; - boolean bt_whck_test; - boolean c2h_bt_inquiry_page; - u8 bt_retry_cnt; - u8 bt_info_ext; - u8 scan_ap_num; - u32 crc_ok_cck; - u32 crc_ok_11g; - u32 crc_ok_11n; - u32 crc_ok_11n_vht; - - u32 crc_err_cck; - u32 crc_err_11g; - u32 crc_err_11n; - u32 crc_err_11n_vht; - - u32 bt_coex_supported_version; - u8 cut_version; - u8 coex_table_type; - boolean force_lps_on; - - u8 dis_ver_info_cnt; -}; - -/* ******************************************* - * The following is interface which will notify coex module. - * ******************************************* */ -void ex_halbtc8821a2ant_power_on_setting(IN struct btc_coexist *btcoexist); -void ex_halbtc8821a2ant_pre_load_firmware(IN struct btc_coexist *btcoexist); -void ex_halbtc8821a2ant_init_hw_config(IN struct btc_coexist *btcoexist, - IN boolean wifi_only); -void ex_halbtc8821a2ant_init_coex_dm(IN struct btc_coexist *btcoexist); -void ex_halbtc8821a2ant_ips_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8821a2ant_lps_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8821a2ant_scan_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8821a2ant_switchband_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8821a2ant_connect_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8821a2ant_media_status_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8821a2ant_specific_packet_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8821a2ant_bt_info_notify(IN struct btc_coexist *btcoexist, - IN u8 *tmp_buf, IN u8 length); -void ex_halbtc8821a2ant_halt_notify(IN struct btc_coexist *btcoexist); -void ex_halbtc8821a2ant_pnp_notify(IN struct btc_coexist *btcoexist, - IN u8 pnp_state); -void ex_halbtc8821a2ant_periodical(IN struct btc_coexist *btcoexist); -void ex_halbtc8821a2ant_display_coex_info(IN struct btc_coexist *btcoexist); - -#else -#define ex_halbtc8821a2ant_power_on_setting(btcoexist) -#define ex_halbtc8821a2ant_pre_load_firmware(btcoexist) -#define ex_halbtc8821a2ant_init_hw_config(btcoexist, wifi_only) -#define ex_halbtc8821a2ant_init_coex_dm(btcoexist) -#define ex_halbtc8821a2ant_ips_notify(btcoexist, type) -#define ex_halbtc8821a2ant_lps_notify(btcoexist, type) -#define ex_halbtc8821a2ant_scan_notify(btcoexist, type) -#define ex_halbtc8821a2ant_switchband_notify(btcoexist, type) -#define ex_halbtc8821a2ant_connect_notify(btcoexist, type) -#define ex_halbtc8821a2ant_media_status_notify(btcoexist, type) -#define ex_halbtc8821a2ant_specific_packet_notify(btcoexist, type) -#define ex_halbtc8821a2ant_bt_info_notify(btcoexist, tmp_buf, length) -#define ex_halbtc8821a2ant_halt_notify(btcoexist) -#define ex_halbtc8821a2ant_pnp_notify(btcoexist, pnp_state) -#define ex_halbtc8821a2ant_periodical(btcoexist) -#define ex_halbtc8821a2ant_display_coex_info(btcoexist) -#endif - -#endif - diff --git a/hal/btc/halbtc8821c1ant.c b/hal/btc/halbtc8821c1ant.c deleted file mode 100644 index 34b1305..0000000 --- a/hal/btc/halbtc8821c1ant.c +++ /dev/null @@ -1,6674 +0,0 @@ -/* ************************************************************ - * Description: - * - * This file is for RTL8821C Co-exist mechanism - * - * History - * 2012/11/15 Cosa first check in. - * - * ************************************************************ */ - -/* ************************************************************ - * include files - * ************************************************************ */ -#include "mp_precomp.h" - -#if (BT_SUPPORT == 1 && COEX_SUPPORT == 1) - -#if (RTL8821C_SUPPORT == 1) -/* ************************************************************ - * Global variables, these are static variables - * ************************************************************ */ -static u8 *trace_buf = &gl_btc_trace_buf[0]; -static struct coex_dm_8821c_1ant glcoex_dm_8821c_1ant; -static struct coex_dm_8821c_1ant *coex_dm = &glcoex_dm_8821c_1ant; -static struct coex_sta_8821c_1ant glcoex_sta_8821c_1ant; -static struct coex_sta_8821c_1ant *coex_sta = &glcoex_sta_8821c_1ant; -static struct psdscan_sta_8821c_1ant gl_psd_scan_8821c_1ant; -static struct psdscan_sta_8821c_1ant *psd_scan = &gl_psd_scan_8821c_1ant; -static struct rfe_type_8821c_1ant gl_rfe_type_8821c_1ant; -static struct rfe_type_8821c_1ant *rfe_type = &gl_rfe_type_8821c_1ant; - - -const char *const glbt_info_src_8821c_1ant[] = { - "BT Info[wifi fw]", - "BT Info[bt rsp]", - "BT Info[bt auto report]", -}; - -u32 glcoex_ver_date_8821c_1ant = 20160805; -u32 glcoex_ver_8821c_1ant = 0x04; -u32 glcoex_ver_btdesired_8821c_1ant = 0x04; - - -/* ************************************************************ - * local function proto type if needed - * ************************************************************ - * ************************************************************ - * local function start with halbtc8821c1ant_ - * ************************************************************ */ -u8 halbtc8821c1ant_bt_rssi_state(u8 level_num, u8 rssi_thresh, u8 rssi_thresh1) -{ - s32 bt_rssi = 0; - u8 bt_rssi_state = coex_sta->pre_bt_rssi_state; - - bt_rssi = coex_sta->bt_rssi; - - if (level_num == 2) { - if ((coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_LOW) || - (coex_sta->pre_bt_rssi_state == - BTC_RSSI_STATE_STAY_LOW)) { - if (bt_rssi >= (rssi_thresh + - BTC_RSSI_COEX_THRESH_TOL_8821C_1ANT)) - bt_rssi_state = BTC_RSSI_STATE_HIGH; - else - bt_rssi_state = BTC_RSSI_STATE_STAY_LOW; - } else { - if (bt_rssi < rssi_thresh) - bt_rssi_state = BTC_RSSI_STATE_LOW; - else - bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH; - } - } else if (level_num == 3) { - if (rssi_thresh > rssi_thresh1) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Rssi thresh error!!\n"); - BTC_TRACE(trace_buf); - return coex_sta->pre_bt_rssi_state; - } - - if ((coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_LOW) || - (coex_sta->pre_bt_rssi_state == - BTC_RSSI_STATE_STAY_LOW)) { - if (bt_rssi >= (rssi_thresh + - BTC_RSSI_COEX_THRESH_TOL_8821C_1ANT)) - bt_rssi_state = BTC_RSSI_STATE_MEDIUM; - else - bt_rssi_state = BTC_RSSI_STATE_STAY_LOW; - } else if ((coex_sta->pre_bt_rssi_state == - BTC_RSSI_STATE_MEDIUM) || - (coex_sta->pre_bt_rssi_state == - BTC_RSSI_STATE_STAY_MEDIUM)) { - if (bt_rssi >= (rssi_thresh1 + - BTC_RSSI_COEX_THRESH_TOL_8821C_1ANT)) - bt_rssi_state = BTC_RSSI_STATE_HIGH; - else if (bt_rssi < rssi_thresh) - bt_rssi_state = BTC_RSSI_STATE_LOW; - else - bt_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM; - } else { - if (bt_rssi < rssi_thresh1) - bt_rssi_state = BTC_RSSI_STATE_MEDIUM; - else - bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH; - } - } - - coex_sta->pre_bt_rssi_state = bt_rssi_state; - - return bt_rssi_state; -} - -u8 halbtc8821c1ant_wifi_rssi_state(IN struct btc_coexist *btcoexist, - IN u8 index, IN u8 level_num, IN u8 rssi_thresh, IN u8 rssi_thresh1) -{ - s32 wifi_rssi = 0; - u8 wifi_rssi_state = coex_sta->pre_wifi_rssi_state[index]; - - btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi); - - if (level_num == 2) { - if ((coex_sta->pre_wifi_rssi_state[index] == BTC_RSSI_STATE_LOW) - || - (coex_sta->pre_wifi_rssi_state[index] == - BTC_RSSI_STATE_STAY_LOW)) { - if (wifi_rssi >= (rssi_thresh + - BTC_RSSI_COEX_THRESH_TOL_8821C_1ANT)) - wifi_rssi_state = BTC_RSSI_STATE_HIGH; - else - wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW; - } else { - if (wifi_rssi < rssi_thresh) - wifi_rssi_state = BTC_RSSI_STATE_LOW; - else - wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH; - } - } else if (level_num == 3) { - if (rssi_thresh > rssi_thresh1) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], wifi RSSI thresh error!!\n"); - BTC_TRACE(trace_buf); - return coex_sta->pre_wifi_rssi_state[index]; - } - - if ((coex_sta->pre_wifi_rssi_state[index] == BTC_RSSI_STATE_LOW) - || - (coex_sta->pre_wifi_rssi_state[index] == - BTC_RSSI_STATE_STAY_LOW)) { - if (wifi_rssi >= (rssi_thresh + - BTC_RSSI_COEX_THRESH_TOL_8821C_1ANT)) - wifi_rssi_state = BTC_RSSI_STATE_MEDIUM; - else - wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW; - } else if ((coex_sta->pre_wifi_rssi_state[index] == - BTC_RSSI_STATE_MEDIUM) || - (coex_sta->pre_wifi_rssi_state[index] == - BTC_RSSI_STATE_STAY_MEDIUM)) { - if (wifi_rssi >= (rssi_thresh1 + - BTC_RSSI_COEX_THRESH_TOL_8821C_1ANT)) - wifi_rssi_state = BTC_RSSI_STATE_HIGH; - else if (wifi_rssi < rssi_thresh) - wifi_rssi_state = BTC_RSSI_STATE_LOW; - else - wifi_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM; - } else { - if (wifi_rssi < rssi_thresh1) - wifi_rssi_state = BTC_RSSI_STATE_MEDIUM; - else - wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH; - } - } - - coex_sta->pre_wifi_rssi_state[index] = wifi_rssi_state; - - return wifi_rssi_state; -} - -void halbtc8821c1ant_update_ra_mask(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u32 dis_rate_mask) -{ - coex_dm->cur_ra_mask = dis_rate_mask; - - if (force_exec || (coex_dm->pre_ra_mask != coex_dm->cur_ra_mask)) - btcoexist->btc_set(btcoexist, BTC_SET_ACT_UPDATE_RAMASK, - &coex_dm->cur_ra_mask); - coex_dm->pre_ra_mask = coex_dm->cur_ra_mask; -} - -void halbtc8821c1ant_auto_rate_fallback_retry(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 type) -{ - boolean wifi_under_b_mode = false; - - coex_dm->cur_arfr_type = type; - - if (force_exec || (coex_dm->pre_arfr_type != coex_dm->cur_arfr_type)) { - switch (coex_dm->cur_arfr_type) { - case 0: /* normal mode */ - btcoexist->btc_write_4byte(btcoexist, 0x430, - coex_dm->backup_arfr_cnt1); - btcoexist->btc_write_4byte(btcoexist, 0x434, - coex_dm->backup_arfr_cnt2); - break; - case 1: - btcoexist->btc_get(btcoexist, - BTC_GET_BL_WIFI_UNDER_B_MODE, - &wifi_under_b_mode); - if (wifi_under_b_mode) { - btcoexist->btc_write_4byte(btcoexist, - 0x430, 0x0); - btcoexist->btc_write_4byte(btcoexist, - 0x434, 0x01010101); - } else { - btcoexist->btc_write_4byte(btcoexist, - 0x430, 0x0); - btcoexist->btc_write_4byte(btcoexist, - 0x434, 0x04030201); - } - break; - default: - break; - } - } - - coex_dm->pre_arfr_type = coex_dm->cur_arfr_type; -} - -void halbtc8821c1ant_retry_limit(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 type) -{ - coex_dm->cur_retry_limit_type = type; - - if (force_exec || - (coex_dm->pre_retry_limit_type != - coex_dm->cur_retry_limit_type)) { - switch (coex_dm->cur_retry_limit_type) { - case 0: /* normal mode */ - btcoexist->btc_write_2byte(btcoexist, 0x42a, - coex_dm->backup_retry_limit); - break; - case 1: /* retry limit=8 */ - btcoexist->btc_write_2byte(btcoexist, 0x42a, - 0x0808); - break; - default: - break; - } - } - - coex_dm->pre_retry_limit_type = coex_dm->cur_retry_limit_type; -} - -void halbtc8821c1ant_ampdu_max_time(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 type) -{ - coex_dm->cur_ampdu_time_type = type; - - if (force_exec || - (coex_dm->pre_ampdu_time_type != coex_dm->cur_ampdu_time_type)) { - switch (coex_dm->cur_ampdu_time_type) { - case 0: /* normal mode */ - btcoexist->btc_write_1byte(btcoexist, 0x456, - coex_dm->backup_ampdu_max_time); - break; - case 1: /* AMPDU timw = 0x38 * 32us */ - btcoexist->btc_write_1byte(btcoexist, 0x456, - 0x38); - break; - default: - break; - } - } - - coex_dm->pre_ampdu_time_type = coex_dm->cur_ampdu_time_type; -} - -void halbtc8821c1ant_limited_tx(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 ra_mask_type, IN u8 arfr_type, - IN u8 retry_limit_type, IN u8 ampdu_time_type) -{ - switch (ra_mask_type) { - case 0: /* normal mode */ - halbtc8821c1ant_update_ra_mask(btcoexist, force_exec, - 0x0); - break; - case 1: /* disable cck 1/2 */ - halbtc8821c1ant_update_ra_mask(btcoexist, force_exec, - 0x00000003); - break; - case 2: /* disable cck 1/2/5.5, ofdm 6/9/12/18/24, mcs 0/1/2/3/4 */ - halbtc8821c1ant_update_ra_mask(btcoexist, force_exec, - 0x0001f1f7); - break; - default: - break; - } - - halbtc8821c1ant_auto_rate_fallback_retry(btcoexist, force_exec, - arfr_type); - halbtc8821c1ant_retry_limit(btcoexist, force_exec, retry_limit_type); - halbtc8821c1ant_ampdu_max_time(btcoexist, force_exec, ampdu_time_type); -} - -void halbtc8821c1ant_limited_rx(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean rej_ap_agg_pkt, - IN boolean bt_ctrl_agg_buf_size, IN u8 agg_buf_size) -{ - boolean reject_rx_agg = rej_ap_agg_pkt; - boolean bt_ctrl_rx_agg_size = bt_ctrl_agg_buf_size; - u8 rx_agg_size = agg_buf_size; - - /* ============================================ */ - /* Rx Aggregation related setting */ - /* ============================================ */ - btcoexist->btc_set(btcoexist, BTC_SET_BL_TO_REJ_AP_AGG_PKT, - &reject_rx_agg); - /* decide BT control aggregation buf size or not */ - btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_CTRL_AGG_SIZE, - &bt_ctrl_rx_agg_size); - /* aggregation buf size, only work when BT control Rx aggregation size. */ - btcoexist->btc_set(btcoexist, BTC_SET_U1_AGG_BUF_SIZE, &rx_agg_size); - /* real update aggregation setting */ - btcoexist->btc_set(btcoexist, BTC_SET_ACT_AGGREGATE_CTRL, NULL); - - -} - -void halbtc8821c1ant_query_bt_info(IN struct btc_coexist *btcoexist) -{ - u8 h2c_parameter[1] = {0}; - - coex_sta->c2h_bt_info_req_sent = true; - - h2c_parameter[0] |= BIT(0); /* trigger */ - - btcoexist->btc_fill_h2c(btcoexist, 0x61, 1, h2c_parameter); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], WL query BT info!!\n"); - BTC_TRACE(trace_buf); -} - -void halbtc8821c1ant_monitor_bt_ctr(IN struct btc_coexist *btcoexist) -{ - u32 reg_hp_txrx, reg_lp_txrx, u32tmp; - u32 reg_hp_tx = 0, reg_hp_rx = 0, reg_lp_tx = 0, reg_lp_rx = 0; - static u8 num_of_bt_counter_chk = 0, cnt_slave = 0; - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - - /* to avoid 0x76e[3] = 1 (WLAN_Act control by PTA) during IPS */ - /* if (! (btcoexist->btc_read_1byte(btcoexist, 0x76e) & 0x8) ) */ - - reg_hp_txrx = 0x770; - reg_lp_txrx = 0x774; - - u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_hp_txrx); - reg_hp_tx = u32tmp & MASKLWORD; - reg_hp_rx = (u32tmp & MASKHWORD) >> 16; - - u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_lp_txrx); - reg_lp_tx = u32tmp & MASKLWORD; - reg_lp_rx = (u32tmp & MASKHWORD) >> 16; - - coex_sta->high_priority_tx = reg_hp_tx; - coex_sta->high_priority_rx = reg_hp_rx; - coex_sta->low_priority_tx = reg_lp_tx; - coex_sta->low_priority_rx = reg_lp_rx; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Hi-Pri Rx/Tx: %d/%d, Lo-Pri Rx/Tx: %d/%d\n", - reg_hp_rx, reg_hp_tx, reg_lp_rx, reg_lp_tx); - - BTC_TRACE(trace_buf); - - /* reset counter */ - btcoexist->btc_write_1byte(btcoexist, 0x76e, 0xc); - - if ((coex_sta->low_priority_tx > 1150) && - (!coex_sta->c2h_bt_inquiry_page)) - coex_sta->pop_event_cnt++; - - if ((coex_sta->low_priority_rx >= 1150) && - (coex_sta->low_priority_rx >= coex_sta->low_priority_tx) - && (!coex_sta->under_ips) && (!coex_sta->c2h_bt_inquiry_page) && - (coex_sta->bt_link_exist)) { - if (cnt_slave >= 3) { - bt_link_info->slave_role = true; - cnt_slave = 3; - } else - cnt_slave++; - } else { - if (cnt_slave == 0) { - bt_link_info->slave_role = false; - cnt_slave = 0; - } else - cnt_slave--; - - } - - if ((coex_sta->high_priority_tx == 0) && - (coex_sta->high_priority_rx == 0) && - (coex_sta->low_priority_tx == 0) && - (coex_sta->low_priority_rx == 0)) { - num_of_bt_counter_chk++; - if (num_of_bt_counter_chk >= 3) { - halbtc8821c1ant_query_bt_info(btcoexist); - num_of_bt_counter_chk = 0; - } - } - - -} - - - -void halbtc8821c1ant_monitor_wifi_ctr(IN struct btc_coexist *btcoexist) -{ -#if 1 - s32 wifi_rssi = 0; - boolean wifi_busy = false, wifi_under_b_mode = false; - static u8 cck_lock_counter = 0; - u32 total_cnt, reg_val1, reg_val2; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_B_MODE, - &wifi_under_b_mode); - - coex_sta->crc_ok_cck = btcoexist->btc_phydm_query_PHY_counter(btcoexist, - PHYDM_INFO_CRC32_OK_CCK); - coex_sta->crc_ok_11g = btcoexist->btc_phydm_query_PHY_counter(btcoexist, - PHYDM_INFO_CRC32_OK_LEGACY); - coex_sta->crc_ok_11n = btcoexist->btc_phydm_query_PHY_counter(btcoexist, - PHYDM_INFO_CRC32_OK_HT); - coex_sta->crc_ok_11n_vht = btcoexist->btc_phydm_query_PHY_counter( - btcoexist, PHYDM_INFO_CRC32_OK_VHT); - - coex_sta->crc_err_cck = btcoexist->btc_phydm_query_PHY_counter( - btcoexist, PHYDM_INFO_CRC32_ERROR_CCK); - coex_sta->crc_err_11g = btcoexist->btc_phydm_query_PHY_counter( - btcoexist, PHYDM_INFO_CRC32_ERROR_LEGACY); - coex_sta->crc_err_11n = btcoexist->btc_phydm_query_PHY_counter( - btcoexist, PHYDM_INFO_CRC32_ERROR_HT); - coex_sta->crc_err_11n_vht = btcoexist->btc_phydm_query_PHY_counter( - btcoexist, PHYDM_INFO_CRC32_ERROR_VHT); - - if ((wifi_busy) && (wifi_rssi >= 30) && (!wifi_under_b_mode)) { - total_cnt = coex_sta->crc_ok_cck + coex_sta->crc_ok_11g + - coex_sta->crc_ok_11n + coex_sta->crc_ok_11n_vht; - - if ((coex_dm->bt_status == BT_8821C_1ANT_BT_STATUS_ACL_BUSY) || - (coex_dm->bt_status == BT_8821C_1ANT_BT_STATUS_ACL_SCO_BUSY) - || - (coex_dm->bt_status == BT_8821C_1ANT_BT_STATUS_SCO_BUSY)) { - if (coex_sta->crc_ok_cck > (total_cnt - - coex_sta->crc_ok_cck)) { - if (cck_lock_counter < 3) - cck_lock_counter++; - } else { - if (cck_lock_counter > 0) - cck_lock_counter--; - } - - } else { - if (cck_lock_counter > 0) - cck_lock_counter--; - } - } else { - if (cck_lock_counter > 0) - cck_lock_counter--; - } - - if (!coex_sta->pre_ccklock) { - - if (cck_lock_counter >= 3) - coex_sta->cck_lock = true; - else - coex_sta->cck_lock = false; - } else { - if (cck_lock_counter == 0) - coex_sta->cck_lock = false; - else - coex_sta->cck_lock = true; - } - - if (coex_sta->cck_lock) - coex_sta->cck_ever_lock = true; - - coex_sta->pre_ccklock = coex_sta->cck_lock; - -#endif -} - -boolean halbtc8821c1ant_is_wifibt_status_changed(IN struct btc_coexist - *btcoexist) -{ - static boolean pre_wifi_busy = false, pre_under_4way = false, - pre_bt_hs_on = false, pre_bt_off = false; - static u8 pre_hid_busy_num = 0; - boolean wifi_busy = false, under_4way = false, bt_hs_on = false; - boolean wifi_connected = false; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS, - &under_4way); - - if (coex_sta->bt_disabled != pre_bt_off) { - pre_bt_off = coex_sta->bt_disabled; - - if (coex_sta->bt_disabled) - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT is disabled !!\n"); - else - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT is enabled !!\n"); - - BTC_TRACE(trace_buf); - - coex_sta->bt_coex_supported_feature = 0; - coex_sta->bt_coex_supported_version = 0; - coex_sta->bt_ble_scan_type = 0; - coex_sta->bt_ble_scan_para[0] = 0; - coex_sta->bt_ble_scan_para[1] = 0; - coex_sta->bt_ble_scan_para[2] = 0; - coex_sta->bt_reg_vendor_ac = 0xffff; - coex_sta->bt_reg_vendor_ae = 0xffff; - return true; - } - - - if (wifi_connected) { - if (wifi_busy != pre_wifi_busy) { - pre_wifi_busy = wifi_busy; - return true; - } - if (under_4way != pre_under_4way) { - pre_under_4way = under_4way; - return true; - } - if (bt_hs_on != pre_bt_hs_on) { - pre_bt_hs_on = bt_hs_on; - return true; - } - - if (!coex_sta->bt_disabled) { - - if (coex_sta->hid_busy_num != pre_hid_busy_num) { - pre_hid_busy_num = coex_sta->hid_busy_num; - return true; - } - } - } - - return false; -} - -void halbtc8821c1ant_update_bt_link_info(IN struct btc_coexist *btcoexist) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - boolean bt_hs_on = false; - boolean bt_busy = false; - - - coex_sta->num_of_profile = 0; - - /* set link exist status */ - if (!(coex_sta->bt_info & BT_INFO_8821C_1ANT_B_CONNECTION)) { - coex_sta->bt_link_exist = false; - coex_sta->pan_exist = false; - coex_sta->a2dp_exist = false; - coex_sta->hid_exist = false; - coex_sta->sco_exist = false; - } else { /* connection exists */ - coex_sta->bt_link_exist = true; - if (coex_sta->bt_info & BT_INFO_8821C_1ANT_B_FTP) { - coex_sta->pan_exist = true; - coex_sta->num_of_profile++; - } else - coex_sta->pan_exist = false; - - if (coex_sta->bt_info & BT_INFO_8821C_1ANT_B_A2DP) { - coex_sta->a2dp_exist = true; - coex_sta->num_of_profile++; - } else - coex_sta->a2dp_exist = false; - - if (coex_sta->bt_info & BT_INFO_8821C_1ANT_B_HID) { - coex_sta->hid_exist = true; - coex_sta->num_of_profile++; - } else - coex_sta->hid_exist = false; - - if (coex_sta->bt_info & BT_INFO_8821C_1ANT_B_SCO_ESCO) { - coex_sta->sco_exist = true; - coex_sta->num_of_profile++; - } else - coex_sta->sco_exist = false; - - } - - btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); - - bt_link_info->bt_link_exist = coex_sta->bt_link_exist; - bt_link_info->sco_exist = coex_sta->sco_exist; - bt_link_info->a2dp_exist = coex_sta->a2dp_exist; - bt_link_info->pan_exist = coex_sta->pan_exist; - bt_link_info->hid_exist = coex_sta->hid_exist; - bt_link_info->acl_busy = coex_sta->acl_busy; - - /* work around for HS mode. */ - if (bt_hs_on) { - bt_link_info->pan_exist = true; - bt_link_info->bt_link_exist = true; - } - - /* check if Sco only */ - if (bt_link_info->sco_exist && - !bt_link_info->a2dp_exist && - !bt_link_info->pan_exist && - !bt_link_info->hid_exist) - bt_link_info->sco_only = true; - else - bt_link_info->sco_only = false; - - /* check if A2dp only */ - if (!bt_link_info->sco_exist && - bt_link_info->a2dp_exist && - !bt_link_info->pan_exist && - !bt_link_info->hid_exist) - bt_link_info->a2dp_only = true; - else - bt_link_info->a2dp_only = false; - - /* check if Pan only */ - if (!bt_link_info->sco_exist && - !bt_link_info->a2dp_exist && - bt_link_info->pan_exist && - !bt_link_info->hid_exist) - bt_link_info->pan_only = true; - else - bt_link_info->pan_only = false; - - /* check if Hid only */ - if (!bt_link_info->sco_exist && - !bt_link_info->a2dp_exist && - !bt_link_info->pan_exist && - bt_link_info->hid_exist) - bt_link_info->hid_only = true; - else - bt_link_info->hid_only = false; - - if (!(coex_sta->bt_info & BT_INFO_8821C_1ANT_B_CONNECTION)) { - coex_dm->bt_status = BT_8821C_1ANT_BT_STATUS_NON_CONNECTED_IDLE; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), BT Non-Connected idle!!!\n"); - } else if (coex_sta->bt_info == BT_INFO_8821C_1ANT_B_CONNECTION) { - /* connection exists but no busy */ - coex_dm->bt_status = BT_8821C_1ANT_BT_STATUS_CONNECTED_IDLE; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), BT Connected-idle!!!\n"); - } else if (((coex_sta->bt_info & BT_INFO_8821C_1ANT_B_SCO_ESCO) || - (coex_sta->bt_info & BT_INFO_8821C_1ANT_B_SCO_BUSY)) && - (coex_sta->bt_info & BT_INFO_8821C_1ANT_B_ACL_BUSY)) { - coex_dm->bt_status = BT_8821C_1ANT_BT_STATUS_ACL_SCO_BUSY; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), BT ACL SCO busy!!!\n"); - } else if ((coex_sta->bt_info & BT_INFO_8821C_1ANT_B_SCO_ESCO) || - (coex_sta->bt_info & BT_INFO_8821C_1ANT_B_SCO_BUSY)) { - coex_dm->bt_status = BT_8821C_1ANT_BT_STATUS_SCO_BUSY; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), BT SCO busy!!!\n"); - } else if (coex_sta->bt_info & BT_INFO_8821C_1ANT_B_ACL_BUSY) { - coex_dm->bt_status = BT_8821C_1ANT_BT_STATUS_ACL_BUSY; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), BT ACL busy!!!\n"); - } else { - coex_dm->bt_status = BT_8821C_1ANT_BT_STATUS_MAX; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), BT Non-Defined state!!!\n"); - } - - BTC_TRACE(trace_buf); - - if ((BT_8821C_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) || - (BT_8821C_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) || - (BT_8821C_1ANT_BT_STATUS_ACL_SCO_BUSY == coex_dm->bt_status)) - bt_busy = true; - else - bt_busy = false; - - btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bt_busy); -} - -void halbtc8821c1ant_update_wifi_channel_info(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - u8 h2c_parameter[3] = {0}; - u32 wifi_bw; - u8 wifi_central_chnl; - - /* only 2.4G we need to inform bt the chnl mask */ - btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_CENTRAL_CHNL, - &wifi_central_chnl); - if ((BTC_MEDIA_CONNECT == type) && - (wifi_central_chnl <= 14)) { - h2c_parameter[0] = - 0x1; /* enable BT AFH skip WL channel for 8821c because BT Rx LO interference */ - /* h2c_parameter[0] = 0x0; */ - h2c_parameter[1] = wifi_central_chnl; - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw); - if (BTC_WIFI_BW_HT40 == wifi_bw) - h2c_parameter[2] = 0x30; - else - h2c_parameter[2] = 0x20; - } - - coex_dm->wifi_chnl_info[0] = h2c_parameter[0]; - coex_dm->wifi_chnl_info[1] = h2c_parameter[1]; - coex_dm->wifi_chnl_info[2] = h2c_parameter[2]; - - btcoexist->btc_fill_h2c(btcoexist, 0x66, 3, h2c_parameter); - -} - -u8 halbtc8821c1ant_action_algorithm(IN struct btc_coexist *btcoexist) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - boolean bt_hs_on = false; - u8 algorithm = BT_8821C_1ANT_COEX_ALGO_UNDEFINED; - u8 num_of_diff_profile = 0; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); - - if (!bt_link_info->bt_link_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], No BT link exists!!!\n"); - BTC_TRACE(trace_buf); - return algorithm; - } - - if (bt_link_info->sco_exist) - num_of_diff_profile++; - if (bt_link_info->hid_exist) - num_of_diff_profile++; - if (bt_link_info->pan_exist) - num_of_diff_profile++; - if (bt_link_info->a2dp_exist) - num_of_diff_profile++; - - if (num_of_diff_profile == 1) { - if (bt_link_info->sco_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = SCO only\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8821C_1ANT_COEX_ALGO_SCO; - } else { - if (bt_link_info->hid_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = HID only\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8821C_1ANT_COEX_ALGO_HID; - } else if (bt_link_info->a2dp_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = A2DP only\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8821C_1ANT_COEX_ALGO_A2DP; - } else if (bt_link_info->pan_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = PAN(HS) only\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8821C_1ANT_COEX_ALGO_PANHS; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = PAN(EDR) only\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8821C_1ANT_COEX_ALGO_PANEDR; - } - } - } - } else if (num_of_diff_profile == 2) { - if (bt_link_info->sco_exist) { - if (bt_link_info->hid_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = SCO + HID\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8821C_1ANT_COEX_ALGO_HID; - } else if (bt_link_info->a2dp_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = SCO + A2DP ==> SCO\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8821C_1ANT_COEX_ALGO_SCO; - } else if (bt_link_info->pan_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = SCO + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8821C_1ANT_COEX_ALGO_SCO; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = SCO + PAN(EDR)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8821C_1ANT_COEX_ALGO_PANEDR_HID; - } - } - } else { - if (bt_link_info->hid_exist && - bt_link_info->a2dp_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = HID + A2DP\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8821C_1ANT_COEX_ALGO_HID_A2DP; - } else if (bt_link_info->hid_exist && - bt_link_info->pan_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = HID + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8821C_1ANT_COEX_ALGO_HID_A2DP; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = HID + PAN(EDR)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8821C_1ANT_COEX_ALGO_PANEDR_HID; - } - } else if (bt_link_info->pan_exist && - bt_link_info->a2dp_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = A2DP + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8821C_1ANT_COEX_ALGO_A2DP_PANHS; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = A2DP + PAN(EDR)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8821C_1ANT_COEX_ALGO_PANEDR_A2DP; - } - } - } - } else if (num_of_diff_profile == 3) { - if (bt_link_info->sco_exist) { - if (bt_link_info->hid_exist && - bt_link_info->a2dp_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = SCO + HID + A2DP ==> HID\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8821C_1ANT_COEX_ALGO_HID; - } else if (bt_link_info->hid_exist && - bt_link_info->pan_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = SCO + HID + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8821C_1ANT_COEX_ALGO_HID_A2DP; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = SCO + HID + PAN(EDR)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8821C_1ANT_COEX_ALGO_PANEDR_HID; - } - } else if (bt_link_info->pan_exist && - bt_link_info->a2dp_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = SCO + A2DP + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8821C_1ANT_COEX_ALGO_SCO; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = SCO + A2DP + PAN(EDR) ==> HID\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8821C_1ANT_COEX_ALGO_PANEDR_HID; - } - } - } else { - if (bt_link_info->hid_exist && - bt_link_info->pan_exist && - bt_link_info->a2dp_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = HID + A2DP + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8821C_1ANT_COEX_ALGO_HID_A2DP; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = HID + A2DP + PAN(EDR)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8821C_1ANT_COEX_ALGO_HID_A2DP_PANEDR; - } - } - } - } else if (num_of_diff_profile >= 3) { - if (bt_link_info->sco_exist) { - if (bt_link_info->hid_exist && - bt_link_info->pan_exist && - bt_link_info->a2dp_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Error!!! BT Profile = SCO + HID + A2DP + PAN(HS)\n"); - BTC_TRACE(trace_buf); - - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = SCO + HID + A2DP + PAN(EDR)==>PAN(EDR)+HID\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8821C_1ANT_COEX_ALGO_PANEDR_HID; - } - } - } - } - - return algorithm; -} - -void halbtc8821c1ant_set_bt_auto_report(IN struct btc_coexist *btcoexist, - IN boolean enable_auto_report) -{ - u8 h2c_parameter[1] = {0}; - - h2c_parameter[0] = 0; - - if (enable_auto_report) - h2c_parameter[0] |= BIT(0); - - btcoexist->btc_fill_h2c(btcoexist, 0x68, 1, h2c_parameter); -} - -void halbtc8821c1ant_bt_auto_report(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean enable_auto_report) -{ - coex_dm->cur_bt_auto_report = enable_auto_report; - - if (!force_exec) { - if (coex_dm->pre_bt_auto_report == coex_dm->cur_bt_auto_report) - return; - } - halbtc8821c1ant_set_bt_auto_report(btcoexist, - coex_dm->cur_bt_auto_report); - - coex_dm->pre_bt_auto_report = coex_dm->cur_bt_auto_report; -} - - -void halbtc8821c1ant_low_penalty_ra(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean low_penalty_ra) -{ - -#if 1 - coex_dm->cur_low_penalty_ra = low_penalty_ra; - - if (!force_exec) { - if (coex_dm->pre_low_penalty_ra == - coex_dm->cur_low_penalty_ra) - return; - } - - if (low_penalty_ra) - btcoexist->btc_phydm_modify_RA_PCR_threshold(btcoexist, 0, 15); - else - btcoexist->btc_phydm_modify_RA_PCR_threshold(btcoexist, 0, 0); - - coex_dm->pre_low_penalty_ra = coex_dm->cur_low_penalty_ra; - -#endif - -} - - -void halbtc8821c1ant_write_score_board( - IN struct btc_coexist *btcoexist, - IN u16 bitpos, - IN boolean state -) -{ - - static u16 originalval = 0x8002; - - if (state) - originalval = originalval | bitpos; - else - originalval = originalval & (~bitpos); - - btcoexist->btc_write_2byte(btcoexist, 0xaa, originalval); -} - -void halbtc8821c1ant_read_score_board( - IN struct btc_coexist *btcoexist, - IN u16 *score_board_val -) -{ - - *score_board_val = (btcoexist->btc_read_2byte(btcoexist, - 0xaa)) & 0x7fff; -} - -void halbtc8821c1ant_post_state_to_bt( - IN struct btc_coexist *btcoexist, - IN u16 type, - IN boolean state -) -{ - - halbtc8821c1ant_write_score_board(btcoexist, (u16) type, state); - -} - -void halbtc8821c1ant_monitor_bt_enable_disable(IN struct btc_coexist *btcoexist) -{ - static u32 bt_disable_cnt = 0; - boolean bt_active = true, bt_disabled = false, wifi_under_5g = false; - u16 u16tmp; - - /* This function check if bt is disabled */ -#if 0 - if (coex_sta->high_priority_tx == 0 && - coex_sta->high_priority_rx == 0 && - coex_sta->low_priority_tx == 0 && - coex_sta->low_priority_rx == 0) - bt_active = false; - if (coex_sta->high_priority_tx == 0xffff && - coex_sta->high_priority_rx == 0xffff && - coex_sta->low_priority_tx == 0xffff && - coex_sta->low_priority_rx == 0xffff) - bt_active = false; - - -#else - - /* Read BT on/off status from scoreboard[1], enable this only if BT patch support this feature */ - halbtc8821c1ant_read_score_board(btcoexist, &u16tmp); - - bt_active = u16tmp & BIT(1); - - -#endif - - if (bt_active) { - bt_disable_cnt = 0; - bt_disabled = false; - btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_DISABLE, - &bt_disabled); - } else { - - bt_disable_cnt++; - if (bt_disable_cnt >= 10) { - bt_disabled = true; - bt_disable_cnt = 10; - } - - btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_DISABLE, - &bt_disabled); - } - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g); - - if ((wifi_under_5g) || (bt_disabled)) - halbtc8821c1ant_low_penalty_ra(btcoexist, NORMAL_EXEC, false); - else - halbtc8821c1ant_low_penalty_ra(btcoexist, NORMAL_EXEC, true); - - - if (coex_sta->bt_disabled != bt_disabled) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT is from %s to %s!!\n", - (coex_sta->bt_disabled ? "disabled" : "enabled"), - (bt_disabled ? "disabled" : "enabled")); - BTC_TRACE(trace_buf); - coex_sta->bt_disabled = bt_disabled; - } - -} - -void halbtc8821c1ant_enable_gnt_to_gpio(IN struct btc_coexist *btcoexist, - boolean isenable) -{ -#if BT_8821C_1ANT_COEX_DBG - static u8 bitVal[5] = {0, 0, 0, 0, 0}; - static boolean state = false; - /* - if (state ==isenable) - return; - else - state = isenable; - */ - if (isenable) { - - /* enable GNT_WL, GNT_BT to GPIO for debug */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x73, 0x8, 0x1); - - /* store original value */ - bitVal[0] = (btcoexist->btc_read_1byte(btcoexist, - 0x66) & BIT(4)) >> 4; /*0x66[4] */ - bitVal[1] = (btcoexist->btc_read_1byte(btcoexist, - 0x67) & BIT(0)); /*0x66[8] */ - bitVal[2] = (btcoexist->btc_read_1byte(btcoexist, - 0x42) & BIT(3)) >> 3; /*0x40[19] */ - bitVal[3] = (btcoexist->btc_read_1byte(btcoexist, - 0x65) & BIT(7)) >> 7; /*0x64[15] */ - bitVal[4] = (btcoexist->btc_read_1byte(btcoexist, - 0x72) & BIT(2)) >> 2; /*0x70[18] */ - - /* switch GPIO Mux */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x66, BIT(4), - 0x0); /*0x66[4] = 0 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, BIT(0), - 0x0); /*0x66[8] = 0 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x42, BIT(3), - 0x0); /*0x40[19] = 0 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x65, BIT(7), - 0x0); /*0x64[15] = 0 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x72, BIT(2), - 0x0); /*0x70[18] = 0 */ - - - } else { - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x73, 0x8, 0x0); - - /* Restore original value */ - /* switch GPIO Mux */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x66, BIT(4), - bitVal[0]); /*0x66[4] = 0 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, BIT(0), - bitVal[1]); /*0x66[8] = 0 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x42, BIT(3), - bitVal[2]); /*0x40[19] = 0 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x65, BIT(7), - bitVal[3]); /*0x64[15] = 0 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x72, BIT(2), - bitVal[4]); /*0x70[18] = 0 */ - } - -#endif -} - -u32 halbtc8821c1ant_ltecoex_indirect_read_reg(IN struct btc_coexist *btcoexist, - IN u16 reg_addr) -{ - u32 j = 0; - - - /* wait for ready bit before access 0x1700 */ - btcoexist->btc_write_4byte(btcoexist, 0x1700, 0x800F0000 | reg_addr); - - do { - j++; - } while (((btcoexist->btc_read_1byte(btcoexist, - 0x1703)&BIT(5)) == 0) && - (j < BT_8821C_1ANT_LTECOEX_INDIRECTREG_ACCESS_TIMEOUT)); - - return btcoexist->btc_read_4byte(btcoexist, - 0x1708); /* get read data */ - -} - -void halbtc8821c1ant_ltecoex_indirect_write_reg(IN struct btc_coexist - *btcoexist, - IN u16 reg_addr, IN u32 bit_mask, IN u32 reg_value) -{ - u32 val, i = 0, j = 0, bitpos = 0; - - - if (bit_mask == 0x0) - return; - if (bit_mask == 0xffffffff) { - btcoexist->btc_write_4byte(btcoexist, 0x1704, - reg_value); /* put write data */ - - /* wait for ready bit before access 0x1700 */ - do { - j++; - } while (((btcoexist->btc_read_1byte(btcoexist, - 0x1703)&BIT(5)) == 0) && - (j < BT_8821C_1ANT_LTECOEX_INDIRECTREG_ACCESS_TIMEOUT)); - - - btcoexist->btc_write_4byte(btcoexist, 0x1700, - 0xc00F0000 | reg_addr); - } else { - for (i = 0; i <= 31; i++) { - if (((bit_mask >> i) & 0x1) == 0x1) { - bitpos = i; - break; - } - } - - /* read back register value before write */ - val = halbtc8821c1ant_ltecoex_indirect_read_reg(btcoexist, - reg_addr); - val = (val & (~bit_mask)) | (reg_value << bitpos); - - btcoexist->btc_write_4byte(btcoexist, 0x1704, - val); /* put write data */ - - /* wait for ready bit before access 0x1700 */ - do { - j++; - } while (((btcoexist->btc_read_1byte(btcoexist, - 0x1703)&BIT(5)) == 0) && - (j < BT_8821C_1ANT_LTECOEX_INDIRECTREG_ACCESS_TIMEOUT)); - - - btcoexist->btc_write_4byte(btcoexist, 0x1700, - 0xc00F0000 | reg_addr); - - } - -} - -void halbtc8821c1ant_ltecoex_enable(IN struct btc_coexist *btcoexist, - IN boolean enable) -{ - u8 val; - - val = (enable) ? 1 : 0; - halbtc8821c1ant_ltecoex_indirect_write_reg(btcoexist, 0x38, 0x80, - val); /* 0x38[7] */ - -} - -void halbtc8821c1ant_ltecoex_pathcontrol_owner(IN struct btc_coexist *btcoexist, - IN boolean wifi_control) -{ - u8 val; - - val = (wifi_control) ? 1 : 0; - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x73, 0x4, - val); /* 0x70[26] */ - -} - -void halbtc8821c1ant_ltecoex_set_gnt_bt(IN struct btc_coexist *btcoexist, - IN u8 control_block, IN boolean sw_control, IN u8 state) -{ - u32 val = 0, bit_mask; - - state = state & 0x1; - val = (sw_control) ? ((state << 1) | 0x1) : 0; - - switch (control_block) { - case BT_8821C_1ANT_GNT_BLOCK_RFC_BB: - default: - bit_mask = 0xc000; - halbtc8821c1ant_ltecoex_indirect_write_reg(btcoexist, - 0x38, bit_mask, val); /* 0x38[15:14] */ - bit_mask = 0x0c00; - halbtc8821c1ant_ltecoex_indirect_write_reg(btcoexist, - 0x38, bit_mask, val); /* 0x38[11:10] */ - break; - case BT_8821C_1ANT_GNT_BLOCK_RFC: - bit_mask = 0xc000; - halbtc8821c1ant_ltecoex_indirect_write_reg(btcoexist, - 0x38, bit_mask, val); /* 0x38[15:14] */ - break; - case BT_8821C_1ANT_GNT_BLOCK_BB: - bit_mask = 0x0c00; - halbtc8821c1ant_ltecoex_indirect_write_reg(btcoexist, - 0x38, bit_mask, val); /* 0x38[11:10] */ - break; - - } - -} - -void halbtc8821c1ant_ltecoex_set_gnt_wl(IN struct btc_coexist *btcoexist, - IN u8 control_block, IN boolean sw_control, IN u8 state) -{ - u32 val = 0, bit_mask; - - state = state & 0x1; - val = (sw_control) ? ((state << 1) | 0x1) : 0; - - switch (control_block) { - case BT_8821C_1ANT_GNT_BLOCK_RFC_BB: - default: - bit_mask = 0x3000; - halbtc8821c1ant_ltecoex_indirect_write_reg(btcoexist, - 0x38, bit_mask, val); /* 0x38[13:12] */ - bit_mask = 0x0300; - halbtc8821c1ant_ltecoex_indirect_write_reg(btcoexist, - 0x38, bit_mask, val); /* 0x38[9:8] */ - break; - case BT_8821C_1ANT_GNT_BLOCK_RFC: - bit_mask = 0x3000; - halbtc8821c1ant_ltecoex_indirect_write_reg(btcoexist, - 0x38, bit_mask, val); /* 0x38[13:12] */ - break; - case BT_8821C_1ANT_GNT_BLOCK_BB: - bit_mask = 0x0300; - halbtc8821c1ant_ltecoex_indirect_write_reg(btcoexist, - 0x38, bit_mask, val); /* 0x38[9:8] */ - break; - - } - -} - -void halbtc8821c1ant_ltecoex_set_coex_table(IN struct btc_coexist *btcoexist, - IN u8 table_type, IN u16 table_content) -{ - u16 reg_addr = 0x0000; - - switch (table_type) { - case BT_8821C_1ANT_CTT_WL_VS_LTE: - reg_addr = 0xa0; - break; - case BT_8821C_1ANT_CTT_BT_VS_LTE: - reg_addr = 0xa4; - break; - } - - if (reg_addr != 0x0000) - halbtc8821c1ant_ltecoex_indirect_write_reg(btcoexist, reg_addr, - 0xffff, table_content); /* 0xa0[15:0] or 0xa4[15:0] */ - - -} - - -void halbtc8821c1ant_ltecoex_set_break_table(IN struct btc_coexist *btcoexist, - IN u8 table_type, IN u8 table_content) -{ - u16 reg_addr = 0x0000; - - switch (table_type) { - case BT_8821C_1ANT_LBTT_WL_BREAK_LTE: - reg_addr = 0xa8; - break; - case BT_8821C_1ANT_LBTT_BT_BREAK_LTE: - reg_addr = 0xac; - break; - case BT_8821C_1ANT_LBTT_LTE_BREAK_WL: - reg_addr = 0xb0; - break; - case BT_8821C_1ANT_LBTT_LTE_BREAK_BT: - reg_addr = 0xb4; - break; - } - - if (reg_addr != 0x0000) - halbtc8821c1ant_ltecoex_indirect_write_reg(btcoexist, reg_addr, - 0xff, table_content); /* 0xa8[15:0] or 0xb4[15:0] */ - - -} - -void halbtc8821c1ant_set_wltoggle_coex_table(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 interval, - IN u8 val0x6c4_b0, IN u8 val0x6c4_b1, IN u8 val0x6c4_b2, - IN u8 val0x6c4_b3) -{ - static u8 pre_h2c_parameter[6] = {0}; - u8 cur_h2c_parameter[6] = {0}; - u8 i, match_cnt = 0; - - cur_h2c_parameter[0] = 0x7; /* op_code, 0x7= wlan toggle slot*/ - - cur_h2c_parameter[1] = interval; - cur_h2c_parameter[2] = val0x6c4_b0; - cur_h2c_parameter[3] = val0x6c4_b1; - cur_h2c_parameter[4] = val0x6c4_b2; - cur_h2c_parameter[5] = val0x6c4_b3; - - if (!force_exec) { - for (i = 1; i <= 5; i++) { - if (cur_h2c_parameter[i] != pre_h2c_parameter[i]) - break; - - match_cnt++; - } - - if (match_cnt == 5) - return; - } - - for (i = 1; i <= 5; i++) - pre_h2c_parameter[i] = cur_h2c_parameter[i]; - - btcoexist->btc_fill_h2c(btcoexist, 0x69, 6, cur_h2c_parameter); -} - - -void halbtc8821c1ant_set_coex_table(IN struct btc_coexist *btcoexist, - IN u32 val0x6c0, IN u32 val0x6c4, IN u32 val0x6c8, IN u8 val0x6cc) -{ - btcoexist->btc_write_4byte(btcoexist, 0x6c0, val0x6c0); - - btcoexist->btc_write_4byte(btcoexist, 0x6c4, val0x6c4); - - btcoexist->btc_write_4byte(btcoexist, 0x6c8, val0x6c8); - - btcoexist->btc_write_1byte(btcoexist, 0x6cc, val0x6cc); -} - -void halbtc8821c1ant_coex_table(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u32 val0x6c0, IN u32 val0x6c4, - IN u32 val0x6c8, IN u8 val0x6cc) -{ - coex_dm->cur_val0x6c0 = val0x6c0; - coex_dm->cur_val0x6c4 = val0x6c4; - coex_dm->cur_val0x6c8 = val0x6c8; - coex_dm->cur_val0x6cc = val0x6cc; - - if (!force_exec) { - if ((coex_dm->pre_val0x6c0 == coex_dm->cur_val0x6c0) && - (coex_dm->pre_val0x6c4 == coex_dm->cur_val0x6c4) && - (coex_dm->pre_val0x6c8 == coex_dm->cur_val0x6c8) && - (coex_dm->pre_val0x6cc == coex_dm->cur_val0x6cc)) - return; - } - - halbtc8821c1ant_set_coex_table(btcoexist, val0x6c0, val0x6c4, val0x6c8, - val0x6cc); - - coex_dm->pre_val0x6c0 = coex_dm->cur_val0x6c0; - coex_dm->pre_val0x6c4 = coex_dm->cur_val0x6c4; - coex_dm->pre_val0x6c8 = coex_dm->cur_val0x6c8; - coex_dm->pre_val0x6cc = coex_dm->cur_val0x6cc; -} - -void halbtc8821c1ant_coex_table_with_type(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 type) -{ - u32 break_table; - u8 select_table; - - coex_sta->coex_table_type = type; - - if (coex_sta->concurrent_rx_mode_on == true) { - break_table = 0xf0ffffff; /* set WL hi-pri can break BT */ - select_table = - 0xb; /* set Tx response = Hi-Pri (ex: Transmitting ACK,BA,CTS) */ - } else { - break_table = 0xffffff; - select_table = 0x3; - } - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** Table-%d **********\n", - coex_sta->coex_table_type); - BTC_TRACE(trace_buf); - - switch (type) { - case 0: - halbtc8821c1ant_coex_table(btcoexist, force_exec, - 0x55555555, 0x55555555, break_table, - select_table); - break; - case 1: - halbtc8821c1ant_coex_table(btcoexist, force_exec, - 0x55555555, 0x5a5a5a5a, break_table, - select_table); - break; - case 2: - halbtc8821c1ant_coex_table(btcoexist, force_exec, - 0xaa5a5a5a, 0xaa5a5a5a, break_table, - select_table); - break; - case 3: - halbtc8821c1ant_coex_table(btcoexist, force_exec, - 0xaa555555, 0xaa5a5a5a, break_table, - select_table); - break; - case 4: - halbtc8821c1ant_coex_table(btcoexist, force_exec, - 0xa5555555, 0xaa5a5a5a, break_table, - select_table); - break; - case 5: - halbtc8821c1ant_coex_table(btcoexist, force_exec, - 0x5a5a5a5a, 0x5a5a5a5a, break_table, - select_table); - break; - case 6: - halbtc8821c1ant_coex_table(btcoexist, force_exec, - 0xa5555555, 0x5a5a5a5a, break_table, - select_table); - break; - case 7: - halbtc8821c1ant_coex_table(btcoexist, force_exec, - 0xaaaaaaaa, 0xaaaaaaaa, break_table, - select_table); - break; - case 8: - halbtc8821c1ant_coex_table(btcoexist, force_exec, - 0xa5555555, 0xaaaaaaaa, break_table, - select_table); - break; - case 9: - halbtc8821c1ant_coex_table(btcoexist, force_exec, - 0x5a5a5a5a, 0xaaaa5aaa, break_table, - select_table); - break; - default: - break; - } -} - -void halbtc8821c1ant_set_fw_ignore_wlan_act(IN struct btc_coexist *btcoexist, - IN boolean enable) -{ - u8 h2c_parameter[1] = {0}; - - if (enable) - h2c_parameter[0] |= BIT(0); /* function enable */ - - btcoexist->btc_fill_h2c(btcoexist, 0x63, 1, h2c_parameter); -} - -void halbtc8821c1ant_ignore_wlan_act(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean enable) -{ - coex_dm->cur_ignore_wlan_act = enable; - - if (!force_exec) { - if (coex_dm->pre_ignore_wlan_act == - coex_dm->cur_ignore_wlan_act) - return; - } - halbtc8821c1ant_set_fw_ignore_wlan_act(btcoexist, enable); - - coex_dm->pre_ignore_wlan_act = coex_dm->cur_ignore_wlan_act; -} - -void halbtc8821c1ant_set_lps_rpwm(IN struct btc_coexist *btcoexist, - IN u8 lps_val, IN u8 rpwm_val) -{ - u8 lps = lps_val; - u8 rpwm = rpwm_val; - - btcoexist->btc_set(btcoexist, BTC_SET_U1_LPS_VAL, &lps); - btcoexist->btc_set(btcoexist, BTC_SET_U1_RPWM_VAL, &rpwm); -} - -void halbtc8821c1ant_lps_rpwm(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 lps_val, IN u8 rpwm_val) -{ - coex_dm->cur_lps = lps_val; - coex_dm->cur_rpwm = rpwm_val; - - if (!force_exec) { - if ((coex_dm->pre_lps == coex_dm->cur_lps) && - (coex_dm->pre_rpwm == coex_dm->cur_rpwm)) - return; - } - halbtc8821c1ant_set_lps_rpwm(btcoexist, lps_val, rpwm_val); - - coex_dm->pre_lps = coex_dm->cur_lps; - coex_dm->pre_rpwm = coex_dm->cur_rpwm; -} - -void halbtc8821c1ant_ps_tdma_check_for_power_save_state( - IN struct btc_coexist *btcoexist, IN boolean new_ps_state) -{ - u8 lps_mode = 0x0; - u8 h2c_parameter[5] = {0x8, 0, 0, 0, 0}; - - btcoexist->btc_get(btcoexist, BTC_GET_U1_LPS_MODE, &lps_mode); - - if (lps_mode) { /* already under LPS state */ - if (new_ps_state) { - /* keep state under LPS, do nothing. */ - } else { - /* will leave LPS state, turn off psTdma first */ - /*halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, - 8); */ - btcoexist->btc_fill_h2c(btcoexist, 0x60, 5, - h2c_parameter); - } - } else { /* NO PS state */ - if (new_ps_state) { - /* will enter LPS state, turn off psTdma first */ - /*halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, - 8);*/ - btcoexist->btc_fill_h2c(btcoexist, 0x60, 5, - h2c_parameter); - } else { - /* keep state under NO PS state, do nothing. */ - } - } -} - -void halbtc8821c1ant_power_save_state(IN struct btc_coexist *btcoexist, - IN u8 ps_type, IN u8 lps_val, IN u8 rpwm_val) -{ - boolean low_pwr_disable = false; - - switch (ps_type) { - case BTC_PS_WIFI_NATIVE: - /* recover to original 32k low power setting */ - coex_sta->force_lps_on = false; - low_pwr_disable = false; - btcoexist->btc_set(btcoexist, - BTC_SET_ACT_DISABLE_LOW_POWER, - &low_pwr_disable); - btcoexist->btc_set(btcoexist, BTC_SET_ACT_NORMAL_LPS, - NULL); - - break; - case BTC_PS_LPS_ON: - coex_sta->force_lps_on = true; - halbtc8821c1ant_ps_tdma_check_for_power_save_state( - btcoexist, true); - halbtc8821c1ant_lps_rpwm(btcoexist, NORMAL_EXEC, - lps_val, rpwm_val); - /* when coex force to enter LPS, do not enter 32k low power. */ - low_pwr_disable = true; - btcoexist->btc_set(btcoexist, - BTC_SET_ACT_DISABLE_LOW_POWER, - &low_pwr_disable); - /* power save must executed before psTdma. */ - btcoexist->btc_set(btcoexist, BTC_SET_ACT_ENTER_LPS, - NULL); - - break; - case BTC_PS_LPS_OFF: - coex_sta->force_lps_on = false; - halbtc8821c1ant_ps_tdma_check_for_power_save_state( - btcoexist, false); - btcoexist->btc_set(btcoexist, BTC_SET_ACT_LEAVE_LPS, - NULL); - - break; - default: - break; - } -} - - -void halbtc8821c1ant_set_fw_pstdma(IN struct btc_coexist *btcoexist, - IN u8 byte1, IN u8 byte2, IN u8 byte3, IN u8 byte4, IN u8 byte5) -{ - u8 h2c_parameter[5] = {0}; - u8 real_byte1 = byte1, real_byte5 = byte5; - boolean ap_enable = false; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, - &ap_enable); - - if (ap_enable) { - if (byte1 & BIT(4) && !(byte1 & BIT(5))) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], FW for 1Ant AP mode\n"); - BTC_TRACE(trace_buf); - real_byte1 &= ~BIT(4); - real_byte1 |= BIT(5); - - real_byte5 |= BIT(5); - real_byte5 &= ~BIT(6); - - halbtc8821c1ant_power_save_state(btcoexist, - BTC_PS_WIFI_NATIVE, 0x0, - 0x0); - } - } else if (byte1 & BIT(4) && !(byte1 & BIT(5))) { - - halbtc8821c1ant_power_save_state( - btcoexist, BTC_PS_LPS_ON, 0x50, - 0x4); - } else { - halbtc8821c1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, - 0x0, - 0x0); - } - - - h2c_parameter[0] = real_byte1; - h2c_parameter[1] = byte2; - h2c_parameter[2] = byte3; - h2c_parameter[3] = byte4; - h2c_parameter[4] = real_byte5; - - coex_dm->ps_tdma_para[0] = real_byte1; - coex_dm->ps_tdma_para[1] = byte2; - coex_dm->ps_tdma_para[2] = byte3; - coex_dm->ps_tdma_para[3] = byte4; - coex_dm->ps_tdma_para[4] = real_byte5; - - btcoexist->btc_fill_h2c(btcoexist, 0x60, 5, h2c_parameter); -} - - -void halbtc8821c1ant_ps_tdma(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean turn_on, IN u8 type) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - struct btc_board_info *board_info = &btcoexist->board_info; - boolean wifi_busy = false; - static u8 psTdmaByte4Modify = 0x0, pre_psTdmaByte4Modify = 0x0; - static boolean pre_wifi_busy = false; - - -#if BT_8821C_1ANT_ANTDET_ENABLE - - if (board_info->btdm_ant_num_by_ant_det == 2) { -#if 0 - if (turn_on) - type = type + - 100; -#endif - } - -#endif - - coex_dm->cur_ps_tdma_on = turn_on; - coex_dm->cur_ps_tdma = type; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - - if (wifi_busy != pre_wifi_busy) { - force_exec = true; - pre_wifi_busy = wifi_busy; - } - - /* 0x778 = 0x1 at wifi slot (no blocking BT Low-Pri pkts) */ - if ((bt_link_info->slave_role) && (bt_link_info->a2dp_exist)) - psTdmaByte4Modify = 0x1; - else - psTdmaByte4Modify = 0x0; - - if (pre_psTdmaByte4Modify != psTdmaByte4Modify) { - - force_exec = true; - pre_psTdmaByte4Modify = psTdmaByte4Modify; - } - - if (!force_exec) { - if ((coex_dm->pre_ps_tdma_on == coex_dm->cur_ps_tdma_on) && - (coex_dm->pre_ps_tdma == coex_dm->cur_ps_tdma)) - return; - } - - if (coex_dm->cur_ps_tdma_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** TDMA(on, %d) **********\n", - coex_dm->cur_ps_tdma); - BTC_TRACE(trace_buf); - - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x550, 0x8, - 0x1); /* enable TBTT nterrupt */ - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** TDMA(off, %d) **********\n", - coex_dm->cur_ps_tdma); - BTC_TRACE(trace_buf); - } - - - if (turn_on) { - switch (type) { - default: - halbtc8821c1ant_set_fw_pstdma(btcoexist, - 0x61, 0x35, 0x03, 0x11, 0x11); - break; - - case 3: - halbtc8821c1ant_set_fw_pstdma(btcoexist, - 0x51, 0x3a, 0x03, 0x10, 0x50); - break; - case 4: - halbtc8821c1ant_set_fw_pstdma(btcoexist, - 0x51, 0x21, 0x03, 0x10, 0x50); - break; - case 5: - halbtc8821c1ant_set_fw_pstdma(btcoexist, - 0x61, 0x15, 0x03, 0x11, 0x11); - break; - case 6: - halbtc8821c1ant_set_fw_pstdma(btcoexist, - 0x61, 0x20, 0x03, 0x11, 0x11); - break; - case 7: - halbtc8821c1ant_set_fw_pstdma(btcoexist, - 0x51, 0x10, 0x03, 0x10, 0x54 | - psTdmaByte4Modify); - break; - case 8: - halbtc8821c1ant_set_fw_pstdma(btcoexist, - 0x51, 0x10, 0x03, 0x10, 0x54 | - psTdmaByte4Modify); - break; - case 9: - halbtc8821c1ant_set_fw_pstdma(btcoexist, - 0x55, 0x10, 0x03, 0x10, 0x54 | - psTdmaByte4Modify); - break; - case 10: - halbtc8821c1ant_set_fw_pstdma(btcoexist, - 0x61, 0x30, 0x03, 0x11, 0x10); - break; - case 13: - halbtc8821c1ant_set_fw_pstdma(btcoexist, - 0x51, 0x25, 0x03, 0x10, 0x50 | - psTdmaByte4Modify); - break; - case 14: - halbtc8821c1ant_set_fw_pstdma(btcoexist, - 0x51, 0x15, 0x03, 0x10, 0x50 | - psTdmaByte4Modify); - break; - case 15: - halbtc8821c1ant_set_fw_pstdma(btcoexist, - 0x51, 0x20, 0x03, 0x10, 0x50 | - psTdmaByte4Modify); - break; - case 17: - halbtc8821c1ant_set_fw_pstdma(btcoexist, - 0x61, 0x10, 0x03, 0x11, 0x14 | - psTdmaByte4Modify); - break; - case 18: - halbtc8821c1ant_set_fw_pstdma(btcoexist, - 0x51, 0x30, 0x03, 0x10, 0x50 | - psTdmaByte4Modify); - break; - case 19: - halbtc8821c1ant_set_fw_pstdma(btcoexist, - 0x61, 0x15, 0x03, 0x11, 0x10); - break; - case 20: - halbtc8821c1ant_set_fw_pstdma(btcoexist, - 0x61, 0x30, 0x03, 0x11, 0x10); - break; - case 21: - halbtc8821c1ant_set_fw_pstdma(btcoexist, - 0x61, 0x30, 0x03, 0x11, 0x10); - break; - case 22: - halbtc8821c1ant_set_fw_pstdma(btcoexist, - 0x61, 0x25, 0x03, 0x11, 0x10); - break; - case 32: - halbtc8821c1ant_set_fw_pstdma(btcoexist, - 0x61, 0x35, 0x03, 0x11, 0x10); - break; - case 33: - halbtc8821c1ant_set_fw_pstdma(btcoexist, - 0x61, 0x35, 0x03, 0x11, 0x10); - break; - case 57: - halbtc8821c1ant_set_fw_pstdma(btcoexist, - 0x51, 0x10, 0x03, 0x10, 0x50 | - psTdmaByte4Modify); - break; - case 58: - halbtc8821c1ant_set_fw_pstdma(btcoexist, - 0x51, 0x10, 0x03, 0x10, 0x50 | - psTdmaByte4Modify); - break; - case 67: - halbtc8821c1ant_set_fw_pstdma(btcoexist, - 0x61, 0x10, 0x03, 0x11, 0x10 | - psTdmaByte4Modify); - break; - - /* 1-Ant to 2-Ant TDMA case */ - case 103: - halbtc8821c1ant_set_fw_pstdma(btcoexist, - 0xd3, 0x3a, 0x03, 0x70, 0x10); - break; - case 104: - halbtc8821c1ant_set_fw_pstdma(btcoexist, - 0xd3, 0x21, 0x03, 0x70, 0x10); - break; - case 105: - halbtc8821c1ant_set_fw_pstdma(btcoexist, - 0xe3, 0x15, 0x03, 0x71, 0x11); - break; - case 106: - halbtc8821c1ant_set_fw_pstdma(btcoexist, - 0xe3, 0x20, 0x03, 0x71, 0x11); - break; - case 107: - halbtc8821c1ant_set_fw_pstdma(btcoexist, - 0xd3, 0x10, 0x03, 0x70, 0x14 | - psTdmaByte4Modify); - break; - case 108: - halbtc8821c1ant_set_fw_pstdma(btcoexist, - 0xd3, 0x10, 0x03, 0x70, 0x14 | - psTdmaByte4Modify); - break; - case 113: - halbtc8821c1ant_set_fw_pstdma(btcoexist, - 0xd3, 0x25, 0x03, 0x70, 0x10 | - psTdmaByte4Modify); - break; - case 114: - halbtc8821c1ant_set_fw_pstdma(btcoexist, - 0xd3, 0x15, 0x03, 0x70, 0x10 | - psTdmaByte4Modify); - break; - case 115: - halbtc8821c1ant_set_fw_pstdma(btcoexist, - 0xd3, 0x20, 0x03, 0x70, 0x10 | - psTdmaByte4Modify); - break; - case 117: - halbtc8821c1ant_set_fw_pstdma(btcoexist, - 0xe3, 0x10, 0x03, 0x71, 0x14 | - psTdmaByte4Modify); - break; - case 119: - halbtc8821c1ant_set_fw_pstdma(btcoexist, - 0xe3, 0x15, 0x03, 0x71, 0x10); - break; - case 120: - halbtc8821c1ant_set_fw_pstdma(btcoexist, - 0xe3, 0x30, 0x03, 0x71, 0x10); - break; - case 121: - halbtc8821c1ant_set_fw_pstdma(btcoexist, - 0xe3, 0x30, 0x03, 0x71, 0x10); - break; - case 122: - halbtc8821c1ant_set_fw_pstdma(btcoexist, - 0xe3, 0x25, 0x03, 0x71, 0x10); - break; - case 132: - halbtc8821c1ant_set_fw_pstdma(btcoexist, - 0xe3, 0x35, 0x03, 0x71, 0x11); - break; - case 133: - halbtc8821c1ant_set_fw_pstdma(btcoexist, - 0xe3, 0x35, 0x03, 0x71, 0x10); - break; - - } - } else { - - /* disable PS tdma */ - switch (type) { - case 8: /* PTA Control */ - halbtc8821c1ant_set_fw_pstdma(btcoexist, 0x8, - 0x0, 0x0, 0x0, 0x0); - break; - case 0: - default: /* Software control, Antenna at BT side */ - halbtc8821c1ant_set_fw_pstdma(btcoexist, 0x0, - 0x0, 0x0, 0x0, 0x0); - break; - case 1: /* 2-Ant, 0x778=3, antenna control by antenna diversity */ - halbtc8821c1ant_set_fw_pstdma(btcoexist, 0x0, - 0x0, 0x0, 0x48, 0x0); - break; - } - } - - /* update pre state */ - coex_dm->pre_ps_tdma_on = coex_dm->cur_ps_tdma_on; - coex_dm->pre_ps_tdma = coex_dm->cur_ps_tdma; -} - -void halbtc8821c1ant_set_int_block(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 pos_type) -{ -#if 0 - u8 regval_0xcba; - u32 u32tmp1 = 0; - - coex_dm->cur_int_block_status = pos_type; - - if (!force_exec) { - if (coex_dm->pre_int_block_status == - coex_dm->cur_int_block_status) - return; - } - - coex_dm->pre_int_block_status = coex_dm->cur_int_block_status; - - regval_0xcba = btcoexist->btc_read_1byte(btcoexist, 0xcba); - - switch (pos_type) { - - case BT_8821C_1ANT_INT_BLOCK_SWITCH_TO_WLG_OF_BTG: - regval_0xcba = (regval_0xcba | BIT(0)) & (~(BIT( - 2))); /* 0xcb8[16] = 1, 0xcb8[18] = 0, WL_G select BTG */ - regval_0xcba = regval_0xcba & 0x0f; - - /*btcoexist->btc_write_1byte_bitmask(btcoexist, 0xc1d, 0x0f, 0x5); */ /* Gain Table */ - /*btcoexist->btc_write_1byte_bitmask(btcoexist, 0xa9e, 0x0f, 0x2); */ /* CCK Gain Table */ - - break; - case BT_8821C_1ANT_INT_BLOCK_SWITCH_TO_WLG_OF_WLAG: - regval_0xcba = regval_0xcba & (~(BIT(2) | BIT( - 0))); /* 0xcb8[16] = 0, 0xcb8[18] = 0, WL_G select WLAG */ - - /* regval_0xcba = regval_0xcba | BIT(4) | BIT(5) ; */ /* 0xcb8[21:20] = 2b'11, WL_G @ WLAG on */ - /* regval_0xcba = (regval_0xcba | BIT(6)) & (~(BIT(7)) ) ; */ /* 0xcb8[23:22] = 2b'01, WL_A @ WLAG off */ - /*btcoexist->btc_write_1byte_bitmask(btcoexist, 0xc1d, 0x0f, 0x0); */ /* Gain Table */ - /*btcoexist->btc_write_1byte_bitmask(btcoexist, 0xa9e, 0x0f, 0x6); */ /* CCK Gain Table */ - - break; - case BT_8821C_1ANT_INT_BLOCK_SWITCH_TO_WLA_OF_WLAG: - regval_0xcba = regval_0xcba & (~(BIT(2) | BIT( - 0))); /* 0xcb8[16] = 0, 0xcb8[18] = 0, WL_G select WLAG */ - /*regval_0xcba = (regval_0xcba | BIT(4)) & (~(BIT(5))); */ /* 0xcb8[21:20] = 2b'01, WL_G @ WLAG off */ - /*regval_0xcba = regval_0xcba | BIT(6) | BIT(7); */ /* 0xcb8[23:22] = 2b'11, WL_A @ WLAG on */ - - break; - } - - btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcba, 0xff, - regval_0xcba); - - u32tmp1 = btcoexist->btc_read_4byte(btcoexist, 0xcb8); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** (After Int Block setup) 0xcb8 = 0x%08x **********\n", - u32tmp1); - BTC_TRACE(trace_buf); - -#endif -} - -void halbtc8821c1ant_set_ext_band_switch(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 pos_type) -{ - -#if 0 - boolean switch_polatiry_inverse = false; - u8 regval_0xcb6; - u32 u32tmp1 = 0, u32tmp2 = 0; - - if (!rfe_type->ext_band_switch_exist) - return; - - coex_dm->cur_ext_band_switch_status = pos_type; - - if (!force_exec) { - if (coex_dm->pre_ext_band_switch_status == - coex_dm->cur_ext_band_switch_status) - return; - } - - coex_dm->pre_ext_band_switch_status = - coex_dm->cur_ext_band_switch_status; - - /* swap control polarity if use different switch control polarity*/ - switch_polatiry_inverse = (rfe_type->ext_band_switch_ctrl_polarity == 1 - ? ~switch_polatiry_inverse : switch_polatiry_inverse); - - /*swap control polarity for WL_A, default polarity 0xcb4[21] = 0 && 0xcb4[23] = 1 is for WL_G */ - switch_polatiry_inverse = (pos_type == - BT_8821C_1ANT_EXT_BAND_SWITCH_TO_WLA ? ~switch_polatiry_inverse - : switch_polatiry_inverse); - - regval_0xcb6 = btcoexist->btc_read_1byte(btcoexist, 0xcb6); - - /* for normal switch polrity, 0xcb4[21] =1 && 0xcb4[23] = 0 for WL_A, vice versa */ - regval_0xcb6 = (switch_polatiry_inverse == 1 ? ((regval_0xcb6 & (~(BIT( - 7)))) | BIT(5)) : ((regval_0xcb6 & (~(BIT(5)))) | BIT(7))); - - btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb6, 0xff, - regval_0xcb6); - - u32tmp1 = btcoexist->btc_read_4byte(btcoexist, 0xcb0); - u32tmp2 = btcoexist->btc_read_4byte(btcoexist, 0xcb4); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** (After Ext Band switch setup) 0xcb0 = 0x%08x, 0xcb4 = 0x%08x**********\n", - u32tmp1, u32tmp2); - BTC_TRACE(trace_buf); -#endif - -} - -void halbtc8821c1ant_set_ext_ant_switch(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 ctrl_type, IN u8 pos_type) -{ - struct btc_board_info *board_info = &btcoexist->board_info; - boolean switch_polatiry_inverse = false; - u8 regval_0xcb7 = 0, regval_0x64; - u32 u32tmp1 = 0, u32tmp2 = 0, u32tmp3 = 0; - - if (!rfe_type->ext_ant_switch_exist) - return; - - coex_dm->cur_ext_ant_switch_status = (ctrl_type << 8) + pos_type; - - if (!force_exec) { - if (coex_dm->pre_ext_ant_switch_status == - coex_dm->cur_ext_ant_switch_status) - return; - } - - coex_dm->pre_ext_ant_switch_status = coex_dm->cur_ext_ant_switch_status; - - /* swap control polarity if use different switch control polarity*/ - /* Normal switch polarity for DPDT, 0xcb4[29:28] = 2b'01 => BTG to Main, WLG to Aux, 0xcb4[29:28] = 2b'10 => BTG to Aux, WLG to Main */ - /* Normal switch polarity for SPDT, 0xcb4[29:28] = 2b'01 => Ant to BTG, 0xcb4[29:28] = 2b'10 => Ant to WLG */ - switch_polatiry_inverse = (rfe_type->ext_ant_switch_ctrl_polarity == 1 ? - ~switch_polatiry_inverse : switch_polatiry_inverse); - - /* swap control polarity if 1-Ant at Aux */ - if ((rfe_type->ext_ant_switch_type == - BT_8821C_1ANT_EXT_ANT_SWITCH_USE_DPDT) && - (board_info->single_ant_path == 0)) - switch_polatiry_inverse = ~switch_polatiry_inverse; - - switch (pos_type) { - default: - case BT_8821C_1ANT_EXT_ANT_SWITCH_TO_BT: - case BT_8821C_1ANT_EXT_ANT_SWITCH_TO_NOCARE: - - break; - case BT_8821C_1ANT_EXT_ANT_SWITCH_TO_WLG: - switch_polatiry_inverse = (rfe_type->wlg_Locate_at_btg - == 0 ? ~switch_polatiry_inverse : - switch_polatiry_inverse); - break; - case BT_8821C_1ANT_EXT_ANT_SWITCH_TO_WLA: - /*switch_polatiry_inverse = (rfe_type->ext_band_switch_exist == 1? ~switch_polatiry_inverse: switch_polatiry_inverse);*/ - break; - } - - if (board_info->ant_div_cfg) - ctrl_type = BT_8821C_1ANT_EXT_ANT_SWITCH_CTRL_BY_ANTDIV; - - - switch (ctrl_type) { - default: - case BT_8821C_1ANT_EXT_ANT_SWITCH_CTRL_BY_BBSW: - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4e, - 0x80, 0x0); /* 0x4c[23] = 0 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4f, - 0x01, 0x1); /* 0x4c[24] = 1 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb4, - 0xff, 0x77); /* BB SW, DPDT use RFE_ctrl8 and RFE_ctrl9 as control pin */ - - regval_0xcb7 = (switch_polatiry_inverse == false ? - 0x1 : 0x2); /* 0xcb4[29:28] = 2b'01 for no switch_polatiry_inverse, DPDT_SEL_N =1, DPDT_SEL_P =0 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb7, - 0x30, regval_0xcb7); - - break; - case BT_8821C_1ANT_EXT_ANT_SWITCH_CTRL_BY_PTA: - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4e, - 0x80, 0x0); /* 0x4c[23] = 0 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4f, - 0x01, 0x1); /* 0x4c[24] = 1 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb4, - 0xff, 0x66); /* PTA, DPDT use RFE_ctrl8 and RFE_ctrl9 as control pin */ - - regval_0xcb7 = (switch_polatiry_inverse == false ? - 0x2 : 0x1); /* 0xcb4[29:28] = 2b'10 for no switch_polatiry_inverse, DPDT_SEL_N =1, DPDT_SEL_P =0 @ GNT_BT=1 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb7, - 0x30, regval_0xcb7); - - break; - case BT_8821C_1ANT_EXT_ANT_SWITCH_CTRL_BY_ANTDIV: - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4e, - 0x80, 0x0); /* 0x4c[23] = 0 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4f, - 0x01, 0x1); /* 0x4c[24] = 1 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb4, - 0xff, 0x88); /* */ - - /* no regval_0xcb7 setup required, because antenna switch control value by antenna diversity */ - - break; - case BT_8821C_1ANT_EXT_ANT_SWITCH_CTRL_BY_MAC: - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4e, - 0x80, 0x1); /* 0x4c[23] = 1 */ - - regval_0x64 = (switch_polatiry_inverse == false ? 0x0 : - 0x1); /* 0x64[0] = 1b'0 for no switch_polatiry_inverse, DPDT_SEL_N =1, DPDT_SEL_P =0 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x64, 0x1, - regval_0x64); - break; - case BT_8821C_1ANT_EXT_ANT_SWITCH_CTRL_BY_BT: - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4e, - 0x80, 0x0); /* 0x4c[23] = 0 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4f, - 0x01, 0x0); /* 0x4c[24] = 0 */ - - /* no setup required, because antenna switch control value by BT vendor 0xac[1:0] */ - break; - } - - /* PAPE, LNA_ON control by BT while WLAN off for current leakage issue */ - if (ctrl_type == BT_8821C_1ANT_EXT_ANT_SWITCH_CTRL_BY_BT) { - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, 0x20, - 0x0); /* PAPE 0x64[29] = 0 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, 0x10, - 0x0); /* LNA_ON 0x64[28] = 0 */ - } else { - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, 0x20, - 0x1); /* PAPE 0x64[29] = 1 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, 0x10, - 0x1); /* LNA_ON 0x64[28] = 1 */ - } - -#if BT_8821C_1ANT_COEX_DBG - u32tmp1 = btcoexist->btc_read_4byte(btcoexist, 0xcb4); - u32tmp2 = btcoexist->btc_read_4byte(btcoexist, 0x4c); - u32tmp3 = btcoexist->btc_read_4byte(btcoexist, 0x64) & 0xff; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], (After Ext Ant switch setup) 0xcb4 = 0x%08x, 0x4c = 0x%08x, 0x64= 0x%02x\n", - u32tmp1, u32tmp2, u32tmp3); - BTC_TRACE(trace_buf); -#endif - -} - -void halbtc8821c1ant_set_rfe_type(IN struct btc_coexist *btcoexist) -{ - struct btc_board_info *board_info = &btcoexist->board_info; - -#if 0 - rfe_type->ext_band_switch_exist = false; - rfe_type->ext_band_switch_type = - BT_8821C_1ANT_EXT_BAND_SWITCH_USE_SPDT; /* SPDT; */ - rfe_type->ext_band_switch_ctrl_polarity = 0; - - if (rfe_type->ext_band_switch_exist) { - - /* band switch use RFE_ctrl1 (pin name: PAPE_A) and RFE_ctrl3 (pin name: LNAON_A) */ - - /* set RFE_ctrl1 as software control */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb0, 0xf0, 0x7); - - /* set RFE_ctrl3 as software control */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb1, 0xf0, 0x7); - - } -#endif - - /* the following setup should be got from Efuse in the future */ - rfe_type->rfe_module_type = board_info->rfe_type & 0x1f; - - rfe_type->ext_ant_switch_ctrl_polarity = 0; - - switch (rfe_type->rfe_module_type) { - case 0: - default: - rfe_type->ext_ant_switch_exist = true; - rfe_type->ext_ant_switch_type = - BT_8821C_1ANT_EXT_ANT_SWITCH_USE_DPDT; /*2-Ant, DPDT, WLG*/ - rfe_type->wlg_Locate_at_btg = false; - break; - case 1: - rfe_type->ext_ant_switch_exist = true; - rfe_type->ext_ant_switch_type = - BT_8821C_1ANT_EXT_ANT_SWITCH_USE_SPDT; /*1-Ant, Main, DPDT or SPDT, WLG */ - rfe_type->wlg_Locate_at_btg = false; - break; - case 2: - rfe_type->ext_ant_switch_exist = true; - rfe_type->ext_ant_switch_type = - BT_8821C_1ANT_EXT_ANT_SWITCH_USE_SPDT; /*1-Ant, Main, DPDT or SPDT, BTG */ - rfe_type->wlg_Locate_at_btg = true; - break; - case 3: - rfe_type->ext_ant_switch_exist = true; - rfe_type->ext_ant_switch_type = - BT_8821C_1ANT_EXT_ANT_SWITCH_USE_DPDT; /*1-Ant, Aux, DPDT, WLG */ - rfe_type->wlg_Locate_at_btg = false; - break; - case 4: - rfe_type->ext_ant_switch_exist = true; - rfe_type->ext_ant_switch_type = - BT_8821C_1ANT_EXT_ANT_SWITCH_USE_DPDT; /*1-Ant, Aux, DPDT, BTG */; - rfe_type->wlg_Locate_at_btg = true; - break; - case 5: - rfe_type->ext_ant_switch_exist = - false; /*2-Ant, no antenna switch, WLG*/ - rfe_type->ext_ant_switch_type = - BT_8821C_1ANT_EXT_ANT_SWITCH_NONE; - rfe_type->wlg_Locate_at_btg = false; - break; - case 6: - rfe_type->ext_ant_switch_exist = - false; /*2-Ant, no antenna switch, WLG*/ - rfe_type->ext_ant_switch_type = - BT_8821C_1ANT_EXT_ANT_SWITCH_NONE; - rfe_type->wlg_Locate_at_btg = false; - break; - case 7: - rfe_type->ext_ant_switch_exist = - true; /*2-Ant, DPDT, BTG*/ - rfe_type->ext_ant_switch_type = - BT_8821C_1ANT_EXT_ANT_SWITCH_USE_DPDT; - rfe_type->wlg_Locate_at_btg = true; - break; - } - - - if (rfe_type->wlg_Locate_at_btg) - halbtc8821c1ant_set_int_block(btcoexist, FORCE_EXEC, - BT_8821C_1ANT_INT_BLOCK_SWITCH_TO_WLG_OF_BTG); - else - halbtc8821c1ant_set_int_block(btcoexist, FORCE_EXEC, - BT_8821C_1ANT_INT_BLOCK_SWITCH_TO_WLG_OF_WLAG); - - -} - - -void halbtc8821c1ant_set_ant_path(IN struct btc_coexist *btcoexist, - IN u8 ant_pos_type, IN boolean force_exec, - IN u8 phase) -{ - struct btc_board_info *board_info = &btcoexist->board_info; - u32 cnt_bt_cal_chk = 0; - boolean is_in_mp_mode = false; - u8 u8tmp = 0; - u32 u32tmp1 = 0, u32tmp2 = 0, u32tmp3 = 0; - u16 u16tmp1 = 0; - -#if BT_8821C_1ANT_ANTDET_ENABLE - - if (ant_pos_type == BTC_ANT_PATH_PTA) { - if ((board_info->btdm_ant_det_finish) && - (board_info->btdm_ant_num_by_ant_det == 2)) { - if (board_info->btdm_ant_pos == - BTC_ANTENNA_AT_MAIN_PORT) - ant_pos_type = BTC_ANT_PATH_WIFI; - else - ant_pos_type = BTC_ANT_PATH_BT; - } - } - -#endif - -#if 1 - u32tmp1 = halbtc8821c1ant_ltecoex_indirect_read_reg(btcoexist, - 0x38); - u32tmp2 = halbtc8821c1ant_ltecoex_indirect_read_reg(btcoexist, - 0x54); - u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x73); - - u32tmp3 = btcoexist->btc_read_4byte(btcoexist, 0xcb4); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex],(Before Ant Setup) 0xcb4 = 0x%x, 0x73 = 0x%x, 0x38= 0x%x, 0x54= 0x%x\n", - u32tmp3, u8tmp, u32tmp1, u32tmp2); - BTC_TRACE(trace_buf); -#endif - - coex_dm->cur_ant_pos_type = (ant_pos_type << 8) + phase; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex],(Before Ant Setup) pre_ant_pos_type = 0x%x, cur_ant_pos_type = 0x%x\n", - coex_dm->pre_ant_pos_type, - coex_dm->cur_ant_pos_type); - BTC_TRACE(trace_buf); - - - if (!force_exec) { - if (coex_dm->cur_ant_pos_type == coex_dm->pre_ant_pos_type) - return; - } - - coex_dm->pre_ant_pos_type = coex_dm->cur_ant_pos_type; - - - switch (phase) { - case BT_8821C_1ANT_PHASE_COEX_POWERON: - - /* set Path control owner to WL at initial step */ - halbtc8821c1ant_ltecoex_pathcontrol_owner(btcoexist, - BT_8821C_1ANT_PCO_BTSIDE); - - /* set GNT_BT to SW high */ - halbtc8821c1ant_ltecoex_set_gnt_bt(btcoexist, - BT_8821C_1ANT_GNT_BLOCK_RFC_BB, - BT_8821C_1ANT_GNT_TYPE_CTRL_BY_SW, - BT_8821C_1ANT_SIG_STA_SET_TO_HIGH); - /* Set GNT_WL to SW high */ - halbtc8821c1ant_ltecoex_set_gnt_wl(btcoexist, - BT_8821C_1ANT_GNT_BLOCK_RFC_BB, - BT_8821C_1ANT_GNT_TYPE_CTRL_BY_SW, - BT_8821C_1ANT_SIG_STA_SET_TO_HIGH); - - if (BTC_ANT_PATH_AUTO == ant_pos_type) - ant_pos_type = BTC_ANT_PATH_BT; - - coex_sta->run_time_state = false; - - break; - case BT_8821C_1ANT_PHASE_COEX_INIT: - /* Disable LTE Coex Function in WiFi side (this should be on if LTE coex is required) */ - halbtc8821c1ant_ltecoex_enable(btcoexist, 0x0); - - /* GNT_WL_LTE always = 1 (this should be config if LTE coex is required) */ - halbtc8821c1ant_ltecoex_set_coex_table( - btcoexist, - BT_8821C_1ANT_CTT_WL_VS_LTE, - 0xffff); - - /* GNT_BT_LTE always = 1 (this should be config if LTE coex is required) */ - halbtc8821c1ant_ltecoex_set_coex_table( - btcoexist, - BT_8821C_1ANT_CTT_BT_VS_LTE, - 0xffff); - - /* Wait If BT IQK running, because Path control owner is at BT during BT IQK (setup by WiFi firmware) */ - while (cnt_bt_cal_chk <= 20) { - u8tmp = btcoexist->btc_read_1byte( - btcoexist, - 0x49c); - cnt_bt_cal_chk++; - if (u8tmp & BIT(1)) { - BTC_SPRINTF( - trace_buf, - BT_TMP_BUF_SIZE, - "[BTCoex], ########### BT is calibrating (wait cnt=%d) ###########\n", - cnt_bt_cal_chk); - BTC_TRACE( - trace_buf); - delay_ms(50); - } else { - BTC_SPRINTF( - trace_buf, - BT_TMP_BUF_SIZE, - "[BTCoex], ********** BT is NOT calibrating (wait cnt=%d)**********\n", - cnt_bt_cal_chk); - BTC_TRACE( - trace_buf); - break; - } - } - - /* set Path control owner to WL at initial step */ - halbtc8821c1ant_ltecoex_pathcontrol_owner( - btcoexist, - BT_8821C_1ANT_PCO_WLSIDE); - - /* set GNT_BT to SW high */ - halbtc8821c1ant_ltecoex_set_gnt_bt(btcoexist, - BT_8821C_1ANT_GNT_BLOCK_RFC_BB, - BT_8821C_1ANT_GNT_TYPE_CTRL_BY_SW, - BT_8821C_1ANT_SIG_STA_SET_TO_HIGH); - /* Set GNT_WL to SW low */ - halbtc8821c1ant_ltecoex_set_gnt_wl(btcoexist, - BT_8821C_1ANT_GNT_BLOCK_RFC_BB, - BT_8821C_1ANT_GNT_TYPE_CTRL_BY_SW, - BT_8821C_1ANT_SIG_STA_SET_TO_LOW); - - coex_sta->run_time_state = false; - - if (BTC_ANT_PATH_AUTO == ant_pos_type) - ant_pos_type = BTC_ANT_PATH_BT; - - break; - case BT_8821C_1ANT_PHASE_WLANONLY_INIT: - /* Disable LTE Coex Function in WiFi side (this should be on if LTE coex is required) */ - halbtc8821c1ant_ltecoex_enable(btcoexist, 0x0); - - /* GNT_WL_LTE always = 1 (this should be config if LTE coex is required) */ - halbtc8821c1ant_ltecoex_set_coex_table( - btcoexist, - BT_8821C_1ANT_CTT_WL_VS_LTE, - 0xffff); - - /* GNT_BT_LTE always = 1 (this should be config if LTE coex is required) */ - halbtc8821c1ant_ltecoex_set_coex_table( - btcoexist, - BT_8821C_1ANT_CTT_BT_VS_LTE, - 0xffff); - - /* set Path control owner to WL at initial step */ - halbtc8821c1ant_ltecoex_pathcontrol_owner( - btcoexist, - BT_8821C_1ANT_PCO_WLSIDE); - - /* set GNT_BT to SW Low */ - halbtc8821c1ant_ltecoex_set_gnt_bt(btcoexist, - BT_8821C_1ANT_GNT_BLOCK_RFC_BB, - BT_8821C_1ANT_GNT_TYPE_CTRL_BY_SW, - BT_8821C_1ANT_SIG_STA_SET_TO_LOW); - /* Set GNT_WL to SW high */ - halbtc8821c1ant_ltecoex_set_gnt_wl(btcoexist, - BT_8821C_1ANT_GNT_BLOCK_RFC_BB, - BT_8821C_1ANT_GNT_TYPE_CTRL_BY_SW, - BT_8821C_1ANT_SIG_STA_SET_TO_HIGH); - - coex_sta->run_time_state = false; - - if (BTC_ANT_PATH_AUTO == ant_pos_type) - ant_pos_type = BTC_ANT_PATH_WIFI; - - break; - case BT_8821C_1ANT_PHASE_WLAN_OFF: - /* Disable LTE Coex Function in WiFi side */ - halbtc8821c1ant_ltecoex_enable(btcoexist, 0x0); - - /* set Path control owner to BT */ - halbtc8821c1ant_ltecoex_pathcontrol_owner( - btcoexist, - BT_8821C_1ANT_PCO_BTSIDE); - - /* Set Ext Ant Switch to BT control at wifi off step */ - halbtc8821c1ant_set_ext_ant_switch(btcoexist, - FORCE_EXEC, - BT_8821C_1ANT_EXT_ANT_SWITCH_CTRL_BY_BT, - BT_8821C_1ANT_EXT_ANT_SWITCH_TO_NOCARE); - - coex_sta->run_time_state = false; - break; - case BT_8821C_1ANT_PHASE_2G_RUNTIME: - - while (cnt_bt_cal_chk <= 20) { - /* 0x49c[0]=1 WL IQK, 0x49c[1]=1 BT IQK*/ - u8tmp = btcoexist->btc_read_1byte( - btcoexist, - 0x49c); - - cnt_bt_cal_chk++; - if (u8tmp & BIT(0)) { - BTC_SPRINTF(trace_buf, - BT_TMP_BUF_SIZE, - "[BTCoex], ########### WL is IQK (wait cnt=%d)\n", - cnt_bt_cal_chk); - BTC_TRACE(trace_buf); - delay_ms(50); - } else if (u8tmp & BIT(1)) { - BTC_SPRINTF(trace_buf, - BT_TMP_BUF_SIZE, - "[BTCoex], ########### BT is IQK (wait cnt=%d)\n", - cnt_bt_cal_chk); - BTC_TRACE(trace_buf); - delay_ms(50); - } else { - BTC_SPRINTF(trace_buf, - BT_TMP_BUF_SIZE, - "[BTCoex], ********** WL and BT is NOT IQK (wait cnt=%d)\n", - cnt_bt_cal_chk); - BTC_TRACE(trace_buf); - break; - } - } - - /* set Path control owner to WL at runtime step */ - halbtc8821c1ant_ltecoex_pathcontrol_owner( - btcoexist, - BT_8821C_1ANT_PCO_WLSIDE); - - /* set GNT_BT to PTA */ - halbtc8821c1ant_ltecoex_set_gnt_bt(btcoexist, - BT_8821C_1ANT_GNT_BLOCK_RFC_BB, - BT_8821C_1ANT_GNT_TYPE_CTRL_BY_PTA, - BT_8821C_1ANT_SIG_STA_SET_BY_HW); - - halbtc8821c1ant_ltecoex_set_gnt_wl(btcoexist, - BT_8821C_1ANT_GNT_BLOCK_RFC_BB, - BT_8821C_1ANT_GNT_TYPE_CTRL_BY_PTA, - BT_8821C_1ANT_SIG_STA_SET_BY_HW); - - coex_sta->run_time_state = true; - - if (BTC_ANT_PATH_AUTO == ant_pos_type) { - if (rfe_type->wlg_Locate_at_btg) - ant_pos_type = - BTC_ANT_PATH_WIFI; - else - ant_pos_type = BTC_ANT_PATH_PTA; - } - - if (rfe_type->wlg_Locate_at_btg) - halbtc8821c1ant_set_int_block(btcoexist, - NORMAL_EXEC, - BT_8821C_1ANT_INT_BLOCK_SWITCH_TO_WLG_OF_BTG); - else - halbtc8821c1ant_set_int_block(btcoexist, - NORMAL_EXEC, - BT_8821C_1ANT_INT_BLOCK_SWITCH_TO_WLG_OF_WLAG); - - break; - case BT_8821C_1ANT_PHASE_5G_RUNTIME: - - /* set Path control owner to WL at runtime step */ - halbtc8821c1ant_ltecoex_pathcontrol_owner( - btcoexist, - BT_8821C_1ANT_PCO_WLSIDE); - - /* set GNT_BT to SW Hi */ - halbtc8821c1ant_ltecoex_set_gnt_bt(btcoexist, - BT_8821C_1ANT_GNT_BLOCK_RFC_BB, - BT_8821C_1ANT_GNT_TYPE_CTRL_BY_PTA, - BT_8821C_1ANT_SIG_STA_SET_BY_HW); - - /* Set GNT_WL to SW Hi */ - halbtc8821c1ant_ltecoex_set_gnt_wl(btcoexist, - BT_8821C_1ANT_GNT_BLOCK_RFC_BB, - BT_8821C_1ANT_GNT_TYPE_CTRL_BY_SW, - BT_8821C_1ANT_SIG_STA_SET_TO_HIGH); - - coex_sta->run_time_state = true; - - if (BTC_ANT_PATH_AUTO == ant_pos_type) { - /* if (rfe_type->ext_band_switch_exist) - ant_pos_type = BTC_ANT_PATH_PTA; - else */ - ant_pos_type = - BTC_ANT_PATH_WIFI5G; - } - - halbtc8821c1ant_set_int_block(btcoexist, - NORMAL_EXEC, - BT_8821C_1ANT_INT_BLOCK_SWITCH_TO_WLA_OF_WLAG); - - break; - case BT_8821C_1ANT_PHASE_BTMPMODE: - /* Disable LTE Coex Function in WiFi side */ - halbtc8821c1ant_ltecoex_enable(btcoexist, 0x0); - - /* set Path control owner to WL */ - halbtc8821c1ant_ltecoex_pathcontrol_owner( - btcoexist, - BT_8821C_1ANT_PCO_WLSIDE); - - /* set GNT_BT to SW Hi */ - halbtc8821c1ant_ltecoex_set_gnt_bt(btcoexist, - BT_8821C_1ANT_GNT_BLOCK_RFC_BB, - BT_8821C_1ANT_GNT_TYPE_CTRL_BY_SW, - BT_8821C_1ANT_SIG_STA_SET_TO_HIGH); - - /* Set GNT_WL to SW Lo */ - halbtc8821c1ant_ltecoex_set_gnt_wl(btcoexist, - BT_8821C_1ANT_GNT_BLOCK_RFC_BB, - BT_8821C_1ANT_GNT_TYPE_CTRL_BY_SW, - BT_8821C_1ANT_SIG_STA_SET_TO_LOW); - - coex_sta->run_time_state = false; - - /* Set Ext Ant Switch to BT side at BT MP mode */ - if (BTC_ANT_PATH_AUTO == ant_pos_type) - ant_pos_type = BTC_ANT_PATH_BT; - - break; - case BT_8821C_1ANT_PHASE_ANTENNA_DET: - halbtc8821c1ant_ltecoex_pathcontrol_owner(btcoexist, - BT_8821C_1ANT_PCO_WLSIDE); - - /* set GNT_BT to high */ - halbtc8821c1ant_ltecoex_set_gnt_bt(btcoexist, - BT_8821C_1ANT_GNT_BLOCK_RFC_BB, - BT_8821C_1ANT_GNT_TYPE_CTRL_BY_SW, - BT_8821C_1ANT_SIG_STA_SET_TO_HIGH); - /* Set GNT_WL to high */ - halbtc8821c1ant_ltecoex_set_gnt_wl(btcoexist, - BT_8821C_1ANT_GNT_BLOCK_RFC_BB, - BT_8821C_1ANT_GNT_TYPE_CTRL_BY_SW, - BT_8821C_1ANT_SIG_STA_SET_TO_HIGH); - - if (BTC_ANT_PATH_AUTO == ant_pos_type) - ant_pos_type = BTC_ANT_PATH_BT; - - coex_sta->run_time_state = false; - - break; - } - - if (phase != BT_8821C_1ANT_PHASE_WLAN_OFF) { - switch (ant_pos_type) { - case BTC_ANT_PATH_WIFI: - halbtc8821c1ant_set_ext_ant_switch( - btcoexist, - force_exec, - BT_8821C_1ANT_EXT_ANT_SWITCH_CTRL_BY_BBSW, - BT_8821C_1ANT_EXT_ANT_SWITCH_TO_WLG); - break; - case BTC_ANT_PATH_WIFI5G - : - halbtc8821c1ant_set_ext_ant_switch( - btcoexist, - force_exec, - BT_8821C_1ANT_EXT_ANT_SWITCH_CTRL_BY_BBSW, - BT_8821C_1ANT_EXT_ANT_SWITCH_TO_WLA); - break; - case BTC_ANT_PATH_BT: - halbtc8821c1ant_set_ext_ant_switch( - btcoexist, - force_exec, - BT_8821C_1ANT_EXT_ANT_SWITCH_CTRL_BY_BBSW, - BT_8821C_1ANT_EXT_ANT_SWITCH_TO_BT); - break; - default: - case BTC_ANT_PATH_PTA: - halbtc8821c1ant_set_ext_ant_switch( - btcoexist, - force_exec, - BT_8821C_1ANT_EXT_ANT_SWITCH_CTRL_BY_PTA, - BT_8821C_1ANT_EXT_ANT_SWITCH_TO_NOCARE); - break; - } - - } -#if 1 - u32tmp1 = halbtc8821c1ant_ltecoex_indirect_read_reg(btcoexist, 0x38); - u32tmp2 = halbtc8821c1ant_ltecoex_indirect_read_reg(btcoexist, 0x54); - u32tmp3 = btcoexist->btc_read_4byte(btcoexist, 0xcb4); - u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x73); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex],(After Ant-Setup phase---%d) 0xcb4 = 0x%x, 0x73 = 0x%x, 0x38= 0x%x, 0x54= 0x%x\n", - phase, u32tmp3, u8tmp, u32tmp1, u32tmp2); - - BTC_TRACE(trace_buf); -#endif -} - - -boolean halbtc8821c1ant_is_common_action(IN struct btc_coexist *btcoexist) -{ - boolean common = false, wifi_connected = false, wifi_busy = false; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - - if (!wifi_connected && - BT_8821C_1ANT_BT_STATUS_NON_CONNECTED_IDLE == - coex_dm->bt_status) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi non connected-idle + BT non connected-idle!!\n"); - BTC_TRACE(trace_buf); - - common = true; - } else if (wifi_connected && - (BT_8821C_1ANT_BT_STATUS_NON_CONNECTED_IDLE == - coex_dm->bt_status)) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi connected + BT non connected-idle!!\n"); - BTC_TRACE(trace_buf); - - common = true; - } else if (!wifi_connected && - (BT_8821C_1ANT_BT_STATUS_CONNECTED_IDLE == - coex_dm->bt_status)) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi non connected-idle + BT connected-idle!!\n"); - BTC_TRACE(trace_buf); - - common = true; - } else if (wifi_connected && - (BT_8821C_1ANT_BT_STATUS_CONNECTED_IDLE == - coex_dm->bt_status)) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi connected + BT connected-idle!!\n"); - BTC_TRACE(trace_buf); - - common = true; - } else if (!wifi_connected && - (BT_8821C_1ANT_BT_STATUS_CONNECTED_IDLE != - coex_dm->bt_status)) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi non connected-idle + BT Busy!!\n"); - BTC_TRACE(trace_buf); - - common = true; - } else { - if (wifi_busy) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi Connected-Busy + BT Busy!!\n"); - BTC_TRACE(trace_buf); - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi Connected-Idle + BT Busy!!\n"); - BTC_TRACE(trace_buf); - } - - common = false; - } - - return common; -} - - -/* ********************************************* - * - * Software Coex Mechanism start - * - * ********************************************* */ - - - -/* ********************************************* - * - * Non-Software Coex Mechanism start - * - * ********************************************* */ -void halbtc8821c1ant_action_bt_whck_test(IN struct btc_coexist *btcoexist) -{ - halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8); - halbtc8821c1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, NORMAL_EXEC, - BT_8821C_1ANT_PHASE_2G_RUNTIME); - halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); -} - -void halbtc8821c1ant_action_wifi_under5g(IN struct btc_coexist *btcoexist) -{ - - halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8); - halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - - halbtc8821c1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, NORMAL_EXEC, - BT_8821C_1ANT_PHASE_5G_RUNTIME); -} - - -void halbtc8821c1ant_action_wifi_only(IN struct btc_coexist *btcoexist) -{ - halbtc8821c1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 8); - halbtc8821c1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, FORCE_EXEC, - BT_8821C_1ANT_PHASE_2G_RUNTIME); - halbtc8821c1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 7); -} - -void halbtc8821c1ant_action_wifi_multi_port(IN struct btc_coexist *btcoexist) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - - halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8); - halbtc8821c1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, NORMAL_EXEC, - BT_8821C_1ANT_PHASE_2G_RUNTIME); - - if (!bt_link_info->pan_exist) - halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - else - halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2); -} - -void halbtc8821c1ant_action_hs(IN struct btc_coexist *btcoexist) -{ - halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 5); - halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2); -} - -void halbtc8821c1ant_action_bt_inquiry(IN struct btc_coexist *btcoexist) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - boolean wifi_connected = false, wifi_busy = false, - bt_busy = false; - boolean wifi_scan = false, wifi_link = false, wifi_roam = false; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bt_busy); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &wifi_scan); - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &wifi_link); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &wifi_roam); - - - if ((wifi_link) || (wifi_roam) || (coex_sta->wifi_is_high_pri_task)) { - - halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 33); - - if ((bt_link_info->sco_exist) || (bt_link_info->hid_exist)) - halbtc8821c1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 1); - else - halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 6); - - } else if (((wifi_scan) || (wifi_busy)) && - (coex_sta->bt_create_connection)) { - - halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 22); - - if ((bt_link_info->sco_exist) || (bt_link_info->hid_exist)) - halbtc8821c1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 1); - else - halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 6); - - } else if ((!wifi_connected) && (!wifi_scan)) { - - halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8); - halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - } else if ((bt_link_info->sco_exist) || (bt_link_info->hid_exist)) { - - halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 6); - halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1); - - } else if ((bt_link_info->a2dp_exist) && (bt_link_info->pan_exist)) { - - halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 22); - halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); - - } else if (bt_link_info->a2dp_exist) { - - halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32); - - halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); - } else if (wifi_scan) { - - halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20); - - halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); - - } else if (wifi_busy) { - halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 21); - - halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); - } else { - halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 19); - - halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); - } -} - -void halbtc8821c1ant_action_bt_sco_hid_only_busy(IN struct btc_coexist - *btcoexist, IN u8 wifi_status) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - boolean wifi_connected = false; - u32 wifi_bw = 1; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, - &wifi_bw); - - if ((wifi_bw == 0) && - ((coex_sta->hid_busy_num >= 2) || - (bt_link_info->sco_exist))) { /* if 11bg mode */ - /*for 4/18 hid or SCO/eSCo */ - halbtc8821c1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 9); - halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 10); - } else { - if (bt_link_info->sco_exist) { - halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 5); - halbtc8821c1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 5); - } else { /* HID */ - halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 6); - halbtc8821c1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 5); - } - } -} - -void halbtc8821c1ant_action_wifi_connected_bt_acl_busy(IN struct btc_coexist - *btcoexist, IN u8 wifi_status) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - boolean wifi_busy = false, wifi_turbo = false; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM, - &coex_sta->scan_ap_num); - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "############# [BTCoex], scan_ap_num = %d\n", - coex_sta->scan_ap_num); - BTC_TRACE(trace_buf); -#if 1 - if ((wifi_busy) && (coex_sta->scan_ap_num <= 4)) - wifi_turbo = true; -#endif - if (bt_link_info->hid_only) { /* HID */ - halbtc8821c1ant_action_bt_sco_hid_only_busy(btcoexist, - wifi_status); - return; - } else if (bt_link_info->a2dp_only) { /* A2DP */ - if (BT_8821C_1ANT_WIFI_STATUS_CONNECTED_IDLE == wifi_status) { - halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 32); - halbtc8821c1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 4); - } else { - - if (coex_sta->scan_ap_num >= - BT_8821C_1ANT_WIFI_NOISY_THRESH) { - - if (coex_sta->is_setupLink) - halbtc8821c1ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 67); - else - halbtc8821c1ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 17); - } else { - if (coex_sta->is_setupLink) - halbtc8821c1ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 57); - else - halbtc8821c1ant_ps_tdma(btcoexist, - NORMAL_EXEC, true, 7); - } - - if (wifi_turbo) - halbtc8821c1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 8); - else - halbtc8821c1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 4); - } - } else if (((bt_link_info->a2dp_exist) && - (bt_link_info->pan_exist)) || - (bt_link_info->hid_exist && bt_link_info->a2dp_exist && - bt_link_info->pan_exist)) { /* A2DP+PAN(OPP,FTP), HID+A2DP+PAN(OPP,FTP) */ - - if (wifi_busy) { - if (((coex_sta->a2dp_bit_pool > 40) && - (coex_sta->a2dp_bit_pool < 255)) || - (!coex_sta->is_A2DP_3M)) - halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 15); - else if (wifi_turbo) - halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 18); - else - halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 13); - } else - halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 14); - - if (bt_link_info->hid_exist) - halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1); - else if (wifi_turbo) - halbtc8821c1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 8); - else - halbtc8821c1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 4); - } else if (bt_link_info->hid_exist && - bt_link_info->a2dp_exist) { /* HID+A2DP */ - - if (coex_sta->is_setupLink) { - halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, - 1); - halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 58); - } else { - - if ((wifi_busy) && (coex_sta->hid_busy_num >= 2)) { /*for 4/18 hid */ - halbtc8821c1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 6); - halbtc8821c1ant_set_wltoggle_coex_table(btcoexist, - NORMAL_EXEC, - 0x2, 0xaa, - 0x5a, 0xaa, - 0xaa); - halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 9); - } else { - halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 8); - halbtc8821c1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 1); - } - } - - } else if ((bt_link_info->pan_only) || (bt_link_info->hid_exist && - bt_link_info->pan_exist)) { /* PAN(OPP,FTP), HID+PAN(OPP,FTP) */ - if (BT_8821C_1ANT_WIFI_STATUS_CONNECTED_IDLE == wifi_status) - halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 4); - else - halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 3); - - if (bt_link_info->hid_exist) - halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1); - else if (wifi_turbo) - halbtc8821c1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 8); - else - halbtc8821c1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 4); - } else { - /* BT no-profile busy (0x9) */ - halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 33); - halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); - } -} - -void halbtc8821c1ant_action_wifi_not_connected(IN struct btc_coexist *btcoexist) -{ - /* tdma and coex table */ - halbtc8821c1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 8); - halbtc8821c1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, NORMAL_EXEC, - BT_8821C_1ANT_PHASE_2G_RUNTIME); - halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); -} - -void halbtc8821c1ant_action_wifi_not_connected_scan(IN struct btc_coexist - *btcoexist) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - boolean wifi_connected = false, bt_hs_on = false; - u32 wifi_link_status = 0; - u32 num_of_wifi_link = 0; - boolean bt_ctrl_agg_buf_size = false; - u8 agg_buf_size = 5; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS, - &wifi_link_status); - - num_of_wifi_link = wifi_link_status >> 16; - - if (num_of_wifi_link >= 2) { - halbtc8821c1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0); - halbtc8821c1ant_limited_rx(btcoexist, NORMAL_EXEC, false, - bt_ctrl_agg_buf_size, agg_buf_size); - - if (coex_sta->c2h_bt_inquiry_page) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "############# [BTCoex], BT Is Inquirying\n"); - BTC_TRACE(trace_buf); - halbtc8821c1ant_action_bt_inquiry(btcoexist); - } else - halbtc8821c1ant_action_wifi_multi_port(btcoexist); - return; - } - - if (coex_sta->c2h_bt_inquiry_page) { - halbtc8821c1ant_action_bt_inquiry(btcoexist); - return; - } else if (bt_hs_on) { - halbtc8821c1ant_action_hs(btcoexist); - return; - } - - /* tdma and coex table */ - if (BT_8821C_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) { - if (bt_link_info->a2dp_exist) { - halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 32); - halbtc8821c1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 4); - } else if (bt_link_info->a2dp_exist && - bt_link_info->pan_exist) { - halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 22); - halbtc8821c1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 4); - } else { - halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 20); - halbtc8821c1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 4); - } - } else if ((BT_8821C_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) || - (BT_8821C_1ANT_BT_STATUS_ACL_SCO_BUSY == - coex_dm->bt_status)) { - halbtc8821c1ant_action_bt_sco_hid_only_busy(btcoexist, - BT_8821C_1ANT_WIFI_STATUS_CONNECTED_SCAN); - } else { - halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8); - halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2); - } -} - -void halbtc8821c1ant_action_wifi_connected_scan(IN struct btc_coexist - *btcoexist) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - boolean wifi_connected = false, bt_hs_on = false; - u32 wifi_link_status = 0; - u32 num_of_wifi_link = 0; - boolean bt_ctrl_agg_buf_size = false; - u8 agg_buf_size = 5; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS, - &wifi_link_status); - - num_of_wifi_link = wifi_link_status >> 16; - - if (num_of_wifi_link >= 2) { - halbtc8821c1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0); - halbtc8821c1ant_limited_rx(btcoexist, NORMAL_EXEC, false, - bt_ctrl_agg_buf_size, agg_buf_size); - - if (coex_sta->c2h_bt_inquiry_page) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "############# [BTCoex], BT Is Inquirying\n"); - BTC_TRACE(trace_buf); - halbtc8821c1ant_action_bt_inquiry(btcoexist); - } else - halbtc8821c1ant_action_wifi_multi_port(btcoexist); - return; - } - - if (coex_sta->c2h_bt_inquiry_page) { - halbtc8821c1ant_action_bt_inquiry(btcoexist); - return; - } else if (bt_hs_on) { - halbtc8821c1ant_action_hs(btcoexist); - return; - } - - - /* tdma and coex table */ - if (BT_8821C_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) { - if (bt_link_info->a2dp_exist) { - halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 32); - halbtc8821c1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 4); - } else if (bt_link_info->a2dp_exist && - bt_link_info->pan_exist) { - halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 22); - halbtc8821c1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 4); - } else { - halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 20); - halbtc8821c1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 4); - } - } else if ((BT_8821C_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) || - (BT_8821C_1ANT_BT_STATUS_ACL_SCO_BUSY == - coex_dm->bt_status)) { - halbtc8821c1ant_action_bt_sco_hid_only_busy(btcoexist, - BT_8821C_1ANT_WIFI_STATUS_CONNECTED_SCAN); - } else { - halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8); - halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2); - } -} - -void halbtc8821c1ant_action_wifi_not_connected_asso_auth( - IN struct btc_coexist *btcoexist) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - boolean wifi_connected = false, bt_hs_on = false; - u32 wifi_link_status = 0; - u32 num_of_wifi_link = 0; - boolean bt_ctrl_agg_buf_size = false; - u8 agg_buf_size = 5; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS, - &wifi_link_status); - - num_of_wifi_link = wifi_link_status >> 16; - - if (num_of_wifi_link >= 2) { - halbtc8821c1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0); - halbtc8821c1ant_limited_rx(btcoexist, NORMAL_EXEC, false, - bt_ctrl_agg_buf_size, agg_buf_size); - - if (coex_sta->c2h_bt_inquiry_page) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "############# [BTCoex], BT Is Inquirying\n"); - BTC_TRACE(trace_buf); - halbtc8821c1ant_action_bt_inquiry(btcoexist); - } else - halbtc8821c1ant_action_wifi_multi_port(btcoexist); - return; - } - - if (coex_sta->c2h_bt_inquiry_page) { - halbtc8821c1ant_action_bt_inquiry(btcoexist); - return; - } else if (bt_hs_on) { - halbtc8821c1ant_action_hs(btcoexist); - return; - } - - /* tdma and coex table */ - if ((bt_link_info->sco_exist) || (bt_link_info->hid_exist) || - (bt_link_info->a2dp_exist)) { - halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32); - halbtc8821c1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 4); - } else if (bt_link_info->pan_exist) { - halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20); - halbtc8821c1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 4); - } else { - halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8); - halbtc8821c1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 2); - } -} - -void halbtc8821c1ant_action_wifi_connected_specific_packet( - IN struct btc_coexist *btcoexist) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - boolean wifi_connected = false, bt_hs_on = false; - u32 wifi_link_status = 0; - u32 num_of_wifi_link = 0; - boolean bt_ctrl_agg_buf_size = false; - u8 agg_buf_size = 5; - boolean wifi_busy = false; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS, - &wifi_link_status); - - num_of_wifi_link = wifi_link_status >> 16; - - if (num_of_wifi_link >= 2) { - halbtc8821c1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0); - halbtc8821c1ant_limited_rx(btcoexist, NORMAL_EXEC, false, - bt_ctrl_agg_buf_size, agg_buf_size); - - if (coex_sta->c2h_bt_inquiry_page) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "############# [BTCoex], BT Is Inquirying\n"); - BTC_TRACE(trace_buf); - halbtc8821c1ant_action_bt_inquiry(btcoexist); - } else - halbtc8821c1ant_action_wifi_multi_port(btcoexist); - return; - } - - if (coex_sta->c2h_bt_inquiry_page) { - halbtc8821c1ant_action_bt_inquiry(btcoexist); - return; - } else if (bt_hs_on) { - halbtc8821c1ant_action_hs(btcoexist); - return; - } - - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - - /* no specific packet process for both WiFi and BT very busy */ - if ((wifi_busy) && ((bt_link_info->pan_exist) || - (coex_sta->num_of_profile >= 2))) - return; - - /* tdma and coex table */ - if ((bt_link_info->sco_exist) || (bt_link_info->hid_exist)) { - halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32); - halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 5); - } else if (bt_link_info->a2dp_exist) { - halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32); - halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); - } else if (bt_link_info->pan_exist) { - halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20); - halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); - } else { - halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8); - halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2); - } -} - -void halbtc8821c1ant_action_wifi_connected(IN struct btc_coexist *btcoexist) -{ - boolean wifi_busy = false; - boolean scan = false, link = false, roam = false; - boolean under_4way = false, wifi_under_5g = false; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], CoexForWifiConnect()===>\n"); - BTC_TRACE(trace_buf); - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g); - - if (wifi_under_5g) { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], WiFi is under 5G!!!\n"); - BTC_TRACE(trace_buf); - - halbtc8821c1ant_action_wifi_under5g(btcoexist); - return; - } - - halbtc8821c1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, - NORMAL_EXEC, - BT_8821C_1ANT_PHASE_2G_RUNTIME); - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS, - &under_4way); - if (under_4way) { - halbtc8821c1ant_action_wifi_connected_specific_packet( - btcoexist); - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], CoexForWifiConnect(), return for wifi is under 4way<===\n"); - BTC_TRACE(trace_buf); - return; - } - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam); - if (scan || link || roam) { - if (scan) - halbtc8821c1ant_action_wifi_connected_scan(btcoexist); - else - halbtc8821c1ant_action_wifi_connected_specific_packet( - btcoexist); - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], CoexForWifiConnect(), return for wifi is under scan<===\n"); - BTC_TRACE(trace_buf); - return; - } - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - - - /* tdma and coex table */ - if (!wifi_busy) { - if (BT_8821C_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) { - halbtc8821c1ant_action_wifi_connected_bt_acl_busy( - btcoexist, - BT_8821C_1ANT_WIFI_STATUS_CONNECTED_IDLE); - } else if ((BT_8821C_1ANT_BT_STATUS_SCO_BUSY == - coex_dm->bt_status) || - (BT_8821C_1ANT_BT_STATUS_ACL_SCO_BUSY == - coex_dm->bt_status)) { - halbtc8821c1ant_action_bt_sco_hid_only_busy(btcoexist, - BT_8821C_1ANT_WIFI_STATUS_CONNECTED_IDLE); - } else { - halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, - 8); - halbtc8821c1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 2); - } - } else { - if (BT_8821C_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) { - halbtc8821c1ant_action_wifi_connected_bt_acl_busy( - btcoexist, - BT_8821C_1ANT_WIFI_STATUS_CONNECTED_BUSY); - } else if ((BT_8821C_1ANT_BT_STATUS_SCO_BUSY == - coex_dm->bt_status) || - (BT_8821C_1ANT_BT_STATUS_ACL_SCO_BUSY == - coex_dm->bt_status)) { - halbtc8821c1ant_action_bt_sco_hid_only_busy(btcoexist, - BT_8821C_1ANT_WIFI_STATUS_CONNECTED_BUSY); - } else { - - halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 32); - halbtc8821c1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 4); - } - } -} - -void halbtc8821c1ant_run_sw_coexist_mechanism(IN struct btc_coexist *btcoexist) -{ - u8 algorithm = 0; - - algorithm = halbtc8821c1ant_action_algorithm(btcoexist); - coex_dm->cur_algorithm = algorithm; - - if (!halbtc8821c1ant_is_common_action(btcoexist)) { - switch (coex_dm->cur_algorithm) { - case BT_8821C_1ANT_COEX_ALGO_SCO: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action algorithm = SCO.\n"); - BTC_TRACE(trace_buf); - /* halbtc8821c1ant_action_sco(btcoexist); */ - break; - case BT_8821C_1ANT_COEX_ALGO_HID: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action algorithm = HID.\n"); - BTC_TRACE(trace_buf); - /* halbtc8821c1ant_action_hid(btcoexist); */ - break; - case BT_8821C_1ANT_COEX_ALGO_A2DP: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action algorithm = A2DP.\n"); - BTC_TRACE(trace_buf); - /* halbtc8821c1ant_action_a2dp(btcoexist); */ - break; - case BT_8821C_1ANT_COEX_ALGO_A2DP_PANHS: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action algorithm = A2DP+PAN(HS).\n"); - BTC_TRACE(trace_buf); - /* halbtc8821c1ant_action_a2dp_pan_hs(btcoexist); */ - break; - case BT_8821C_1ANT_COEX_ALGO_PANEDR: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action algorithm = PAN(EDR).\n"); - BTC_TRACE(trace_buf); - /* halbtc8821c1ant_action_pan_edr(btcoexist); */ - break; - case BT_8821C_1ANT_COEX_ALGO_PANHS: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action algorithm = HS mode.\n"); - BTC_TRACE(trace_buf); - /* halbtc8821c1ant_action_pan_hs(btcoexist); */ - break; - case BT_8821C_1ANT_COEX_ALGO_PANEDR_A2DP: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action algorithm = PAN+A2DP.\n"); - BTC_TRACE(trace_buf); - /* halbtc8821c1ant_action_pan_edr_a2dp(btcoexist); */ - break; - case BT_8821C_1ANT_COEX_ALGO_PANEDR_HID: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action algorithm = PAN(EDR)+HID.\n"); - BTC_TRACE(trace_buf); - /* halbtc8821c1ant_action_pan_edr_hid(btcoexist); */ - break; - case BT_8821C_1ANT_COEX_ALGO_HID_A2DP_PANEDR: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action algorithm = HID+A2DP+PAN.\n"); - BTC_TRACE(trace_buf); - /* halbtc8821c1ant_action_hid_a2dp_pan_edr(btcoexist); */ - break; - case BT_8821C_1ANT_COEX_ALGO_HID_A2DP: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action algorithm = HID+A2DP.\n"); - BTC_TRACE(trace_buf); - /* halbtc8821c1ant_action_hid_a2dp(btcoexist); */ - break; - default: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action algorithm = coexist All Off!!\n"); - BTC_TRACE(trace_buf); - /* halbtc8821c1ant_coex_all_off(btcoexist); */ - break; - } - coex_dm->pre_algorithm = coex_dm->cur_algorithm; - } -} - - -void halbtc8821c1ant_run_coexist_mechanism(IN struct btc_coexist *btcoexist) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - boolean wifi_connected = false, bt_hs_on = false; - boolean increase_scan_dev_num = false; - boolean bt_ctrl_agg_buf_size = false; - boolean miracast_plus_bt = false, wifi_under_5g = false; - u8 agg_buf_size = 5; - u32 wifi_link_status = 0; - u32 num_of_wifi_link = 0, wifi_bw; - u8 iot_peer = BTC_IOT_PEER_UNKNOWN; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], RunCoexistMechanism()===>\n"); - BTC_TRACE(trace_buf); - - if (btcoexist->manual_control) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], RunCoexistMechanism(), return for Manual CTRL <===\n"); - BTC_TRACE(trace_buf); - return; - } - - if (btcoexist->stop_coex_dm) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], RunCoexistMechanism(), return for Stop Coex DM <===\n"); - BTC_TRACE(trace_buf); - return; - } - - if (coex_sta->under_ips) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], wifi is under IPS !!!\n"); - BTC_TRACE(trace_buf); - return; - } - - if (!coex_sta->run_time_state) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], return for run_time_state = false !!!\n"); - BTC_TRACE(trace_buf); - return; - } - - if (coex_sta->freeze_coexrun_by_btinfo) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), return for freeze_coexrun_by_btinfo\n"); - BTC_TRACE(trace_buf); - return; - } - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g); - - if (wifi_under_5g) { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], WiFi is under 5G!!!\n"); - BTC_TRACE(trace_buf); - - halbtc8821c1ant_action_wifi_under5g(btcoexist); - return; - } - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], WiFi is under 2G!!!\n"); - BTC_TRACE(trace_buf); - - halbtc8821c1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, - NORMAL_EXEC, - BT_8821C_1ANT_PHASE_2G_RUNTIME); - - if (coex_sta->bt_whck_test) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT is under WHCK TEST!!!\n"); - BTC_TRACE(trace_buf); - halbtc8821c1ant_action_bt_whck_test(btcoexist); - return; - } - - if (coex_sta->bt_disabled) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT is disabled !!!\n"); - halbtc8821c1ant_action_wifi_only(btcoexist); - return; - } - - if ((BT_8821C_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) || - (BT_8821C_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) || - (BT_8821C_1ANT_BT_STATUS_ACL_SCO_BUSY == coex_dm->bt_status)) - increase_scan_dev_num = true; - - btcoexist->btc_set(btcoexist, BTC_SET_BL_INC_SCAN_DEV_NUM, - &increase_scan_dev_num); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS, - &wifi_link_status); - num_of_wifi_link = wifi_link_status >> 16; - - if ((num_of_wifi_link >= 2) || - (wifi_link_status & WIFI_P2P_GO_CONNECTED)) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "############# [BTCoex], Multi-Port num_of_wifi_link = %d, wifi_link_status = 0x%x\n", - num_of_wifi_link, wifi_link_status); - BTC_TRACE(trace_buf); - - if (bt_link_info->bt_link_exist) { - halbtc8821c1ant_limited_tx(btcoexist, NORMAL_EXEC, 1, 1, - 0, 1); - miracast_plus_bt = true; - } else { - halbtc8821c1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, - 0, 0); - miracast_plus_bt = false; - } - btcoexist->btc_set(btcoexist, BTC_SET_BL_MIRACAST_PLUS_BT, - &miracast_plus_bt); - halbtc8821c1ant_limited_rx(btcoexist, NORMAL_EXEC, false, - bt_ctrl_agg_buf_size, agg_buf_size); - - if (coex_sta->c2h_bt_inquiry_page) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "############# [BTCoex], BT Is Inquirying\n"); - BTC_TRACE(trace_buf); - halbtc8821c1ant_action_bt_inquiry(btcoexist); - } else - halbtc8821c1ant_action_wifi_multi_port(btcoexist); - - - return; - } - - miracast_plus_bt = false; - btcoexist->btc_set(btcoexist, BTC_SET_BL_MIRACAST_PLUS_BT, - &miracast_plus_bt); - - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw); - - if ((bt_link_info->bt_link_exist) && (wifi_connected)) { - halbtc8821c1ant_limited_tx(btcoexist, NORMAL_EXEC, 1, 1, 0, 1); - - btcoexist->btc_get(btcoexist, BTC_GET_U1_IOT_PEER, &iot_peer); - - if (BTC_IOT_PEER_CISCO != iot_peer) { - if (bt_link_info->sco_exist) /* if (bt_link_info->bt_hi_pri_link_exist) */ - halbtc8821c1ant_limited_rx(btcoexist, - NORMAL_EXEC, true, false, 0x5); - else - halbtc8821c1ant_limited_rx(btcoexist, - NORMAL_EXEC, false, false, 0x5); - } else { - if (bt_link_info->sco_exist) - halbtc8821c1ant_limited_rx(btcoexist, - NORMAL_EXEC, true, false, 0x5); - else { - if (BTC_WIFI_BW_HT40 == wifi_bw) - halbtc8821c1ant_limited_rx(btcoexist, - NORMAL_EXEC, false, true, 0x10); - else - halbtc8821c1ant_limited_rx(btcoexist, - NORMAL_EXEC, false, true, 0x8); - } - } - - halbtc8821c1ant_run_sw_coexist_mechanism( - btcoexist); /* just print debug message */ - } else { - halbtc8821c1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0); - - halbtc8821c1ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, - 0x5); - - halbtc8821c1ant_run_sw_coexist_mechanism( - btcoexist); /* just print debug message */ - } - - btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); - if (coex_sta->c2h_bt_inquiry_page) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "############# [BTCoex], BT Is Inquirying\n"); - BTC_TRACE(trace_buf); - halbtc8821c1ant_action_bt_inquiry(btcoexist); - return; - } else if (bt_hs_on) { - halbtc8821c1ant_action_hs(btcoexist); - return; - } - - - if (!wifi_connected) { - boolean scan = false, link = false, roam = false; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], wifi is non connected-idle !!!\n"); - BTC_TRACE(trace_buf); - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam); - - if (scan || link || roam) { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], scan = %d, link = %d, roam = %d !!!\n", - scan, link, roam); - BTC_TRACE(trace_buf); - - if (scan) - halbtc8821c1ant_action_wifi_not_connected_scan( - btcoexist); - else - halbtc8821c1ant_action_wifi_not_connected_asso_auth( - btcoexist); - } else - halbtc8821c1ant_action_wifi_not_connected(btcoexist); - } else /* wifi LPS/Busy */ - halbtc8821c1ant_action_wifi_connected(btcoexist); -} - -void halbtc8821c1ant_init_coex_dm(IN struct btc_coexist *btcoexist) -{ - /* force to reset coex mechanism */ - halbtc8821c1ant_low_penalty_ra(btcoexist, FORCE_EXEC, false); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Coex Mechanism Init!!\n"); - BTC_TRACE(trace_buf); - - coex_sta->pop_event_cnt = 0; - coex_sta->cnt_RemoteNameReq = 0; - coex_sta->cnt_ReInit = 0; - coex_sta->cnt_setupLink = 0; - coex_sta->cnt_IgnWlanAct = 0; - coex_sta->cnt_Page = 0; - - halbtc8821c1ant_query_bt_info(btcoexist); -} - -void halbtc8821c1ant_init_hw_config(IN struct btc_coexist *btcoexist, - IN boolean back_up, IN boolean wifi_only) -{ - u32 u32tmp1 = 0, u32tmp2 = 0, u32tmp3 = 0; - u16 u16tmp1 = 0; - struct btc_board_info *board_info = &btcoexist->board_info; - - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], 1Ant Init HW Config!!\n"); - BTC_TRACE(trace_buf); - - u32tmp3 = btcoexist->btc_read_4byte(btcoexist, 0xcb4); - u32tmp1 = halbtc8821c1ant_ltecoex_indirect_read_reg(btcoexist, 0x38); - u32tmp2 = halbtc8821c1ant_ltecoex_indirect_read_reg(btcoexist, 0x54); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex],(Before Init HW config) 0xcb4 = 0x%x, 0x38= 0x%x, 0x54= 0x%x\n", - u32tmp3, u32tmp1, u32tmp2); - BTC_TRACE(trace_buf); - - - coex_sta->bt_coex_supported_feature = 0; - coex_sta->bt_coex_supported_version = 0; - coex_sta->bt_ble_scan_type = 0; - coex_sta->bt_ble_scan_para[0] = 0; - coex_sta->bt_ble_scan_para[1] = 0; - coex_sta->bt_ble_scan_para[2] = 0; - coex_sta->bt_reg_vendor_ac = 0xffff; - coex_sta->bt_reg_vendor_ae = 0xffff; - coex_sta->isolation_btween_wb = BT_8821C_1ANT_DEFAULT_ISOLATION; - - - /* Setup RF front end type */ - halbtc8821c1ant_set_rfe_type(btcoexist); - - /* 0xf0[15:12] --> Chip Cut information */ - coex_sta->cut_version = (btcoexist->btc_read_1byte(btcoexist, - 0xf1) & 0xf0) >> 4; - - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x550, 0x8, - 0x1); /* enable TBTT nterrupt */ - - /* BT report packet sample rate */ - btcoexist->btc_write_1byte(btcoexist, 0x790, 0x5); - - /* Init 0x778 = 0x1 for 1-Ant */ - btcoexist->btc_write_1byte(btcoexist, 0x778, 0x1); - - /* Enable PTA (3-wire function form BT side) */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x40, 0x20, 0x1); - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x41, 0x02, 0x1); - - /* Enable PTA (tx/rx signal form WiFi side) */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4c6, 0x10, 0x1); - - /* set GNT_BT=1 for coex table select both */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x763, 0x10, 0x1); - - halbtc8821c1ant_enable_gnt_to_gpio(btcoexist, true); - - /* check if WL firmware download ok */ - /*if (btcoexist->btc_read_1byte(btcoexist, 0x80) == 0xc6)*/ - halbtc8821c1ant_post_state_to_bt(btcoexist, - BT_8821C_1ANT_SCOREBOARD_ONOFF, true); - - /* PTA parameter */ - halbtc8821c1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 8); - - halbtc8821c1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 0); - - psd_scan->ant_det_is_ant_det_available = true; - - /* Antenna config */ - if (wifi_only) { - coex_sta->concurrent_rx_mode_on = false; - halbtc8821c1ant_set_ant_path(btcoexist, BTC_ANT_PATH_WIFI, - FORCE_EXEC, - BT_8821C_1ANT_PHASE_WLANONLY_INIT); - - btcoexist->stop_coex_dm = true; - } else { - /*Set BT polluted packet on for Tx rate adaptive not including Tx retry break by PTA, 0x45c[19] =1 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x45e, 0x8, 0x1); - - coex_sta->concurrent_rx_mode_on = true; - /* btcoexist->btc_write_1byte_bitmask(btcoexist, 0x953, 0x2, 0x1); */ - - /* RF 0x1[1] = 0->Set GNT_WL_RF_Rx always = 1 for con-current Rx, mask Tx only */ - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0x2, 0x0); - - halbtc8821c1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, - FORCE_EXEC, - BT_8821C_1ANT_PHASE_COEX_INIT); - - btcoexist->stop_coex_dm = false; - } - - u32tmp3 = btcoexist->btc_read_4byte(btcoexist, 0xcb4); - u32tmp1 = halbtc8821c1ant_ltecoex_indirect_read_reg(btcoexist, 0x38); - u32tmp2 = halbtc8821c1ant_ltecoex_indirect_read_reg(btcoexist, 0x54); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], (After Init HW config) 0xcb4 = 0x%x, 0x38= 0x%x, 0x54= 0x%x\n", - u32tmp3, u32tmp1, u32tmp2); - BTC_TRACE(trace_buf); - -} - -#if 0 -u32 halbtc8821c1ant_psd_log2base(IN struct btc_coexist *btcoexist, IN u32 val) -{ - u8 j; - u32 tmp, tmp2, val_integerd_b = 0, tindex, shiftcount = 0; - u32 result, val_fractiond_b = 0, table_fraction[21] = {0, 432, 332, 274, 232, 200, - 174, 151, 132, 115, 100, 86, 74, 62, 51, 42, - 32, 23, 15, 7, 0 - }; - - if (val == 0) - return 0; - - tmp = val; - - while (1) { - if (tmp == 1) - break; - - tmp = (tmp >> 1); - shiftcount++; - } - - - val_integerd_b = shiftcount + 1; - - tmp2 = 1; - for (j = 1; j <= val_integerd_b; j++) - tmp2 = tmp2 * 2; - - tmp = (val * 100) / tmp2; - tindex = tmp / 5; - - if (tindex > 20) - tindex = 20; - - val_fractiond_b = table_fraction[tindex]; - - result = val_integerd_b * 100 - val_fractiond_b; - - return result; - - -} - -void halbtc8821c1ant_psd_show_antenna_detect_result(IN struct btc_coexist - *btcoexist) -{ - u8 *cli_buf = btcoexist->cli_buf; - struct btc_board_info *board_info = &btcoexist->board_info; - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n============[Antenna Detection info] ============\n"); - CL_PRINTF(cli_buf); - - if (psd_scan->ant_det_result == 12) { /* Get Ant Det from BT */ - - if (board_info->btdm_ant_num_by_ant_det == 1) - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %s (%d~%d)", - "Ant Det Result", "1-Antenna", - BT_8821C_1ANT_ANTDET_PSDTHRES_1ANT, - BT_8821C_1ANT_ANTDET_PSDTHRES_2ANT_GOODISOLATION); - else { - - if (psd_scan->ant_det_psd_scan_peak_val > - (BT_8821C_1ANT_ANTDET_PSDTHRES_2ANT_BADISOLATION) - * 100) - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %s (>%d)", - "Ant Det Result", "2-Antenna (Bad-Isolation)", - BT_8821C_1ANT_ANTDET_PSDTHRES_2ANT_BADISOLATION); - else - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %s (%d~%d)", - "Ant Det Result", "2-Antenna (Good-Isolation)", - BT_8821C_1ANT_ANTDET_PSDTHRES_2ANT_GOODISOLATION, - BT_8821C_1ANT_ANTDET_PSDTHRES_2ANT_BADISOLATION); - } - } else if (psd_scan->ant_det_result == 1) - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s (>%d)", - "Ant Det Result", "2-Antenna (Bad-Isolation)", - BT_8821C_1ANT_ANTDET_PSDTHRES_2ANT_BADISOLATION); - else if (psd_scan->ant_det_result == 2) - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s (%d~%d)", - "Ant Det Result", "2-Antenna (Good-Isolation)", - BT_8821C_1ANT_ANTDET_PSDTHRES_2ANT_GOODISOLATION - + psd_scan->ant_det_thres_offset, - BT_8821C_1ANT_ANTDET_PSDTHRES_2ANT_BADISOLATION); - else - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s (%d~%d)", - "Ant Det Result", "1-Antenna", - BT_8821C_1ANT_ANTDET_PSDTHRES_1ANT, - BT_8821C_1ANT_ANTDET_PSDTHRES_2ANT_GOODISOLATION - + psd_scan->ant_det_thres_offset); - - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s ", - "Antenna Detection Finish", - (board_info->btdm_ant_det_finish - ? "Yes" : "No")); - CL_PRINTF(cli_buf); - - switch (psd_scan->ant_det_result) { - case 0: - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "(BT is not available)"); - break; - case 1: /* 2-Ant bad-isolation */ - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "(BT is available)"); - break; - case 2: /* 2-Ant good-isolation */ - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "(BT is available)"); - break; - case 3: /* 1-Ant */ - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "(BT is available)"); - break; - case 4: - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "(Uncertainty result)"); - break; - case 5: - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "(Pre-Scan fai)"); - break; - case 6: - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "(WiFi is Scanning)"); - break; - case 7: - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "(BT is not idle)"); - break; - case 8: - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "(Abort by WiFi Scanning)"); - break; - case 9: - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "(Antenna Init is not ready)"); - break; - case 10: - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "(BT is Inquiry or page)"); - break; - case 11: - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "(BT is Disabled)"); - case 12: - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "(BT is available, result from BT"); - break; - } - CL_PRINTF(cli_buf); - - if (psd_scan->ant_det_result == 12) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d dB", - "PSD Scan Peak Value", - psd_scan->ant_det_psd_scan_peak_val / 100); - CL_PRINTF(cli_buf); - return; - } - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d", - "Ant Detect Total Count", psd_scan->ant_det_try_count); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d", - "Ant Detect Fail Count", psd_scan->ant_det_fail_count); - CL_PRINTF(cli_buf); - - if ((!board_info->btdm_ant_det_finish) && - (psd_scan->ant_det_result != 5)) - return; - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s", "BT Response", - (psd_scan->ant_det_result ? "ok" : "fail")); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d ms", "BT Tx Time", - psd_scan->ant_det_bt_tx_time); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d", "BT Tx Ch", - psd_scan->ant_det_bt_le_channel); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d", - "WiFi PSD Cent-Ch/Offset/Span", - psd_scan->real_cent_freq, psd_scan->real_offset, - psd_scan->real_span); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d dB", - "PSD Pre-Scan Peak Value", - psd_scan->ant_det_pre_psdscan_peak_val / 100); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s (<= %d)", - "PSD Pre-Scan result", - (psd_scan->ant_det_result != 5 ? "ok" : "fail"), - BT_8821C_1ANT_ANTDET_PSDTHRES_BACKGROUND - + psd_scan->ant_det_thres_offset); - CL_PRINTF(cli_buf); - - if (psd_scan->ant_det_result == 5) - return; - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s dB", - "PSD Scan Peak Value", psd_scan->ant_det_peak_val); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s MHz", - "PSD Scan Peak Freq", psd_scan->ant_det_peak_freq); - CL_PRINTF(cli_buf); - - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s", "TFBGA Package", - (board_info->tfbga_package) ? "Yes" : "No"); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d", - "PSD Threshold Offset", psd_scan->ant_det_thres_offset); - CL_PRINTF(cli_buf); - -} - - - -void halbtc8821c1ant_psd_showdata(IN struct btc_coexist *btcoexist) -{ - u8 *cli_buf = btcoexist->cli_buf; - u32 delta_freq_per_point; - u32 freq, freq1, freq2, n = 0, i = 0, j = 0, m = 0, psd_rep1, psd_rep2; - - if (psd_scan->ant_det_result == 12) - return; - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n\n============[PSD info] (%d)============\n", - psd_scan->psd_gen_count); - CL_PRINTF(cli_buf); - - if (psd_scan->psd_gen_count == 0) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n No data !!\n"); - CL_PRINTF(cli_buf); - return; - } - - if (psd_scan->psd_point == 0) - delta_freq_per_point = 0; - else - delta_freq_per_point = psd_scan->psd_band_width / - psd_scan->psd_point; - - /* if (psd_scan->is_psd_show_max_only) */ - if (0) { - psd_rep1 = psd_scan->psd_max_value / 100; - psd_rep2 = psd_scan->psd_max_value - psd_rep1 * 100; - - freq = ((psd_scan->real_cent_freq - 20) * 1000000 + - psd_scan->psd_max_value_point * delta_freq_per_point); - freq1 = freq / 1000000; - freq2 = freq / 1000 - freq1 * 1000; - - if (freq2 < 100) - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n Freq = %d.0%d MHz", - freq1, freq2); - else - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n Freq = %d.%d MHz", - freq1, freq2); - - if (psd_rep2 < 10) - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - ", Value = %d.0%d dB, (%d)\n", - psd_rep1, psd_rep2, psd_scan->psd_max_value); - else - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - ", Value = %d.%d dB, (%d)\n", - psd_rep1, psd_rep2, psd_scan->psd_max_value); - - CL_PRINTF(cli_buf); - } else { - m = psd_scan->psd_start_point; - n = psd_scan->psd_start_point; - i = 1; - j = 1; - - while (1) { - do { - freq = ((psd_scan->real_cent_freq - 20) * - 1000000 + m * - delta_freq_per_point); - freq1 = freq / 1000000; - freq2 = freq / 1000 - freq1 * 1000; - - if (i == 1) { - if (freq2 == 0) - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "\r\n Freq%6d.000", - freq1); - else if (freq2 < 100) - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "\r\n Freq%6d.0%2d", - freq1, - freq2); - else - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "\r\n Freq%6d.%3d", - freq1, - freq2); - } else if ((i % 8 == 0) || - (m == psd_scan->psd_stop_point)) { - if (freq2 == 0) - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "%6d.000\n", freq1); - else if (freq2 < 100) - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "%6d.0%2d\n", freq1, - freq2); - else - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "%6d.%3d\n", freq1, - freq2); - } else { - if (freq2 == 0) - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "%6d.000", freq1); - else if (freq2 < 100) - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "%6d.0%2d", freq1, - freq2); - else - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "%6d.%3d", freq1, - freq2); - } - - i++; - m++; - CL_PRINTF(cli_buf); - - } while ((i <= 8) && (m <= psd_scan->psd_stop_point)); - - - do { - psd_rep1 = psd_scan->psd_report_max_hold[n] / - 100; - psd_rep2 = psd_scan->psd_report_max_hold[n] - - psd_rep1 * - 100; - - if (j == 1) { - if (psd_rep2 < 10) - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "\r\n Val %7d.0%d", - psd_rep1, - psd_rep2); - else - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "\r\n Val %7d.%d", - psd_rep1, - psd_rep2); - } else if ((j % 8 == 0) || - (n == psd_scan->psd_stop_point)) { - if (psd_rep2 < 10) - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "%7d.0%d\n", psd_rep1, - psd_rep2); - else - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "%7d.%d\n", psd_rep1, - psd_rep2); - } else { - if (psd_rep2 < 10) - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "%7d.0%d", psd_rep1, - psd_rep2); - else - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "%7d.%d", psd_rep1, - psd_rep2); - } - - j++; - n++; - CL_PRINTF(cli_buf); - - } while ((j <= 8) && (n <= psd_scan->psd_stop_point)); - - if ((m > psd_scan->psd_stop_point) || - (n > psd_scan->psd_stop_point)) - break; - - i = 1; - j = 1; - - } - } - - -} - -#pragma optimize("", off) -void halbtc8821c1ant_psd_maxholddata(IN struct btc_coexist *btcoexist, - IN u32 gen_count) -{ - u32 i = 0; - u32 loop_i_max = 0, loop_val_max = 0; - - if (gen_count == 1) { - memcpy(psd_scan->psd_report_max_hold, - psd_scan->psd_report, - BT_8821C_1ANT_ANTDET_PSD_POINTS * sizeof(u32)); - } - - for (i = psd_scan->psd_start_point; - i <= psd_scan->psd_stop_point; i++) { - - /* update max-hold value at each freq point */ - if (psd_scan->psd_report[i] > psd_scan->psd_report_max_hold[i]) - psd_scan->psd_report_max_hold[i] = - psd_scan->psd_report[i]; - - /* search the max value in this seep */ - if (psd_scan->psd_report[i] > loop_val_max) { - loop_val_max = psd_scan->psd_report[i]; - loop_i_max = i; - } - } - - if (gen_count <= BT_8821C_1ANT_ANTDET_PSD_SWWEEPCOUNT) - psd_scan->psd_loop_max_value[gen_count - 1] = loop_val_max; -} - -#pragma optimize("", off) -u32 halbtc8821c1ant_psd_getdata(IN struct btc_coexist *btcoexist, IN u32 point) -{ - /* reg 0x808[9:0]: FFT data x */ - /* reg 0x808[22]: 0-->1 to get 1 FFT data y */ - /* reg 0x8b4[15:0]: FFT data y report */ - - u32 val = 0, psd_report = 0; - int k = 0; - - val = btcoexist->btc_read_4byte(btcoexist, 0x808); - - val &= 0xffbffc00; - val |= point; - - btcoexist->btc_write_4byte(btcoexist, 0x808, val); - - val |= 0x00400000; - btcoexist->btc_write_4byte(btcoexist, 0x808, val); - - while (1) { - if (k++ > BT_8821C_1ANT_ANTDET_SWEEPPOINT_DELAY) - break; - } - - val = btcoexist->btc_read_4byte(btcoexist, 0x8b4); - - psd_report = val & 0x0000ffff; - - return psd_report; -} - -#pragma optimize("", off) -boolean halbtc8821c1ant_psd_sweep_point(IN struct btc_coexist *btcoexist, - IN u32 cent_freq, IN s32 offset, IN u32 span, IN u32 points, - IN u32 avgnum, IN u32 loopcnt) -{ - u32 i = 0, val = 0, n = 0, k = 0, j, point_index = 0; - u32 points1 = 0, psd_report = 0; - u32 start_p = 0, stop_p = 0, delta_freq_per_point = 156250; - u32 psd_center_freq = 20 * 10 ^ 6; - boolean outloop = false, scan , roam, is_sweep_ok = true; - u8 flag = 0; - u32 tmp = 0, u32tmp1 = 0; - u32 wifi_original_channel = 1; - u32 psd_sum = 0, avg_cnt = 0; - u32 i_max = 0, val_max = 0, val_max2 = 0; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx PSD Sweep Start!!\n"); - BTC_TRACE(trace_buf); - - do { - switch (flag) { - case 0: /* Get PSD parameters */ - default: - - psd_scan->psd_band_width = 40 * 1000000; - psd_scan->psd_point = points; - psd_scan->psd_start_base = points / 2; - psd_scan->psd_avg_num = avgnum; - psd_scan->real_cent_freq = cent_freq; - psd_scan->real_offset = offset; - psd_scan->real_span = span; - - - points1 = psd_scan->psd_point; - delta_freq_per_point = psd_scan->psd_band_width / - psd_scan->psd_point; - - /* PSD point setup */ - val = btcoexist->btc_read_4byte(btcoexist, 0x808); - val &= 0xffff0fff; - - switch (psd_scan->psd_point) { - case 128: - val |= 0x0; - break; - case 256: - default: - val |= 0x00004000; - break; - case 512: - val |= 0x00008000; - break; - case 1024: - val |= 0x0000c000; - break; - } - - switch (psd_scan->psd_avg_num) { - case 1: - val |= 0x0; - break; - case 8: - val |= 0x00001000; - break; - case 16: - val |= 0x00002000; - break; - case 32: - default: - val |= 0x00003000; - break; - } - btcoexist->btc_write_4byte(btcoexist, 0x808, val); - - flag = 1; - break; - case 1: /* calculate the PSD point index from freq/offset/span */ - psd_center_freq = psd_scan->psd_band_width / 2 + - offset * (1000000); - - start_p = psd_scan->psd_start_base + (psd_center_freq - - span * (1000000) / 2) / delta_freq_per_point; - psd_scan->psd_start_point = start_p - - psd_scan->psd_start_base; - - stop_p = psd_scan->psd_start_base + (psd_center_freq + - span * (1000000) / 2) / delta_freq_per_point; - psd_scan->psd_stop_point = stop_p - - psd_scan->psd_start_base - 1; - - flag = 2; - break; - case 2: /* set RF channel/BW/Mode */ - - /* set 3-wire off */ - val = btcoexist->btc_read_4byte(btcoexist, 0x88c); - val |= 0x00300000; - btcoexist->btc_write_4byte(btcoexist, 0x88c, val); - - /* CCK off */ - val = btcoexist->btc_read_4byte(btcoexist, 0x800); - val &= 0xfeffffff; - btcoexist->btc_write_4byte(btcoexist, 0x800, val); - - /* Tx-pause on */ - btcoexist->btc_write_1byte(btcoexist, 0x522, 0x6f); - - /* store WiFi original channel */ - wifi_original_channel = btcoexist->btc_get_rf_reg( - btcoexist, BTC_RF_A, 0x18, 0x3ff); - - /* Set RF channel */ - if (cent_freq == 2484) - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, - 0x18, 0x3ff, 0xe); - else - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, - 0x18, 0x3ff, (cent_freq - 2412) / 5 + - 1); /* WiFi TRx Mask on */ - - /* save original RCK value */ - u32tmp1 = btcoexist->btc_get_rf_reg( - btcoexist, BTC_RF_A, 0x1d, 0xfffff); - - /* Enter debug mode */ - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0xde, - 0x2, 0x1); - - /* Set RF Rx filter corner */ - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1d, - 0xfffff, 0x2e); - - - /* Set RF mode = Rx, RF Gain = 0x320a0 */ - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x0, - 0xfffff, 0x320a0); - - while (1) { - if (k++ > BT_8821C_1ANT_ANTDET_SWEEPPOINT_DELAY) - break; - } - flag = 3; - break; - case 3: - psd_scan->psd_gen_count = 0; - for (j = 1; j <= loopcnt; j++) { - - btcoexist->btc_get(btcoexist, - BTC_GET_BL_WIFI_SCAN, &scan); - btcoexist->btc_get(btcoexist, - BTC_GET_BL_WIFI_ROAM, &roam); - - if (scan || roam) { - is_sweep_ok = false; - break; - } - memset(psd_scan->psd_report, 0, - psd_scan->psd_point * sizeof(u32)); - start_p = psd_scan->psd_start_point + - psd_scan->psd_start_base; - stop_p = psd_scan->psd_stop_point + - psd_scan->psd_start_base + 1; - - i = start_p; - point_index = 0; - - while (i < stop_p) { - if (i >= points1) - psd_report = - halbtc8821c1ant_psd_getdata( - btcoexist, i - points1); - else - psd_report = - halbtc8821c1ant_psd_getdata( - btcoexist, i); - - if (psd_report == 0) - tmp = 0; - else - /* tmp = 20*log10((double)psd_report); */ - /* 20*log2(x)/log2(10), log2Base return theresult of the psd_report*100 */ - tmp = 6 * halbtc8821c1ant_psd_log2base( - btcoexist, psd_report); - - n = i - psd_scan->psd_start_base; - psd_scan->psd_report[n] = tmp; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "Point=%d, psd_dB_data = %d\n", - i, psd_scan->psd_report[n]); - BTC_TRACE(trace_buf); - - i++; - - } - - halbtc8821c1ant_psd_maxholddata(btcoexist, j); - - psd_scan->psd_gen_count = j; - - /*Accumulate Max PSD value in this loop if the value > threshold */ - if (psd_scan->psd_loop_max_value[j - 1] >= - 4000) { - psd_sum = psd_sum + - psd_scan->psd_loop_max_value[j - - 1]; - avg_cnt++; - } - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "Loop=%d, Max_dB_data = %d\n", - j, psd_scan->psd_loop_max_value[j - - 1]); - BTC_TRACE(trace_buf); - - } - - if (loopcnt == BT_8821C_1ANT_ANTDET_PSD_SWWEEPCOUNT) { - - /* search the Max Value between each-freq-point-max-hold value of all sweep*/ - for (i = 1; - i <= BT_8821C_1ANT_ANTDET_PSD_SWWEEPCOUNT; - i++) { - - if (i == 1) { - i_max = i; - val_max = psd_scan->psd_loop_max_value[i - - 1]; - val_max2 = - psd_scan->psd_loop_max_value[i - - 1]; - } else if ( - psd_scan->psd_loop_max_value[i - - 1] > val_max) { - val_max2 = val_max; - i_max = i; - val_max = psd_scan->psd_loop_max_value[i - - 1]; - } else if ( - psd_scan->psd_loop_max_value[i - - 1] > val_max2) - val_max2 = - psd_scan->psd_loop_max_value[i - - 1]; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "i = %d, val_hold= %d, val_max = %d, val_max2 = %d\n", - i, psd_scan->psd_loop_max_value[i - - 1], - val_max, val_max2); - - BTC_TRACE(trace_buf); - } - - psd_scan->psd_max_value_point = i_max; - psd_scan->psd_max_value = val_max; - psd_scan->psd_max_value2 = val_max2; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "val_max = %d, val_max2 = %d\n", - psd_scan->psd_max_value, - psd_scan->psd_max_value2); - BTC_TRACE(trace_buf); - } - - if (avg_cnt != 0) { - psd_scan->psd_avg_value = (psd_sum / avg_cnt); - if ((psd_sum % avg_cnt) >= (avg_cnt / 2)) - psd_scan->psd_avg_value++; - } else - psd_scan->psd_avg_value = 0; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "AvgLoop=%d, Avg_dB_data = %d\n", - avg_cnt, psd_scan->psd_avg_value); - BTC_TRACE(trace_buf); - - flag = 100; - break; - case 99: /* error */ - - outloop = true; - break; - case 100: /* recovery */ - - /* set 3-wire on */ - val = btcoexist->btc_read_4byte(btcoexist, 0x88c); - val &= 0xffcfffff; - btcoexist->btc_write_4byte(btcoexist, 0x88c, val); - - /* CCK on */ - val = btcoexist->btc_read_4byte(btcoexist, 0x800); - val |= 0x01000000; - btcoexist->btc_write_4byte(btcoexist, 0x800, val); - - /* Tx-pause off */ - btcoexist->btc_write_1byte(btcoexist, 0x522, 0x0); - - /* PSD off */ - val = btcoexist->btc_read_4byte(btcoexist, 0x808); - val &= 0xffbfffff; - btcoexist->btc_write_4byte(btcoexist, 0x808, val); - - /* restore RF Rx filter corner */ - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1d, - 0xfffff, u32tmp1); - - /* Exit debug mode */ - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0xde, - 0x2, 0x0); - - /* restore WiFi original channel */ - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x18, - 0x3ff, wifi_original_channel); - - outloop = true; - break; - - } - - } while (!outloop); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx PSD Sweep Stop!!\n"); - BTC_TRACE(trace_buf); - return is_sweep_ok; - -} - -#pragma optimize("", off) -boolean halbtc8821c1ant_psd_antenna_detection(IN struct btc_coexist - *btcoexist) -{ - u32 i = 0; - u32 wlpsd_cent_freq = 2484, wlpsd_span = 2; - s32 wlpsd_offset = -4; - u32 bt_tx_time, bt_le_channel; - u8 bt_le_ch[13] = {3, 6, 8, 11, 13, 16, 18, 21, 23, 26, 28, 31, 33}; - - u8 h2c_parameter[3] = {0}, u8tmpa, u8tmpb; - - u8 state = 0; - boolean outloop = false, bt_resp = false, ant_det_finish = false; - u32 freq, freq1, freq2, psd_rep1, psd_rep2, delta_freq_per_point, - u32tmp, u32tmp0, u32tmp1, u32tmp2; - struct btc_board_info *board_info = &btcoexist->board_info; - - memset(psd_scan->ant_det_peak_val, 0, 16 * sizeof(u8)); - memset(psd_scan->ant_det_peak_freq, 0, 16 * sizeof(u8)); - - psd_scan->ant_det_bt_tx_time = - BT_8821C_1ANT_ANTDET_BTTXTIME; /* 0.42ms*50 = 20ms (0.42ms = 1 PSD sweep) */ - psd_scan->ant_det_bt_le_channel = BT_8821C_1ANT_ANTDET_BTTXCHANNEL; - - bt_tx_time = psd_scan->ant_det_bt_tx_time; - bt_le_channel = psd_scan->ant_det_bt_le_channel; - - if (board_info->tfbga_package) /* for TFBGA */ - psd_scan->ant_det_thres_offset = 5; - else - psd_scan->ant_det_thres_offset = 0; - - do { - switch (state) { - case 0: - if (bt_le_channel == 39) - wlpsd_cent_freq = 2484; - else { - for (i = 1; i <= 13; i++) { - if (bt_le_ch[i - 1] == - bt_le_channel) { - wlpsd_cent_freq = 2412 - + (i - 1) * 5; - break; - } - } - - if (i == 14) { - - BTC_SPRINTF(trace_buf, - BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Abort!!, Invalid LE channel = %d\n ", - bt_le_channel); - BTC_TRACE(trace_buf); - outloop = true; - break; - } - } -#if 0 - wlpsd_sweep_count = bt_tx_time * 238 / - 100; /* bt_tx_time/0.42 */ - wlpsd_sweep_count = wlpsd_sweep_count / 5; - - if (wlpsd_sweep_count % 5 != 0) - wlpsd_sweep_count = (wlpsd_sweep_count / - 5 + 1) * 5; -#endif - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), BT_LETxTime=%d, BT_LECh = %d\n", - bt_tx_time, bt_le_channel); - BTC_TRACE(trace_buf); - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), wlpsd_cent_freq=%d, wlpsd_offset = %d, wlpsd_span = %d, wlpsd_sweep_count = %d\n", - wlpsd_cent_freq, - wlpsd_offset, - wlpsd_span, - BT_8821C_1ANT_ANTDET_PSD_SWWEEPCOUNT); - BTC_TRACE(trace_buf); - - state = 1; - break; - case 1: /* stop coex DM & set antenna path */ - /* Stop Coex DM */ - btcoexist->stop_coex_dm = true; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Stop Coex DM!!\n"); - BTC_TRACE(trace_buf); - - /* Set TDMA off, */ - halbtc8821c1ant_ps_tdma(btcoexist, FORCE_EXEC, - false, 0); - - /* Set coex table */ - halbtc8821c1ant_coex_table_with_type(btcoexist, - FORCE_EXEC, 0); - - if (board_info->btdm_ant_pos == - BTC_ANTENNA_AT_MAIN_PORT) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Antenna at Main Port\n"); - BTC_TRACE(trace_buf); - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Antenna at Aux Port\n"); - BTC_TRACE(trace_buf); - } - - /* Set Antenna path, switch WiFi to un-certain antenna port */ - /* Set Antenna Path, both GNT_WL/GNT_BT = 1, and control by SW */ - halbtc8821c1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT, - FORCE_EXEC, - BT_8821C_1ANT_PHASE_ANTENNA_DET); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Set Antenna to BT!!\n"); - BTC_TRACE(trace_buf); - - /* Set AFH mask on at WiFi channel 2472MHz +/- 10MHz */ - h2c_parameter[0] = 0x1; - h2c_parameter[1] = 0xd; - h2c_parameter[2] = 0x14; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Set AFH on, Cent-Ch= %d, Mask=%d\n", - h2c_parameter[1], - h2c_parameter[2]); - BTC_TRACE(trace_buf); - - btcoexist->btc_fill_h2c(btcoexist, 0x66, 3, - h2c_parameter); - - u32tmp0 = btcoexist->btc_read_4byte(btcoexist, 0x70); - u32tmp1 = halbtc8821c1ant_ltecoex_indirect_read_reg( - btcoexist, 0x38); - u32tmp2 = halbtc8821c1ant_ltecoex_indirect_read_reg( - btcoexist, 0x54); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** 0x70 = 0x%x, 0x38= 0x%x, 0x54= 0x%x (Before Ant Det)\n", - u32tmp0, u32tmp1, u32tmp2); - BTC_TRACE(trace_buf); - - state = 2; - break; - case 2: /* Pre-sweep background psd */ - if (!halbtc8821c1ant_psd_sweep_point(btcoexist, - wlpsd_cent_freq, wlpsd_offset, wlpsd_span, - BT_8821C_1ANT_ANTDET_PSD_POINTS, - BT_8821C_1ANT_ANTDET_PSD_AVGNUM, 3)) { - ant_det_finish = false; - board_info->btdm_ant_num_by_ant_det = 1; - psd_scan->ant_det_result = 8; - state = 99; - break; - } - - psd_scan->ant_det_pre_psdscan_peak_val = - psd_scan->psd_max_value; - - if (psd_scan->ant_det_pre_psdscan_peak_val > - (BT_8821C_1ANT_ANTDET_PSDTHRES_BACKGROUND - + psd_scan->ant_det_thres_offset) * 100) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Abort Antenna Detection!! becaus background = %d > thres (%d)\n", - psd_scan->ant_det_pre_psdscan_peak_val / - 100, - BT_8821C_1ANT_ANTDET_PSDTHRES_BACKGROUND - + psd_scan->ant_det_thres_offset); - BTC_TRACE(trace_buf); - ant_det_finish = false; - board_info->btdm_ant_num_by_ant_det = 1; - psd_scan->ant_det_result = 5; - state = 99; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Start Antenna Detection!! becaus background = %d <= thres (%d)\n", - psd_scan->ant_det_pre_psdscan_peak_val / - 100, - BT_8821C_1ANT_ANTDET_PSDTHRES_BACKGROUND - + psd_scan->ant_det_thres_offset); - BTC_TRACE(trace_buf); - state = 3; - } - break; - case 3: - - bt_resp = btcoexist->btc_set_bt_ant_detection( - btcoexist, (u8)(bt_tx_time & 0xff), - (u8)(bt_le_channel & 0xff)); - - /* Sync WL Rx PSD with BT Tx time because H2C->Mailbox delay */ - delay_ms(20); - - if (!halbtc8821c1ant_psd_sweep_point(btcoexist, - wlpsd_cent_freq, wlpsd_offset, - wlpsd_span, - BT_8821C_1ANT_ANTDET_PSD_POINTS, - BT_8821C_1ANT_ANTDET_PSD_AVGNUM, - BT_8821C_1ANT_ANTDET_PSD_SWWEEPCOUNT)) { - ant_det_finish = false; - board_info->btdm_ant_num_by_ant_det = 1; - psd_scan->ant_det_result = 8; - state = 99; - break; - } - -#if 1 - psd_scan->ant_det_psd_scan_peak_val = - psd_scan->psd_max_value; -#endif -#if 0 - psd_scan->ant_det_psd_scan_peak_val = - ((psd_scan->psd_max_value - psd_scan->psd_avg_value) < - 800) ? - psd_scan->psd_max_value : (( - psd_scan->psd_max_value - - psd_scan->psd_max_value2 <= 300) ? - psd_scan->psd_avg_value : - psd_scan->psd_max_value2); -#endif - psd_scan->ant_det_psd_scan_peak_freq = - psd_scan->psd_max_value_point; - state = 4; - break; - case 4: - - if (psd_scan->psd_point == 0) - delta_freq_per_point = 0; - else - delta_freq_per_point = - psd_scan->psd_band_width / - psd_scan->psd_point; - - psd_rep1 = psd_scan->ant_det_psd_scan_peak_val / 100; - psd_rep2 = psd_scan->ant_det_psd_scan_peak_val - - psd_rep1 * - 100; - - freq = ((psd_scan->real_cent_freq - 20) * - 1000000 + psd_scan->psd_max_value_point - * delta_freq_per_point); - freq1 = freq / 1000000; - freq2 = freq / 1000 - freq1 * 1000; - - if (freq2 < 100) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Max Value: Freq = %d.0%d MHz", - freq1, freq2); - BTC_TRACE(trace_buf); - CL_SPRINTF(psd_scan->ant_det_peak_freq, - BT_8821C_1ANT_ANTDET_BUF_LEN, - "%d.0%d", freq1, freq2); - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Max Value: Freq = %d.%d MHz", - freq1, freq2); - BTC_TRACE(trace_buf); - CL_SPRINTF(psd_scan->ant_det_peak_freq, - BT_8821C_1ANT_ANTDET_BUF_LEN, - "%d.%d", freq1, freq2); - } - - if (psd_rep2 < 10) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - ", Value = %d.0%d dB\n", - psd_rep1, psd_rep2); - BTC_TRACE(trace_buf); - CL_SPRINTF(psd_scan->ant_det_peak_val, - BT_8821C_1ANT_ANTDET_BUF_LEN, - "%d.0%d", psd_rep1, psd_rep2); - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - ", Value = %d.%d dB\n", - psd_rep1, psd_rep2); - BTC_TRACE(trace_buf); - CL_SPRINTF(psd_scan->ant_det_peak_val, - BT_8821C_1ANT_ANTDET_BUF_LEN, - "%d.%d", psd_rep1, psd_rep2); - } - - psd_scan->ant_det_is_btreply_available = true; - - if (bt_resp == false) { - psd_scan->ant_det_is_btreply_available = - false; - psd_scan->ant_det_result = 0; - ant_det_finish = false; - board_info->btdm_ant_num_by_ant_det = 1; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), BT Response = Fail\n "); - BTC_TRACE(trace_buf); - } else if (psd_scan->ant_det_psd_scan_peak_val > - (BT_8821C_1ANT_ANTDET_PSDTHRES_2ANT_BADISOLATION) - * 100) { - psd_scan->ant_det_result = 1; - ant_det_finish = true; - board_info->btdm_ant_num_by_ant_det = 2; - coex_sta->isolation_btween_wb = (u8)(85 - - psd_scan->ant_det_psd_scan_peak_val / - 100) & 0xff; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Detect Result = 2-Ant, Bad-Isolation!!\n"); - BTC_TRACE(trace_buf); - } else if (psd_scan->ant_det_psd_scan_peak_val > - (BT_8821C_1ANT_ANTDET_PSDTHRES_2ANT_GOODISOLATION - + psd_scan->ant_det_thres_offset) * 100) { - psd_scan->ant_det_result = 2; - ant_det_finish = true; - board_info->btdm_ant_num_by_ant_det = 2; - coex_sta->isolation_btween_wb = (u8)(85 - - psd_scan->ant_det_psd_scan_peak_val / - 100) & 0xff; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Detect Result = 2-Ant, Good-Isolation!!\n"); - BTC_TRACE(trace_buf); - } else if (psd_scan->ant_det_psd_scan_peak_val > - (BT_8821C_1ANT_ANTDET_PSDTHRES_1ANT) * - 100) { - psd_scan->ant_det_result = 3; - ant_det_finish = true; - board_info->btdm_ant_num_by_ant_det = 1; - coex_sta->isolation_btween_wb = (u8)(85 - - psd_scan->ant_det_psd_scan_peak_val / - 100) & 0xff; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Detect Result = 1-Ant!!\n"); - BTC_TRACE(trace_buf); - } else { - psd_scan->ant_det_result = 4; - ant_det_finish = false; - board_info->btdm_ant_num_by_ant_det = 1; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Detect Result = 1-Ant, un-certainity!!\n"); - BTC_TRACE(trace_buf); - } - - state = 99; - break; - case 99: /* restore setup */ - - /* Set AFH mask off at WiFi channel 2472MHz +/- 10MHz */ - h2c_parameter[0] = 0x0; - h2c_parameter[1] = 0x0; - h2c_parameter[2] = 0x0; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Set AFH on, Cent-Ch= %d, Mask=%d\n", - h2c_parameter[1], h2c_parameter[2]); - BTC_TRACE(trace_buf); - - btcoexist->btc_fill_h2c(btcoexist, 0x66, 3, - h2c_parameter); - - /* Set Antenna Path, GNT_WL/GNT_BT control by PTA */ - /* Set Antenna path, switch WiFi to certain antenna port */ - halbtc8821c1ant_set_ant_path(btcoexist, - BTC_ANT_PATH_AUTO, FORCE_EXEC, - BT_8821C_1ANT_PHASE_2G_RUNTIME); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Set Antenna to PTA\n!!"); - BTC_TRACE(trace_buf); - - btcoexist->stop_coex_dm = false; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Resume Coex DM\n!!"); - BTC_TRACE(trace_buf); - - outloop = true; - break; - } - - } while (!outloop); - - return ant_det_finish; - -} - -#pragma optimize("", off) -boolean halbtc8821c1ant_psd_antenna_detection_check(IN struct btc_coexist - *btcoexist) -{ - static u32 ant_det_count = 0, ant_det_fail_count = 0; - struct btc_board_info *board_info = &btcoexist->board_info; - - boolean scan, roam, ant_det_finish = false; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam); - - ant_det_count++; - - psd_scan->ant_det_try_count = ant_det_count; - - if (scan || roam) { - ant_det_finish = false; - psd_scan->ant_det_result = 6; - } else if (coex_sta->bt_disabled) { - ant_det_finish = false; - psd_scan->ant_det_result = 11; - } else if (coex_sta->num_of_profile >= 1) { - ant_det_finish = false; - psd_scan->ant_det_result = 7; - } else if ( - !psd_scan->ant_det_is_ant_det_available) { /* Antenna initial setup is not ready */ - ant_det_finish = false; - psd_scan->ant_det_result = 9; - } else if (coex_sta->c2h_bt_inquiry_page) { - ant_det_finish = false; - psd_scan->ant_det_result = 10; - } else { - - ant_det_finish = halbtc8821c1ant_psd_antenna_detection( - btcoexist); - - delay_ms(psd_scan->ant_det_bt_tx_time); - } - - - if (!ant_det_finish) - ant_det_fail_count++; - - psd_scan->ant_det_fail_count = ant_det_fail_count; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), result = %d, fail_count = %d, finish = %s\n", - psd_scan->ant_det_result, - psd_scan->ant_det_fail_count, - ant_det_finish == true ? "Yes" : "No"); - BTC_TRACE(trace_buf); - - return ant_det_finish; - -} - -#endif - -/* ************************************************************ - * work around function start with wa_halbtc8821c1ant_ - * ************************************************************ - * ************************************************************ - * extern function start with ex_halbtc8821c1ant_ - * ************************************************************ */ -void ex_halbtc8821c1ant_power_on_setting(IN struct btc_coexist *btcoexist) -{ - struct btc_board_info *board_info = &btcoexist->board_info; - u8 u8tmp = 0x0; - u16 u16tmp = 0x0; - u32 value = 0; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx Execute 8821c 1-Ant PowerOn Setting xxxxxxxxxxxxxxxx!!\n"); - BTC_TRACE(trace_buf); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "Ant Det Finish = %s, Ant Det Number = %d\n", - (board_info->btdm_ant_det_finish ? "Yes" : "No"), - board_info->btdm_ant_num_by_ant_det); - BTC_TRACE(trace_buf); - - btcoexist->stop_coex_dm = true; - psd_scan->ant_det_is_ant_det_available = false; - - /* enable BB, REG_SYS_FUNC_EN such that we can write BB Register correctly. */ - u16tmp = btcoexist->btc_read_2byte(btcoexist, 0x2); - btcoexist->btc_write_2byte(btcoexist, 0x2, u16tmp | BIT(0) | BIT(1)); - - /* Local setting bit define */ - /* BIT0: "0" for no antenna inverse; "1" for antenna inverse */ - /* BIT1: "0" for internal switch; "1" for external switch */ - /* BIT2: "0" for one antenna; "1" for two antenna */ - /* NOTE: here default all internal switch and 1-antenna ==> BIT1=0 and BIT2=0 */ - - /* Set Antenna Path to BT side */ - /* Check efuse 0xc3[6] for Single Antenna Path */ - if (board_info->single_ant_path == 0) { - - board_info->btdm_ant_pos = BTC_ANTENNA_AT_AUX_PORT; - u8tmp = 1; - } else if (board_info->single_ant_path == 1) { - - board_info->btdm_ant_pos = BTC_ANTENNA_AT_MAIN_PORT; - u8tmp = 0; - } - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** (Power On) single_ant_path = %d, btdm_ant_pos = %d\n", - board_info->single_ant_path , board_info->btdm_ant_pos); - BTC_TRACE(trace_buf); - - /* Setup RF front end type */ - halbtc8821c1ant_set_rfe_type(btcoexist); - - /* Set Antenna Path to BT side */ - halbtc8821c1ant_set_ant_path(btcoexist, - BTC_ANT_PATH_AUTO, - FORCE_EXEC, - BT_8821C_1ANT_PHASE_COEX_POWERON); - - /* Save"single antenna position" info in Local register setting for FW reading, because FW may not ready at power on */ - if (btcoexist->chip_interface == BTC_INTF_PCI) - btcoexist->btc_write_local_reg_1byte(btcoexist, 0x3e0, u8tmp); - else if (btcoexist->chip_interface == BTC_INTF_USB) - btcoexist->btc_write_local_reg_1byte(btcoexist, 0xfe08, u8tmp); - else if (btcoexist->chip_interface == BTC_INTF_SDIO) - btcoexist->btc_write_local_reg_1byte(btcoexist, 0x60, u8tmp); - - /* enable GNT_WL/GNT_BT debug signal to GPIO14/15 */ - halbtc8821c1ant_enable_gnt_to_gpio(btcoexist, true); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** LTE coex Reg 0x38 (Power-On) = 0x%x\n", - halbtc8821c1ant_ltecoex_indirect_read_reg(btcoexist, 0x38)); - BTC_TRACE(trace_buf); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** MAC Reg 0x70/ BB Reg 0xcb4 (Power-On) = 0x%x / 0x%x\n", - btcoexist->btc_read_4byte(btcoexist, 0x70), - btcoexist->btc_read_4byte(btcoexist, 0xcb4)); - BTC_TRACE(trace_buf); - -} - -void ex_halbtc8821c1ant_pre_load_firmware(IN struct btc_coexist *btcoexist) -{ -} - -void ex_halbtc8821c1ant_init_hw_config(IN struct btc_coexist *btcoexist, - IN boolean wifi_only) -{ - halbtc8821c1ant_init_hw_config(btcoexist, true, wifi_only); -} - -void ex_halbtc8821c1ant_init_coex_dm(IN struct btc_coexist *btcoexist) -{ - halbtc8821c1ant_init_coex_dm(btcoexist); -} - -void ex_halbtc8821c1ant_display_coex_info(IN struct btc_coexist *btcoexist) -{ - struct btc_board_info *board_info = &btcoexist->board_info; - struct btc_stack_info *stack_info = &btcoexist->stack_info; - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - - u8 *cli_buf = btcoexist->cli_buf; - u8 u8tmp[4], i, bt_info_ext, ps_tdma_case = 0; - u16 u16tmp[4]; - u32 u32tmp[4]; - u32 fa_ofdm, fa_cck, cca_ofdm, cca_cck; - u32 fw_ver = 0, bt_patch_ver = 0, bt_coex_ver = 0; - static u8 pop_report_in_10s = 0; - u32 phyver = 0; - boolean lte_coex_on = false; - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n ============[BT Coexist info]============"); - CL_PRINTF(cli_buf); - - if (btcoexist->manual_control) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n ============[Under Manual Control]============"); - CL_PRINTF(cli_buf); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n =========================================="); - CL_PRINTF(cli_buf); - } - if (btcoexist->stop_coex_dm) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n ============[Coex is STOPPED]============"); - CL_PRINTF(cli_buf); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n =========================================="); - CL_PRINTF(cli_buf); - } - - if (psd_scan->ant_det_try_count == 0) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %d/ %d/ %s / %d", - "Ant PG Num/ Mech/ Pos/ RFE", - board_info->pg_ant_num, board_info->btdm_ant_num, - (board_info->btdm_ant_pos == BTC_ANTENNA_AT_MAIN_PORT - ? "Main" : "Aux"), - rfe_type->rfe_module_type); - CL_PRINTF(cli_buf); - } else { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %d/ %d/ %s/ %d (%d/%d/%d)", - "Ant PG Num/ Mech(Ant_Det)/ Pos/ RFE", - board_info->pg_ant_num, - board_info->btdm_ant_num_by_ant_det, - (board_info->btdm_ant_pos == BTC_ANTENNA_AT_MAIN_PORT - ? "Main" : "Aux"), - rfe_type->rfe_module_type, - psd_scan->ant_det_try_count, - psd_scan->ant_det_fail_count, - psd_scan->ant_det_result); - CL_PRINTF(cli_buf); - - if (board_info->btdm_ant_det_finish) { - - if (psd_scan->ant_det_result != 12) - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s", - "Ant Det PSD Value", - psd_scan->ant_det_peak_val); - else - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %d", - "Ant Det PSD Value", - psd_scan->ant_det_psd_scan_peak_val - / 100); - CL_PRINTF(cli_buf); - } - } - - bt_patch_ver = btcoexist->bt_info.bt_get_fw_ver; - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, &fw_ver); - phyver = btcoexist->btc_get_bt_phydm_version(btcoexist); - - bt_coex_ver = ((coex_sta->bt_coex_supported_version & 0xff00) >> 8); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %d_%02x/ 0x%02x/ 0x%02x (%s)", - "CoexVer WL/ BT_Desired/ BT_Report", - glcoex_ver_date_8821c_1ant, glcoex_ver_8821c_1ant, - glcoex_ver_btdesired_8821c_1ant, - bt_coex_ver, - (bt_coex_ver == 0xff ? "Unknown" : - (bt_coex_ver >= glcoex_ver_btdesired_8821c_1ant ? - "Match" : "Mis-Match"))); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = 0x%x/ 0x%x/ v%d/ %c", - "W_FW/ B_FW/ Phy/ Kt", - fw_ver, bt_patch_ver, phyver, - coex_sta->cut_version + 65); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x ", - "AFH Map to BT", - coex_dm->wifi_chnl_info[0], coex_dm->wifi_chnl_info[1], - coex_dm->wifi_chnl_info[2]); - CL_PRINTF(cli_buf); - - /* wifi status */ - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s", - "============[Wifi Status]============"); - CL_PRINTF(cli_buf); - btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_WIFI_STATUS); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s", - "============[BT Status]============"); - CL_PRINTF(cli_buf); - - pop_report_in_10s++; - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = [%s/ %d dBm/ %d/ %d] ", - "BT [status/ rssi/ retryCnt/ popCnt]", - ((coex_sta->bt_disabled) ? ("disabled") : (( - coex_sta->c2h_bt_inquiry_page) ? ("inquiry/page") - : ((BT_8821C_1ANT_BT_STATUS_NON_CONNECTED_IDLE == - coex_dm->bt_status) ? "non-connected idle" : - ((BT_8821C_1ANT_BT_STATUS_CONNECTED_IDLE == coex_dm->bt_status) - ? "connected-idle" : "busy")))), - coex_sta->bt_rssi - 100, coex_sta->bt_retry_cnt, - coex_sta->pop_event_cnt); - CL_PRINTF(cli_buf); - - if (pop_report_in_10s >= 5) { - coex_sta->pop_event_cnt = 0; - pop_report_in_10s = 0; - } - - if (coex_sta->num_of_profile != 0) - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %s%s%s%s%s", - "Profiles", - ((bt_link_info->a2dp_exist) ? "A2DP," : ""), - ((bt_link_info->sco_exist) ? "SCO," : ""), - ((bt_link_info->hid_exist) ? - ((coex_sta->hid_busy_num >= 2) ? "HID(4/18)," : - "HID(2/18),") : ""), - ((bt_link_info->pan_exist) ? "PAN," : ""), - ((coex_sta->voice_over_HOGP) ? "Voice" : "")); - else - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = None", "Profiles"); - - CL_PRINTF(cli_buf); - - if (bt_link_info->a2dp_exist) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %s", - "A2DP Rate/Bitpool/Auto_Slot", - ((coex_sta->is_A2DP_3M) ? "3M" : "No_3M"), - coex_sta->a2dp_bit_pool, - ((coex_sta->is_autoslot) ? "On" : "Off") - ); - CL_PRINTF(cli_buf); - } - - if (bt_link_info->hid_exist) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", - "HID PairNum/Forbid_Slot", - coex_sta->hid_pair_cnt, - coex_sta->forbidden_slot - ); - CL_PRINTF(cli_buf); - } - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s / %s/ 0x%x/ 0x%x", - "Role/IgnWlanAct/Feature/BLEScan", - ((bt_link_info->slave_role) ? "Slave" : "Master"), - ((coex_dm->cur_ignore_wlan_act) ? "Yes" : "No"), - coex_sta->bt_coex_supported_feature, - coex_sta->bt_ble_scan_type); - CL_PRINTF(cli_buf); - - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d/ %d", - "ReInit/ReLink/IgnWlact/Page/NameReq", - coex_sta->cnt_ReInit, - coex_sta->cnt_setupLink, - coex_sta->cnt_IgnWlanAct, - coex_sta->cnt_Page, - coex_sta->cnt_RemoteNameReq - ); - CL_PRINTF(cli_buf); - - halbtc8821c1ant_read_score_board(btcoexist, &u16tmp[0]); - - if ((coex_sta->bt_reg_vendor_ae == 0xffff) || - (coex_sta->bt_reg_vendor_ac == 0xffff)) - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = x/ x/ %04x", - "0xae[4]/0xac[1:0]/Scoreboard", u16tmp[0]); - else - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = 0x%x/ 0x%x/ %04x", - "0xae[4]/0xac[1:0]/Scoreboard", - ((coex_sta->bt_reg_vendor_ae & BIT(4)) >> 4), - coex_sta->bt_reg_vendor_ac & 0x3, u16tmp[0]); - CL_PRINTF(cli_buf); - - for (i = 0; i < BT_INFO_SRC_8821C_1ANT_MAX; i++) { - if (coex_sta->bt_info_c2h_cnt[i]) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %02x %02x %02x %02x %02x %02x %02x(%d)", - glbt_info_src_8821c_1ant[i], - coex_sta->bt_info_c2h[i][0], - coex_sta->bt_info_c2h[i][1], - coex_sta->bt_info_c2h[i][2], - coex_sta->bt_info_c2h[i][3], - coex_sta->bt_info_c2h[i][4], - coex_sta->bt_info_c2h[i][5], - coex_sta->bt_info_c2h[i][6], - coex_sta->bt_info_c2h_cnt[i]); - CL_PRINTF(cli_buf); - } - } - - - if (btcoexist->manual_control) - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s", - "============[mechanisms] (before Manual)============"); - else - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s", - "============[Mechanisms]============"); - - CL_PRINTF(cli_buf); - - ps_tdma_case = coex_dm->cur_ps_tdma; - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %02x %02x %02x %02x %02x (case-%d, %s)", - "TDMA", - coex_dm->ps_tdma_para[0], coex_dm->ps_tdma_para[1], - coex_dm->ps_tdma_para[2], coex_dm->ps_tdma_para[3], - coex_dm->ps_tdma_para[4], ps_tdma_case, - (coex_dm->cur_ps_tdma_on ? "TDMA On" : "TDMA Off")); - - CL_PRINTF(cli_buf); - - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x6c0); - u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x6c4); - u32tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0x6c8); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %d/ 0x%x/ 0x%x/ 0x%x", - "Table/0x6c0/0x6c4/0x6c8", - coex_sta->coex_table_type, u32tmp[0], u32tmp[1], u32tmp[2]); - CL_PRINTF(cli_buf); - - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x778); - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x6cc); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = 0x%x/ 0x%x", - "0x778/0x6cc", - u8tmp[0], u32tmp[0]); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s/ %s", - "AntDiv/ForceLPS/LPRA", - ((board_info->ant_div_cfg) ? "On" : "Off"), - ((coex_sta->force_lps_on) ? "On" : "Off"), - ((coex_dm->cur_low_penalty_ra) ? "On" : "Off")); - CL_PRINTF(cli_buf); - - u32tmp[0] = halbtc8821c1ant_ltecoex_indirect_read_reg(btcoexist, 0x38); - lte_coex_on = ((u32tmp[0] & BIT(7)) >> 7) ? true : false; - - if (lte_coex_on) { - - u32tmp[0] = halbtc8821c1ant_ltecoex_indirect_read_reg(btcoexist, - 0xa0); - u32tmp[1] = halbtc8821c1ant_ltecoex_indirect_read_reg(btcoexist, - 0xa4); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", - "LTE Coex Table W_L/B_L", - u32tmp[0] & 0xffff, u32tmp[1] & 0xffff); - CL_PRINTF(cli_buf); - - u32tmp[0] = halbtc8821c1ant_ltecoex_indirect_read_reg(btcoexist, - 0xa8); - u32tmp[1] = halbtc8821c1ant_ltecoex_indirect_read_reg(btcoexist, - 0xac); - u32tmp[2] = halbtc8821c1ant_ltecoex_indirect_read_reg(btcoexist, - 0xb0); - u32tmp[3] = halbtc8821c1ant_ltecoex_indirect_read_reg(btcoexist, - 0xb4); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", - "LTE Break Table W_L/B_L/L_W/L_B", - u32tmp[0] & 0xffff, u32tmp[1] & 0xffff, - u32tmp[2] & 0xffff, u32tmp[3] & 0xffff); - CL_PRINTF(cli_buf); - } - - /* Hw setting */ - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s", - "============[Hw setting]============"); - CL_PRINTF(cli_buf); - /* - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x430); - u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x434); - u16tmp[0] = btcoexist->btc_read_2byte(btcoexist, 0x42a); - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x456); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/0x%x/0x%x/0x%x", - "0x430/0x434/0x42a/0x456", - u32tmp[0], u32tmp[1], u16tmp[0], u8tmp[0]); - CL_PRINTF(cli_buf); - */ - - u32tmp[0] = halbtc8821c1ant_ltecoex_indirect_read_reg(btcoexist, 0x38); - u32tmp[1] = halbtc8821c1ant_ltecoex_indirect_read_reg(btcoexist, 0x54); - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x73); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s", - "LTE Coex/Path Owner", - ((lte_coex_on) ? "On" : "Off") , - ((u8tmp[0] & BIT(2)) ? "WL" : "BT")); - CL_PRINTF(cli_buf); - - if (lte_coex_on) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d", - "LTE 3Wire/OPMode/UART/UARTMode", - (int)((u32tmp[0] & BIT(6)) >> 6), - (int)((u32tmp[0] & (BIT(5) | BIT(4))) >> 4), - (int)((u32tmp[0] & BIT(3)) >> 3), - (int)(u32tmp[0] & (BIT(2) | BIT(1) | BIT(0)))); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", - "LTE_Busy/UART_Busy", - (int)((u32tmp[1] & BIT(1)) >> 1), (int)(u32tmp[1] & BIT(0))); - CL_PRINTF(cli_buf); - } - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %s (BB:%s)/ %s (BB:%s)/ %s", - "GNT_WL_Ctrl/GNT_BT_Ctrl/Dbg", - ((u32tmp[0] & BIT(12)) ? "SW" : "HW"), - ((u32tmp[0] & BIT(8)) ? "SW" : "HW"), - ((u32tmp[0] & BIT(14)) ? "SW" : "HW"), - ((u32tmp[0] & BIT(10)) ? "SW" : "HW"), - ((u8tmp[0] & BIT(3)) ? "On" : "Off")); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", - "GNT_WL/GNT_BT", - (int)((u32tmp[1] & BIT(2)) >> 2), - (int)((u32tmp[1] & BIT(3)) >> 3)); - CL_PRINTF(cli_buf); - - - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xcb0); - u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0xcb4); - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0xcba); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = 0x%04x/ 0x%04x/ 0x%02x %s", - "0xcb0/0xcb4/0xcb8[23:16]", - u32tmp[0], u32tmp[1], u8tmp[0], - ((u8tmp[0] & 0x1) == 0x1 ? "(BTG)" : "(WL_A+G)")); - CL_PRINTF(cli_buf); - - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x4c); - u8tmp[2] = btcoexist->btc_read_1byte(btcoexist, 0x64); - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x4c6); - u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0x40); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", - "0x4c[24:23]/0x64[0]/x4c6[4]/0x40[5]", - (u32tmp[0] & (BIT(24) | BIT(23))) >> 23 , u8tmp[2] & 0x1 , - (int)((u8tmp[0] & BIT(4)) >> 4), - (int)((u8tmp[1] & BIT(5)) >> 5)); - CL_PRINTF(cli_buf); - - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x550); - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x522); - u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0x953); - u8tmp[2] = btcoexist->btc_read_1byte(btcoexist, 0xc50); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = 0x%x/ 0x%x/ %s/ 0x%x", - "0x550/0x522/4-RxAGC/0xc50", - u32tmp[0], u8tmp[0], (u8tmp[1] & 0x2) ? "On" : "Off", u8tmp[2]); - CL_PRINTF(cli_buf); - - fa_ofdm = btcoexist->btc_phydm_query_PHY_counter(btcoexist, - PHYDM_INFO_FA_OFDM); - fa_cck = btcoexist->btc_phydm_query_PHY_counter(btcoexist, - PHYDM_INFO_FA_CCK); - cca_ofdm = btcoexist->btc_phydm_query_PHY_counter(btcoexist, - PHYDM_INFO_CCA_OFDM); - cca_cck = btcoexist->btc_phydm_query_PHY_counter(btcoexist, - PHYDM_INFO_CCA_CCK); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", - "CCK-CCA/CCK-FA/OFDM-CCA/OFDM-FA", - cca_cck, fa_cck, cca_ofdm, fa_ofdm); - CL_PRINTF(cli_buf); - - -#if 1 - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d", - "CRC_OK CCK/11g/11n/11ac", - coex_sta->crc_ok_cck, coex_sta->crc_ok_11g, - coex_sta->crc_ok_11n, coex_sta->crc_ok_11n_vht); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d", - "CRC_Err CCK/11g/11n/11ac", - coex_sta->crc_err_cck, coex_sta->crc_err_11g, - coex_sta->crc_err_11n, coex_sta->crc_err_11n_vht); - CL_PRINTF(cli_buf); -#endif - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s/ %s", - "Wifi-HiPri/ Ccklock/ CckEverLock", - (coex_sta->wifi_is_high_pri_task ? "Yes" : "No"), - (coex_sta->cck_lock ? "Yes" : "No"), - (coex_sta->cck_ever_lock ? "Yes" : "No")); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", - "0x770(Hi-pri rx/tx)", - coex_sta->high_priority_rx, coex_sta->high_priority_tx); - CL_PRINTF(cli_buf); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", - "0x774(Lo-pri rx/tx)", - coex_sta->low_priority_rx, coex_sta->low_priority_tx); - CL_PRINTF(cli_buf); - - btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_COEX_STATISTICS); -} - - -void ex_halbtc8821c1ant_ips_notify(IN struct btc_coexist *btcoexist, IN u8 type) -{ - if (btcoexist->manual_control || btcoexist->stop_coex_dm) - return; - - if (BTC_IPS_ENTER == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], IPS ENTER notify\n"); - BTC_TRACE(trace_buf); - coex_sta->under_ips = true; - - /* Write WL "Active" in Score-board for LPS off */ - halbtc8821c1ant_post_state_to_bt(btcoexist, - BT_8821C_1ANT_SCOREBOARD_ACTIVE, false); - - halbtc8821c1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); - - halbtc8821c1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, - FORCE_EXEC, - BT_8821C_1ANT_PHASE_WLAN_OFF); - - halbtc8821c1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - } else if (BTC_IPS_LEAVE == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], IPS LEAVE notify\n"); - BTC_TRACE(trace_buf); - halbtc8821c1ant_post_state_to_bt(btcoexist, - BT_8821C_1ANT_SCOREBOARD_ACTIVE, true); - - halbtc8821c1ant_init_hw_config(btcoexist, false, false); - halbtc8821c1ant_init_coex_dm(btcoexist); - - coex_sta->under_ips = false; - } -} - -void ex_halbtc8821c1ant_lps_notify(IN struct btc_coexist *btcoexist, IN u8 type) -{ - if (btcoexist->manual_control || btcoexist->stop_coex_dm) - return; - - if (BTC_LPS_ENABLE == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], LPS ENABLE notify\n"); - BTC_TRACE(trace_buf); - coex_sta->under_lps = true; - - if (coex_sta->force_lps_on == true) { /* LPS No-32K */ - /* Write WL "Active" in Score-board for PS-TDMA */ - halbtc8821c1ant_post_state_to_bt(btcoexist, - BT_8821C_1ANT_SCOREBOARD_ACTIVE, true); - - } else { /* LPS-32K, need check if this h2c 0x71 can work?? (2015/08/28) */ - /* Write WL "Non-Active" in Score-board for Native-PS */ - halbtc8821c1ant_post_state_to_bt(btcoexist, - BT_8821C_1ANT_SCOREBOARD_ACTIVE, false); - - } - } else if (BTC_LPS_DISABLE == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], LPS DISABLE notify\n"); - BTC_TRACE(trace_buf); - coex_sta->under_lps = false; - - /* Write WL "Active" in Score-board for LPS off */ - halbtc8821c1ant_post_state_to_bt(btcoexist, - BT_8821C_1ANT_SCOREBOARD_ACTIVE, true); - - } -} - -void ex_halbtc8821c1ant_scan_notify(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - boolean wifi_connected = false; - boolean wifi_under_5g = false; - - if (btcoexist->manual_control || - btcoexist->stop_coex_dm) - return; - - coex_sta->freeze_coexrun_by_btinfo = false; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - - if (wifi_connected) - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** WL connected before SCAN\n"); - else - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** WL is not connected before SCAN\n"); - - BTC_TRACE(trace_buf); - - halbtc8821c1ant_query_bt_info(btcoexist); - - if (BTC_SCAN_START == type) { - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, - &wifi_under_5g); - - if (wifi_under_5g) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** SCAN START notify (5g)\n"); - BTC_TRACE(trace_buf); - - halbtc8821c1ant_action_wifi_under5g(btcoexist); - return; - } - - coex_sta->wifi_is_high_pri_task = true; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** SCAN START notify (2g)\n"); - BTC_TRACE(trace_buf); - - /* Force antenna setup for no scan result issue */ - halbtc8821c1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, - FORCE_EXEC, - BT_8821C_1ANT_PHASE_2G_RUNTIME); - - if (!wifi_connected) /* non-connected scan */ - halbtc8821c1ant_action_wifi_not_connected_scan( - btcoexist); - else /* wifi is connected */ - halbtc8821c1ant_action_wifi_connected_scan( - btcoexist); - - return; - } - - if (BTC_SCAN_START_2G == type) { - - if (!wifi_connected) - coex_sta->wifi_is_high_pri_task = true; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCAN START notify (2G)\n"); - BTC_TRACE(trace_buf); - - halbtc8821c1ant_post_state_to_bt(btcoexist, - BT_8821C_1ANT_SCOREBOARD_SCAN, true); - halbtc8821c1ant_post_state_to_bt(btcoexist, - BT_8821C_1ANT_SCOREBOARD_ACTIVE, true); - - /* Force antenna setup for no scan result issue */ - halbtc8821c1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, - FORCE_EXEC, - BT_8821C_1ANT_PHASE_2G_RUNTIME); - - if (!wifi_connected) /* non-connected scan */ - halbtc8821c1ant_action_wifi_not_connected_scan( - btcoexist); - else /* wifi is connected */ - halbtc8821c1ant_action_wifi_connected_scan(btcoexist); - - } else { - - coex_sta->wifi_is_high_pri_task = false; - - btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM, - &coex_sta->scan_ap_num); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCAN FINISH notify (Scan-AP = %d)\n", - coex_sta->scan_ap_num); - BTC_TRACE(trace_buf); - - halbtc8821c1ant_post_state_to_bt(btcoexist, - BT_8821C_1ANT_SCOREBOARD_SCAN, false); - - if (!wifi_connected) - halbtc8821c1ant_action_wifi_not_connected(btcoexist); - else - halbtc8821c1ant_action_wifi_connected(btcoexist); - } - - -} - -void ex_halbtc8821c1ant_switchband_notify(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - - boolean wifi_connected = false, bt_hs_on = false; - u32 wifi_link_status = 0; - u32 num_of_wifi_link = 0; - boolean bt_ctrl_agg_buf_size = false; - u8 agg_buf_size = 5; - - - if (btcoexist->manual_control || - btcoexist->stop_coex_dm) - return; - - - if (type == BTC_SWITCH_TO_5G) { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], switchband_notify --- switch to 5G\n"); - BTC_TRACE(trace_buf); - - halbtc8821c1ant_action_wifi_under5g(btcoexist); - - } else if (type == BTC_SWITCH_TO_24G_NOFORSCAN) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** switchband_notify BTC_SWITCH_TO_2G (no for scan)\n"); - BTC_TRACE(trace_buf); - - halbtc8821c1ant_run_coexist_mechanism(btcoexist); - - } else { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], switchband_notify --- switch to 2G\n"); - BTC_TRACE(trace_buf); - - ex_halbtc8821c1ant_scan_notify(btcoexist, - BTC_SCAN_START_2G); - } -} - - -void ex_halbtc8821c1ant_connect_notify(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - boolean wifi_connected = false; - - - halbtc8821c1ant_post_state_to_bt(btcoexist, - BT_8821C_1ANT_SCOREBOARD_ACTIVE, true); - - if (btcoexist->manual_control || - btcoexist->stop_coex_dm) - return; - - if ((BTC_ASSOCIATE_5G_START == type) || - (BTC_ASSOCIATE_5G_FINISH == type)) { - - if (BTC_ASSOCIATE_5G_START == type) - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], connect_notify --- 5G start\n"); - else - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], connect_notify --- 5G finish\n"); - - BTC_TRACE(trace_buf); - - halbtc8821c1ant_action_wifi_under5g(btcoexist); - return; - } - - if (BTC_ASSOCIATE_START == type) { - - coex_sta->wifi_is_high_pri_task = true; - - /* Force antenna setup for no scan result issue */ - halbtc8821c1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, - FORCE_EXEC, - BT_8821C_1ANT_PHASE_2G_RUNTIME); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], CONNECT START notify (2G)\n"); - BTC_TRACE(trace_buf); - - coex_dm->arp_cnt = 0; - - halbtc8821c1ant_action_wifi_not_connected_asso_auth(btcoexist); - - /* To keep TDMA case during connect process, - to avoid changed by Btinfo and runcoexmechanism */ - coex_sta->freeze_coexrun_by_btinfo = true; - } else { - - coex_sta->wifi_is_high_pri_task = false; - coex_sta->freeze_coexrun_by_btinfo = false; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], CONNECT FINISH notify (2G)\n"); - BTC_TRACE(trace_buf); - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - - if (!wifi_connected) /* non-connected scan */ - halbtc8821c1ant_action_wifi_not_connected(btcoexist); - else - halbtc8821c1ant_action_wifi_connected(btcoexist); - } - -} - -void ex_halbtc8821c1ant_media_status_notify(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - boolean wifi_under_b_mode = false, wifi_under_5g = false; - - - if (btcoexist->manual_control || - btcoexist->stop_coex_dm) - return; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g); - - if (BTC_MEDIA_CONNECT == type) { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], MEDIA connect notify\n"); - BTC_TRACE(trace_buf); - - halbtc8821c1ant_post_state_to_bt(btcoexist, - BT_8821C_1ANT_SCOREBOARD_ACTIVE, true); - - if (wifi_under_5g) { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], WiFi is under 5G!!!\n"); - BTC_TRACE(trace_buf); - - halbtc8821c1ant_action_wifi_under5g(btcoexist); - return; - } - - /* Force antenna setup for no scan result issue */ - halbtc8821c1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, - FORCE_EXEC, - BT_8821C_1ANT_PHASE_2G_RUNTIME); - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_B_MODE, - &wifi_under_b_mode); - - /* Set CCK Tx/Rx high Pri except 11b mode */ - if (wifi_under_b_mode) { - btcoexist->btc_write_1byte(btcoexist, 0x6cd, - 0x00); /* CCK Tx */ - btcoexist->btc_write_1byte(btcoexist, 0x6cf, - 0x00); /* CCK Rx */ - } else { - /* btcoexist->btc_write_1byte(btcoexist, 0x6cd, 0x10); */ /*CCK Tx */ - /* btcoexist->btc_write_1byte(btcoexist, 0x6cf, 0x10); */ /*CCK Rx */ - btcoexist->btc_write_1byte(btcoexist, 0x6cd, - 0x00); /* CCK Tx */ - btcoexist->btc_write_1byte(btcoexist, 0x6cf, - 0x10); /* CCK Rx */ - } - - coex_dm->backup_arfr_cnt1 = btcoexist->btc_read_4byte(btcoexist, - 0x430); - coex_dm->backup_arfr_cnt2 = btcoexist->btc_read_4byte(btcoexist, - 0x434); - coex_dm->backup_retry_limit = btcoexist->btc_read_2byte( - btcoexist, 0x42a); - coex_dm->backup_ampdu_max_time = btcoexist->btc_read_1byte( - btcoexist, 0x456); - } else { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], MEDIA disconnect notify\n"); - BTC_TRACE(trace_buf); - - halbtc8821c1ant_post_state_to_bt(btcoexist, - BT_8821C_1ANT_SCOREBOARD_ACTIVE, false); - - btcoexist->btc_write_1byte(btcoexist, 0x6cd, 0x0); /* CCK Tx */ - btcoexist->btc_write_1byte(btcoexist, 0x6cf, 0x0); /* CCK Rx */ - - coex_sta->cck_ever_lock = false; - } - - halbtc8821c1ant_update_wifi_channel_info(btcoexist, type); - -} - -void ex_halbtc8821c1ant_specific_packet_notify(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - boolean under_4way = false, wifi_under_5g = false; - - if (btcoexist->manual_control || - btcoexist->stop_coex_dm) - return; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g); - - if (wifi_under_5g) { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], WiFi is under 5G!!!\n"); - BTC_TRACE(trace_buf); - - halbtc8821c1ant_action_wifi_under5g(btcoexist); - return; - } - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS, - &under_4way); - - if (under_4way) { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], specific Packet ---- under_4way!!\n"); - BTC_TRACE(trace_buf); - - coex_sta->wifi_is_high_pri_task = true; - coex_sta->specific_pkt_period_cnt = 2; - } else if (BTC_PACKET_ARP == type) { - - coex_dm->arp_cnt++; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], specific Packet ARP notify -cnt = %d\n", - coex_dm->arp_cnt); - BTC_TRACE(trace_buf); - - } else { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], specific Packet DHCP or EAPOL notify [Type = %d]\n", - type); - BTC_TRACE(trace_buf); - - coex_sta->wifi_is_high_pri_task = true; - coex_sta->specific_pkt_period_cnt = 2; - } - - if (coex_sta->wifi_is_high_pri_task) - halbtc8821c1ant_action_wifi_connected_specific_packet( - btcoexist); -} - -void ex_halbtc8821c1ant_bt_info_notify(IN struct btc_coexist *btcoexist, - IN u8 *tmp_buf, IN u8 length) -{ - u8 i, rsp_source = 0; - boolean wifi_connected = false; - - if (psd_scan->is_AntDet_running == true) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], bt_info_notify return for AntDet is running\n"); - BTC_TRACE(trace_buf); - return; - } - - rsp_source = tmp_buf[0] & 0xf; - if (rsp_source >= BT_INFO_SRC_8821C_1ANT_MAX) - rsp_source = BT_INFO_SRC_8821C_1ANT_WIFI_FW; - coex_sta->bt_info_c2h_cnt[rsp_source]++; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Bt_info[%d], len=%d, data=[", rsp_source, - length); - BTC_TRACE(trace_buf); - - for (i = 0; i < length; i++) { - coex_sta->bt_info_c2h[rsp_source][i] = tmp_buf[i]; - - if (i == length - 1) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "0x%02x]\n", - tmp_buf[i]); - BTC_TRACE(trace_buf); - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "0x%02x, ", - tmp_buf[i]); - BTC_TRACE(trace_buf); - } - } - - coex_sta->bt_info = coex_sta->bt_info_c2h[rsp_source][1]; - coex_sta->bt_info_ext = coex_sta->bt_info_c2h[rsp_source][4]; - coex_sta->bt_info_ext2 = coex_sta->bt_info_c2h[rsp_source][5]; - - if (BT_INFO_SRC_8821C_1ANT_WIFI_FW != rsp_source) { - - /* if 0xff, it means BT is under WHCK test */ - coex_sta->bt_whck_test = ((coex_sta->bt_info == 0xff) ? true : - false); - - coex_sta->bt_create_connection = (( - coex_sta->bt_info_c2h[rsp_source][2] & 0x80) ? true : - false); - - /* unit: %, value-100 to translate to unit: dBm */ - coex_sta->bt_rssi = coex_sta->bt_info_c2h[rsp_source][3] * 2 + - 10; - - coex_sta->c2h_bt_remote_name_req = (( - coex_sta->bt_info_c2h[rsp_source][2] & 0x20) ? true : - false); - - coex_sta->is_A2DP_3M = ((coex_sta->bt_info_c2h[rsp_source][2] & - 0x10) ? true : false); - - coex_sta->acl_busy = ((coex_sta->bt_info_c2h[rsp_source][1] & - 0x9) ? true : false); - - coex_sta->voice_over_HOGP = ((coex_sta->bt_info_ext & 0x10) ? - true : false); - - coex_sta->c2h_bt_inquiry_page = ((coex_sta->bt_info & - BT_INFO_8821C_1ANT_B_INQ_PAGE) ? true : false); - - coex_sta->a2dp_bit_pool = ((( - coex_sta->bt_info_c2h[rsp_source][1] & 0x49) == 0x49) ? - coex_sta->bt_info_c2h[rsp_source][6] : 0); - - coex_sta->bt_retry_cnt = coex_sta->bt_info_c2h[rsp_source][2] & - 0xf; - - coex_sta->is_autoslot = coex_sta->bt_info_ext2 & 0x8; - - coex_sta->forbidden_slot = coex_sta->bt_info_ext2 & 0x7; - - coex_sta->hid_busy_num = (coex_sta->bt_info_ext2 & 0x30) >> 4; - - coex_sta->hid_pair_cnt = (coex_sta->bt_info_ext2 & 0xc0) >> 6; - - if (coex_sta->bt_retry_cnt >= 1) - coex_sta->pop_event_cnt++; - - if (coex_sta->c2h_bt_remote_name_req) - coex_sta->cnt_RemoteNameReq++; - - if (coex_sta->bt_info_ext & BIT(1)) - coex_sta->cnt_ReInit++; - - if (coex_sta->bt_info_ext & BIT(2)) { - coex_sta->cnt_setupLink++; - coex_sta->is_setupLink = true; - } else - coex_sta->is_setupLink = false; - - if (coex_sta->bt_info_ext & BIT(3)) - coex_sta->cnt_IgnWlanAct++; - - if (coex_sta->bt_create_connection) - coex_sta->cnt_Page++; - - /* Here we need to resend some wifi info to BT */ - /* because bt is reset and loss of the info. */ - - if ((!btcoexist->manual_control) && - (!btcoexist->stop_coex_dm)) { - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - - /* Re-Init */ - if ((coex_sta->bt_info_ext & BIT(1))) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT ext info bit1 check, send wifi BW&Chnl to BT!!\n"); - BTC_TRACE(trace_buf); - if (wifi_connected) - halbtc8821c1ant_update_wifi_channel_info( - btcoexist, BTC_MEDIA_CONNECT); - else - halbtc8821c1ant_update_wifi_channel_info( - btcoexist, - BTC_MEDIA_DISCONNECT); - } - - - /* If Ignore_WLanAct && not SetUp_Link */ - if ((coex_sta->bt_info_ext & BIT(3)) && - (!(coex_sta->bt_info_ext & BIT(2)))) { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT ext info bit3 check, set BT NOT to ignore Wlan active!!\n"); - BTC_TRACE(trace_buf); - halbtc8821c1ant_ignore_wlan_act(btcoexist, - FORCE_EXEC, false); - } - } - - } - - - halbtc8821c1ant_update_bt_link_info(btcoexist); - - if (btcoexist->manual_control) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), No run_coexist_mechanism for Manual CTRL\n"); - BTC_TRACE(trace_buf); - return; - } - - if (btcoexist->stop_coex_dm) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), No run_coexist_mechanism for Stop Coex DM\n"); - BTC_TRACE(trace_buf); - return; - } - - coex_sta->c2h_bt_info_req_sent = false; - - halbtc8821c1ant_run_coexist_mechanism(btcoexist); -} - - - -void ex_halbtc8821c1ant_rf_status_notify(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], RF Status notify\n"); - BTC_TRACE(trace_buf); - - if (BTC_RF_ON == type) { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], RF is turned ON!!\n"); - BTC_TRACE(trace_buf); - - coex_sta->wl_rf_off_on_event = true; - btcoexist->stop_coex_dm = false; - - halbtc8821c1ant_post_state_to_bt(btcoexist, - BT_8821C_1ANT_SCOREBOARD_ACTIVE, true); - halbtc8821c1ant_post_state_to_bt(btcoexist, - BT_8821C_1ANT_SCOREBOARD_ONOFF, true); - - } else if (BTC_RF_OFF == type) { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], RF is turned OFF!!\n"); - BTC_TRACE(trace_buf); - - halbtc8821c1ant_post_state_to_bt(btcoexist, - BT_8821C_1ANT_SCOREBOARD_ACTIVE, false); - halbtc8821c1ant_post_state_to_bt(btcoexist, - BT_8821C_1ANT_SCOREBOARD_ONOFF, false); - - halbtc8821c1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 0); - - halbtc8821c1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, - FORCE_EXEC, - BT_8821C_1ANT_PHASE_WLAN_OFF); - - btcoexist->stop_coex_dm = true; - coex_sta->wl_rf_off_on_event = false; - } -} - -void ex_halbtc8821c1ant_halt_notify(IN struct btc_coexist *btcoexist) -{ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], Halt notify\n"); - BTC_TRACE(trace_buf); - - halbtc8821c1ant_post_state_to_bt(btcoexist, - BT_8821C_1ANT_SCOREBOARD_ACTIVE, false); - halbtc8821c1ant_post_state_to_bt(btcoexist, - BT_8821C_1ANT_SCOREBOARD_ONOFF, false); - - halbtc8821c1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 0); - - halbtc8821c1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, FORCE_EXEC, - BT_8821C_1ANT_PHASE_WLAN_OFF); - - halbtc8821c1ant_ignore_wlan_act(btcoexist, FORCE_EXEC, true); - - ex_halbtc8821c1ant_media_status_notify(btcoexist, BTC_MEDIA_DISCONNECT); - - btcoexist->stop_coex_dm = true; -} - -void ex_halbtc8821c1ant_pnp_notify(IN struct btc_coexist *btcoexist, - IN u8 pnp_state) -{ - boolean wifi_under_5g = false; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], Pnp notify\n"); - BTC_TRACE(trace_buf); - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g); - - if ((BTC_WIFI_PNP_SLEEP == pnp_state) || - (BTC_WIFI_PNP_SLEEP_KEEP_ANT == pnp_state)) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Pnp notify to SLEEP\n"); - BTC_TRACE(trace_buf); - - halbtc8821c1ant_post_state_to_bt(btcoexist, - BT_8821C_1ANT_SCOREBOARD_ACTIVE, false); - halbtc8821c1ant_post_state_to_bt(btcoexist, - BT_8821C_1ANT_SCOREBOARD_ONOFF, false); - - if (BTC_WIFI_PNP_SLEEP_KEEP_ANT == pnp_state) { - - if (wifi_under_5g) - halbtc8821c1ant_set_ant_path(btcoexist, - BTC_ANT_PATH_AUTO, FORCE_EXEC, - BT_8821C_1ANT_PHASE_5G_RUNTIME); - else - halbtc8821c1ant_set_ant_path(btcoexist, - BTC_ANT_PATH_AUTO, FORCE_EXEC, - BT_8821C_1ANT_PHASE_2G_RUNTIME); - } else { - - halbtc8821c1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, - FORCE_EXEC, - BT_8821C_1ANT_PHASE_WLAN_OFF); - } - - btcoexist->stop_coex_dm = true; - } else if (BTC_WIFI_PNP_WAKE_UP == pnp_state) { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Pnp notify to WAKE UP\n"); - BTC_TRACE(trace_buf); - - halbtc8821c1ant_post_state_to_bt(btcoexist, - BT_8821C_1ANT_SCOREBOARD_ACTIVE, true); - halbtc8821c1ant_post_state_to_bt(btcoexist, - BT_8821C_1ANT_SCOREBOARD_ONOFF, true); - - btcoexist->stop_coex_dm = false; - } -} - - -void ex_halbtc8821c1ant_coex_dm_reset(IN struct btc_coexist *btcoexist) -{ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], *****************Coex DM Reset*****************\n"); - BTC_TRACE(trace_buf); - - halbtc8821c1ant_init_hw_config(btcoexist, false, false); - halbtc8821c1ant_init_coex_dm(btcoexist); -} - -void ex_halbtc8821c1ant_periodical(IN struct btc_coexist *btcoexist) -{ - - struct btc_board_info *board_info = &btcoexist->board_info; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ************* Periodical *************\n"); - BTC_TRACE(trace_buf); - -#if (BT_AUTO_REPORT_ONLY_8821C_1ANT == 0) - halbtc8821c1ant_query_bt_info(btcoexist); - -#endif - - halbtc8821c1ant_monitor_bt_ctr(btcoexist); - halbtc8821c1ant_monitor_wifi_ctr(btcoexist); - - halbtc8821c1ant_monitor_bt_enable_disable(btcoexist); - - /* for 4-way, DHCP, EAPOL packet */ - if (coex_sta->specific_pkt_period_cnt > 0) { - - coex_sta->specific_pkt_period_cnt--; - - if ((coex_sta->specific_pkt_period_cnt == 0) && - (coex_sta->wifi_is_high_pri_task)) - coex_sta->wifi_is_high_pri_task = false; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ***************** Hi-Pri Task = %s*****************\n", - (coex_sta->wifi_is_high_pri_task ? "Yes" : - "No")); - BTC_TRACE(trace_buf); - - } - - if (!coex_sta->bt_disabled) { - if (coex_sta->bt_coex_supported_feature == 0) - coex_sta->bt_coex_supported_feature = - btcoexist->btc_get_bt_coex_supported_feature( - btcoexist); - - if ((coex_sta->bt_coex_supported_version == 0) || - (coex_sta->bt_coex_supported_version == 0xffff)) - coex_sta->bt_coex_supported_version = - btcoexist->btc_get_bt_coex_supported_version( - btcoexist); - - /*coex_sta->bt_ble_scan_type = btcoexist->btc_get_ble_scan_type_from_bt(btcoexist); */ - - if (coex_sta->bt_reg_vendor_ac == 0xffff) - coex_sta->bt_reg_vendor_ac = (u16)( - btcoexist->btc_get_bt_reg(btcoexist, 3, - 0xac) & 0xffff); - - if (coex_sta->bt_reg_vendor_ae == 0xffff) - coex_sta->bt_reg_vendor_ae = (u16)( - btcoexist->btc_get_bt_reg(btcoexist, 3, - 0xae) & 0xffff); - -#if BT_8821C_1ANT_ANTDET_ENABLE - - if (board_info->btdm_ant_det_finish) { - if ((psd_scan->ant_det_result == 12) && - (psd_scan->ant_det_psd_scan_peak_val == 0) - && (!psd_scan->is_AntDet_running)) - psd_scan->ant_det_psd_scan_peak_val = - btcoexist->btc_get_ant_det_val_from_bt( - btcoexist) * 100; - } - -#endif - } - - if (halbtc8821c1ant_is_wifibt_status_changed(btcoexist)) - halbtc8821c1ant_run_coexist_mechanism(btcoexist); - - -} - -/*#pragma optimize( "", off )*/ -void ex_halbtc8821c1ant_antenna_detection(IN struct btc_coexist *btcoexist, - IN u32 cent_freq, IN u32 offset, IN u32 span, IN u32 seconds) -{ -#if 0 - - static u32 ant_det_count = 0, ant_det_fail_count = 0; - struct btc_board_info *board_info = &btcoexist->board_info; - u16 u16tmp; - u8 AntDetval = 0; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx Ext Call AntennaDetect()!!\n"); - BTC_TRACE(trace_buf); - -#if BT_8821C_1ANT_ANTDET_ENABLE - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx Call AntennaDetect()!!\n"); - BTC_TRACE(trace_buf); - - if (seconds == 0) { - psd_scan->ant_det_try_count = 0; - psd_scan->ant_det_fail_count = 0; - ant_det_count = 0; - ant_det_fail_count = 0; - board_info->btdm_ant_det_finish = false; - board_info->btdm_ant_num_by_ant_det = 1; - return; - } - - if (!board_info->btdm_ant_det_finish) { - psd_scan->ant_det_inteval_count = - psd_scan->ant_det_inteval_count + 2; - - if (psd_scan->ant_det_inteval_count >= - BT_8821C_2ANT_ANTDET_RETRY_INTERVAL) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Antenna Det Timer is up, Try Detect!!\n"); - BTC_TRACE(trace_buf); - - psd_scan->is_AntDet_running = true; - - halbtc8821c1ant_read_score_board(btcoexist, &u16tmp); - - if (u16tmp & BIT( - 2)) { /* Antenna detection is already done before last WL power on */ - board_info->btdm_ant_det_finish = true; - psd_scan->ant_det_try_count = 1; - psd_scan->ant_det_fail_count = 0; - board_info->btdm_ant_num_by_ant_det = (u16tmp & - BIT(3)) ? 1 : 2; - psd_scan->ant_det_result = 12; - - psd_scan->ant_det_psd_scan_peak_val = - btcoexist->btc_get_ant_det_val_from_bt( - btcoexist) * 100; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Antenna Det Result from BT (%d-Ant)\n", - board_info->btdm_ant_num_by_ant_det); - BTC_TRACE(trace_buf); - } else - board_info->btdm_ant_det_finish = - halbtc8821c1ant_psd_antenna_detection_check( - btcoexist); - - btcoexist->bdontenterLPS = false; - - if (board_info->btdm_ant_det_finish) { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Antenna Det Success!!\n"); - BTC_TRACE(trace_buf); - - if (board_info->btdm_ant_num_by_ant_det == 2) { - board_info->ant_div_cfg = true; - halbtc8821c1ant_set_ant_path(btcoexist, - BTC_ANT_PATH_WIFI, FORCE_EXEC, - BT_8821C_1ANT_PHASE_2G_RUNTIME); - } else - halbtc8821c1ant_set_ant_path(btcoexist, - BTC_ANT_PATH_AUTO, FORCE_EXEC, - BT_8821C_1ANT_PHASE_2G_RUNTIME); - - /*for 8821c, btc_set_bt_trx_mask is just used to - notify BT stop le tx and Ant Det Result , not set BT RF TRx Mask */ - if (psd_scan->ant_det_result != 12) { - - AntDetval = (u8)(( - psd_scan->ant_det_psd_scan_peak_val - / 100) & 0x7f); - - AntDetval = - (board_info->btdm_ant_num_by_ant_det - == 1) ? (AntDetval | 0x80) : - AntDetval; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxx AntennaDetect(), Ant Count = %d, PSD Val = %d\n", - ((AntDetval & - 0x80) ? 1 - : 2), AntDetval - & 0x7f); - BTC_TRACE(trace_buf); - - if (btcoexist->btc_set_bt_trx_mask( - btcoexist, AntDetval)) - BTC_SPRINTF(trace_buf, - BT_TMP_BUF_SIZE, - "xxxxxx AntennaDetect(), Notify BT stop le tx by set_bt_trx_mask ok!\n"); - else - BTC_SPRINTF(trace_buf, - BT_TMP_BUF_SIZE, - "xxxxxx AntennaDetect(), Notify BT stop le tx by set_bt_trx_mask fail!\n"); - - BTC_TRACE(trace_buf); - } - - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Antenna Det Fail!!\n"); - BTC_TRACE(trace_buf); - } - - psd_scan->ant_det_inteval_count = 0; - psd_scan->is_AntDet_running = false; - /* stimulate coex running */ - halbtc8821c1ant_run_coexist_mechanism( - btcoexist); - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Stimulate Coex running\n!!"); - BTC_TRACE(trace_buf); - - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Antenna Det Timer is not up! (%d)\n", - psd_scan->ant_det_inteval_count); - BTC_TRACE(trace_buf); - - if (psd_scan->ant_det_inteval_count == 8) - btcoexist->bdontenterLPS = true; - else - btcoexist->bdontenterLPS = false; - } - - } -#endif - -#endif -} - - -void ex_halbtc8821c1ant_display_ant_detection(IN struct btc_coexist *btcoexist) -{ - -#if 0 -#if BT_8821C_1ANT_ANTDET_ENABLE - struct btc_board_info *board_info = &btcoexist->board_info; - - if (psd_scan->ant_det_try_count != 0) { - halbtc8821c1ant_psd_show_antenna_detect_result(btcoexist); - - if (board_info->btdm_ant_det_finish) - halbtc8821c1ant_psd_showdata(btcoexist); - } -#endif -#endif -} - -void ex_halbtc8821c1ant_antenna_isolation(IN struct btc_coexist *btcoexist, - IN u32 cent_freq, IN u32 offset, IN u32 span, IN u32 seconds) -{ - - -} - -void ex_halbtc8821c1ant_psd_scan(IN struct btc_coexist *btcoexist, - IN u32 cent_freq, IN u32 offset, IN u32 span, IN u32 seconds) -{ - - -} - - -#endif - -#endif /* #if (BT_SUPPORT == 1 && COEX_SUPPORT == 1) */ - diff --git a/hal/btc/halbtc8821c1ant.h b/hal/btc/halbtc8821c1ant.h deleted file mode 100644 index f712494..0000000 --- a/hal/btc/halbtc8821c1ant.h +++ /dev/null @@ -1,473 +0,0 @@ - -#if (BT_SUPPORT == 1 && COEX_SUPPORT == 1) - -#if (RTL8821C_SUPPORT == 1) - -/* ******************************************* - * The following is for 8821C 1ANT BT Co-exist definition - * ******************************************* */ -#define BT_8821C_1ANT_COEX_DBG 0 -#define BT_AUTO_REPORT_ONLY_8821C_1ANT 1 - -#define BT_INFO_8821C_1ANT_B_FTP BIT(7) -#define BT_INFO_8821C_1ANT_B_A2DP BIT(6) -#define BT_INFO_8821C_1ANT_B_HID BIT(5) -#define BT_INFO_8821C_1ANT_B_SCO_BUSY BIT(4) -#define BT_INFO_8821C_1ANT_B_ACL_BUSY BIT(3) -#define BT_INFO_8821C_1ANT_B_INQ_PAGE BIT(2) -#define BT_INFO_8821C_1ANT_B_SCO_ESCO BIT(1) -#define BT_INFO_8821C_1ANT_B_CONNECTION BIT(0) - -#define BT_INFO_8821C_1ANT_A2DP_BASIC_RATE(_BT_INFO_EXT_) \ - (((_BT_INFO_EXT_&BIT(0))) ? true : false) - -#define BTC_RSSI_COEX_THRESH_TOL_8821C_1ANT 2 - -#define BT_8821C_1ANT_WIFI_NOISY_THRESH 30 /* max: 255 */ -#define BT_8821C_1ANT_DEFAULT_ISOLATION 15 /* unit: dB */ - - -/* for Antenna detection */ -#define BT_8821C_1ANT_ANTDET_PSDTHRES_BACKGROUND 50 -#define BT_8821C_1ANT_ANTDET_PSDTHRES_2ANT_BADISOLATION 70 -#define BT_8821C_1ANT_ANTDET_PSDTHRES_2ANT_GOODISOLATION 55 -#define BT_8821C_1ANT_ANTDET_PSDTHRES_1ANT 35 -#define BT_8821C_1ANT_ANTDET_RETRY_INTERVAL 10 /* retry timer if ant det is fail, unit: second */ -#define BT_8821C_1ANT_ANTDET_SWEEPPOINT_DELAY 60000 -#define BT_8821C_1ANT_ANTDET_ENABLE 0 -#define BT_8821C_1ANT_ANTDET_BTTXTIME 100 -#define BT_8821C_1ANT_ANTDET_BTTXCHANNEL 39 -#define BT_8821C_1ANT_ANTDET_PSD_SWWEEPCOUNT 50 - -#define BT_8821C_1ANT_LTECOEX_INDIRECTREG_ACCESS_TIMEOUT 30000 - -enum bt_8821c_1ant_signal_state { - BT_8821C_1ANT_SIG_STA_SET_TO_LOW = 0x0, - BT_8821C_1ANT_SIG_STA_SET_BY_HW = 0x0, - BT_8821C_1ANT_SIG_STA_SET_TO_HIGH = 0x1, - BT_8821C_1ANT_SIG_STA_MAX -}; - -enum bt_8821c_1ant_path_ctrl_owner { - BT_8821C_1ANT_PCO_BTSIDE = 0x0, - BT_8821C_1ANT_PCO_WLSIDE = 0x1, - BT_8821C_1ANT_PCO_MAX -}; - -enum bt_8821c_1ant_gnt_ctrl_type { - BT_8821C_1ANT_GNT_TYPE_CTRL_BY_PTA = 0x0, - BT_8821C_1ANT_GNT_TYPE_CTRL_BY_SW = 0x1, - BT_8821C_1ANT_GNT_TYPE_MAX -}; - -enum bt_8821c_1ant_gnt_ctrl_block { - BT_8821C_1ANT_GNT_BLOCK_RFC_BB = 0x0, - BT_8821C_1ANT_GNT_BLOCK_RFC = 0x1, - BT_8821C_1ANT_GNT_BLOCK_BB = 0x2, - BT_8821C_1ANT_GNT_BLOCK_MAX -}; - -enum bt_8821c_1ant_lte_coex_table_type { - BT_8821C_1ANT_CTT_WL_VS_LTE = 0x0, - BT_8821C_1ANT_CTT_BT_VS_LTE = 0x1, - BT_8821C_1ANT_CTT_MAX -}; - -enum bt_8821c_1ant_lte_break_table_type { - BT_8821C_1ANT_LBTT_WL_BREAK_LTE = 0x0, - BT_8821C_1ANT_LBTT_BT_BREAK_LTE = 0x1, - BT_8821C_1ANT_LBTT_LTE_BREAK_WL = 0x2, - BT_8821C_1ANT_LBTT_LTE_BREAK_BT = 0x3, - BT_8821C_1ANT_LBTT_MAX -}; - -enum bt_info_src_8821c_1ant { - BT_INFO_SRC_8821C_1ANT_WIFI_FW = 0x0, - BT_INFO_SRC_8821C_1ANT_BT_RSP = 0x1, - BT_INFO_SRC_8821C_1ANT_BT_ACTIVE_SEND = 0x2, - BT_INFO_SRC_8821C_1ANT_MAX -}; - -enum bt_8821c_1ant_bt_status { - BT_8821C_1ANT_BT_STATUS_NON_CONNECTED_IDLE = 0x0, - BT_8821C_1ANT_BT_STATUS_CONNECTED_IDLE = 0x1, - BT_8821C_1ANT_BT_STATUS_INQ_PAGE = 0x2, - BT_8821C_1ANT_BT_STATUS_ACL_BUSY = 0x3, - BT_8821C_1ANT_BT_STATUS_SCO_BUSY = 0x4, - BT_8821C_1ANT_BT_STATUS_ACL_SCO_BUSY = 0x5, - BT_8821C_1ANT_BT_STATUS_MAX -}; - -enum bt_8821c_1ant_wifi_status { - BT_8821C_1ANT_WIFI_STATUS_NON_CONNECTED_IDLE = 0x0, - BT_8821C_1ANT_WIFI_STATUS_NON_CONNECTED_ASSO_AUTH_SCAN = 0x1, - BT_8821C_1ANT_WIFI_STATUS_CONNECTED_SCAN = 0x2, - BT_8821C_1ANT_WIFI_STATUS_CONNECTED_SPECIFIC_PKT = 0x3, - BT_8821C_1ANT_WIFI_STATUS_CONNECTED_IDLE = 0x4, - BT_8821C_1ANT_WIFI_STATUS_CONNECTED_BUSY = 0x5, - BT_8821C_1ANT_WIFI_STATUS_MAX -}; - -enum bt_8821c_1ant_coex_algo { - BT_8821C_1ANT_COEX_ALGO_UNDEFINED = 0x0, - BT_8821C_1ANT_COEX_ALGO_SCO = 0x1, - BT_8821C_1ANT_COEX_ALGO_HID = 0x2, - BT_8821C_1ANT_COEX_ALGO_A2DP = 0x3, - BT_8821C_1ANT_COEX_ALGO_A2DP_PANHS = 0x4, - BT_8821C_1ANT_COEX_ALGO_PANEDR = 0x5, - BT_8821C_1ANT_COEX_ALGO_PANHS = 0x6, - BT_8821C_1ANT_COEX_ALGO_PANEDR_A2DP = 0x7, - BT_8821C_1ANT_COEX_ALGO_PANEDR_HID = 0x8, - BT_8821C_1ANT_COEX_ALGO_HID_A2DP_PANEDR = 0x9, - BT_8821C_1ANT_COEX_ALGO_HID_A2DP = 0xa, - BT_8821C_1ANT_COEX_ALGO_MAX = 0xb, -}; - -enum bt_8821c_1ant_ext_ant_switch_type { - BT_8821C_1ANT_EXT_ANT_SWITCH_USE_DPDT = 0x0, - BT_8821C_1ANT_EXT_ANT_SWITCH_USE_SPDT = 0x1, - BT_8821C_1ANT_EXT_ANT_SWITCH_NONE = 0x2, - BT_8821C_1ANT_EXT_ANT_SWITCH_MAX -}; - - -enum bt_8821c_1ant_ext_ant_switch_ctrl_type { - BT_8821C_1ANT_EXT_ANT_SWITCH_CTRL_BY_BBSW = 0x0, - BT_8821C_1ANT_EXT_ANT_SWITCH_CTRL_BY_PTA = 0x1, - BT_8821C_1ANT_EXT_ANT_SWITCH_CTRL_BY_ANTDIV = 0x2, - BT_8821C_1ANT_EXT_ANT_SWITCH_CTRL_BY_MAC = 0x3, - BT_8821C_1ANT_EXT_ANT_SWITCH_CTRL_BY_BT = 0x4, - BT_8821C_1ANT_EXT_ANT_SWITCH_CTRL_MAX -}; - -enum bt_8821c_1ant_ext_ant_switch_pos_type { - BT_8821C_1ANT_EXT_ANT_SWITCH_TO_BT = 0x0, - BT_8821C_1ANT_EXT_ANT_SWITCH_TO_WLG = 0x1, - BT_8821C_1ANT_EXT_ANT_SWITCH_TO_WLA = 0x2, - BT_8821C_1ANT_EXT_ANT_SWITCH_TO_NOCARE = 0x3, - BT_8821C_1ANT_EXT_ANT_SWITCH_TO_MAX -}; - -enum bt_8821c_1ant_ext_band_switch_pos_type { - BT_8821C_1ANT_EXT_BAND_SWITCH_TO_WLG = 0x0, - BT_8821C_1ANT_EXT_BAND_SWITCH_TO_WLA = 0x1, - BT_8821C_1ANT_EXT_BAND_SWITCH_TO_MAX -}; - -enum bt_8821c_1ant_int_block { - BT_8821C_1ANT_INT_BLOCK_SWITCH_TO_WLG_OF_BTG = 0x0, - BT_8821C_1ANT_INT_BLOCK_SWITCH_TO_WLG_OF_WLAG = 0x1, - BT_8821C_1ANT_INT_BLOCK_SWITCH_TO_WLA_OF_WLAG = 0x2, - BT_8821C_1ANT_INT_BLOCK_SWITCH_TO_MAX -}; - -enum bt_8821c_1ant_phase { - BT_8821C_1ANT_PHASE_COEX_INIT = 0x0, - BT_8821C_1ANT_PHASE_WLANONLY_INIT = 0x1, - BT_8821C_1ANT_PHASE_WLAN_OFF = 0x2, - BT_8821C_1ANT_PHASE_2G_RUNTIME = 0x3, - BT_8821C_1ANT_PHASE_5G_RUNTIME = 0x4, - BT_8821C_1ANT_PHASE_BTMPMODE = 0x5, - BT_8821C_1ANT_PHASE_ANTENNA_DET = 0x6, - BT_8821C_1ANT_PHASE_COEX_POWERON = 0x7, - BT_8821C_1ANT_PHASE_MAX -}; - -enum bt_8821c_1ant_Scoreboard { - BT_8821C_1ANT_SCOREBOARD_ACTIVE = BIT(0), - BT_8821C_1ANT_SCOREBOARD_ONOFF = BIT(1), - BT_8821C_1ANT_SCOREBOARD_SCAN = BIT(2) -}; - -struct coex_dm_8821c_1ant { - /* hw setting */ - u32 pre_ant_pos_type; - u32 cur_ant_pos_type; - /* fw mechanism */ - boolean cur_ignore_wlan_act; - boolean pre_ignore_wlan_act; - u8 pre_ps_tdma; - u8 cur_ps_tdma; - u8 ps_tdma_para[5]; - u8 ps_tdma_du_adj_type; - boolean pre_ps_tdma_on; - boolean cur_ps_tdma_on; - boolean pre_bt_auto_report; - boolean cur_bt_auto_report; - u8 pre_lps; - u8 cur_lps; - u8 pre_rpwm; - u8 cur_rpwm; - - /* sw mechanism */ - boolean pre_low_penalty_ra; - boolean cur_low_penalty_ra; - u32 pre_val0x6c0; - u32 cur_val0x6c0; - u32 pre_val0x6c4; - u32 cur_val0x6c4; - u32 pre_val0x6c8; - u32 cur_val0x6c8; - u8 pre_val0x6cc; - u8 cur_val0x6cc; - boolean limited_dig; - - u32 backup_arfr_cnt1; /* Auto Rate Fallback Retry cnt */ - u32 backup_arfr_cnt2; /* Auto Rate Fallback Retry cnt */ - u16 backup_retry_limit; - u8 backup_ampdu_max_time; - - /* algorithm related */ - u8 pre_algorithm; - u8 cur_algorithm; - u8 bt_status; - u8 wifi_chnl_info[3]; - - u32 pre_ra_mask; - u32 cur_ra_mask; - u8 pre_arfr_type; - u8 cur_arfr_type; - u8 pre_retry_limit_type; - u8 cur_retry_limit_type; - u8 pre_ampdu_time_type; - u8 cur_ampdu_time_type; - u32 arp_cnt; - - u32 pre_ext_ant_switch_status; - u32 cur_ext_ant_switch_status; - - u8 pre_ext_band_switch_status; - u8 cur_ext_band_switch_status; - - u8 pre_int_block_status; - u8 cur_int_block_status; - - u8 error_condition; -}; - -struct coex_sta_8821c_1ant { - boolean bt_disabled; - boolean bt_link_exist; - boolean sco_exist; - boolean a2dp_exist; - boolean hid_exist; - boolean pan_exist; - boolean bt_hi_pri_link_exist; - u8 num_of_profile; - - boolean under_lps; - boolean under_ips; - u32 specific_pkt_period_cnt; - u32 high_priority_tx; - u32 high_priority_rx; - u32 low_priority_tx; - u32 low_priority_rx; - s8 bt_rssi; - boolean bt_tx_rx_mask; - u8 pre_bt_rssi_state; - u8 pre_wifi_rssi_state[4]; - boolean c2h_bt_info_req_sent; - u8 bt_info_c2h[BT_INFO_SRC_8821C_1ANT_MAX][10]; - u32 bt_info_c2h_cnt[BT_INFO_SRC_8821C_1ANT_MAX]; - boolean bt_whck_test; - boolean c2h_bt_inquiry_page; - boolean c2h_bt_remote_name_req; - boolean c2h_bt_page; /* Add for win8.1 page out issue */ - boolean wifi_is_high_pri_task; /* Add for win8.1 page out issue */ - u8 bt_retry_cnt; - u8 bt_info_ext; - u8 bt_info_ext2; - u32 pop_event_cnt; - u8 scan_ap_num; - - u32 crc_ok_cck; - u32 crc_ok_11g; - u32 crc_ok_11n; - u32 crc_ok_11n_vht; - - u32 crc_err_cck; - u32 crc_err_11g; - u32 crc_err_11n; - u32 crc_err_11n_vht; - - boolean cck_lock; - boolean pre_ccklock; - boolean cck_ever_lock; - u8 coex_table_type; - - boolean force_lps_on; - u32 wrong_profile_notification; - - boolean concurrent_rx_mode_on; - - u16 score_board; - u8 isolation_btween_wb; /* 0~ 50 */ - - u8 a2dp_bit_pool; - u8 cut_version; - boolean acl_busy; - boolean wl_rf_off_on_event; - boolean bt_create_connection; - - u32 bt_coex_supported_feature; - u32 bt_coex_supported_version; - - u8 bt_ble_scan_type; - u8 bt_ble_scan_para[3]; - - boolean run_time_state; - boolean freeze_coexrun_by_btinfo; - - boolean is_A2DP_3M; - boolean voice_over_HOGP; - u8 bt_info; - boolean is_autoslot; - u8 forbidden_slot; - u8 hid_busy_num; - u8 hid_pair_cnt; - - u32 cnt_RemoteNameReq; - u32 cnt_setupLink; - u32 cnt_ReInit; - u32 cnt_IgnWlanAct; - u32 cnt_Page; - - u16 bt_reg_vendor_ac; - u16 bt_reg_vendor_ae; - - boolean is_setupLink; -}; - - -#define BT_8821C_1ANT_EXT_BAND_SWITCH_USE_DPDT 0 -#define BT_8821C_1ANT_EXT_BAND_SWITCH_USE_SPDT 1 - - -struct rfe_type_8821c_1ant { - - u8 rfe_module_type; - boolean ext_ant_switch_exist; - u8 ext_ant_switch_type; /* 0:DPDT, 1:SPDT */ - u8 ext_ant_switch_ctrl_polarity; /* iF 0: DPDT_P=0, DPDT_N=1 => BTG to Main, WL_A+G to Aux */ - - boolean ext_band_switch_exist; - u8 ext_band_switch_type; /* 0:DPDT, 1:SPDT */ - u8 ext_band_switch_ctrl_polarity; - - boolean wlg_Locate_at_btg; /* If true: WLG at BTG, If false: WLG at WLAG */ - - boolean ext_ant_switch_diversity; /* If diversity on */ -}; - -#define BT_8821C_1ANT_ANTDET_PSD_POINTS 256 /* MAX:1024 */ -#define BT_8821C_1ANT_ANTDET_PSD_AVGNUM 1 /* MAX:3 */ -#define BT_8821C_1ANT_ANTDET_BUF_LEN 16 - -struct psdscan_sta_8821c_1ant { - - u32 ant_det_bt_le_channel; /* BT LE Channel ex:2412 */ - u32 ant_det_bt_tx_time; - u32 ant_det_pre_psdscan_peak_val; - boolean ant_det_is_ant_det_available; - u32 ant_det_psd_scan_peak_val; - boolean ant_det_is_btreply_available; - u32 ant_det_psd_scan_peak_freq; - - u8 ant_det_result; - u8 ant_det_peak_val[BT_8821C_1ANT_ANTDET_BUF_LEN]; - u8 ant_det_peak_freq[BT_8821C_1ANT_ANTDET_BUF_LEN]; - u32 ant_det_try_count; - u32 ant_det_fail_count; - u32 ant_det_inteval_count; - u32 ant_det_thres_offset; - - u32 real_cent_freq; - s32 real_offset; - u32 real_span; - - u32 psd_band_width; /* unit: Hz */ - u32 psd_point; /* 128/256/512/1024 */ - u32 psd_report[1024]; /* unit:dB (20logx), 0~255 */ - u32 psd_report_max_hold[1024]; /* unit:dB (20logx), 0~255 */ - u32 psd_start_point; - u32 psd_stop_point; - u32 psd_max_value_point; - u32 psd_max_value; - u32 psd_max_value2; - u32 psd_avg_value; /* filter loop_max_value that below BT_8821C_1ANT_ANTDET_PSDTHRES_1ANT, and average the rest*/ - u32 psd_loop_max_value[BT_8821C_1ANT_ANTDET_PSD_SWWEEPCOUNT]; /*max value in each loop */ - u32 psd_start_base; - u32 psd_avg_num; /* 1/8/16/32 */ - u32 psd_gen_count; - boolean is_AntDet_running; - boolean is_psd_show_max_only; -}; - -/* ******************************************* - * The following is interface which will notify coex module. - * ******************************************* */ -void ex_halbtc8821c1ant_power_on_setting(IN struct btc_coexist *btcoexist); -void ex_halbtc8821c1ant_pre_load_firmware(IN struct btc_coexist *btcoexist); -void ex_halbtc8821c1ant_init_hw_config(IN struct btc_coexist *btcoexist, - IN boolean wifi_only); -void ex_halbtc8821c1ant_init_coex_dm(IN struct btc_coexist *btcoexist); -void ex_halbtc8821c1ant_ips_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8821c1ant_lps_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8821c1ant_scan_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8821c1ant_switchband_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8821c1ant_connect_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8821c1ant_media_status_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8821c1ant_specific_packet_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8821c1ant_bt_info_notify(IN struct btc_coexist *btcoexist, - IN u8 *tmp_buf, IN u8 length); -void ex_halbtc8821c1ant_rf_status_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8821c1ant_halt_notify(IN struct btc_coexist *btcoexist); -void ex_halbtc8821c1ant_pnp_notify(IN struct btc_coexist *btcoexist, - IN u8 pnp_state); -void ex_halbtc8821c1ant_coex_dm_reset(IN struct btc_coexist *btcoexist); -void ex_halbtc8821c1ant_periodical(IN struct btc_coexist *btcoexist); -void ex_halbtc8821c1ant_display_coex_info(IN struct btc_coexist *btcoexist); -void ex_halbtc8821c1ant_antenna_detection(IN struct btc_coexist *btcoexist, - IN u32 cent_freq, IN u32 offset, IN u32 span, IN u32 seconds); -void ex_halbtc8821c1ant_antenna_isolation(IN struct btc_coexist *btcoexist, - IN u32 cent_freq, IN u32 offset, IN u32 span, IN u32 seconds); - -void ex_halbtc8821c1ant_psd_scan(IN struct btc_coexist *btcoexist, - IN u32 cent_freq, IN u32 offset, IN u32 span, IN u32 seconds); -void ex_halbtc8821c1ant_display_ant_detection(IN struct btc_coexist *btcoexist); - -#else -#define ex_halbtc8821c1ant_power_on_setting(btcoexist) -#define ex_halbtc8821c1ant_pre_load_firmware(btcoexist) -#define ex_halbtc8821c1ant_init_hw_config(btcoexist, wifi_only) -#define ex_halbtc8821c1ant_init_coex_dm(btcoexist) -#define ex_halbtc8821c1ant_ips_notify(btcoexist, type) -#define ex_halbtc8821c1ant_lps_notify(btcoexist, type) -#define ex_halbtc8821c1ant_scan_notify(btcoexist, type) -#define ex_halbtc8821c1ant_switchband_notify(btcoexist,type) -#define ex_halbtc8821c1ant_connect_notify(btcoexist, type) -#define ex_halbtc8821c1ant_media_status_notify(btcoexist, type) -#define ex_halbtc8821c1ant_specific_packet_notify(btcoexist, type) -#define ex_halbtc8821c1ant_bt_info_notify(btcoexist, tmp_buf, length) -#define ex_halbtc8821c1ant_rf_status_notify(btcoexist, type) -#define ex_halbtc8821c1ant_halt_notify(btcoexist) -#define ex_halbtc8821c1ant_pnp_notify(btcoexist, pnp_state) -#define ex_halbtc8821c1ant_coex_dm_reset(btcoexist) -#define ex_halbtc8821c1ant_periodical(btcoexist) -#define ex_halbtc8821c1ant_display_coex_info(btcoexist) -#define ex_halbtc8821c1ant_antenna_detection(btcoexist, cent_freq, offset, span, seconds) -#define ex_halbtc8821c1ant_antenna_isolation(btcoexist, cent_freq, offset, span, seconds) -#define ex_halbtc8821c1ant_psd_scan(btcoexist, cent_freq, offset, span, seconds) -#define ex_halbtc8821c1ant_display_ant_detection(btcoexist) -#endif - -#endif - diff --git a/hal/btc/halbtc8821c2ant.c b/hal/btc/halbtc8821c2ant.c deleted file mode 100644 index 5bae816..0000000 --- a/hal/btc/halbtc8821c2ant.c +++ /dev/null @@ -1,6936 +0,0 @@ -/* ************************************************************ - * Description: - * - * This file is for RTL8821C Co-exist mechanism - * - * History - * 2012/11/15 Cosa first check in. - * - * ************************************************************ */ - -/* ************************************************************ - * include files - * ************************************************************ */ -#include "mp_precomp.h" - -#if (BT_SUPPORT == 1 && COEX_SUPPORT == 1) - -#if (RTL8821C_SUPPORT == 1) -/* ************************************************************ - * Global variables, these are static variables - * ************************************************************ */ -static u8 *trace_buf = &gl_btc_trace_buf[0]; -static struct coex_dm_8821c_2ant glcoex_dm_8821c_2ant; -static struct coex_dm_8821c_2ant *coex_dm = &glcoex_dm_8821c_2ant; -static struct coex_sta_8821c_2ant glcoex_sta_8821c_2ant; -static struct coex_sta_8821c_2ant *coex_sta = &glcoex_sta_8821c_2ant; -static struct psdscan_sta_8821c_2ant gl_psd_scan_8821c_2ant; -static struct psdscan_sta_8821c_2ant *psd_scan = &gl_psd_scan_8821c_2ant; -static struct rfe_type_8821c_2ant gl_rfe_type_8821c_2ant; -static struct rfe_type_8821c_2ant *rfe_type = &gl_rfe_type_8821c_2ant; - -const char *const glbt_info_src_8821c_2ant[] = { - "BT Info[wifi fw]", - "BT Info[bt rsp]", - "BT Info[bt auto report]", -}; - -u32 glcoex_ver_date_8821c_2ant = 20160805; -u32 glcoex_ver_8821c_2ant = 0x04; -u32 glcoex_ver_btdesired_8821c_2ant = 0x04; - - -/* ************************************************************ - * local function proto type if needed - * ************************************************************ - * ************************************************************ - * local function start with halbtc8821c2ant_ - * ************************************************************ */ -u8 halbtc8821c2ant_bt_rssi_state(u8 *ppre_bt_rssi_state, u8 level_num, - u8 rssi_thresh, u8 rssi_thresh1) -{ - s32 bt_rssi = 0; - u8 bt_rssi_state = *ppre_bt_rssi_state; - - bt_rssi = coex_sta->bt_rssi; - - if (level_num == 2) { - if ((*ppre_bt_rssi_state == BTC_RSSI_STATE_LOW) || - (*ppre_bt_rssi_state == BTC_RSSI_STATE_STAY_LOW)) { - if (bt_rssi >= (rssi_thresh + - BTC_RSSI_COEX_THRESH_TOL_8821C_2ANT)) - bt_rssi_state = BTC_RSSI_STATE_HIGH; - else - bt_rssi_state = BTC_RSSI_STATE_STAY_LOW; - } else { - if (bt_rssi < rssi_thresh) - bt_rssi_state = BTC_RSSI_STATE_LOW; - else - bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH; - } - } else if (level_num == 3) { - if (rssi_thresh > rssi_thresh1) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Rssi thresh error!!\n"); - BTC_TRACE(trace_buf); - return *ppre_bt_rssi_state; - } - - if ((*ppre_bt_rssi_state == BTC_RSSI_STATE_LOW) || - (*ppre_bt_rssi_state == BTC_RSSI_STATE_STAY_LOW)) { - if (bt_rssi >= (rssi_thresh + - BTC_RSSI_COEX_THRESH_TOL_8821C_2ANT)) - bt_rssi_state = BTC_RSSI_STATE_MEDIUM; - else - bt_rssi_state = BTC_RSSI_STATE_STAY_LOW; - } else if ((*ppre_bt_rssi_state == BTC_RSSI_STATE_MEDIUM) || - (*ppre_bt_rssi_state == BTC_RSSI_STATE_STAY_MEDIUM)) { - if (bt_rssi >= (rssi_thresh1 + - BTC_RSSI_COEX_THRESH_TOL_8821C_2ANT)) - bt_rssi_state = BTC_RSSI_STATE_HIGH; - else if (bt_rssi < rssi_thresh) - bt_rssi_state = BTC_RSSI_STATE_LOW; - else - bt_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM; - } else { - if (bt_rssi < rssi_thresh1) - bt_rssi_state = BTC_RSSI_STATE_MEDIUM; - else - bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH; - } - } - - *ppre_bt_rssi_state = bt_rssi_state; - - return bt_rssi_state; -} - -u8 halbtc8821c2ant_wifi_rssi_state(IN struct btc_coexist *btcoexist, - IN u8 *pprewifi_rssi_state, IN u8 level_num, IN u8 rssi_thresh, - IN u8 rssi_thresh1) -{ - s32 wifi_rssi = 0; - u8 wifi_rssi_state = *pprewifi_rssi_state; - - btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi); - - if (level_num == 2) { - if ((*pprewifi_rssi_state == BTC_RSSI_STATE_LOW) || - (*pprewifi_rssi_state == BTC_RSSI_STATE_STAY_LOW)) { - if (wifi_rssi >= (rssi_thresh + - BTC_RSSI_COEX_THRESH_TOL_8821C_2ANT)) - wifi_rssi_state = BTC_RSSI_STATE_HIGH; - else - wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW; - } else { - if (wifi_rssi < rssi_thresh) - wifi_rssi_state = BTC_RSSI_STATE_LOW; - else - wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH; - } - } else if (level_num == 3) { - if (rssi_thresh > rssi_thresh1) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], wifi RSSI thresh error!!\n"); - BTC_TRACE(trace_buf); - return *pprewifi_rssi_state; - } - - if ((*pprewifi_rssi_state == BTC_RSSI_STATE_LOW) || - (*pprewifi_rssi_state == BTC_RSSI_STATE_STAY_LOW)) { - if (wifi_rssi >= (rssi_thresh + - BTC_RSSI_COEX_THRESH_TOL_8821C_2ANT)) - wifi_rssi_state = BTC_RSSI_STATE_MEDIUM; - else - wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW; - } else if ((*pprewifi_rssi_state == BTC_RSSI_STATE_MEDIUM) || - (*pprewifi_rssi_state == BTC_RSSI_STATE_STAY_MEDIUM)) { - if (wifi_rssi >= (rssi_thresh1 + - BTC_RSSI_COEX_THRESH_TOL_8821C_2ANT)) - wifi_rssi_state = BTC_RSSI_STATE_HIGH; - else if (wifi_rssi < rssi_thresh) - wifi_rssi_state = BTC_RSSI_STATE_LOW; - else - wifi_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM; - } else { - if (wifi_rssi < rssi_thresh1) - wifi_rssi_state = BTC_RSSI_STATE_MEDIUM; - else - wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH; - } - } - - *pprewifi_rssi_state = wifi_rssi_state; - - return wifi_rssi_state; -} - -void halbtc8821c2ant_coex_switch_threshold(IN struct btc_coexist *btcoexist, - IN u8 isolation_measuared) -{ - s8 interference_wl_tx = 0, interference_bt_tx = 0; - - - interference_wl_tx = BT_8821C_2ANT_WIFI_MAX_TX_POWER - - isolation_measuared; - interference_bt_tx = BT_8821C_2ANT_BT_MAX_TX_POWER - - isolation_measuared; - - - - coex_sta->wifi_coex_thres = BT_8821C_2ANT_WIFI_RSSI_COEXSWITCH_THRES1; - coex_sta->wifi_coex_thres2 = BT_8821C_2ANT_WIFI_RSSI_COEXSWITCH_THRES2; - - coex_sta->bt_coex_thres = BT_8821C_2ANT_BT_RSSI_COEXSWITCH_THRES1; - coex_sta->bt_coex_thres2 = BT_8821C_2ANT_BT_RSSI_COEXSWITCH_THRES2; - - - /* - coex_sta->wifi_coex_thres = interference_wl_tx + BT_8821C_2ANT_WIFI_SIR_THRES1; - coex_sta->wifi_coex_thres2 = interference_wl_tx + BT_8821C_2ANT_WIFI_SIR_THRES2; - - coex_sta->bt_coex_thres = interference_bt_tx + BT_8821C_2ANT_BT_SIR_THRES1; - coex_sta->bt_coex_thres2 = interference_bt_tx + BT_8821C_2ANT_BT_SIR_THRES2; - */ - - - - - - /* - if ( BT_8821C_2ANT_WIFI_RSSI_COEXSWITCH_THRES1 < (isolation_measuared - - BT_8821C_2ANT_DEFAULT_ISOLATION) ) - coex_sta->wifi_coex_thres = BT_8821C_2ANT_WIFI_RSSI_COEXSWITCH_THRES1; - else - coex_sta->wifi_coex_thres = BT_8821C_2ANT_WIFI_RSSI_COEXSWITCH_THRES1 - (isolation_measuared - - BT_8821C_2ANT_DEFAULT_ISOLATION); - - if ( BT_8821C_2ANT_BT_RSSI_COEXSWITCH_THRES1 < (isolation_measuared - - BT_8821C_2ANT_DEFAULT_ISOLATION) ) - coex_sta->bt_coex_thres = BT_8821C_2ANT_BT_RSSI_COEXSWITCH_THRES1; - else - coex_sta->bt_coex_thres = BT_8821C_2ANT_BT_RSSI_COEXSWITCH_THRES1 - (isolation_measuared - - BT_8821C_2ANT_DEFAULT_ISOLATION); - - */ -} - - -void halbtc8821c2ant_limited_rx(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean rej_ap_agg_pkt, - IN boolean bt_ctrl_agg_buf_size, IN u8 agg_buf_size) -{ - boolean reject_rx_agg = rej_ap_agg_pkt; - boolean bt_ctrl_rx_agg_size = bt_ctrl_agg_buf_size; - u8 rx_agg_size = agg_buf_size; - - /* ============================================ */ - /* Rx Aggregation related setting */ - /* ============================================ */ - btcoexist->btc_set(btcoexist, BTC_SET_BL_TO_REJ_AP_AGG_PKT, - &reject_rx_agg); - /* decide BT control aggregation buf size or not */ - btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_CTRL_AGG_SIZE, - &bt_ctrl_rx_agg_size); - /* aggregation buf size, only work when BT control Rx aggregation size. */ - btcoexist->btc_set(btcoexist, BTC_SET_U1_AGG_BUF_SIZE, &rx_agg_size); - /* real update aggregation setting */ - btcoexist->btc_set(btcoexist, BTC_SET_ACT_AGGREGATE_CTRL, NULL); -} - -void halbtc8821c2ant_query_bt_info(IN struct btc_coexist *btcoexist) -{ - u8 h2c_parameter[1] = {0}; - - coex_sta->c2h_bt_info_req_sent = true; - - h2c_parameter[0] |= BIT(0); /* trigger */ - - btcoexist->btc_fill_h2c(btcoexist, 0x61, 1, h2c_parameter); -} - -void halbtc8821c2ant_monitor_bt_ctr(IN struct btc_coexist *btcoexist) -{ - u32 reg_hp_txrx, reg_lp_txrx, u32tmp; - u32 reg_hp_tx = 0, reg_hp_rx = 0, reg_lp_tx = 0, reg_lp_rx = 0; - static u8 num_of_bt_counter_chk = 0, cnt_slave = 0; - - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - - reg_hp_txrx = 0x770; - reg_lp_txrx = 0x774; - - u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_hp_txrx); - reg_hp_tx = u32tmp & MASKLWORD; - reg_hp_rx = (u32tmp & MASKHWORD) >> 16; - - u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_lp_txrx); - reg_lp_tx = u32tmp & MASKLWORD; - reg_lp_rx = (u32tmp & MASKHWORD) >> 16; - - coex_sta->high_priority_tx = reg_hp_tx; - coex_sta->high_priority_rx = reg_hp_rx; - coex_sta->low_priority_tx = reg_lp_tx; - coex_sta->low_priority_rx = reg_lp_rx; - - - /* reset counter */ - btcoexist->btc_write_1byte(btcoexist, 0x76e, 0xc); - - if ((coex_sta->low_priority_tx > 1050) && - (!coex_sta->c2h_bt_inquiry_page)) - coex_sta->pop_event_cnt++; - - if ((coex_sta->low_priority_rx >= 950) && - (coex_sta->low_priority_rx >= coex_sta->low_priority_tx) - && (!coex_sta->under_ips) && (!coex_sta->c2h_bt_inquiry_page) && - (coex_sta->bt_link_exist)) { - if (cnt_slave >= 2) { - bt_link_info->slave_role = true; - cnt_slave = 2; - } else - cnt_slave++; - } else { - if (cnt_slave == 0) { - bt_link_info->slave_role = false; - cnt_slave = 0; - } else - cnt_slave--; - - } - - if ((coex_sta->high_priority_tx == 0) && - (coex_sta->high_priority_rx == 0) && - (coex_sta->low_priority_tx == 0) && - (coex_sta->low_priority_rx == 0)) { - num_of_bt_counter_chk++; - if (num_of_bt_counter_chk >= 3) { - halbtc8821c2ant_query_bt_info(btcoexist); - num_of_bt_counter_chk = 0; - } - } - -} - -void halbtc8821c2ant_monitor_wifi_ctr(IN struct btc_coexist *btcoexist) -{ -#if 1 - s32 wifi_rssi = 0; - boolean wifi_busy = false, wifi_under_b_mode = false; - static u8 cck_lock_counter = 0; - u32 total_cnt, reg_val1, reg_val2; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_B_MODE, - &wifi_under_b_mode); - - coex_sta->crc_ok_cck = btcoexist->btc_phydm_query_PHY_counter( - btcoexist, PHYDM_INFO_CRC32_OK_CCK); - coex_sta->crc_ok_11g = btcoexist->btc_phydm_query_PHY_counter( - btcoexist, PHYDM_INFO_CRC32_OK_LEGACY); - coex_sta->crc_ok_11n = btcoexist->btc_phydm_query_PHY_counter( - btcoexist, PHYDM_INFO_CRC32_OK_HT); - coex_sta->crc_ok_11n_vht = - btcoexist->btc_phydm_query_PHY_counter(btcoexist, - PHYDM_INFO_CRC32_OK_VHT); - - coex_sta->crc_err_cck = btcoexist->btc_phydm_query_PHY_counter( - btcoexist, PHYDM_INFO_CRC32_ERROR_CCK); - coex_sta->crc_err_11g = btcoexist->btc_phydm_query_PHY_counter( - btcoexist, PHYDM_INFO_CRC32_ERROR_LEGACY); - coex_sta->crc_err_11n = btcoexist->btc_phydm_query_PHY_counter( - btcoexist, PHYDM_INFO_CRC32_ERROR_HT); - coex_sta->crc_err_11n_vht = - btcoexist->btc_phydm_query_PHY_counter(btcoexist, - PHYDM_INFO_CRC32_ERROR_VHT); - - - if ((wifi_busy) && (wifi_rssi >= 30) && (!wifi_under_b_mode)) { - total_cnt = coex_sta->crc_ok_cck + coex_sta->crc_ok_11g - + - coex_sta->crc_ok_11n + - coex_sta->crc_ok_11n_vht; - - if ((coex_dm->bt_status == - BT_8821C_1ANT_BT_STATUS_ACL_BUSY) || - (coex_dm->bt_status == - BT_8821C_1ANT_BT_STATUS_ACL_SCO_BUSY) || - (coex_dm->bt_status == - BT_8821C_1ANT_BT_STATUS_SCO_BUSY)) { - if (coex_sta->crc_ok_cck > (total_cnt - - coex_sta->crc_ok_cck)) { - if (cck_lock_counter < 3) - cck_lock_counter++; - } else { - if (cck_lock_counter > 0) - cck_lock_counter--; - } - - } else { - if (cck_lock_counter > 0) - cck_lock_counter--; - } - } else { - if (cck_lock_counter > 0) - cck_lock_counter--; - } - - if (!coex_sta->pre_ccklock) { - - if (cck_lock_counter >= 3) - coex_sta->cck_lock = true; - else - coex_sta->cck_lock = false; - } else { - if (cck_lock_counter == 0) - coex_sta->cck_lock = false; - else - coex_sta->cck_lock = true; - } - - if (coex_sta->cck_lock) - coex_sta->cck_ever_lock = true; - - coex_sta->pre_ccklock = coex_sta->cck_lock; - -#endif -} - -boolean halbtc8821c2ant_is_wifibt_status_changed(IN struct btc_coexist - *btcoexist) -{ - static boolean pre_wifi_busy = false, pre_under_4way = false, - pre_bt_hs_on = false, pre_bt_off = false; - static u8 pre_hid_busy_num = 0; - boolean wifi_busy = false, under_4way = false, bt_hs_on = false; - boolean wifi_connected = false; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS, - &under_4way); - - if (coex_sta->bt_disabled != pre_bt_off) { - pre_bt_off = coex_sta->bt_disabled; - - if (coex_sta->bt_disabled) - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT is disabled !!\n"); - else - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT is enabled !!\n"); - - BTC_TRACE(trace_buf); - - coex_sta->bt_coex_supported_feature = 0; - coex_sta->bt_coex_supported_version = 0; - coex_sta->bt_ble_scan_type = 0; - coex_sta->bt_ble_scan_para[0] = 0; - coex_sta->bt_ble_scan_para[1] = 0; - coex_sta->bt_ble_scan_para[2] = 0; - coex_sta->bt_reg_vendor_ac = 0xffff; - coex_sta->bt_reg_vendor_ae = 0xffff; - return true; - } - - - if (wifi_connected) { - if (wifi_busy != pre_wifi_busy) { - pre_wifi_busy = wifi_busy; - return true; - } - if (under_4way != pre_under_4way) { - pre_under_4way = under_4way; - return true; - } - if (bt_hs_on != pre_bt_hs_on) { - pre_bt_hs_on = bt_hs_on; - return true; - } - - if (!coex_sta->bt_disabled) { - - if (coex_sta->hid_busy_num != pre_hid_busy_num) { - pre_hid_busy_num = coex_sta->hid_busy_num; - return true; - } - } - } - - return false; -} - - -void halbtc8821c2ant_update_bt_link_info(IN struct btc_coexist *btcoexist) -{ - - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - boolean bt_hs_on = false; - boolean bt_busy = false; - - coex_sta->num_of_profile = 0; - - /* set link exist status */ - if (!(coex_sta->bt_info & BT_INFO_8821C_1ANT_B_CONNECTION)) { - coex_sta->bt_link_exist = false; - coex_sta->pan_exist = false; - coex_sta->a2dp_exist = false; - coex_sta->hid_exist = false; - coex_sta->sco_exist = false; - } else { /* connection exists */ - coex_sta->bt_link_exist = true; - if (coex_sta->bt_info & BT_INFO_8821C_1ANT_B_FTP) { - coex_sta->pan_exist = true; - coex_sta->num_of_profile++; - } else - coex_sta->pan_exist = false; - - if (coex_sta->bt_info & BT_INFO_8821C_1ANT_B_A2DP) { - coex_sta->a2dp_exist = true; - coex_sta->num_of_profile++; - } else - coex_sta->a2dp_exist = false; - - if (coex_sta->bt_info & BT_INFO_8821C_1ANT_B_HID) { - coex_sta->hid_exist = true; - coex_sta->num_of_profile++; - } else - coex_sta->hid_exist = false; - - if (coex_sta->bt_info & BT_INFO_8821C_1ANT_B_SCO_ESCO) { - coex_sta->sco_exist = true; - coex_sta->num_of_profile++; - } else - coex_sta->sco_exist = false; - - } - - - btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); - - bt_link_info->bt_link_exist = coex_sta->bt_link_exist; - bt_link_info->sco_exist = coex_sta->sco_exist; - bt_link_info->a2dp_exist = coex_sta->a2dp_exist; - bt_link_info->pan_exist = coex_sta->pan_exist; - bt_link_info->hid_exist = coex_sta->hid_exist; - bt_link_info->acl_busy = coex_sta->acl_busy; - - /* work around for HS mode. */ - if (bt_hs_on) { - bt_link_info->pan_exist = true; - bt_link_info->bt_link_exist = true; - } - - /* check if Sco only */ - if (bt_link_info->sco_exist && - !bt_link_info->a2dp_exist && - !bt_link_info->pan_exist && - !bt_link_info->hid_exist) - bt_link_info->sco_only = true; - else - bt_link_info->sco_only = false; - - /* check if A2dp only */ - if (!bt_link_info->sco_exist && - bt_link_info->a2dp_exist && - !bt_link_info->pan_exist && - !bt_link_info->hid_exist) - bt_link_info->a2dp_only = true; - else - bt_link_info->a2dp_only = false; - - /* check if Pan only */ - if (!bt_link_info->sco_exist && - !bt_link_info->a2dp_exist && - bt_link_info->pan_exist && - !bt_link_info->hid_exist) - bt_link_info->pan_only = true; - else - bt_link_info->pan_only = false; - - /* check if Hid only */ - if (!bt_link_info->sco_exist && - !bt_link_info->a2dp_exist && - !bt_link_info->pan_exist && - bt_link_info->hid_exist) - bt_link_info->hid_only = true; - else - bt_link_info->hid_only = false; - - if (!(coex_sta->bt_info & BT_INFO_8821C_2ANT_B_CONNECTION)) { - coex_dm->bt_status = BT_8821C_2ANT_BT_STATUS_NON_CONNECTED_IDLE; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), BT Non-Connected idle!!!\n"); - } else if (coex_sta->bt_info == BT_INFO_8821C_2ANT_B_CONNECTION) { - /* connection exists but no busy */ - coex_dm->bt_status = BT_8821C_2ANT_BT_STATUS_CONNECTED_IDLE; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), BT Connected-idle!!!\n"); - } else if (((coex_sta->bt_info & BT_INFO_8821C_2ANT_B_SCO_ESCO) || - (coex_sta->bt_info & BT_INFO_8821C_2ANT_B_SCO_BUSY)) && - (coex_sta->bt_info & BT_INFO_8821C_2ANT_B_ACL_BUSY)) { - coex_dm->bt_status = BT_8821C_2ANT_BT_STATUS_ACL_SCO_BUSY; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), BT ACL SCO busy!!!\n"); - } else if ((coex_sta->bt_info & BT_INFO_8821C_2ANT_B_SCO_ESCO) || - (coex_sta->bt_info & BT_INFO_8821C_2ANT_B_SCO_BUSY)) { - coex_dm->bt_status = BT_8821C_2ANT_BT_STATUS_SCO_BUSY; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), BT SCO busy!!!\n"); - } else if (coex_sta->bt_info & BT_INFO_8821C_2ANT_B_ACL_BUSY) { - coex_dm->bt_status = BT_8821C_2ANT_BT_STATUS_ACL_BUSY; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), BT ACL busy!!!\n"); - } else { - coex_dm->bt_status = BT_8821C_2ANT_BT_STATUS_MAX; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), BT Non-Defined state!!!\n"); - } - - BTC_TRACE(trace_buf); - - if ((BT_8821C_2ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) || - (BT_8821C_2ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) || - (BT_8821C_2ANT_BT_STATUS_ACL_SCO_BUSY == coex_dm->bt_status)) - bt_busy = true; - else - bt_busy = false; - - btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bt_busy); -} - -void halbtc8821c2ant_update_wifi_channel_info(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - u8 h2c_parameter[3] = {0}; - u32 wifi_bw; - u8 wifi_central_chnl; - - /* only 2.4G we need to inform bt the chnl mask */ - btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_CENTRAL_CHNL, - &wifi_central_chnl); - if ((BTC_MEDIA_CONNECT == type) && - (wifi_central_chnl <= 14)) { - h2c_parameter[0] = - 0x1; /* enable BT AFH skip WL channel for 8821c because BT Rx LO interference */ - /* h2c_parameter[0] = 0x0; */ - h2c_parameter[1] = wifi_central_chnl; - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw); - if (BTC_WIFI_BW_HT40 == wifi_bw) - h2c_parameter[2] = 0x30; - else - h2c_parameter[2] = 0x20; - } - - coex_dm->wifi_chnl_info[0] = h2c_parameter[0]; - coex_dm->wifi_chnl_info[1] = h2c_parameter[1]; - coex_dm->wifi_chnl_info[2] = h2c_parameter[2]; - - btcoexist->btc_fill_h2c(btcoexist, 0x66, 3, h2c_parameter); - -} - -void halbtc8821c2ant_set_fw_dac_swing_level(IN struct btc_coexist *btcoexist, - IN u8 dac_swing_lvl) -{ - u8 h2c_parameter[1] = {0}; - - /* There are several type of dacswing */ - /* 0x18/ 0x10/ 0xc/ 0x8/ 0x4/ 0x6 */ - h2c_parameter[0] = dac_swing_lvl; - - btcoexist->btc_fill_h2c(btcoexist, 0x64, 1, h2c_parameter); -} - -void halbtc8821c2ant_fw_dac_swing_lvl(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 fw_dac_swing_lvl) -{ - coex_dm->cur_fw_dac_swing_lvl = fw_dac_swing_lvl; - - if (!force_exec) { - if (coex_dm->pre_fw_dac_swing_lvl == - coex_dm->cur_fw_dac_swing_lvl) - return; - } - - halbtc8821c2ant_set_fw_dac_swing_level(btcoexist, - coex_dm->cur_fw_dac_swing_lvl); - - coex_dm->pre_fw_dac_swing_lvl = coex_dm->cur_fw_dac_swing_lvl; -} - -void halbtc8821c2ant_set_fw_dec_bt_pwr(IN struct btc_coexist *btcoexist, - IN u8 dec_bt_pwr_lvl) -{ - u8 h2c_parameter[1] = {0}; - - h2c_parameter[0] = dec_bt_pwr_lvl; - - btcoexist->btc_fill_h2c(btcoexist, 0x62, 1, h2c_parameter); -} - -void halbtc8821c2ant_dec_bt_pwr(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 dec_bt_pwr_lvl) -{ - coex_dm->cur_bt_dec_pwr_lvl = dec_bt_pwr_lvl; - - if (!force_exec) { - if (coex_dm->pre_bt_dec_pwr_lvl == coex_dm->cur_bt_dec_pwr_lvl) - return; - } - halbtc8821c2ant_set_fw_dec_bt_pwr(btcoexist, - coex_dm->cur_bt_dec_pwr_lvl); - - coex_dm->pre_bt_dec_pwr_lvl = coex_dm->cur_bt_dec_pwr_lvl; -} - - -void halbtc8821c2ant_low_penalty_ra(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean low_penalty_ra) -{ - -#if 1 - coex_dm->cur_low_penalty_ra = low_penalty_ra; - - if (!force_exec) { - if (coex_dm->pre_low_penalty_ra == - coex_dm->cur_low_penalty_ra) - return; - } - - if (low_penalty_ra) - btcoexist->btc_phydm_modify_RA_PCR_threshold(btcoexist, 0, 15); - else - btcoexist->btc_phydm_modify_RA_PCR_threshold(btcoexist, 0, 0); - - coex_dm->pre_low_penalty_ra = coex_dm->cur_low_penalty_ra; - -#endif - -} - - -void halbtc8821c2ant_set_bt_auto_report(IN struct btc_coexist *btcoexist, - IN boolean enable_auto_report) -{ - u8 h2c_parameter[1] = {0}; - - h2c_parameter[0] = 0; - - if (enable_auto_report) - h2c_parameter[0] |= BIT(0); - - btcoexist->btc_fill_h2c(btcoexist, 0x68, 1, h2c_parameter); -} - -void halbtc8821c2ant_bt_auto_report(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean enable_auto_report) -{ - coex_dm->cur_bt_auto_report = enable_auto_report; - - if (!force_exec) { - if (coex_dm->pre_bt_auto_report == coex_dm->cur_bt_auto_report) - return; - } - halbtc8821c2ant_set_bt_auto_report(btcoexist, - coex_dm->cur_bt_auto_report); - - coex_dm->pre_bt_auto_report = coex_dm->cur_bt_auto_report; -} - -void halbtc8821c2ant_write_score_board( - IN struct btc_coexist *btcoexist, - IN u16 bitpos, - IN boolean state -) -{ - - static u16 originalval = 0x8002; - - if (state) - originalval = originalval | bitpos; - else - originalval = originalval & (~bitpos); - - - btcoexist->btc_write_2byte(btcoexist, 0xaa, originalval); - -} - -void halbtc8821c2ant_read_score_board( - IN struct btc_coexist *btcoexist, - IN u16 *score_board_val -) -{ - - *score_board_val = (btcoexist->btc_read_2byte(btcoexist, - 0xaa)) & 0x7fff; -} - - -void halbtc8821c2ant_post_state_to_bt( - IN struct btc_coexist *btcoexist, - IN u16 type, - IN boolean state -) -{ - - halbtc8821c2ant_write_score_board(btcoexist, (u16) type, state); - -} - -void halbtc8821c2ant_monitor_bt_enable_disable(IN struct btc_coexist *btcoexist) -{ - static u32 bt_disable_cnt = 0; - boolean bt_active = true, bt_disabled = false, wifi_under_5g = false; - u16 u16tmp; - - /* This function check if bt is disabled */ -#if 0 - if (coex_sta->high_priority_tx == 0 && - coex_sta->high_priority_rx == 0 && - coex_sta->low_priority_tx == 0 && - coex_sta->low_priority_rx == 0) - bt_active = false; - if (coex_sta->high_priority_tx == 0xffff && - coex_sta->high_priority_rx == 0xffff && - coex_sta->low_priority_tx == 0xffff && - coex_sta->low_priority_rx == 0xffff) - bt_active = false; - - -#else - - /* Read BT on/off status from scoreboard[1], enable this only if BT patch support this feature */ - halbtc8821c2ant_read_score_board(btcoexist, &u16tmp); - - bt_active = u16tmp & BIT(1); - - -#endif - - if (bt_active) { - bt_disable_cnt = 0; - bt_disabled = false; - btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_DISABLE, - &bt_disabled); - } else { - - bt_disable_cnt++; - if (bt_disable_cnt >= 10) { - bt_disabled = true; - bt_disable_cnt = 10; - } - - btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_DISABLE, - &bt_disabled); - } - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g); - - if ((wifi_under_5g) || (bt_disabled)) - halbtc8821c2ant_low_penalty_ra(btcoexist, NORMAL_EXEC, false); - else - halbtc8821c2ant_low_penalty_ra(btcoexist, NORMAL_EXEC, true); - - - if (coex_sta->bt_disabled != bt_disabled) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT is from %s to %s!!\n", - (coex_sta->bt_disabled ? "disabled" : "enabled"), - (bt_disabled ? "disabled" : "enabled")); - BTC_TRACE(trace_buf); - coex_sta->bt_disabled = bt_disabled; - } - -} - -void halbtc8821c2ant_enable_gnt_to_gpio(IN struct btc_coexist *btcoexist, - boolean isenable) -{ -#if BT_8821C_2ANT_COEX_DBG - static u8 bitVal[5] = {0, 0, 0, 0, 0}; - static boolean state = false; - /* - if (state ==isenable) - return; - else - state = isenable; - */ - if (isenable) { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], enable_gnt_to_gpio!!\n"); - BTC_TRACE(trace_buf); - - /* enable GNT_WL, GNT_BT to GPIO for debug */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x73, 0x8, 0x1); - - /* store original value */ - bitVal[0] = (btcoexist->btc_read_1byte(btcoexist, - 0x66) & BIT(4)) >> 4; /*0x66[4] */ - bitVal[1] = (btcoexist->btc_read_1byte(btcoexist, - 0x67) & BIT(0)); /*0x66[8] */ - bitVal[2] = (btcoexist->btc_read_1byte(btcoexist, - 0x42) & BIT(3)) >> 3; /*0x40[19] */ - bitVal[3] = (btcoexist->btc_read_1byte(btcoexist, - 0x65) & BIT(7)) >> 7; /*0x64[15] */ - bitVal[4] = (btcoexist->btc_read_1byte(btcoexist, - 0x72) & BIT(2)) >> 2; /*0x70[18] */ - - /* switch GPIO Mux */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x66, BIT(4), - 0x0); /*0x66[4] = 0 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, BIT(0), - 0x0); /*0x66[8] = 0 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x42, BIT(3), - 0x0); /*0x40[19] = 0 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x65, BIT(7), - 0x0); /*0x64[15] = 0 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x72, BIT(2), - 0x0); /*0x70[18] = 0 */ - - - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], disable_gnt_to_gpio!!\n"); - BTC_TRACE(trace_buf); - - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x73, 0x8, 0x0); - - /* Restore original value */ - /* switch GPIO Mux */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x66, BIT(4), - bitVal[0]); /*0x66[4] = 0 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, BIT(0), - bitVal[1]); /*0x66[8] = 0 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x42, BIT(3), - bitVal[2]); /*0x40[19] = 0 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x65, BIT(7), - bitVal[3]); /*0x64[15] = 0 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x72, BIT(2), - bitVal[4]); /*0x70[18] = 0 */ - } - -#endif -} - -u32 halbtc8821c2ant_ltecoex_indirect_read_reg(IN struct btc_coexist *btcoexist, - IN u16 reg_addr) -{ - u32 j = 0; - - - /* wait for ready bit before access 0x1700 */ - btcoexist->btc_write_4byte(btcoexist, 0x1700, 0x800F0000 | reg_addr); - - do { - j++; - } while (((btcoexist->btc_read_1byte(btcoexist, - 0x1703)&BIT(5)) == 0) && - (j < BT_8821C_2ANT_LTECOEX_INDIRECTREG_ACCESS_TIMEOUT)); - - - return btcoexist->btc_read_4byte(btcoexist, - 0x1708); /* get read data */ - -} - -void halbtc8821c2ant_ltecoex_indirect_write_reg(IN struct btc_coexist - *btcoexist, - IN u16 reg_addr, IN u32 bit_mask, IN u32 reg_value) -{ - u32 val, i = 0, j = 0, bitpos = 0; - - - if (bit_mask == 0x0) - return; - if (bit_mask == 0xffffffff) { - btcoexist->btc_write_4byte(btcoexist, 0x1704, - reg_value); /* put write data */ - - /* wait for ready bit before access 0x1700 */ - do { - j++; - } while (((btcoexist->btc_read_1byte(btcoexist, - 0x1703)&BIT(5)) == 0) && - (j < BT_8821C_2ANT_LTECOEX_INDIRECTREG_ACCESS_TIMEOUT)); - - - btcoexist->btc_write_4byte(btcoexist, 0x1700, - 0xc00F0000 | reg_addr); - } else { - for (i = 0; i <= 31; i++) { - if (((bit_mask >> i) & 0x1) == 0x1) { - bitpos = i; - break; - } - } - - /* read back register value before write */ - val = halbtc8821c2ant_ltecoex_indirect_read_reg(btcoexist, - reg_addr); - val = (val & (~bit_mask)) | (reg_value << bitpos); - - btcoexist->btc_write_4byte(btcoexist, 0x1704, - val); /* put write data */ - - /* wait for ready bit before access 0x7c0 */ - do { - j++; - } while (((btcoexist->btc_read_1byte(btcoexist, - 0x1703)&BIT(5)) == 0) && - (j < BT_8821C_2ANT_LTECOEX_INDIRECTREG_ACCESS_TIMEOUT)); - - - btcoexist->btc_write_4byte(btcoexist, 0x1700, - 0xc00F0000 | reg_addr); - - } - -} - -void halbtc8821c2ant_ltecoex_enable(IN struct btc_coexist *btcoexist, - IN boolean enable) -{ - u8 val; - - val = (enable) ? 1 : 0; - halbtc8821c2ant_ltecoex_indirect_write_reg(btcoexist, 0x38, 0x80, - val); /* 0x38[7] */ - -} - -void halbtc8821c2ant_ltecoex_pathcontrol_owner(IN struct btc_coexist *btcoexist, - IN boolean wifi_control) -{ - u8 val; - - val = (wifi_control) ? 1 : 0; - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x73, 0x4, - val); /* 0x70[26] */ - -} - -void halbtc8821c2ant_ltecoex_set_gnt_bt(IN struct btc_coexist *btcoexist, - IN u8 control_block, IN boolean sw_control, IN u8 state) -{ - u32 val = 0, bit_mask; - - state = state & 0x1; - val = (sw_control) ? ((state << 1) | 0x1) : 0; - - switch (control_block) { - case BT_8821C_2ANT_GNT_BLOCK_RFC_BB: - default: - bit_mask = 0xc000; - halbtc8821c2ant_ltecoex_indirect_write_reg(btcoexist, - 0x38, bit_mask, val); /* 0x38[15:14] */ - bit_mask = 0x0c00; - halbtc8821c2ant_ltecoex_indirect_write_reg(btcoexist, - 0x38, bit_mask, val); /* 0x38[11:10] */ - break; - case BT_8821C_2ANT_GNT_BLOCK_RFC: - bit_mask = 0xc000; - halbtc8821c2ant_ltecoex_indirect_write_reg(btcoexist, - 0x38, bit_mask, val); /* 0x38[15:14] */ - break; - case BT_8821C_2ANT_GNT_BLOCK_BB: - bit_mask = 0x0c00; - halbtc8821c2ant_ltecoex_indirect_write_reg(btcoexist, - 0x38, bit_mask, val); /* 0x38[11:10] */ - break; - - } - -} - -void halbtc8821c2ant_ltecoex_set_gnt_wl(IN struct btc_coexist *btcoexist, - IN u8 control_block, IN boolean sw_control, IN u8 state) -{ - u32 val = 0, bit_mask; - - state = state & 0x1; - val = (sw_control) ? ((state << 1) | 0x1) : 0; - - switch (control_block) { - case BT_8821C_2ANT_GNT_BLOCK_RFC_BB: - default: - bit_mask = 0x3000; - halbtc8821c2ant_ltecoex_indirect_write_reg(btcoexist, - 0x38, bit_mask, val); /* 0x38[13:12] */ - bit_mask = 0x0300; - halbtc8821c2ant_ltecoex_indirect_write_reg(btcoexist, - 0x38, bit_mask, val); /* 0x38[9:8] */ - break; - case BT_8821C_2ANT_GNT_BLOCK_RFC: - bit_mask = 0x3000; - halbtc8821c2ant_ltecoex_indirect_write_reg(btcoexist, - 0x38, bit_mask, val); /* 0x38[13:12] */ - break; - case BT_8821C_2ANT_GNT_BLOCK_BB: - bit_mask = 0x0300; - halbtc8821c2ant_ltecoex_indirect_write_reg(btcoexist, - 0x38, bit_mask, val); /* 0x38[9:8] */ - break; - - } - -} - -void halbtc8821c2ant_ltecoex_set_coex_table(IN struct btc_coexist *btcoexist, - IN u8 table_type, IN u16 table_content) -{ - u16 reg_addr = 0x0000; - - switch (table_type) { - case BT_8821C_2ANT_CTT_WL_VS_LTE: - reg_addr = 0xa0; - break; - case BT_8821C_2ANT_CTT_BT_VS_LTE: - reg_addr = 0xa4; - break; - } - - if (reg_addr != 0x0000) - halbtc8821c2ant_ltecoex_indirect_write_reg(btcoexist, reg_addr, - 0xffff, table_content); /* 0xa0[15:0] or 0xa4[15:0] */ - - -} - - -void halbtc8821c2ant_ltecoex_set_break_table(IN struct btc_coexist *btcoexist, - IN u8 table_type, IN u8 table_content) -{ - u16 reg_addr = 0x0000; - - switch (table_type) { - case BT_8821C_2ANT_LBTT_WL_BREAK_LTE: - reg_addr = 0xa8; - break; - case BT_8821C_2ANT_LBTT_BT_BREAK_LTE: - reg_addr = 0xac; - break; - case BT_8821C_2ANT_LBTT_LTE_BREAK_WL: - reg_addr = 0xb0; - break; - case BT_8821C_2ANT_LBTT_LTE_BREAK_BT: - reg_addr = 0xb4; - break; - } - - if (reg_addr != 0x0000) - halbtc8821c2ant_ltecoex_indirect_write_reg(btcoexist, reg_addr, - 0xff, table_content); /* 0xa8[15:0] or 0xb4[15:0] */ - - -} - -void halbtc8821c2ant_set_wltoggle_coex_table(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 interval, - IN u8 val0x6c4_b0, IN u8 val0x6c4_b1, IN u8 val0x6c4_b2, - IN u8 val0x6c4_b3) -{ - static u8 pre_h2c_parameter[6] = {0}; - u8 cur_h2c_parameter[6] = {0}; - u8 i, match_cnt = 0; - - cur_h2c_parameter[0] = 0x7; /* op_code, 0x7= wlan toggle slot*/ - - cur_h2c_parameter[1] = interval; - cur_h2c_parameter[2] = val0x6c4_b0; - cur_h2c_parameter[3] = val0x6c4_b1; - cur_h2c_parameter[4] = val0x6c4_b2; - cur_h2c_parameter[5] = val0x6c4_b3; - - if (!force_exec) { - for (i = 1; i <= 5; i++) { - if (cur_h2c_parameter[i] != pre_h2c_parameter[i]) - break; - - match_cnt++; - } - - if (match_cnt == 5) - return; - } - - for (i = 1; i <= 5; i++) - pre_h2c_parameter[i] = cur_h2c_parameter[i]; - - btcoexist->btc_fill_h2c(btcoexist, 0x69, 6, cur_h2c_parameter); -} - - - -void halbtc8821c2ant_set_coex_table(IN struct btc_coexist *btcoexist, - IN u32 val0x6c0, IN u32 val0x6c4, IN u32 val0x6c8, IN u8 val0x6cc) -{ - btcoexist->btc_write_4byte(btcoexist, 0x6c0, val0x6c0); - - btcoexist->btc_write_4byte(btcoexist, 0x6c4, val0x6c4); - - btcoexist->btc_write_4byte(btcoexist, 0x6c8, val0x6c8); - - btcoexist->btc_write_1byte(btcoexist, 0x6cc, val0x6cc); -} - -void halbtc8821c2ant_coex_table(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u32 val0x6c0, IN u32 val0x6c4, - IN u32 val0x6c8, IN u8 val0x6cc) -{ - coex_dm->cur_val0x6c0 = val0x6c0; - coex_dm->cur_val0x6c4 = val0x6c4; - coex_dm->cur_val0x6c8 = val0x6c8; - coex_dm->cur_val0x6cc = val0x6cc; - - if (!force_exec) { - if ((coex_dm->pre_val0x6c0 == coex_dm->cur_val0x6c0) && - (coex_dm->pre_val0x6c4 == coex_dm->cur_val0x6c4) && - (coex_dm->pre_val0x6c8 == coex_dm->cur_val0x6c8) && - (coex_dm->pre_val0x6cc == coex_dm->cur_val0x6cc)) - return; - } - halbtc8821c2ant_set_coex_table(btcoexist, val0x6c0, val0x6c4, val0x6c8, - val0x6cc); - - coex_dm->pre_val0x6c0 = coex_dm->cur_val0x6c0; - coex_dm->pre_val0x6c4 = coex_dm->cur_val0x6c4; - coex_dm->pre_val0x6c8 = coex_dm->cur_val0x6c8; - coex_dm->pre_val0x6cc = coex_dm->cur_val0x6cc; -} - -void halbtc8821c2ant_coex_table_with_type(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 type) -{ - u32 break_table; - u8 select_table; - - coex_sta->coex_table_type = type; - - if (coex_sta->concurrent_rx_mode_on == true) { - break_table = 0xf0ffffff; /* set WL hi-pri can break BT */ - select_table = - 0xb; /* set Tx response = Hi-Pri (ex: Transmitting ACK,BA,CTS) */ - } else { - break_table = 0xffffff; - select_table = 0x3; - } - - switch (type) { - case 0: - halbtc8821c2ant_coex_table(btcoexist, force_exec, - 0xffffffff, 0xffffffff, break_table, select_table); - break; - case 1: - halbtc8821c2ant_coex_table(btcoexist, force_exec, - 0x55555555, 0x5a5a5a5a, break_table, select_table); - break; - case 2: - halbtc8821c2ant_coex_table(btcoexist, force_exec, - 0x5a5a5a5a, 0x5a5a5a5a, break_table, select_table); - break; - case 3: - halbtc8821c2ant_coex_table(btcoexist, force_exec, - 0x5a5a5a5a, 0x5a5a5a5a, break_table, select_table); - break; - case 4: - halbtc8821c2ant_coex_table(btcoexist, force_exec, - 0x55555555, 0x5a5a5a5a, break_table, select_table); - break; - case 5: - halbtc8821c2ant_coex_table(btcoexist, force_exec, - 0x55555555, 0x55555555, break_table, select_table); - break; - case 6: - halbtc8821c2ant_coex_table(btcoexist, force_exec, - 0xa5555555, 0xaaaaaaaa, break_table, select_table); - break; - case 7: - halbtc8821c2ant_coex_table(btcoexist, force_exec, - 0xa5555555, 0xaa5a5a5a, break_table, select_table); - break; - case 8: - halbtc8821c2ant_coex_table(btcoexist, force_exec, - 0xa5555555, 0x5a5a5a5a, break_table, select_table); - break; - case 9: - halbtc8821c2ant_coex_table(btcoexist, force_exec, - 0x5a5a5a5a, 0xaaaa5aaa, break_table, select_table); - break; - default: - break; - } -} - -void halbtc8821c2ant_set_fw_ignore_wlan_act(IN struct btc_coexist *btcoexist, - IN boolean enable) -{ - u8 h2c_parameter[1] = {0}; - - if (enable) { - h2c_parameter[0] |= BIT(0); /* function enable */ - } - - btcoexist->btc_fill_h2c(btcoexist, 0x63, 1, h2c_parameter); -} - -void halbtc8821c2ant_ignore_wlan_act(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean enable) -{ - coex_dm->cur_ignore_wlan_act = enable; - - if (!force_exec) { - if (coex_dm->pre_ignore_wlan_act == - coex_dm->cur_ignore_wlan_act) - return; - } - halbtc8821c2ant_set_fw_ignore_wlan_act(btcoexist, enable); - - coex_dm->pre_ignore_wlan_act = coex_dm->cur_ignore_wlan_act; -} - -void halbtc8821c2ant_set_lps_rpwm(IN struct btc_coexist *btcoexist, - IN u8 lps_val, IN u8 rpwm_val) -{ - u8 lps = lps_val; - u8 rpwm = rpwm_val; - - btcoexist->btc_set(btcoexist, BTC_SET_U1_LPS_VAL, &lps); - btcoexist->btc_set(btcoexist, BTC_SET_U1_RPWM_VAL, &rpwm); -} - -void halbtc8821c2ant_lps_rpwm(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 lps_val, IN u8 rpwm_val) -{ - coex_dm->cur_lps = lps_val; - coex_dm->cur_rpwm = rpwm_val; - - if (!force_exec) { - if ((coex_dm->pre_lps == coex_dm->cur_lps) && - (coex_dm->pre_rpwm == coex_dm->cur_rpwm)) - return; - } - halbtc8821c2ant_set_lps_rpwm(btcoexist, lps_val, rpwm_val); - - coex_dm->pre_lps = coex_dm->cur_lps; - coex_dm->pre_rpwm = coex_dm->cur_rpwm; -} - -void halbtc8821c2ant_ps_tdma_check_for_power_save_state( - IN struct btc_coexist *btcoexist, IN boolean new_ps_state) -{ - u8 lps_mode = 0x0; - u8 h2c_parameter[5] = {0, 0, 0, 0x40, 0}; - - btcoexist->btc_get(btcoexist, BTC_GET_U1_LPS_MODE, &lps_mode); - - if (lps_mode) { /* already under LPS state */ - if (new_ps_state) { - /* keep state under LPS, do nothing. */ - } else { - /* will leave LPS state, turn off psTdma first */ - /*halbtc8821c2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, - 8); */ - btcoexist->btc_fill_h2c(btcoexist, 0x60, 5, - h2c_parameter); - } - } else { /* NO PS state */ - if (new_ps_state) { - /* will enter LPS state, turn off psTdma first */ - /*halbtc8821c2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, - 8);*/ - btcoexist->btc_fill_h2c(btcoexist, 0x60, 5, - h2c_parameter); - } else { - /* keep state under NO PS state, do nothing. */ - } - } -} - -void halbtc8821c2ant_power_save_state(IN struct btc_coexist *btcoexist, - IN u8 ps_type, IN u8 lps_val, IN u8 rpwm_val) -{ - boolean low_pwr_disable = false; - - switch (ps_type) { - case BTC_PS_WIFI_NATIVE: - /* recover to original 32k low power setting */ - low_pwr_disable = false; - btcoexist->btc_set(btcoexist, - BTC_SET_ACT_DISABLE_LOW_POWER, - &low_pwr_disable); - btcoexist->btc_set(btcoexist, BTC_SET_ACT_NORMAL_LPS, - NULL); - coex_sta->force_lps_on = false; - break; - case BTC_PS_LPS_ON: - halbtc8821c2ant_ps_tdma_check_for_power_save_state( - btcoexist, true); - halbtc8821c2ant_lps_rpwm(btcoexist, NORMAL_EXEC, - lps_val, rpwm_val); - /* when coex force to enter LPS, do not enter 32k low power. */ - low_pwr_disable = true; - btcoexist->btc_set(btcoexist, - BTC_SET_ACT_DISABLE_LOW_POWER, - &low_pwr_disable); - /* power save must executed before psTdma. */ - btcoexist->btc_set(btcoexist, BTC_SET_ACT_ENTER_LPS, - NULL); - coex_sta->force_lps_on = true; - break; - case BTC_PS_LPS_OFF: - halbtc8821c2ant_ps_tdma_check_for_power_save_state( - btcoexist, false); - btcoexist->btc_set(btcoexist, BTC_SET_ACT_LEAVE_LPS, - NULL); - coex_sta->force_lps_on = false; - break; - default: - break; - } -} - - - -void halbtc8821c2ant_set_fw_pstdma(IN struct btc_coexist *btcoexist, - IN u8 byte1, IN u8 byte2, IN u8 byte3, IN u8 byte4, IN u8 byte5) -{ - u8 h2c_parameter[5] = {0}; - u8 real_byte1 = byte1, real_byte5 = byte5; - boolean ap_enable = false; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, - &ap_enable); - - if (ap_enable) { - if (byte1 & BIT(4) && !(byte1 & BIT(5))) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], FW for AP mode\n"); - BTC_TRACE(trace_buf); - real_byte1 &= ~BIT(4); - real_byte1 |= BIT(5); - - real_byte5 |= BIT(5); - real_byte5 &= ~BIT(6); - - halbtc8821c2ant_power_save_state(btcoexist, - BTC_PS_WIFI_NATIVE, 0x0, - 0x0); - } - } else if (byte1 & BIT(4) && !(byte1 & BIT(5))) { - - halbtc8821c2ant_power_save_state( - btcoexist, BTC_PS_LPS_ON, 0x50, - 0x4); - } else { - halbtc8821c2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, - 0x0, - 0x0); - } - - - h2c_parameter[0] = real_byte1; - h2c_parameter[1] = byte2; - h2c_parameter[2] = byte3; - h2c_parameter[3] = byte4; - h2c_parameter[4] = real_byte5; - - coex_dm->ps_tdma_para[0] = real_byte1; - coex_dm->ps_tdma_para[1] = byte2; - coex_dm->ps_tdma_para[2] = byte3; - coex_dm->ps_tdma_para[3] = byte4; - coex_dm->ps_tdma_para[4] = real_byte5; - - btcoexist->btc_fill_h2c(btcoexist, 0x60, 5, h2c_parameter); -} - -void halbtc8821c2ant_ps_tdma(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean turn_on, IN u8 type) -{ - - static u8 psTdmaByte4Modify = 0x0, pre_psTdmaByte4Modify = 0x0; - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - - - coex_dm->cur_ps_tdma_on = turn_on; - coex_dm->cur_ps_tdma = type; - - /* 0x778 = 0x1 at wifi slot (no blocking BT Low-Pri pkts) */ - if ((bt_link_info->slave_role) && (bt_link_info->a2dp_exist)) - psTdmaByte4Modify = 0x1; - else - psTdmaByte4Modify = 0x0; - - if (pre_psTdmaByte4Modify != psTdmaByte4Modify) { - - force_exec = true; - pre_psTdmaByte4Modify = psTdmaByte4Modify; - } - - if (!force_exec) { - if ((coex_dm->pre_ps_tdma_on == coex_dm->cur_ps_tdma_on) && - (coex_dm->pre_ps_tdma == coex_dm->cur_ps_tdma)) - return; - } - - if (coex_dm->cur_ps_tdma_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** TDMA(on, %d) **********\n", - coex_dm->cur_ps_tdma); - BTC_TRACE(trace_buf); - - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x550, 0x8, - 0x1); /* enable TBTT nterrupt */ - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** TDMA(off, %d) **********\n", - coex_dm->cur_ps_tdma); - BTC_TRACE(trace_buf); - } - - - if (turn_on) { - switch (type) { - case 1: - halbtc8821c2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x10, 0x03, 0xf1, - 0x54 | psTdmaByte4Modify); - break; - case 2: - default: - halbtc8821c2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x35, 0x03, 0x71, - 0x11 | psTdmaByte4Modify); - break; - case 3: - halbtc8821c2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x3a, 0x3, 0xf1, - 0x10 | psTdmaByte4Modify); - break; - case 4: - halbtc8821c2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x21, 0x3, 0xf1, - 0x10 | psTdmaByte4Modify); - break; - case 5: - halbtc8821c2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x25, 0x3, 0xf1, - 0x10 | psTdmaByte4Modify); - break; - case 6: - halbtc8821c2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x10, 0x3, 0xf1, - 0x10 | psTdmaByte4Modify); - break; - case 7: - halbtc8821c2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x20, 0x3, 0xf1, - 0x10 | psTdmaByte4Modify); - break; - case 10: - halbtc8821c2ant_set_fw_pstdma(btcoexist, 0x61, - 0x30, 0x03, 0x11, - 0x10); - break; - case 11: - halbtc8821c2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x30, 0x03, 0x71, - 0x10 | psTdmaByte4Modify); - break; - case 12: - halbtc8821c2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x21, 0x03, 0x71, - 0x11 | psTdmaByte4Modify); - break; - case 13: - halbtc8821c2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x1c, 0x03, 0x71, - 0x10 | psTdmaByte4Modify); - break; - case 14: - halbtc8821c2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x30, 0x03, 0x71, - 0x11); - break; - case 51: - halbtc8821c2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x10, 0x03, 0xf1, - 0x10 | psTdmaByte4Modify); - break; - case 101: - halbtc8821c2ant_set_fw_pstdma(btcoexist, 0xd3, - 0x10, 0x03, 0x70, - 0x54 | psTdmaByte4Modify); - break; - case 102: - halbtc8821c2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x35, 0x03, 0x71, - 0x11 | psTdmaByte4Modify); - break; - case 103: - halbtc8821c2ant_set_fw_pstdma(btcoexist, 0xd3, - 0x3a, 0x3, 0x70, - 0x50 | psTdmaByte4Modify); - break; - case 104: - halbtc8821c2ant_set_fw_pstdma(btcoexist, 0xd3, - 0x21, 0x3, 0x70, - 0x50 | psTdmaByte4Modify); - break; - case 105: - halbtc8821c2ant_set_fw_pstdma(btcoexist, 0xd3, - 0x25, 0x3, 0x70, - 0x50 | psTdmaByte4Modify); - break; - case 106: - halbtc8821c2ant_set_fw_pstdma(btcoexist, 0xd3, - 0x10, 0x3, 0x70, - 0x50 | psTdmaByte4Modify); - break; - case 107: - halbtc8821c2ant_set_fw_pstdma(btcoexist, 0xd3, - 0x20, 0x3, 0x70, - 0x50 | psTdmaByte4Modify); - break; - case 108: - halbtc8821c2ant_set_fw_pstdma(btcoexist, 0xd3, - 0x30, 0x3, 0x70, - 0x50 | psTdmaByte4Modify); - break; - case 109: - halbtc8821c2ant_set_fw_pstdma(btcoexist, 0xd7, - 0x10, 0x03, 0x10, - 0x54 | psTdmaByte4Modify); - break; - case 151: - halbtc8821c2ant_set_fw_pstdma(btcoexist, 0xd3, - 0x10, 0x03, 0x70, - 0x50 | psTdmaByte4Modify); - break; - } - } else { - /* disable PS tdma */ - switch (type) { - case 0: - halbtc8821c2ant_set_fw_pstdma(btcoexist, 0x0, - 0x0, 0x0, 0x40, 0x0); - break; - case 1: - halbtc8821c2ant_set_fw_pstdma(btcoexist, 0x0, - 0x0, 0x0, 0x48, 0x0); - break; - default: - halbtc8821c2ant_set_fw_pstdma(btcoexist, 0x0, - 0x0, 0x0, 0x40, 0x0); - break; - } - } - - /* update pre state */ - coex_dm->pre_ps_tdma_on = coex_dm->cur_ps_tdma_on; - coex_dm->pre_ps_tdma = coex_dm->cur_ps_tdma; -} - -void halbtc8821c2ant_set_int_block(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 pos_type) -{ -#if 0 - u8 regval_0xcba; - u32 u32tmp1 = 0; - - coex_dm->cur_int_block_status = pos_type; - - if (!force_exec) { - if (coex_dm->pre_int_block_status == - coex_dm->cur_int_block_status) - return; - } - - coex_dm->pre_int_block_status = coex_dm->cur_int_block_status; - - regval_0xcba = btcoexist->btc_read_1byte(btcoexist, 0xcba); - - switch (pos_type) { - - case BT_8821C_1ANT_INT_BLOCK_SWITCH_TO_WLG_OF_BTG: - regval_0xcba = (regval_0xcba | BIT(0)) & (~(BIT( - 2))); /* 0xcb8[16] = 1, 0xcb8[18] = 0, WL_G select BTG */ - regval_0xcba = regval_0xcba & 0x0f; - - /*btcoexist->btc_write_1byte_bitmask(btcoexist, 0xc1d, 0x0f, 0x5); */ /* Gain Table */ - /*btcoexist->btc_write_1byte_bitmask(btcoexist, 0xa9e, 0x0f, 0x2); */ /* CCK Gain Table */ - - break; - case BT_8821C_1ANT_INT_BLOCK_SWITCH_TO_WLG_OF_WLAG: - regval_0xcba = regval_0xcba & (~(BIT(2) | BIT( - 0))); /* 0xcb8[16] = 0, 0xcb8[18] = 0, WL_G select WLAG */ - - /* regval_0xcba = regval_0xcba | BIT(4) | BIT(5) ; */ /* 0xcb8[21:20] = 2b'11, WL_G @ WLAG on */ - /* regval_0xcba = (regval_0xcba | BIT(6)) & (~(BIT(7)) ) ; */ /* 0xcb8[23:22] = 2b'01, WL_A @ WLAG off */ - /*btcoexist->btc_write_1byte_bitmask(btcoexist, 0xc1d, 0x0f, 0x0); */ /* Gain Table */ - /*btcoexist->btc_write_1byte_bitmask(btcoexist, 0xa9e, 0x0f, 0x6); */ /* CCK Gain Table */ - - break; - case BT_8821C_1ANT_INT_BLOCK_SWITCH_TO_WLA_OF_WLAG: - regval_0xcba = regval_0xcba & (~(BIT(2) | BIT( - 0))); /* 0xcb8[16] = 0, 0xcb8[18] = 0, WL_G select WLAG */ - /*regval_0xcba = (regval_0xcba | BIT(4)) & (~(BIT(5))); */ /* 0xcb8[21:20] = 2b'01, WL_G @ WLAG off */ - /*regval_0xcba = regval_0xcba | BIT(6) | BIT(7); */ /* 0xcb8[23:22] = 2b'11, WL_A @ WLAG on */ - - break; - } - - btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcba, 0xff, - regval_0xcba); - - u32tmp1 = btcoexist->btc_read_4byte(btcoexist, 0xcb8); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** (After Int Block setup) 0xcb8 = 0x%08x **********\n", - u32tmp1); - BTC_TRACE(trace_buf); - -#endif -} - -void halbtc8821c2ant_set_ext_band_switch(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 pos_type) -{ - -#if 0 - boolean switch_polatiry_inverse = false; - u8 regval_0xcb6; - u32 u32tmp1 = 0, u32tmp2 = 0; - - if (!rfe_type->ext_band_switch_exist) - return; - - coex_dm->cur_ext_band_switch_status = pos_type; - - if (!force_exec) { - if (coex_dm->pre_ext_band_switch_status == - coex_dm->cur_ext_band_switch_status) - return; - } - - coex_dm->pre_ext_band_switch_status = - coex_dm->cur_ext_band_switch_status; - - /* swap control polarity if use different switch control polarity*/ - switch_polatiry_inverse = (rfe_type->ext_band_switch_ctrl_polarity == 1 - ? ~switch_polatiry_inverse : switch_polatiry_inverse); - - /*swap control polarity for WL_A, default polarity 0xcb4[21] = 0 && 0xcb4[23] = 1 is for WL_G */ - switch_polatiry_inverse = (pos_type == - BT_8821C_2ANT_EXT_BAND_SWITCH_TO_WLA ? ~switch_polatiry_inverse - : switch_polatiry_inverse); - - regval_0xcb6 = btcoexist->btc_read_1byte(btcoexist, 0xcb6); - - /* for normal switch polrity, 0xcb4[21] =1 && 0xcb4[23] = 0 for WL_A, vice versa */ - regval_0xcb6 = (switch_polatiry_inverse == 1 ? ((regval_0xcb6 & (~(BIT( - 7)))) | BIT(5)) : ((regval_0xcb6 & (~(BIT(5)))) | BIT(7))); - - btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb6, 0xff, - regval_0xcb6); - - u32tmp1 = btcoexist->btc_read_4byte(btcoexist, 0xcb0); - u32tmp2 = btcoexist->btc_read_4byte(btcoexist, 0xcb4); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** (After Ext Band switch setup) 0xcb0 = 0x%08x, 0xcb4 = 0x%08x**********\n", - u32tmp1, u32tmp2); - BTC_TRACE(trace_buf); -#endif - -} - -void halbtc8821c2ant_set_ext_ant_switch(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 ctrl_type, IN u8 pos_type) -{ - struct btc_board_info *board_info = &btcoexist->board_info; - boolean switch_polatiry_inverse = false; - u8 regval_0xcb7 = 0, regval_0x64; - u32 u32tmp1 = 0, u32tmp2 = 0, u32tmp3 = 0; - - if (!rfe_type->ext_ant_switch_exist) - return; - - coex_dm->cur_ext_ant_switch_status = (ctrl_type << 8) + pos_type; - - if (!force_exec) { - if (coex_dm->pre_ext_ant_switch_status == - coex_dm->cur_ext_ant_switch_status) - return; - } - - coex_dm->pre_ext_ant_switch_status = coex_dm->cur_ext_ant_switch_status; - - /* swap control polarity if use different switch control polarity*/ - /* Normal switch polarity for DPDT, 0xcb4[29:28] = 2b'01 => BTG to Main, WLG to Aux, 0xcb4[29:28] = 2b'10 => BTG to Aux, WLG to Main */ - /* Normal switch polarity for SPDT, 0xcb4[29:28] = 2b'01 => Ant to BTG, 0xcb4[29:28] = 2b'10 => Ant to WLG */ - switch_polatiry_inverse = (rfe_type->ext_ant_switch_ctrl_polarity == 1 ? - ~switch_polatiry_inverse : switch_polatiry_inverse); - - switch (pos_type) { - default: - case BT_8821C_2ANT_EXT_ANT_SWITCH_MAIN_TO_BT: - case BT_8821C_2ANT_EXT_ANT_SWITCH_MAIN_TO_NOCARE: - - break; - case BT_8821C_2ANT_EXT_ANT_SWITCH_MAIN_TO_WLG: - switch_polatiry_inverse = - (rfe_type->wlg_Locate_at_btg == 0 ? - ~switch_polatiry_inverse : - switch_polatiry_inverse); - break; - case BT_8821C_2ANT_EXT_ANT_SWITCH_MAIN_TO_WLA: - - break; - } - - if (board_info->ant_div_cfg) - ctrl_type = BT_8821C_2ANT_EXT_ANT_SWITCH_CTRL_BY_ANTDIV; - - - switch (ctrl_type) { - default: - case BT_8821C_2ANT_EXT_ANT_SWITCH_CTRL_BY_BBSW: - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4e, - 0x80, 0x0); /* 0x4c[23] = 0 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4f, - 0x01, 0x1); /* 0x4c[24] = 1 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb4, - 0xff, 0x77); /* BB SW, DPDT use RFE_ctrl8 and RFE_ctrl9 as control pin */ - - regval_0xcb7 = (switch_polatiry_inverse == false ? - 0x1 : 0x2); /* 0xcb4[29:28] = 2b'01 for no switch_polatiry_inverse, DPDT_SEL_N =1, DPDT_SEL_P =0 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb7, - 0x30, regval_0xcb7); - - break; - case BT_8821C_2ANT_EXT_ANT_SWITCH_CTRL_BY_PTA: - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4e, - 0x80, 0x0); /* 0x4c[23] = 0 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4f, - 0x01, 0x1); /* 0x4c[24] = 1 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb4, - 0xff, 0x66); /* PTA, DPDT use RFE_ctrl8 and RFE_ctrl9 as control pin */ - - regval_0xcb7 = (switch_polatiry_inverse == false ? - 0x2 : 0x1); /* 0xcb4[29:28] = 2b'10 for no switch_polatiry_inverse, DPDT_SEL_N =1, DPDT_SEL_P =0 @ GNT_BT=1 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb7, - 0x30, regval_0xcb7); - - break; - case BT_8821C_2ANT_EXT_ANT_SWITCH_CTRL_BY_ANTDIV: - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4e, - 0x80, 0x0); /* 0x4c[23] = 0 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4f, - 0x01, 0x1); /* 0x4c[24] = 1 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb4, - 0xff, 0x88); /* */ - - /* no regval_0xcb7 setup required, because antenna switch control value by antenna diversity */ - - break; - case BT_8821C_2ANT_EXT_ANT_SWITCH_CTRL_BY_MAC: - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4e, - 0x80, 0x1); /* 0x4c[23] = 1 */ - - regval_0x64 = (switch_polatiry_inverse == false ? 0x0 : - 0x1); /* 0x64[0] = 1b'0 for no switch_polatiry_inverse, DPDT_SEL_N =1, DPDT_SEL_P =0 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x64, 0x1, - regval_0x64); - break; - case BT_8821C_2ANT_EXT_ANT_SWITCH_CTRL_BY_BT: - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4e, - 0x80, 0x0); /* 0x4c[23] = 0 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4f, - 0x01, 0x0); /* 0x4c[24] = 0 */ - - /* no setup required, because antenna switch control value by BT vendor 0x1c[1:0] */ - break; - } - - /* PAPE, LNA_ON control by BT while WLAN off for current leakage issue */ - if (ctrl_type == BT_8821C_2ANT_EXT_ANT_SWITCH_CTRL_BY_BT) { - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, 0x20, - 0x0); /* PAPE 0x64[29] = 0 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, 0x10, - 0x0); /* LNA_ON 0x64[28] = 0 */ - } else { - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, 0x20, - 0x1); /* PAPE 0x64[29] = 1 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, 0x10, - 0x1); /* LNA_ON 0x64[28] = 1 */ - } - -#if BT_8821C_2ANT_COEX_DBG - - u32tmp1 = btcoexist->btc_read_4byte(btcoexist, 0xcb4); - u32tmp2 = btcoexist->btc_read_4byte(btcoexist, 0x4c); - u32tmp3 = btcoexist->btc_read_4byte(btcoexist, 0x64) & 0xff; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], (After Ext Ant switch setup) 0xcb4 = 0x%08x, 0x4c = 0x%08x, 0x64= 0x%02x\n", - u32tmp1, u32tmp2, u32tmp3); - BTC_TRACE(trace_buf); -#endif - -} - -void halbtc8821c2ant_set_rfe_type(IN struct btc_coexist *btcoexist) -{ - struct btc_board_info *board_info = &btcoexist->board_info; - -#if 0 - rfe_type->ext_band_switch_exist = false; - rfe_type->ext_band_switch_type = - BT_8821C_2ANT_EXT_BAND_SWITCH_USE_SPDT; /* SPDT; */ - rfe_type->ext_band_switch_ctrl_polarity = 0; - - if (rfe_type->ext_band_switch_exist) { - - /* band switch use RFE_ctrl1 (pin name: PAPE_A) and RFE_ctrl3 (pin name: LNAON_A) */ - - /* set RFE_ctrl1 as software control */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb0, 0xf0, 0x7); - - /* set RFE_ctrl3 as software control */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb1, 0xf0, 0x7); - - } -#endif - - /* the following setup should be got from Efuse in the future */ - rfe_type->rfe_module_type = board_info->rfe_type & 0x1f; - - rfe_type->ext_ant_switch_ctrl_polarity = 0; - - switch (rfe_type->rfe_module_type) { - case 0: - default: - rfe_type->ext_ant_switch_exist = true; - rfe_type->ext_ant_switch_type = - BT_8821C_2ANT_EXT_ANT_SWITCH_USE_DPDT; /*2-Ant, DPDT, WLG*/ - rfe_type->wlg_Locate_at_btg = false; - break; - case 1: - rfe_type->ext_ant_switch_exist = true; - rfe_type->ext_ant_switch_type = - BT_8821C_2ANT_EXT_ANT_SWITCH_USE_SPDT; /*1-Ant, Main, DPDT or SPDT, WLG */ - rfe_type->wlg_Locate_at_btg = false; - break; - case 2: - rfe_type->ext_ant_switch_exist = true; - rfe_type->ext_ant_switch_type = - BT_8821C_2ANT_EXT_ANT_SWITCH_USE_SPDT; /*1-Ant, Main, DPDT or SPDT, BTG */ - rfe_type->wlg_Locate_at_btg = true; - break; - case 3: - rfe_type->ext_ant_switch_exist = true; - rfe_type->ext_ant_switch_type = - BT_8821C_2ANT_EXT_ANT_SWITCH_USE_DPDT; /*1-Ant, Aux, DPDT, WLG */ - rfe_type->wlg_Locate_at_btg = false; - break; - case 4: - rfe_type->ext_ant_switch_exist = true; - rfe_type->ext_ant_switch_type = - BT_8821C_2ANT_EXT_ANT_SWITCH_USE_DPDT; /*1-Ant, Aux, DPDT, BTG */; - rfe_type->wlg_Locate_at_btg = true; - break; - case 5: - rfe_type->ext_ant_switch_exist = - false; /*2-Ant, no antenna switch, WLG*/ - rfe_type->ext_ant_switch_type = - BT_8821C_2ANT_EXT_ANT_SWITCH_NONE; - rfe_type->wlg_Locate_at_btg = false; - break; - case 6: - rfe_type->ext_ant_switch_exist = - false; /*2-Ant, no antenna switch, WLG*/ - rfe_type->ext_ant_switch_type = - BT_8821C_2ANT_EXT_ANT_SWITCH_NONE; - rfe_type->wlg_Locate_at_btg = false; - break; - case 7: - rfe_type->ext_ant_switch_exist = true; - rfe_type->ext_ant_switch_type = - BT_8821C_2ANT_EXT_ANT_SWITCH_USE_DPDT; /*2-Ant, DPDT, BTG*/ - rfe_type->wlg_Locate_at_btg = true; - break; - - } - - - if (rfe_type->wlg_Locate_at_btg) - halbtc8821c2ant_set_int_block(btcoexist, FORCE_EXEC, - BT_8821C_2ANT_INT_BLOCK_SWITCH_TO_WLG_OF_BTG); - else - halbtc8821c2ant_set_int_block(btcoexist, FORCE_EXEC, - BT_8821C_2ANT_INT_BLOCK_SWITCH_TO_WLG_OF_WLAG); - - -} - - -void halbtc8821c2ant_set_ant_path(IN struct btc_coexist *btcoexist, - IN u8 ant_pos_type, IN boolean force_exec, - IN u8 phase) -{ - struct btc_board_info *board_info = &btcoexist->board_info; - u32 cnt_bt_cal_chk = 0; - boolean is_in_mp_mode = false; - u8 u8tmp = 0; - u32 u32tmp1 = 0, u32tmp2 = 0, u32tmp3 = 0; - u16 u16tmp1 = 0; - -#if BT_8821C_2ANT_ANTDET_ENABLE - - if (ant_pos_type == BTC_ANT_PATH_AUTO) { - if ((board_info->btdm_ant_det_finish) && - (board_info->btdm_ant_num_by_ant_det == 2)) { - if (board_info->btdm_ant_pos == - BTC_ANTENNA_AT_MAIN_PORT) - ant_pos_type = BTC_ANT_WIFI_AT_MAIN; - else - ant_pos_type = BTC_ANT_WIFI_AT_AUX; - } - } - -#endif - - coex_dm->cur_ant_pos_type = (ant_pos_type << 8) + phase; - - if (!force_exec) { - if (coex_dm->cur_ant_pos_type == coex_dm->pre_ant_pos_type) - return; - } - - coex_dm->pre_ant_pos_type = coex_dm->cur_ant_pos_type; - -#if BT_8821C_2ANT_COEX_DBG - u32tmp1 = halbtc8821c2ant_ltecoex_indirect_read_reg(btcoexist, - 0x38); - u32tmp2 = halbtc8821c2ant_ltecoex_indirect_read_reg(btcoexist, - 0x54); - u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x73); - - u32tmp3 = btcoexist->btc_read_4byte(btcoexist, 0xcb4); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], (Before Ant Setup) 0xcb4 = 0x%x, 0x73 = 0x%x, 0x38= 0x%x, 0x54= 0x%x\n", - u32tmp3, u8tmp, u32tmp1, u32tmp2); - BTC_TRACE(trace_buf); -#endif - - switch (phase) { - case BT_8821C_2ANT_PHASE_COEX_POWERON: - - /* set Path control owner to WL at initial step */ - halbtc8821c2ant_ltecoex_pathcontrol_owner(btcoexist, - BT_8821C_2ANT_PCO_BTSIDE); - - /* set GNT_BT to SW high */ - halbtc8821c2ant_ltecoex_set_gnt_bt(btcoexist, - BT_8821C_2ANT_GNT_BLOCK_RFC_BB, - BT_8821C_2ANT_GNT_TYPE_CTRL_BY_SW, - BT_8821C_2ANT_SIG_STA_SET_TO_HIGH); - /* Set GNT_WL to SW high */ - halbtc8821c2ant_ltecoex_set_gnt_wl(btcoexist, - BT_8821C_2ANT_GNT_BLOCK_RFC_BB, - BT_8821C_2ANT_GNT_TYPE_CTRL_BY_SW, - BT_8821C_2ANT_SIG_STA_SET_TO_HIGH); - - if (BTC_ANT_PATH_AUTO == ant_pos_type) { - if (board_info->btdm_ant_pos == - BTC_ANTENNA_AT_MAIN_PORT) - ant_pos_type = - BTC_ANT_WIFI_AT_MAIN; - else - ant_pos_type = - BTC_ANT_WIFI_AT_AUX; - } - - coex_sta->run_time_state = false; - - break; - case BT_8821C_2ANT_PHASE_COEX_INIT: - /* Disable LTE Coex Function in WiFi side (this should be on if LTE coex is required) */ - halbtc8821c2ant_ltecoex_enable(btcoexist, 0x0); - - /* GNT_WL_LTE always = 1 (this should be config if LTE coex is required) */ - halbtc8821c2ant_ltecoex_set_coex_table( - btcoexist, - BT_8821C_2ANT_CTT_WL_VS_LTE, - 0xffff); - - /* GNT_BT_LTE always = 1 (this should be config if LTE coex is required) */ - halbtc8821c2ant_ltecoex_set_coex_table( - btcoexist, - BT_8821C_2ANT_CTT_BT_VS_LTE, - 0xffff); - - - /* Wait If BT IQK running, because Path control owner is at BT during BT IQK (setup by WiFi firmware) */ - while (cnt_bt_cal_chk <= 20) { - u8tmp = btcoexist->btc_read_1byte( - btcoexist, 0x49c); - cnt_bt_cal_chk++; - - if (u8tmp & BIT(1)) { - BTC_SPRINTF(trace_buf, - BT_TMP_BUF_SIZE, - "[BTCoex], ########### BT is calibrating (wait cnt=%d) ###########\n", - cnt_bt_cal_chk); - BTC_TRACE(trace_buf); - delay_ms(50); - } else { - BTC_SPRINTF(trace_buf, - BT_TMP_BUF_SIZE, - "[BTCoex], ********** BT is NOT calibrating (wait cnt=%d)**********\n", - cnt_bt_cal_chk); - BTC_TRACE(trace_buf); - break; - } - } - - /* set Path control owner to WL at initial step */ - halbtc8821c2ant_ltecoex_pathcontrol_owner( - btcoexist, - BT_8821C_2ANT_PCO_WLSIDE); - - /* set GNT_BT to SW high */ - halbtc8821c2ant_ltecoex_set_gnt_bt(btcoexist, - BT_8821C_2ANT_GNT_BLOCK_RFC_BB, - BT_8821C_2ANT_GNT_TYPE_CTRL_BY_SW, - BT_8821C_2ANT_SIG_STA_SET_TO_HIGH); - /* Set GNT_WL to SW high */ - halbtc8821c2ant_ltecoex_set_gnt_wl(btcoexist, - BT_8821C_2ANT_GNT_BLOCK_RFC_BB, - BT_8821C_2ANT_GNT_TYPE_CTRL_BY_SW, - BT_8821C_2ANT_SIG_STA_SET_TO_HIGH); - - coex_sta->run_time_state = false; - - if (BTC_ANT_PATH_AUTO == ant_pos_type) { - if (board_info->btdm_ant_pos == - BTC_ANTENNA_AT_MAIN_PORT) - ant_pos_type = - BTC_ANT_WIFI_AT_MAIN; - else - ant_pos_type = - BTC_ANT_WIFI_AT_AUX; - } - - break; - case BT_8821C_2ANT_PHASE_WLANONLY_INIT: - /* Disable LTE Coex Function in WiFi side (this should be on if LTE coex is required) */ - halbtc8821c2ant_ltecoex_enable(btcoexist, 0x0); - - /* GNT_WL_LTE always = 1 (this should be config if LTE coex is required) */ - halbtc8821c2ant_ltecoex_set_coex_table( - btcoexist, - BT_8821C_2ANT_CTT_WL_VS_LTE, - 0xffff); - - /* GNT_BT_LTE always = 1 (this should be config if LTE coex is required) */ - halbtc8821c2ant_ltecoex_set_coex_table( - btcoexist, - BT_8821C_2ANT_CTT_BT_VS_LTE, - 0xffff); - - /* set Path control owner to WL at initial step */ - halbtc8821c2ant_ltecoex_pathcontrol_owner( - btcoexist, - BT_8821C_2ANT_PCO_WLSIDE); - - /* set GNT_BT to SW Low */ - halbtc8821c2ant_ltecoex_set_gnt_bt(btcoexist, - BT_8821C_2ANT_GNT_BLOCK_RFC_BB, - BT_8821C_2ANT_GNT_TYPE_CTRL_BY_SW, - BT_8821C_2ANT_SIG_STA_SET_TO_LOW); - /* Set GNT_WL to SW high */ - halbtc8821c2ant_ltecoex_set_gnt_wl(btcoexist, - BT_8821C_2ANT_GNT_BLOCK_RFC_BB, - BT_8821C_2ANT_GNT_TYPE_CTRL_BY_SW, - BT_8821C_2ANT_SIG_STA_SET_TO_HIGH); - - coex_sta->run_time_state = false; - - if (BTC_ANT_PATH_AUTO == ant_pos_type) { - if (board_info->btdm_ant_pos == - BTC_ANTENNA_AT_MAIN_PORT) - ant_pos_type = - BTC_ANT_WIFI_AT_MAIN; - else - ant_pos_type = - BTC_ANT_WIFI_AT_AUX; - } - - break; - case BT_8821C_2ANT_PHASE_WLAN_OFF: - /* Disable LTE Coex Function in WiFi side */ - halbtc8821c2ant_ltecoex_enable(btcoexist, 0x0); - - /* set Path control owner to BT */ - halbtc8821c2ant_ltecoex_pathcontrol_owner( - btcoexist, - BT_8821C_2ANT_PCO_BTSIDE); - - /* Set Ext Ant Switch to BT control at wifi off step */ - halbtc8821c2ant_set_ext_ant_switch(btcoexist, - FORCE_EXEC, - BT_8821C_2ANT_EXT_ANT_SWITCH_CTRL_BY_BT, - BT_8821C_2ANT_EXT_ANT_SWITCH_MAIN_TO_NOCARE); - coex_sta->run_time_state = false; - break; - case BT_8821C_2ANT_PHASE_2G_RUNTIME: - case BT_8821C_2ANT_PHASE_2G_RUNTIME_CONCURRENT: - - while (cnt_bt_cal_chk <= 20) { - /* 0x49c[0]=1 WL IQK, 0x49c[1]=1 BT IQK*/ - u8tmp = btcoexist->btc_read_1byte(btcoexist, - 0x49c); - - cnt_bt_cal_chk++; - if (u8tmp & BIT(0)) { - BTC_SPRINTF(trace_buf, - BT_TMP_BUF_SIZE, - "[BTCoex], ########### WL is IQK (wait cnt=%d)\n", - cnt_bt_cal_chk); - BTC_TRACE(trace_buf); - delay_ms(50); - } else if (u8tmp & BIT(1)) { - BTC_SPRINTF(trace_buf, - BT_TMP_BUF_SIZE, - "[BTCoex], ########### BT is IQK (wait cnt=%d)\n", - cnt_bt_cal_chk); - BTC_TRACE(trace_buf); - delay_ms(50); - } else { - BTC_SPRINTF(trace_buf, - BT_TMP_BUF_SIZE, - "[BTCoex], ********** WL and BT is NOT IQK (wait cnt=%d)\n", - cnt_bt_cal_chk); - BTC_TRACE(trace_buf); - break; - } - } - - /* set Path control owner to WL at runtime step */ - halbtc8821c2ant_ltecoex_pathcontrol_owner( - btcoexist, - BT_8821C_2ANT_PCO_WLSIDE); - - if (phase == - BT_8821C_2ANT_PHASE_2G_RUNTIME_CONCURRENT) { - /* set GNT_BT to PTA */ - halbtc8821c2ant_ltecoex_set_gnt_bt( - btcoexist, - BT_8821C_2ANT_GNT_BLOCK_RFC_BB, - BT_8821C_2ANT_GNT_TYPE_CTRL_BY_PTA, - BT_8821C_2ANT_SIG_STA_SET_BY_HW); - - /* Set GNT_WL to SW High */ - halbtc8821c2ant_ltecoex_set_gnt_wl( - btcoexist, - BT_8821C_2ANT_GNT_BLOCK_RFC_BB, - BT_8821C_2ANT_GNT_TYPE_CTRL_BY_SW, - BT_8821C_2ANT_SIG_STA_SET_TO_HIGH); - } else { - /* set GNT_BT to PTA */ - halbtc8821c2ant_ltecoex_set_gnt_bt( - btcoexist, - BT_8821C_2ANT_GNT_BLOCK_RFC_BB, - BT_8821C_2ANT_GNT_TYPE_CTRL_BY_PTA, - BT_8821C_2ANT_SIG_STA_SET_BY_HW); - - /* Set GNT_WL to PTA */ - halbtc8821c2ant_ltecoex_set_gnt_wl( - btcoexist, - BT_8821C_2ANT_GNT_BLOCK_RFC_BB, - BT_8821C_2ANT_GNT_TYPE_CTRL_BY_PTA, - BT_8821C_2ANT_SIG_STA_SET_BY_HW); - } - coex_sta->run_time_state = true; - - if (rfe_type->wlg_Locate_at_btg) - halbtc8821c2ant_set_int_block(btcoexist, - NORMAL_EXEC, - BT_8821C_2ANT_INT_BLOCK_SWITCH_TO_WLG_OF_BTG); - else - halbtc8821c2ant_set_int_block(btcoexist, - NORMAL_EXEC, - BT_8821C_2ANT_INT_BLOCK_SWITCH_TO_WLG_OF_WLAG); - - if (BTC_ANT_PATH_AUTO == ant_pos_type) { - if (board_info->btdm_ant_pos == - BTC_ANTENNA_AT_MAIN_PORT) - ant_pos_type = - BTC_ANT_WIFI_AT_MAIN; - else - ant_pos_type = - BTC_ANT_WIFI_AT_AUX; - } - - break; - case BT_8821C_2ANT_PHASE_5G_RUNTIME: - - /* set Path control owner to WL at runtime step */ - halbtc8821c2ant_ltecoex_pathcontrol_owner( - btcoexist, - BT_8821C_2ANT_PCO_WLSIDE); - - /* set GNT_BT to SW Hi */ - halbtc8821c2ant_ltecoex_set_gnt_bt(btcoexist, - BT_8821C_2ANT_GNT_BLOCK_RFC_BB, - BT_8821C_2ANT_GNT_TYPE_CTRL_BY_PTA, - BT_8821C_2ANT_SIG_STA_SET_BY_HW); - - /* Set GNT_WL to SW Hi */ - halbtc8821c2ant_ltecoex_set_gnt_wl(btcoexist, - BT_8821C_2ANT_GNT_BLOCK_RFC_BB, - BT_8821C_2ANT_GNT_TYPE_CTRL_BY_SW, - BT_8821C_2ANT_SIG_STA_SET_TO_HIGH); - - coex_sta->run_time_state = true; - - halbtc8821c2ant_set_int_block(btcoexist, - NORMAL_EXEC, - BT_8821C_2ANT_INT_BLOCK_SWITCH_TO_WLA_OF_WLAG); - - - if (BTC_ANT_PATH_AUTO == ant_pos_type) { - if (board_info->btdm_ant_pos == - BTC_ANTENNA_AT_MAIN_PORT) - ant_pos_type = - BTC_ANT_WIFI_AT_MAIN; - else - ant_pos_type = - BTC_ANT_WIFI_AT_AUX; - } - - - break; - case BT_8821C_2ANT_PHASE_BTMPMODE: - /* Disable LTE Coex Function in WiFi side */ - halbtc8821c2ant_ltecoex_enable(btcoexist, 0x0); - - /* set Path control owner to WL */ - halbtc8821c2ant_ltecoex_pathcontrol_owner( - btcoexist, - BT_8821C_2ANT_PCO_WLSIDE); - - /* set GNT_BT to SW Hi */ - halbtc8821c2ant_ltecoex_set_gnt_bt(btcoexist, - BT_8821C_2ANT_GNT_BLOCK_RFC_BB, - BT_8821C_2ANT_GNT_TYPE_CTRL_BY_SW, - BT_8821C_2ANT_SIG_STA_SET_TO_HIGH); - - /* Set GNT_WL to SW Lo */ - halbtc8821c2ant_ltecoex_set_gnt_wl(btcoexist, - BT_8821C_2ANT_GNT_BLOCK_RFC_BB, - BT_8821C_2ANT_GNT_TYPE_CTRL_BY_SW, - BT_8821C_2ANT_SIG_STA_SET_TO_LOW); - - coex_sta->run_time_state = false; - - if (BTC_ANT_PATH_AUTO == ant_pos_type) { - if (board_info->btdm_ant_pos == - BTC_ANTENNA_AT_MAIN_PORT) - ant_pos_type = - BTC_ANT_WIFI_AT_MAIN; - else - ant_pos_type = - BTC_ANT_WIFI_AT_AUX; - } - - break; - case BT_8821C_2ANT_PHASE_ANTENNA_DET: - halbtc8821c2ant_ltecoex_pathcontrol_owner(btcoexist, - BT_8821C_2ANT_PCO_WLSIDE); - - /* set GNT_BT to high */ - halbtc8821c2ant_ltecoex_set_gnt_bt(btcoexist, - BT_8821C_2ANT_GNT_BLOCK_RFC_BB, - BT_8821C_2ANT_GNT_TYPE_CTRL_BY_SW, - BT_8821C_2ANT_SIG_STA_SET_TO_HIGH); - /* Set GNT_WL to high */ - halbtc8821c2ant_ltecoex_set_gnt_wl(btcoexist, - BT_8821C_2ANT_GNT_BLOCK_RFC_BB, - BT_8821C_2ANT_GNT_TYPE_CTRL_BY_SW, - BT_8821C_2ANT_SIG_STA_SET_TO_HIGH); - - if (BTC_ANT_PATH_AUTO == ant_pos_type) { - if (board_info->btdm_ant_pos == - BTC_ANTENNA_AT_MAIN_PORT) - ant_pos_type = - BTC_ANT_WIFI_AT_MAIN; - else - ant_pos_type = - BTC_ANT_WIFI_AT_AUX; - } - - coex_sta->run_time_state = false; - - break; - } - - if (phase != BT_8821C_2ANT_PHASE_WLAN_OFF) { - switch (ant_pos_type) { - default: - case BTC_ANT_WIFI_AT_MAIN - : - halbtc8821c2ant_set_ext_ant_switch( - btcoexist, - force_exec, - BT_8821C_2ANT_EXT_ANT_SWITCH_CTRL_BY_BBSW, - BT_8821C_2ANT_EXT_ANT_SWITCH_MAIN_TO_WLG); - break; - case BTC_ANT_WIFI_AT_AUX - : - halbtc8821c2ant_set_ext_ant_switch( - btcoexist, - force_exec, - BT_8821C_2ANT_EXT_ANT_SWITCH_CTRL_BY_BBSW, - BT_8821C_2ANT_EXT_ANT_SWITCH_MAIN_TO_BT); - break; - case BTC_ANT_WIFI_AT_DIVERSITY - : - halbtc8821c2ant_set_ext_ant_switch( - btcoexist, - force_exec, - BT_8821C_2ANT_EXT_ANT_SWITCH_CTRL_BY_ANTDIV, - BT_8821C_2ANT_EXT_ANT_SWITCH_MAIN_TO_NOCARE); - break; - } - - } - - - -#if BT_8821C_2ANT_COEX_DBG - u32tmp1 = halbtc8821c2ant_ltecoex_indirect_read_reg(btcoexist, 0x38); - u32tmp2 = halbtc8821c2ant_ltecoex_indirect_read_reg(btcoexist, 0x54); - u32tmp3 = btcoexist->btc_read_4byte(btcoexist, 0xcb4); - u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x73); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], (After Ant-Setup phase---%d) 0xcb4 = 0x%x, 0x73 = 0x%x, 0x38= 0x%x, 0x54= 0x%x\n", - phase, u32tmp3, u8tmp, u32tmp1, u32tmp2); - - BTC_TRACE(trace_buf); -#endif - -} - - -u8 halbtc8821c2ant_action_algorithm(IN struct btc_coexist *btcoexist) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - boolean bt_hs_on = false; - u8 algorithm = BT_8821C_2ANT_COEX_ALGO_UNDEFINED; - u8 num_of_diff_profile = 0; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); - - if (!bt_link_info->bt_link_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], No BT link exists!!!\n"); - BTC_TRACE(trace_buf); - return algorithm; - } - - if (bt_link_info->sco_exist) - num_of_diff_profile++; - if (bt_link_info->hid_exist) - num_of_diff_profile++; - if (bt_link_info->pan_exist) - num_of_diff_profile++; - if (bt_link_info->a2dp_exist) - num_of_diff_profile++; - - if (num_of_diff_profile == 0) { - - if (bt_link_info->acl_busy) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], No-Profile busy\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8821C_2ANT_COEX_ALGO_NOPROFILEBUSY; - } - } else if (num_of_diff_profile == 1) { - if (bt_link_info->sco_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCO only\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8821C_2ANT_COEX_ALGO_SCO; - } else { - if (bt_link_info->hid_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], HID only\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8821C_2ANT_COEX_ALGO_HID; - } else if (bt_link_info->a2dp_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], A2DP only\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8821C_2ANT_COEX_ALGO_A2DP; - } else if (bt_link_info->pan_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], PAN(HS) only\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8821C_2ANT_COEX_ALGO_PANHS; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], PAN(EDR) only\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8821C_2ANT_COEX_ALGO_PANEDR; - } - } - } - } else if (num_of_diff_profile == 2) { - if (bt_link_info->sco_exist) { - if (bt_link_info->hid_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCO + HID\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8821C_2ANT_COEX_ALGO_SCO; - } else if (bt_link_info->a2dp_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCO + A2DP ==> A2DP\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8821C_2ANT_COEX_ALGO_A2DP; - } else if (bt_link_info->pan_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCO + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8821C_2ANT_COEX_ALGO_SCO; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCO + PAN(EDR)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8821C_2ANT_COEX_ALGO_PANEDR; - } - } - } else { - if (bt_link_info->hid_exist && - bt_link_info->a2dp_exist) { - { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], HID + A2DP\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8821C_2ANT_COEX_ALGO_HID_A2DP; - } - } else if (bt_link_info->hid_exist && - bt_link_info->pan_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], HID + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8821C_2ANT_COEX_ALGO_HID; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], HID + PAN(EDR)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8821C_2ANT_COEX_ALGO_PANEDR_HID; - } - } else if (bt_link_info->pan_exist && - bt_link_info->a2dp_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], A2DP + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8821C_2ANT_COEX_ALGO_A2DP_PANHS; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], A2DP + PAN(EDR)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8821C_2ANT_COEX_ALGO_PANEDR_A2DP; - } - } - } - } else if (num_of_diff_profile == 3) { - if (bt_link_info->sco_exist) { - if (bt_link_info->hid_exist && - bt_link_info->a2dp_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCO + HID + A2DP ==> HID + A2DP\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8821C_2ANT_COEX_ALGO_HID_A2DP; - } else if (bt_link_info->hid_exist && - bt_link_info->pan_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCO + HID + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8821C_2ANT_COEX_ALGO_PANEDR_HID; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCO + HID + PAN(EDR)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8821C_2ANT_COEX_ALGO_PANEDR_HID; - } - } else if (bt_link_info->pan_exist && - bt_link_info->a2dp_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCO + A2DP + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8821C_2ANT_COEX_ALGO_PANEDR_A2DP; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCO + A2DP + PAN(EDR) ==> HID\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8821C_2ANT_COEX_ALGO_PANEDR_A2DP; - } - } - } else { - if (bt_link_info->hid_exist && - bt_link_info->pan_exist && - bt_link_info->a2dp_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], HID + A2DP + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8821C_2ANT_COEX_ALGO_HID_A2DP_PANEDR; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], HID + A2DP + PAN(EDR)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8821C_2ANT_COEX_ALGO_HID_A2DP_PANEDR; - } - } - } - } else if (num_of_diff_profile >= 3) { - if (bt_link_info->sco_exist) { - if (bt_link_info->hid_exist && - bt_link_info->pan_exist && - bt_link_info->a2dp_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Error!!! SCO + HID + A2DP + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8821C_2ANT_COEX_ALGO_HID_A2DP_PANEDR; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCO + HID + A2DP + PAN(EDR)==>PAN(EDR)+HID\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8821C_2ANT_COEX_ALGO_HID_A2DP_PANEDR; - } - } - } - } - - return algorithm; -} - - - -void halbtc8821c2ant_action_coex_all_off(IN struct btc_coexist *btcoexist) -{ - - halbtc8821c2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - - /* fw all off */ - halbtc8821c2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); - - halbtc8821c2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8); - halbtc8821c2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - -} - -void halbtc8821c2ant_action_wifi_under5g(IN struct btc_coexist *btcoexist) -{ - - /* fw all off */ - halbtc8821c2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); - halbtc8821c2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - - halbtc8821c2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8); - halbtc8821c2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - halbtc8821c2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, NORMAL_EXEC, - BT_8821C_2ANT_PHASE_5G_RUNTIME); -} - - -void halbtc8821c2ant_action_bt_inquiry(IN struct btc_coexist *btcoexist) -{ - - boolean wifi_connected = false; - boolean scan = false, link = false, roam = false; - boolean wifi_busy = false; - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam); - - if (link || roam || coex_sta->wifi_is_high_pri_task) { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi link/roam/hi-pri-task process + BT Inq/Page!!\n"); - BTC_TRACE(trace_buf); - - halbtc8821c2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, - 8); - halbtc8821c2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 11); - - } else if (scan) { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi scan process + BT Inq/Page!!\n"); - BTC_TRACE(trace_buf); - - halbtc8821c2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, - 8); - - if (coex_sta->bt_create_connection) - halbtc8821c2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 12); - else - halbtc8821c2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 11); - - } else if (wifi_connected) { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi connected + BT Inq/Page!!\n"); - BTC_TRACE(trace_buf); - - halbtc8821c2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, - 8); - - if (wifi_busy) { - - if ((bt_link_info->a2dp_exist) && - (bt_link_info->acl_busy)) - halbtc8821c2ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 13); - else - halbtc8821c2ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 11); - - } else - halbtc8821c2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 13); - - } else { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi no-link + BT Inq/Page!!\n"); - BTC_TRACE(trace_buf); - - halbtc8821c2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - - halbtc8821c2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); - } - - halbtc8821c2ant_fw_dac_swing_lvl(btcoexist, FORCE_EXEC, 0xd8); - halbtc8821c2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); -} - -void halbtc8821c2ant_action_wifi_link_process(IN struct btc_coexist *btcoexist) -{ - u32 u32tmp, u32tmpb; - u8 u8tmpa; - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - - halbtc8821c2ant_fw_dac_swing_lvl(btcoexist, FORCE_EXEC, 0xd8); - halbtc8821c2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - halbtc8821c2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7); - - if ((bt_link_info->a2dp_exist) && (bt_link_info->acl_busy)) - halbtc8821c2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 14); - else - halbtc8821c2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 11); - -} - - -void halbtc8821c2ant_action_wifi_nonconnected(IN struct btc_coexist *btcoexist) -{ - halbtc8821c2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - - /* fw all off */ - halbtc8821c2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); - - halbtc8821c2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8); - halbtc8821c2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); -} - -void halbtc8821c2ant_action_bt_idle(IN struct btc_coexist *btcoexist) -{ - static u8 prewifi_rssi_state = BTC_RSSI_STATE_LOW; - static u8 pre_bt_rssi_state = BTC_RSSI_STATE_LOW; - u8 wifi_rssi_state, bt_rssi_state; - - static u8 prewifi_rssi_state2 = BTC_RSSI_STATE_LOW; - static u8 pre_bt_rssi_state2 = BTC_RSSI_STATE_LOW; - u8 wifi_rssi_state2, bt_rssi_state2; - - boolean wifi_connected = false; - boolean scan = false, link = false, roam = false; - boolean wifi_busy = false; - - wifi_rssi_state = halbtc8821c2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state, 2, - coex_sta->wifi_coex_thres , 0); - - wifi_rssi_state2 = halbtc8821c2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state2, 2, - coex_sta->wifi_coex_thres2 , 0); - - bt_rssi_state = halbtc8821c2ant_bt_rssi_state(&pre_bt_rssi_state, 2, - coex_sta->bt_coex_thres , 0); - - bt_rssi_state2 = halbtc8821c2ant_bt_rssi_state(&pre_bt_rssi_state2, 2, - coex_sta->bt_coex_thres2 , 0); - - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam); - - if (scan || link || roam) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi link process + BT Idle!!\n"); - BTC_TRACE(trace_buf); - - halbtc8821c2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, - 7); - - halbtc8821c2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 11); - } else if (wifi_connected) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi connected + BT Idle!!\n"); - BTC_TRACE(trace_buf); - - if (wifi_busy) - halbtc8821c2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 0); - - else - halbtc8821c2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 0); - - halbtc8821c2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); - - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi no-link + BT Idle!!\n"); - BTC_TRACE(trace_buf); - - halbtc8821c2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - halbtc8821c2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); - } - - halbtc8821c2ant_fw_dac_swing_lvl(btcoexist, FORCE_EXEC, 0xd8); - halbtc8821c2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - -} - - -/* SCO only or SCO+PAN(HS) */ -void halbtc8821c2ant_action_sco(IN struct btc_coexist *btcoexist) -{ - static u8 prewifi_rssi_state = BTC_RSSI_STATE_LOW; - static u8 pre_bt_rssi_state = BTC_RSSI_STATE_LOW; - u8 wifi_rssi_state, bt_rssi_state; - - static u8 prewifi_rssi_state2 = BTC_RSSI_STATE_LOW; - static u8 pre_bt_rssi_state2 = BTC_RSSI_STATE_LOW; - u8 wifi_rssi_state2, bt_rssi_state2; - boolean wifi_busy = false; - u32 wifi_bw = 1; - - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, - &wifi_bw); - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - - wifi_rssi_state = halbtc8821c2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state, 2, - coex_sta->wifi_coex_thres , 0); - - wifi_rssi_state2 = halbtc8821c2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state2, 2, - coex_sta->wifi_coex_thres2 , 0); - - bt_rssi_state = halbtc8821c2ant_bt_rssi_state(&pre_bt_rssi_state, 2, - coex_sta->bt_coex_thres , 0); - - bt_rssi_state2 = halbtc8821c2ant_bt_rssi_state(&pre_bt_rssi_state2, 2, - coex_sta->bt_coex_thres2 , 0); - - - if (BTC_RSSI_HIGH(wifi_rssi_state) && - BTC_RSSI_HIGH(bt_rssi_state)) { - - halbtc8821c2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8); - halbtc8821c2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - coex_dm->is_switch_to_1dot5_ant = false; - - halbtc8821c2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - - halbtc8821c2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); - } else { - - halbtc8821c2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8); - halbtc8821c2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - coex_dm->is_switch_to_1dot5_ant = false; - - if (wifi_bw == 0) { /* if 11bg mode */ - /*for 4/18 hid */ - halbtc8821c2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 9); - halbtc8821c2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 10); - } else { - halbtc8821c2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, - 3); - halbtc8821c2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); - } - } - -} - - -void halbtc8821c2ant_action_hid(IN struct btc_coexist *btcoexist) -{ - static u8 prewifi_rssi_state = BTC_RSSI_STATE_LOW; - static u8 pre_bt_rssi_state = BTC_RSSI_STATE_LOW; - u8 wifi_rssi_state, bt_rssi_state; - - static u8 prewifi_rssi_state2 = BTC_RSSI_STATE_LOW; - static u8 pre_bt_rssi_state2 = BTC_RSSI_STATE_LOW; - u8 wifi_rssi_state2, bt_rssi_state2; - boolean wifi_busy = false; - u32 wifi_bw = 1; - - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw); - - wifi_rssi_state = halbtc8821c2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state, 2, - coex_sta->wifi_coex_thres , 0); - - wifi_rssi_state2 = halbtc8821c2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state2, 2, - coex_sta->wifi_coex_thres2 , 0); - - bt_rssi_state = halbtc8821c2ant_bt_rssi_state(&pre_bt_rssi_state, 2, - coex_sta->bt_coex_thres , 0); - - bt_rssi_state2 = halbtc8821c2ant_bt_rssi_state(&pre_bt_rssi_state2, 2, - coex_sta->bt_coex_thres2 , 0); - - - if (BTC_RSSI_HIGH(wifi_rssi_state) && - BTC_RSSI_HIGH(bt_rssi_state)) { - - halbtc8821c2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8); - halbtc8821c2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - coex_dm->is_switch_to_1dot5_ant = false; - - halbtc8821c2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - - halbtc8821c2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); - } else { - - halbtc8821c2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8); - halbtc8821c2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - coex_dm->is_switch_to_1dot5_ant = false; - - if ((wifi_bw == 0) && - (coex_sta->hid_busy_num >= 2)) { /* if 11bg mode */ - /*for 4/18 hid */ - halbtc8821c2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 9); - halbtc8821c2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 10); - - } else { - - halbtc8821c2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, - 3); - halbtc8821c2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); - } - } - -} - -/* A2DP only / PAN(EDR) only/ A2DP+PAN(HS) */ -void halbtc8821c2ant_action_a2dp(IN struct btc_coexist *btcoexist) -{ - static u8 prewifi_rssi_state = BTC_RSSI_STATE_LOW; - static u8 pre_bt_rssi_state = BTC_RSSI_STATE_LOW; - u8 wifi_rssi_state, bt_rssi_state; - - static u8 prewifi_rssi_state2 = BTC_RSSI_STATE_LOW; - static u8 pre_bt_rssi_state2 = BTC_RSSI_STATE_LOW; - u8 wifi_rssi_state2, bt_rssi_state2; - boolean wifi_busy = false, wifi_turbo = false; - - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM, - &coex_sta->scan_ap_num); - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "############# [BTCoex], scan_ap_num = %d\n", - coex_sta->scan_ap_num); - BTC_TRACE(trace_buf); - -#if 1 - if ((wifi_busy) && (coex_sta->scan_ap_num <= 4)) - wifi_turbo = true; -#endif - - wifi_rssi_state = halbtc8821c2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state, 2, - coex_sta->wifi_coex_thres , 0); - - wifi_rssi_state2 = halbtc8821c2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state2, 2, - coex_sta->wifi_coex_thres2 , 0); - - bt_rssi_state = halbtc8821c2ant_bt_rssi_state(&pre_bt_rssi_state, 2, - coex_sta->bt_coex_thres , 0); - - bt_rssi_state2 = halbtc8821c2ant_bt_rssi_state(&pre_bt_rssi_state2, 2, - coex_sta->bt_coex_thres2 , 0); - - - if (BTC_RSSI_HIGH(wifi_rssi_state) && - BTC_RSSI_HIGH(bt_rssi_state)) { - - halbtc8821c2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8); - halbtc8821c2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - coex_dm->is_switch_to_1dot5_ant = false; - - halbtc8821c2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - - halbtc8821c2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); - } else if (BTC_RSSI_HIGH(wifi_rssi_state2) && - BTC_RSSI_HIGH(bt_rssi_state2)) { - - halbtc8821c2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xc8); - halbtc8821c2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2); - - coex_dm->is_switch_to_1dot5_ant = false; - - halbtc8821c2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); - - if (wifi_busy) { - if (coex_sta->is_setupLink) - halbtc8821c2ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 51); - else - halbtc8821c2ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 1); - } else - - halbtc8821c2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 2); - } else { - - halbtc8821c2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8); - halbtc8821c2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - coex_dm->is_switch_to_1dot5_ant = true; - - if (wifi_turbo) - halbtc8821c2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 6); - else - halbtc8821c2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, - 7); - - if (wifi_busy) { - if (coex_sta->is_setupLink) - halbtc8821c2ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 151); - else - halbtc8821c2ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 101); - } else - halbtc8821c2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 102); - - } - -} - -void halbtc8821c2ant_action_pan_edr(IN struct btc_coexist *btcoexist) -{ - static u8 prewifi_rssi_state = BTC_RSSI_STATE_LOW; - static u8 pre_bt_rssi_state = BTC_RSSI_STATE_LOW; - u8 wifi_rssi_state, bt_rssi_state; - - static u8 prewifi_rssi_state2 = BTC_RSSI_STATE_LOW; - static u8 pre_bt_rssi_state2 = BTC_RSSI_STATE_LOW; - u8 wifi_rssi_state2, bt_rssi_state2; - boolean wifi_busy = false, wifi_turbo = false; - - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM, - &coex_sta->scan_ap_num); - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "############# [BTCoex], scan_ap_num = %d\n", - coex_sta->scan_ap_num); - BTC_TRACE(trace_buf); - -#if 1 - if ((wifi_busy) && (coex_sta->scan_ap_num <= 4)) - wifi_turbo = true; -#endif - - wifi_rssi_state = halbtc8821c2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state, 2, - coex_sta->wifi_coex_thres , 0); - - wifi_rssi_state2 = halbtc8821c2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state2, 2, - coex_sta->wifi_coex_thres2 , 0); - - bt_rssi_state = halbtc8821c2ant_bt_rssi_state(&pre_bt_rssi_state, 2, - coex_sta->bt_coex_thres , 0); - - bt_rssi_state2 = halbtc8821c2ant_bt_rssi_state(&pre_bt_rssi_state2, 2, - coex_sta->bt_coex_thres2 , 0); - -#if 0 - halbtc8821c2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8); - halbtc8821c2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - coex_dm->is_switch_to_1dot5_ant = false; - - halbtc8821c2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - - halbtc8821c2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); -#endif - - -#if 1 - if (BTC_RSSI_HIGH(wifi_rssi_state) && - BTC_RSSI_HIGH(bt_rssi_state)) { - - halbtc8821c2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8); - halbtc8821c2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - coex_dm->is_switch_to_1dot5_ant = false; - - halbtc8821c2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - - halbtc8821c2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); - } else if (BTC_RSSI_HIGH(wifi_rssi_state2) && - BTC_RSSI_HIGH(bt_rssi_state2)) { - - halbtc8821c2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xc8); - halbtc8821c2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2); - - coex_dm->is_switch_to_1dot5_ant = false; - - halbtc8821c2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); - - if (wifi_busy) - halbtc8821c2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 3); - else - halbtc8821c2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 4); - } else { - - halbtc8821c2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8); - halbtc8821c2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - coex_dm->is_switch_to_1dot5_ant = true; - - if (wifi_turbo) - halbtc8821c2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 6); - else - halbtc8821c2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, - 7); - - if (wifi_busy) - halbtc8821c2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 103); - else - halbtc8821c2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 104); - - } - -#endif - -} - - -/* PAN(HS) only */ -void halbtc8821c2ant_action_pan_hs(IN struct btc_coexist *btcoexist) -{ - static u8 prewifi_rssi_state = BTC_RSSI_STATE_LOW; - static u8 pre_bt_rssi_state = BTC_RSSI_STATE_LOW; - u8 wifi_rssi_state, bt_rssi_state; - - static u8 prewifi_rssi_state2 = BTC_RSSI_STATE_LOW; - static u8 pre_bt_rssi_state2 = BTC_RSSI_STATE_LOW; - u8 wifi_rssi_state2, bt_rssi_state2; - boolean wifi_busy = false, wifi_turbo = false; - - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM, - &coex_sta->scan_ap_num); - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "############# [BTCoex], scan_ap_num = %d\n", - coex_sta->scan_ap_num); - BTC_TRACE(trace_buf); - -#if 1 - if ((wifi_busy) && (coex_sta->scan_ap_num <= 4)) - wifi_turbo = true; -#endif - - - wifi_rssi_state = halbtc8821c2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state, 2, - coex_sta->wifi_coex_thres , 0); - - wifi_rssi_state2 = halbtc8821c2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state2, 2, - coex_sta->wifi_coex_thres2 , 0); - - bt_rssi_state = halbtc8821c2ant_bt_rssi_state(&pre_bt_rssi_state, 2, - coex_sta->bt_coex_thres , 0); - - bt_rssi_state2 = halbtc8821c2ant_bt_rssi_state(&pre_bt_rssi_state2, 2, - coex_sta->bt_coex_thres2 , 0); - - if (BTC_RSSI_HIGH(wifi_rssi_state) && - BTC_RSSI_HIGH(bt_rssi_state)) { - - halbtc8821c2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8); - halbtc8821c2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - coex_dm->is_switch_to_1dot5_ant = false; - - halbtc8821c2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - - halbtc8821c2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); - } else if (BTC_RSSI_HIGH(wifi_rssi_state2) && - BTC_RSSI_HIGH(bt_rssi_state2)) { - - halbtc8821c2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xc8); - halbtc8821c2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2); - - coex_dm->is_switch_to_1dot5_ant = false; - - halbtc8821c2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - - halbtc8821c2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); - - - } else { - - halbtc8821c2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8); - halbtc8821c2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - coex_dm->is_switch_to_1dot5_ant = true; - - halbtc8821c2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - - halbtc8821c2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); - } - -} - - -void halbtc8821c2ant_action_hid_a2dp(IN struct btc_coexist *btcoexist) -{ - static u8 prewifi_rssi_state = BTC_RSSI_STATE_LOW; - static u8 pre_bt_rssi_state = BTC_RSSI_STATE_LOW; - u8 wifi_rssi_state, bt_rssi_state; - - static u8 prewifi_rssi_state2 = BTC_RSSI_STATE_LOW; - static u8 pre_bt_rssi_state2 = BTC_RSSI_STATE_LOW; - u8 wifi_rssi_state2, bt_rssi_state2; - boolean wifi_busy = false; - - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - - wifi_rssi_state = halbtc8821c2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state, 2, - coex_sta->wifi_coex_thres , 0); - - wifi_rssi_state2 = halbtc8821c2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state2, 2, - coex_sta->wifi_coex_thres2 , 0); - - bt_rssi_state = halbtc8821c2ant_bt_rssi_state(&pre_bt_rssi_state, 2, - coex_sta->bt_coex_thres , 0); - - bt_rssi_state2 = halbtc8821c2ant_bt_rssi_state(&pre_bt_rssi_state2, 2, - coex_sta->bt_coex_thres2 , 0); - - - if (BTC_RSSI_HIGH(wifi_rssi_state) && - BTC_RSSI_HIGH(bt_rssi_state)) { - - halbtc8821c2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8); - halbtc8821c2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - coex_dm->is_switch_to_1dot5_ant = false; - - halbtc8821c2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - halbtc8821c2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); - } else if (BTC_RSSI_HIGH(wifi_rssi_state2) && - BTC_RSSI_HIGH(bt_rssi_state2)) { - - halbtc8821c2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xc8); - halbtc8821c2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2); - - coex_dm->is_switch_to_1dot5_ant = false; - - halbtc8821c2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); - - if (wifi_busy) { - if (coex_sta->is_setupLink) - halbtc8821c2ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 51); - else - halbtc8821c2ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 1); - } else - halbtc8821c2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 2); - } else { - - halbtc8821c2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8); - halbtc8821c2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - coex_dm->is_switch_to_1dot5_ant = true; - - - if (wifi_busy) { - if (coex_sta->hid_busy_num >= 2) { - halbtc8821c2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 8); - halbtc8821c2ant_set_wltoggle_coex_table(btcoexist, - NORMAL_EXEC, - 0x2, 0xaa, - 0x5a, 0xaa, - 0xaa); - halbtc8821c2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 109); - } else if (coex_sta->is_setupLink) { - halbtc8821c2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1); - halbtc8821c2ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 151); - } else { - halbtc8821c2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1); - halbtc8821c2ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 101); - } - } else { - halbtc8821c2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, - 1); - halbtc8821c2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 102); - } - - } - -} - - -void halbtc8821c2ant_action_a2dp_pan_hs(IN struct btc_coexist *btcoexist) -{ - static u8 prewifi_rssi_state = BTC_RSSI_STATE_LOW; - static u8 pre_bt_rssi_state = BTC_RSSI_STATE_LOW; - u8 wifi_rssi_state, bt_rssi_state; - - static u8 prewifi_rssi_state2 = BTC_RSSI_STATE_LOW; - static u8 pre_bt_rssi_state2 = BTC_RSSI_STATE_LOW; - u8 wifi_rssi_state2, bt_rssi_state2; - boolean wifi_busy = false, wifi_turbo = false; - - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM, - &coex_sta->scan_ap_num); - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "############# [BTCoex], scan_ap_num = %d\n", - coex_sta->scan_ap_num); - BTC_TRACE(trace_buf); - -#if 1 - if ((wifi_busy) && (coex_sta->scan_ap_num <= 4)) - wifi_turbo = true; -#endif - - - wifi_rssi_state = halbtc8821c2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state, 2, - coex_sta->wifi_coex_thres , 0); - - wifi_rssi_state2 = halbtc8821c2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state2, 2, - coex_sta->wifi_coex_thres2 , 0); - - bt_rssi_state = halbtc8821c2ant_bt_rssi_state(&pre_bt_rssi_state, 2, - coex_sta->bt_coex_thres , 0); - - bt_rssi_state2 = halbtc8821c2ant_bt_rssi_state(&pre_bt_rssi_state2, 2, - coex_sta->bt_coex_thres2 , 0); - - - if (BTC_RSSI_HIGH(wifi_rssi_state) && - BTC_RSSI_HIGH(bt_rssi_state)) { - - halbtc8821c2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8); - halbtc8821c2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - coex_dm->is_switch_to_1dot5_ant = false; - - halbtc8821c2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - - halbtc8821c2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); - } else if (BTC_RSSI_HIGH(wifi_rssi_state2) && - BTC_RSSI_HIGH(bt_rssi_state2)) { - - halbtc8821c2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xc8); - halbtc8821c2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2); - - coex_dm->is_switch_to_1dot5_ant = false; - - halbtc8821c2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); - - if (wifi_busy) { - - if ((coex_sta->a2dp_bit_pool > 40) && - (coex_sta->a2dp_bit_pool < 255)) - halbtc8821c2ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 7); - else - halbtc8821c2ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 5); - } else - halbtc8821c2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 6); - - } else { - - halbtc8821c2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8); - halbtc8821c2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - coex_dm->is_switch_to_1dot5_ant = true; - - if (wifi_turbo) - halbtc8821c2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 6); - else - halbtc8821c2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, - 7); - - if (wifi_busy) { - - if ((coex_sta->a2dp_bit_pool > 40) && - (coex_sta->a2dp_bit_pool < 255)) - halbtc8821c2ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 107); - else - halbtc8821c2ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 105); - } else - halbtc8821c2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 106); - - } - -} - - - -/* PAN(EDR)+A2DP */ -void halbtc8821c2ant_action_pan_edr_a2dp(IN struct btc_coexist *btcoexist) -{ - static u8 prewifi_rssi_state = BTC_RSSI_STATE_LOW; - static u8 pre_bt_rssi_state = BTC_RSSI_STATE_LOW; - u8 wifi_rssi_state, bt_rssi_state; - - static u8 prewifi_rssi_state2 = BTC_RSSI_STATE_LOW; - static u8 pre_bt_rssi_state2 = BTC_RSSI_STATE_LOW; - u8 wifi_rssi_state2, bt_rssi_state2; - boolean wifi_busy = false, wifi_turbo = false; - - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM, - &coex_sta->scan_ap_num); - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "############# [BTCoex], scan_ap_num = %d\n", - coex_sta->scan_ap_num); - BTC_TRACE(trace_buf); - -#if 1 - if ((wifi_busy) && (coex_sta->scan_ap_num <= 4)) - wifi_turbo = true; -#endif - - - wifi_rssi_state = halbtc8821c2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state, 2, - coex_sta->wifi_coex_thres , 0); - - wifi_rssi_state2 = halbtc8821c2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state2, 2, - coex_sta->wifi_coex_thres2 , 0); - - bt_rssi_state = halbtc8821c2ant_bt_rssi_state(&pre_bt_rssi_state, 2, - coex_sta->bt_coex_thres , 0); - - bt_rssi_state2 = halbtc8821c2ant_bt_rssi_state(&pre_bt_rssi_state2, 2, - coex_sta->bt_coex_thres2 , 0); - - if (BTC_RSSI_HIGH(wifi_rssi_state) && - BTC_RSSI_HIGH(bt_rssi_state)) { - - halbtc8821c2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8); - halbtc8821c2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - coex_dm->is_switch_to_1dot5_ant = false; - - halbtc8821c2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - halbtc8821c2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); - } else if (BTC_RSSI_HIGH(wifi_rssi_state2) && - BTC_RSSI_HIGH(bt_rssi_state2)) { - - halbtc8821c2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xc8); - halbtc8821c2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2); - - coex_dm->is_switch_to_1dot5_ant = false; - - halbtc8821c2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); - - if (wifi_busy) { - - if (((coex_sta->a2dp_bit_pool > 40) && - (coex_sta->a2dp_bit_pool < 255)) || - (!coex_sta->is_A2DP_3M)) - halbtc8821c2ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 7); - else - halbtc8821c2ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 5); - } else - halbtc8821c2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 6); - } else { - - halbtc8821c2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8); - halbtc8821c2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - coex_dm->is_switch_to_1dot5_ant = true; - - if (wifi_turbo) - halbtc8821c2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 6); - else - halbtc8821c2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, - 7); - - if (wifi_busy) { - - if ((coex_sta->a2dp_bit_pool > 40) && - (coex_sta->a2dp_bit_pool < 255)) - halbtc8821c2ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 107); - else if (wifi_turbo) - halbtc8821c2ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 108); - else - halbtc8821c2ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 105); - } else - halbtc8821c2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 106); - - } - -} - -void halbtc8821c2ant_action_pan_edr_hid(IN struct btc_coexist *btcoexist) -{ - static u8 prewifi_rssi_state = BTC_RSSI_STATE_LOW; - static u8 pre_bt_rssi_state = BTC_RSSI_STATE_LOW; - u8 wifi_rssi_state, bt_rssi_state; - - static u8 prewifi_rssi_state2 = BTC_RSSI_STATE_LOW; - static u8 pre_bt_rssi_state2 = BTC_RSSI_STATE_LOW; - u8 wifi_rssi_state2, bt_rssi_state2; - boolean wifi_busy = false; - - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - - wifi_rssi_state = halbtc8821c2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state, 2, - coex_sta->wifi_coex_thres , 0); - - wifi_rssi_state2 = halbtc8821c2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state2, 2, - coex_sta->wifi_coex_thres2 , 0); - - bt_rssi_state = halbtc8821c2ant_bt_rssi_state(&pre_bt_rssi_state, 2, - coex_sta->bt_coex_thres , 0); - - bt_rssi_state2 = halbtc8821c2ant_bt_rssi_state(&pre_bt_rssi_state2, 2, - coex_sta->bt_coex_thres2 , 0); - - - if (BTC_RSSI_HIGH(wifi_rssi_state) && - BTC_RSSI_HIGH(bt_rssi_state)) { - - halbtc8821c2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8); - halbtc8821c2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - coex_dm->is_switch_to_1dot5_ant = false; - - halbtc8821c2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - halbtc8821c2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); - } else if (BTC_RSSI_HIGH(wifi_rssi_state2) && - BTC_RSSI_HIGH(bt_rssi_state2)) { - - halbtc8821c2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xc8); - halbtc8821c2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2); - - coex_dm->is_switch_to_1dot5_ant = false; - - halbtc8821c2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); - - if (wifi_busy) - - halbtc8821c2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 3); - else - - halbtc8821c2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 4); - - - } else { - - halbtc8821c2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8); - halbtc8821c2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - coex_dm->is_switch_to_1dot5_ant = true; - - halbtc8821c2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1); - - if (wifi_busy) - - halbtc8821c2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 103); - else - - halbtc8821c2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 104); - - } - -} - -/* HID+A2DP+PAN(EDR) */ -void halbtc8821c2ant_action_hid_a2dp_pan_edr(IN struct btc_coexist *btcoexist) -{ - static u8 prewifi_rssi_state = BTC_RSSI_STATE_LOW; - static u8 pre_bt_rssi_state = BTC_RSSI_STATE_LOW; - u8 wifi_rssi_state, bt_rssi_state; - - static u8 prewifi_rssi_state2 = BTC_RSSI_STATE_LOW; - static u8 pre_bt_rssi_state2 = BTC_RSSI_STATE_LOW; - u8 wifi_rssi_state2, bt_rssi_state2; - boolean wifi_busy = false; - - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - - wifi_rssi_state = halbtc8821c2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state, 2, - coex_sta->wifi_coex_thres , 0); - - wifi_rssi_state2 = halbtc8821c2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state2, 2, - coex_sta->wifi_coex_thres2 , 0); - - bt_rssi_state = halbtc8821c2ant_bt_rssi_state(&pre_bt_rssi_state, 2, - coex_sta->bt_coex_thres , 0); - - bt_rssi_state2 = halbtc8821c2ant_bt_rssi_state(&pre_bt_rssi_state2, 2, - coex_sta->bt_coex_thres2 , 0); - - - if (BTC_RSSI_HIGH(wifi_rssi_state) && - BTC_RSSI_HIGH(bt_rssi_state)) { - - halbtc8821c2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8); - halbtc8821c2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - coex_dm->is_switch_to_1dot5_ant = false; - - halbtc8821c2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - halbtc8821c2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); - } else if (BTC_RSSI_HIGH(wifi_rssi_state2) && - BTC_RSSI_HIGH(bt_rssi_state2)) { - - halbtc8821c2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xc8); - halbtc8821c2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2); - - coex_dm->is_switch_to_1dot5_ant = false; - - halbtc8821c2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); - - if (wifi_busy) { - - if (((coex_sta->a2dp_bit_pool > 40) && - (coex_sta->a2dp_bit_pool < 255)) || - (!coex_sta->is_A2DP_3M)) - halbtc8821c2ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 7); - else - halbtc8821c2ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 5); - } else - halbtc8821c2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 6); - } else { - - halbtc8821c2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8); - halbtc8821c2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - coex_dm->is_switch_to_1dot5_ant = true; - - halbtc8821c2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1); - - if (wifi_busy) { - - if ((coex_sta->a2dp_bit_pool > 40) && - (coex_sta->a2dp_bit_pool < 255)) - halbtc8821c2ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 107); - else - halbtc8821c2ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 105); - } else - halbtc8821c2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 106); - } - -} - - - -void halbtc8821c2ant_action_bt_whck_test(IN struct btc_coexist *btcoexist) -{ - halbtc8821c2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8); - halbtc8821c2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - halbtc8821c2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - halbtc8821c2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); -} - -void halbtc8821c2ant_action_wifi_multi_port(IN struct btc_coexist *btcoexist) -{ - halbtc8821c2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8); - halbtc8821c2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - /* hw all off */ - halbtc8821c2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - halbtc8821c2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); -} - -void halbtc8821c2ant_run_coexist_mechanism(IN struct btc_coexist *btcoexist) -{ - u8 algorithm = 0; - u32 num_of_wifi_link = 0; - u32 wifi_link_status = 0; - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - boolean miracast_plus_bt = false; - boolean scan = false, link = false, roam = false, - wifi_connected = false, wifi_under_5g = false; - - - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], RunCoexistMechanism()===>\n"); - BTC_TRACE(trace_buf); - - if (btcoexist->manual_control) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], RunCoexistMechanism(), return for Manual CTRL <===\n"); - BTC_TRACE(trace_buf); - return; - } - - if (btcoexist->stop_coex_dm) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], RunCoexistMechanism(), return for Stop Coex DM <===\n"); - BTC_TRACE(trace_buf); - return; - } - - if (coex_sta->under_ips) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], wifi is under IPS !!!\n"); - BTC_TRACE(trace_buf); - return; - } - - if (!coex_sta->run_time_state) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], return for run_time_state = false !!!\n"); - BTC_TRACE(trace_buf); - return; - } - - if (coex_sta->freeze_coexrun_by_btinfo) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), return for freeze_coexrun_by_btinfo\n"); - BTC_TRACE(trace_buf); - return; - } - - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g); - - if (wifi_under_5g) { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], WiFi is under 5G!!!\n"); - BTC_TRACE(trace_buf); - - halbtc8821c2ant_action_wifi_under5g(btcoexist); - return; - } else { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], WiFi is under 2G!!!\n"); - BTC_TRACE(trace_buf); - - halbtc8821c2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, - NORMAL_EXEC, - BT_8821C_2ANT_PHASE_2G_RUNTIME); - } - - - if (coex_sta->bt_whck_test) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT is under WHCK TEST!!!\n"); - BTC_TRACE(trace_buf); - halbtc8821c2ant_action_bt_whck_test(btcoexist); - return; - } - - if (coex_sta->bt_disabled) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT is disabled!!!\n"); - BTC_TRACE(trace_buf); - halbtc8821c2ant_action_coex_all_off(btcoexist); - return; - } - - if (coex_sta->c2h_bt_inquiry_page) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT is under inquiry/page scan !!\n"); - BTC_TRACE(trace_buf); - halbtc8821c2ant_action_bt_inquiry(btcoexist); - return; - } - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam); - - if (scan || link || roam) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], WiFi is under Link Process !!\n"); - BTC_TRACE(trace_buf); - halbtc8821c2ant_action_wifi_link_process(btcoexist); - return; - } - - /* for P2P */ - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS, - &wifi_link_status); - num_of_wifi_link = wifi_link_status >> 16; - - if ((num_of_wifi_link >= 2) || - (wifi_link_status & WIFI_P2P_GO_CONNECTED)) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "############# [BTCoex], Multi-Port num_of_wifi_link = %d, wifi_link_status = 0x%x\n", - num_of_wifi_link, wifi_link_status); - BTC_TRACE(trace_buf); - - if (bt_link_info->bt_link_exist) - miracast_plus_bt = true; - else - miracast_plus_bt = false; - - btcoexist->btc_set(btcoexist, BTC_SET_BL_MIRACAST_PLUS_BT, - &miracast_plus_bt); - halbtc8821c2ant_action_wifi_multi_port(btcoexist); - - return; - } else { - miracast_plus_bt = false; - btcoexist->btc_set(btcoexist, BTC_SET_BL_MIRACAST_PLUS_BT, - &miracast_plus_bt); - } - - - algorithm = halbtc8821c2ant_action_algorithm(btcoexist); - coex_dm->cur_algorithm = algorithm; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], Algorithm = %d\n", - coex_dm->cur_algorithm); - BTC_TRACE(trace_buf); - - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - - if (!wifi_connected) { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, wifi non-connected!!.\n"); - BTC_TRACE(trace_buf); - halbtc8821c2ant_action_wifi_nonconnected(btcoexist); - - } else if ((BT_8821C_2ANT_BT_STATUS_NON_CONNECTED_IDLE == - coex_dm->bt_status) || - (BT_8821C_2ANT_BT_STATUS_CONNECTED_IDLE == - coex_dm->bt_status)) { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, bt idle!!.\n"); - BTC_TRACE(trace_buf); - - halbtc8821c2ant_action_bt_idle(btcoexist); - - } else { - - if (coex_dm->cur_algorithm != coex_dm->pre_algorithm) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], pre_algorithm=%d, cur_algorithm=%d\n", - coex_dm->pre_algorithm, coex_dm->cur_algorithm); - BTC_TRACE(trace_buf); - } - - switch (coex_dm->cur_algorithm) { - - case BT_8821C_2ANT_COEX_ALGO_SCO: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, algorithm = SCO.\n"); - BTC_TRACE(trace_buf); - halbtc8821c2ant_action_sco(btcoexist); - break; - case BT_8821C_2ANT_COEX_ALGO_HID: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, algorithm = HID.\n"); - BTC_TRACE(trace_buf); - halbtc8821c2ant_action_hid(btcoexist); - break; - case BT_8821C_2ANT_COEX_ALGO_A2DP: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, algorithm = A2DP.\n"); - BTC_TRACE(trace_buf); - halbtc8821c2ant_action_a2dp(btcoexist); - break; - case BT_8821C_2ANT_COEX_ALGO_A2DP_PANHS: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, algorithm = A2DP+PAN(HS).\n"); - BTC_TRACE(trace_buf); - halbtc8821c2ant_action_a2dp_pan_hs(btcoexist); - break; - case BT_8821C_2ANT_COEX_ALGO_PANEDR: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, algorithm = PAN(EDR).\n"); - BTC_TRACE(trace_buf); - halbtc8821c2ant_action_pan_edr(btcoexist); - break; - case BT_8821C_2ANT_COEX_ALGO_PANHS: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, algorithm = HS mode.\n"); - BTC_TRACE(trace_buf); - halbtc8821c2ant_action_pan_hs(btcoexist); - break; - case BT_8821C_2ANT_COEX_ALGO_PANEDR_A2DP: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, algorithm = PAN+A2DP.\n"); - BTC_TRACE(trace_buf); - halbtc8821c2ant_action_pan_edr_a2dp(btcoexist); - break; - case BT_8821C_2ANT_COEX_ALGO_PANEDR_HID: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, algorithm = PAN(EDR)+HID.\n"); - BTC_TRACE(trace_buf); - halbtc8821c2ant_action_pan_edr_hid(btcoexist); - break; - case BT_8821C_2ANT_COEX_ALGO_HID_A2DP_PANEDR: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, algorithm = HID+A2DP+PAN.\n"); - BTC_TRACE(trace_buf); - halbtc8821c2ant_action_hid_a2dp_pan_edr( - btcoexist); - break; - case BT_8821C_2ANT_COEX_ALGO_HID_A2DP: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, algorithm = HID+A2DP.\n"); - BTC_TRACE(trace_buf); - halbtc8821c2ant_action_hid_a2dp(btcoexist); - break; - case BT_8821C_2ANT_COEX_ALGO_NOPROFILEBUSY: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, algorithm = No-Profile busy.\n"); - BTC_TRACE(trace_buf); - halbtc8821c2ant_action_bt_idle(btcoexist); - break; - default: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, algorithm = coexist All Off!!\n"); - BTC_TRACE(trace_buf); - halbtc8821c2ant_action_coex_all_off(btcoexist); - break; - } - coex_dm->pre_algorithm = coex_dm->cur_algorithm; - } -} - -void halbtc8821c2ant_init_coex_dm(IN struct btc_coexist *btcoexist) -{ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Coex Mechanism Init!!\n"); - BTC_TRACE(trace_buf); - - halbtc8821c2ant_low_penalty_ra(btcoexist, NORMAL_EXEC, false); - - halbtc8821c2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - - /* fw all off */ - halbtc8821c2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); - - halbtc8821c2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8); - halbtc8821c2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - coex_sta->pop_event_cnt = 0; - coex_sta->cnt_RemoteNameReq = 0; - coex_sta->cnt_ReInit = 0; - coex_sta->cnt_setupLink = 0; - coex_sta->cnt_IgnWlanAct = 0; - coex_sta->cnt_Page = 0; - - halbtc8821c2ant_query_bt_info(btcoexist); -} - - -void halbtc8821c2ant_init_hw_config(IN struct btc_coexist *btcoexist, - IN boolean wifi_only) -{ - u8 u8tmp = 0; - u32 vendor; - u32 u32tmp0 = 0, u32tmp1 = 0, u32tmp2 = 0, u32tmp3 = 0; - - - u32tmp3 = btcoexist->btc_read_4byte(btcoexist, 0xcb4); - u32tmp1 = halbtc8821c2ant_ltecoex_indirect_read_reg(btcoexist, 0x38); - u32tmp2 = halbtc8821c2ant_ltecoex_indirect_read_reg(btcoexist, 0x54); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], (Before Init HW config) 0xcb4 = 0x%x, 0x38= 0x%x, 0x54= 0x%x\n", - u32tmp3, u32tmp1, u32tmp2); - BTC_TRACE(trace_buf);; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], 2Ant Init HW Config!!\n"); - BTC_TRACE(trace_buf); - - coex_sta->bt_coex_supported_feature = 0; - coex_sta->bt_coex_supported_version = 0; - coex_sta->bt_ble_scan_type = 0; - coex_sta->bt_ble_scan_para[0] = 0; - coex_sta->bt_ble_scan_para[1] = 0; - coex_sta->bt_ble_scan_para[2] = 0; - coex_sta->bt_reg_vendor_ac = 0xffff; - coex_sta->bt_reg_vendor_ae = 0xffff; - coex_sta->isolation_btween_wb = BT_8821C_2ANT_DEFAULT_ISOLATION; - - - /* 0xf0[15:12] --> Chip Cut information */ - coex_sta->cut_version = (btcoexist->btc_read_1byte(btcoexist, - 0xf1) & 0xf0) >> 4; - - coex_sta->dis_ver_info_cnt = 0; - - halbtc8821c2ant_coex_switch_threshold(btcoexist, - coex_sta->isolation_btween_wb); - - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x550, 0x8, - 0x1); /* enable TBTT nterrupt */ - - /* BT report packet sample rate */ - btcoexist->btc_write_1byte(btcoexist, 0x790, 0x5); - - /* Init 0x778 = 0x1 for 2-Ant */ - btcoexist->btc_write_1byte(btcoexist, 0x778, 0x1); - - /* Enable PTA (3-wire function form BT side) */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x40, 0x20, 0x1); - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x41, 0x02, 0x1); - - /* Enable PTA (tx/rx signal form WiFi side) */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4c6, 0x10, 0x1); - - /* set GNT_BT=1 for coex table select both */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x763, 0x10, 0x1); - - halbtc8821c2ant_enable_gnt_to_gpio(btcoexist, true); - - /* check if WL firmware download ok */ - /*if (btcoexist->btc_read_1byte(btcoexist, 0x80) == 0xc6)*/ - halbtc8821c2ant_post_state_to_bt(btcoexist, - BT_8821C_2ANT_SCOREBOARD_ONOFF, true); - - /* Enable counter statistics */ - btcoexist->btc_write_1byte(btcoexist, 0x76e, - 0x4); /* 0x76e[3] =1, WLAN_Act control by PTA */ - - /* WLAN_Tx by GNT_WL 0x950[29] = 0 */ - /* btcoexist->btc_write_1byte_bitmask(btcoexist, 0x953, 0x20, 0x0); */ - - halbtc8821c2ant_coex_table_with_type(btcoexist, FORCE_EXEC, 0); - - halbtc8821c2ant_ps_tdma(btcoexist, FORCE_EXEC, false, 0); - - psd_scan->ant_det_is_ant_det_available = true; - - if (wifi_only) { - coex_sta->concurrent_rx_mode_on = false; - /* Path config */ - /* Set Antenna Path */ - halbtc8821c2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, - FORCE_EXEC, - BT_8821C_2ANT_PHASE_WLANONLY_INIT); - - btcoexist->stop_coex_dm = true; - } else { - /*Set BT polluted packet on for Tx rate adaptive not including Tx retry break by PTA, 0x45c[19] =1 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x45e, 0x8, 0x1); - - coex_sta->concurrent_rx_mode_on = true; - /* btcoexist->btc_write_1byte_bitmask(btcoexist, 0x953, 0x2, 0x1); */ - - /* RF 0x1[1] = 0->Set GNT_WL_RF_Rx always = 1 for con-current Rx, mask Tx only */ - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0x2, 0x0); - - /* Set Antenna Path */ - halbtc8821c2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, - FORCE_EXEC, - BT_8821C_2ANT_PHASE_COEX_INIT); - - btcoexist->stop_coex_dm = false; - } - - -} - -#if 0 -u32 halbtc8821c2ant_psd_log2base(IN struct btc_coexist *btcoexist, IN u32 val) -{ - u8 j; - u32 tmp, tmp2, val_integerd_b = 0, tindex, shiftcount = 0; - u32 result, val_fractiond_b = 0, table_fraction[21] = {0, 432, 332, 274, 232, 200, - 174, 151, 132, 115, 100, 86, 74, 62, 51, 42, - 32, 23, 15, 7, 0 - }; - - if (val == 0) - return 0; - - tmp = val; - - while (1) { - if (tmp == 1) - break; - else { - tmp = (tmp >> 1); - shiftcount++; - } - } - - - val_integerd_b = shiftcount + 1; - - tmp2 = 1; - for (j = 1; j <= val_integerd_b; j++) - tmp2 = tmp2 * 2; - - tmp = (val * 100) / tmp2; - tindex = tmp / 5; - - if (tindex > 20) - tindex = 20; - - val_fractiond_b = table_fraction[tindex]; - - result = val_integerd_b * 100 - val_fractiond_b; - - return result; - - -} - -void halbtc8821c2ant_psd_show_antenna_detect_result(IN struct btc_coexist - *btcoexist) -{ - u8 *cli_buf = btcoexist->cli_buf; - struct btc_board_info *board_info = &btcoexist->board_info; - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n============[Antenna Detection info] ============\n"); - CL_PRINTF(cli_buf); - - if (psd_scan->ant_det_result == 12) { /* Get Ant Det from BT */ - - if (board_info->btdm_ant_num_by_ant_det == 1) - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %s (%d~%d)", - "Ant Det Result", "1-Antenna", - BT_8821C_2ANT_ANTDET_PSDTHRES_1ANT, - BT_8821C_2ANT_ANTDET_PSDTHRES_2ANT_GOODISOLATION); - else { - - if (psd_scan->ant_det_psd_scan_peak_val > - (BT_8821C_2ANT_ANTDET_PSDTHRES_2ANT_BADISOLATION) - * 100) - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %s (>%d)", - "Ant Det Result", "2-Antenna (Bad-Isolation)", - BT_8821C_2ANT_ANTDET_PSDTHRES_2ANT_BADISOLATION); - else - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %s (%d~%d)", - "Ant Det Result", "2-Antenna (Good-Isolation)", - BT_8821C_2ANT_ANTDET_PSDTHRES_2ANT_GOODISOLATION - + psd_scan->ant_det_thres_offset, - BT_8821C_2ANT_ANTDET_PSDTHRES_2ANT_BADISOLATION); - } - - } else if (psd_scan->ant_det_result == 1) - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s (>%d)", - "Ant Det Result", "2-Antenna (Bad-Isolation)", - BT_8821C_2ANT_ANTDET_PSDTHRES_2ANT_BADISOLATION); - else if (psd_scan->ant_det_result == 2) - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s (%d~%d)", - "Ant Det Result", "2-Antenna (Good-Isolation)", - BT_8821C_2ANT_ANTDET_PSDTHRES_2ANT_GOODISOLATION - + psd_scan->ant_det_thres_offset, - BT_8821C_2ANT_ANTDET_PSDTHRES_2ANT_BADISOLATION); - else - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s (%d~%d)", - "Ant Det Result", "1-Antenna", - BT_8821C_2ANT_ANTDET_PSDTHRES_1ANT, - BT_8821C_2ANT_ANTDET_PSDTHRES_2ANT_GOODISOLATION - + psd_scan->ant_det_thres_offset); - - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s ", - "Antenna Detection Finish", - (board_info->btdm_ant_det_finish - ? "Yes" : "No")); - CL_PRINTF(cli_buf); - - switch (psd_scan->ant_det_result) { - case 0: - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "(BT is not available)"); - break; - case 1: /* 2-Ant bad-isolation */ - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "(BT is available)"); - break; - case 2: /* 2-Ant good-isolation */ - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "(BT is available)"); - break; - case 3: /* 1-Ant */ - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "(BT is available)"); - break; - case 4: - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "(Uncertainty result)"); - break; - case 5: - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "(Pre-Scan fai)"); - break; - case 6: - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "(WiFi is Scanning)"); - break; - case 7: - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "(BT is not idle)"); - break; - case 8: - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "(Abort by WiFi Scanning)"); - break; - case 9: - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "(Antenna Init is not ready)"); - break; - case 10: - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "(BT is Inquiry or page)"); - break; - case 11: - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "(BT is Disabled)"); - break; - case 12: - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "(BT is available, result from BT"); - break; - } - CL_PRINTF(cli_buf); - - if (psd_scan->ant_det_result == 12) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d dB", - "PSD Scan Peak Value", - psd_scan->ant_det_psd_scan_peak_val / 100); - CL_PRINTF(cli_buf); - return; - } - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d", - "Ant Detect Total Count", psd_scan->ant_det_try_count); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d", - "Ant Detect Fail Count", psd_scan->ant_det_fail_count); - CL_PRINTF(cli_buf); - - if ((!board_info->btdm_ant_det_finish) && - (psd_scan->ant_det_result != 5)) - return; - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s", "BT Response", - (psd_scan->ant_det_result ? "ok" : "fail")); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d ms", "BT Tx Time", - psd_scan->ant_det_bt_tx_time); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d", "BT Tx Ch", - psd_scan->ant_det_bt_le_channel); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d", - "WiFi PSD Cent-Ch/Offset/Span", - psd_scan->real_cent_freq, psd_scan->real_offset, - psd_scan->real_span); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d dB", - "PSD Pre-Scan Peak Value", - psd_scan->ant_det_pre_psdscan_peak_val / 100); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s (<= %d)", - "PSD Pre-Scan result", - (psd_scan->ant_det_result != 5 ? "ok" : "fail"), - BT_8821C_2ANT_ANTDET_PSDTHRES_BACKGROUND - + psd_scan->ant_det_thres_offset); - CL_PRINTF(cli_buf); - - if (psd_scan->ant_det_result == 5) - return; - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s dB", - "PSD Scan Peak Value", psd_scan->ant_det_peak_val); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s MHz", - "PSD Scan Peak Freq", psd_scan->ant_det_peak_freq); - CL_PRINTF(cli_buf); - - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s", "TFBGA Package", - (board_info->tfbga_package) ? "Yes" : "No"); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d", - "PSD Threshold Offset", psd_scan->ant_det_thres_offset); - CL_PRINTF(cli_buf); - -} - -void halbtc8821c2ant_psd_showdata(IN struct btc_coexist *btcoexist) -{ - u8 *cli_buf = btcoexist->cli_buf; - u32 delta_freq_per_point; - u32 freq, freq1, freq2, n = 0, i = 0, j = 0, m = 0, psd_rep1, psd_rep2; - - if (psd_scan->ant_det_result == 12) - return; - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n\n============[PSD info] (%d)============\n", - psd_scan->psd_gen_count); - CL_PRINTF(cli_buf); - - if (psd_scan->psd_gen_count == 0) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n No data !!\n"); - CL_PRINTF(cli_buf); - return; - } - - if (psd_scan->psd_point == 0) - delta_freq_per_point = 0; - else - delta_freq_per_point = psd_scan->psd_band_width / - psd_scan->psd_point; - - /* if (psd_scan->is_psd_show_max_only) */ - if (0) { - psd_rep1 = psd_scan->psd_max_value / 100; - psd_rep2 = psd_scan->psd_max_value - psd_rep1 * 100; - - freq = ((psd_scan->real_cent_freq - 20) * 1000000 + - psd_scan->psd_max_value_point * delta_freq_per_point); - freq1 = freq / 1000000; - freq2 = freq / 1000 - freq1 * 1000; - - if (freq2 < 100) - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n Freq = %d.0%d MHz", - freq1, freq2); - else - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n Freq = %d.%d MHz", - freq1, freq2); - - if (psd_rep2 < 10) - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - ", Value = %d.0%d dB, (%d)\n", - psd_rep1, psd_rep2, psd_scan->psd_max_value); - else - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - ", Value = %d.%d dB, (%d)\n", - psd_rep1, psd_rep2, psd_scan->psd_max_value); - - CL_PRINTF(cli_buf); - } else { - m = psd_scan->psd_start_point; - n = psd_scan->psd_start_point; - i = 1; - j = 1; - - while (1) { - do { - freq = ((psd_scan->real_cent_freq - 20) * - 1000000 + m * - delta_freq_per_point); - freq1 = freq / 1000000; - freq2 = freq / 1000 - freq1 * 1000; - - if (i == 1) { - if (freq2 == 0) - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "\r\n Freq%6d.000", - freq1); - else if (freq2 < 100) - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "\r\n Freq%6d.0%2d", - freq1, - freq2); - else - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "\r\n Freq%6d.%3d", - freq1, - freq2); - } else if ((i % 8 == 0) || - (m == psd_scan->psd_stop_point)) { - if (freq2 == 0) - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "%6d.000\n", freq1); - else if (freq2 < 100) - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "%6d.0%2d\n", freq1, - freq2); - else - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "%6d.%3d\n", freq1, - freq2); - } else { - if (freq2 == 0) - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "%6d.000", freq1); - else if (freq2 < 100) - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "%6d.0%2d", freq1, - freq2); - else - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "%6d.%3d", freq1, - freq2); - } - - i++; - m++; - CL_PRINTF(cli_buf); - - } while ((i <= 8) && (m <= psd_scan->psd_stop_point)); - - - do { - psd_rep1 = psd_scan->psd_report_max_hold[n] / - 100; - psd_rep2 = psd_scan->psd_report_max_hold[n] - - psd_rep1 * - 100; - - if (j == 1) { - if (psd_rep2 < 10) - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "\r\n Val %7d.0%d", - psd_rep1, - psd_rep2); - else - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "\r\n Val %7d.%d", - psd_rep1, - psd_rep2); - } else if ((j % 8 == 0) || - (n == psd_scan->psd_stop_point)) { - if (psd_rep2 < 10) - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "%7d.0%d\n", psd_rep1, - psd_rep2); - else - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "%7d.%d\n", psd_rep1, - psd_rep2); - } else { - if (psd_rep2 < 10) - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "%7d.0%d", psd_rep1, - psd_rep2); - else - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "%7d.%d", psd_rep1, - psd_rep2); - } - - j++; - n++; - CL_PRINTF(cli_buf); - - } while ((j <= 8) && (n <= psd_scan->psd_stop_point)); - - if ((m > psd_scan->psd_stop_point) || - (n > psd_scan->psd_stop_point)) - break; - else { - i = 1; - j = 1; - } - - } - } - - -} - -#pragma optimize("", off) -void halbtc8821c2ant_psd_maxholddata(IN struct btc_coexist *btcoexist, - IN u32 gen_count) -{ - u32 i = 0; - u32 loop_i_max = 0, loop_val_max = 0; - - if (gen_count == 1) { - memcpy(psd_scan->psd_report_max_hold, - psd_scan->psd_report, - BT_8821C_2ANT_ANTDET_PSD_POINTS * sizeof(u32)); - } - - for (i = psd_scan->psd_start_point; - i <= psd_scan->psd_stop_point; i++) { - - /* update max-hold value at each freq point */ - if (psd_scan->psd_report[i] > psd_scan->psd_report_max_hold[i]) - psd_scan->psd_report_max_hold[i] = - psd_scan->psd_report[i]; - - /* search the max value in this seep */ - if (psd_scan->psd_report[i] > loop_val_max) { - loop_val_max = psd_scan->psd_report[i]; - loop_i_max = i; - } - } - - if (gen_count <= BT_8821C_2ANT_ANTDET_PSD_SWWEEPCOUNT) - psd_scan->psd_loop_max_value[gen_count - 1] = loop_val_max; - -} - - -#pragma optimize("", off) -u32 halbtc8821c2ant_psd_getdata(IN struct btc_coexist *btcoexist, IN u32 point) -{ - /* reg 0x808[9:0]: FFT data x */ - /* reg 0x808[22]: 0-->1 to get 1 FFT data y */ - /* reg 0x8b4[15:0]: FFT data y report */ - - u32 val = 0, psd_report = 0; - int k = 0; - - val = btcoexist->btc_read_4byte(btcoexist, 0x808); - - val &= 0xffbffc00; - val |= point; - - btcoexist->btc_write_4byte(btcoexist, 0x808, val); - - val |= 0x00400000; - btcoexist->btc_write_4byte(btcoexist, 0x808, val); - - while (1) { - if (k++ > BT_8821C_2ANT_ANTDET_SWEEPPOINT_DELAY) - break; - } - - val = btcoexist->btc_read_4byte(btcoexist, 0x8b4); - - psd_report = val & 0x0000ffff; - - return psd_report; -} - -#pragma optimize("", off) -boolean halbtc8821c2ant_psd_sweep_point(IN struct btc_coexist *btcoexist, - IN u32 cent_freq, IN s32 offset, IN u32 span, IN u32 points, - IN u32 avgnum, IN u32 loopcnt) -{ - u32 i = 0, val = 0, n = 0, k = 0, j, point_index = 0; - u32 points1 = 0, psd_report = 0; - u32 start_p = 0, stop_p = 0, delta_freq_per_point = 156250; - u32 psd_center_freq = 20 * 10 ^ 6; - boolean outloop = false, scan , roam, is_sweep_ok = true; - u8 flag = 0; - u32 tmp = 0, u32tmp1 = 0; - u32 wifi_original_channel = 1; - u32 psd_sum = 0, avg_cnt = 0; - u32 i_max = 0, val_max = 0, val_max2 = 0; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx PSD Sweep Start!!\n"); - BTC_TRACE(trace_buf); - - do { - switch (flag) { - case 0: /* Get PSD parameters */ - default: - - psd_scan->psd_band_width = 40 * 1000000; - psd_scan->psd_point = points; - psd_scan->psd_start_base = points / 2; - psd_scan->psd_avg_num = avgnum; - psd_scan->real_cent_freq = cent_freq; - psd_scan->real_offset = offset; - psd_scan->real_span = span; - - - points1 = psd_scan->psd_point; - delta_freq_per_point = psd_scan->psd_band_width / - psd_scan->psd_point; - - /* PSD point setup */ - val = btcoexist->btc_read_4byte(btcoexist, 0x808); - val &= 0xffff0fff; - - switch (psd_scan->psd_point) { - case 128: - val |= 0x0; - break; - case 256: - default: - val |= 0x00004000; - break; - case 512: - val |= 0x00008000; - break; - case 1024: - val |= 0x0000c000; - break; - } - - switch (psd_scan->psd_avg_num) { - case 1: - val |= 0x0; - break; - case 8: - val |= 0x00001000; - break; - case 16: - val |= 0x00002000; - break; - case 32: - default: - val |= 0x00003000; - break; - } - btcoexist->btc_write_4byte(btcoexist, 0x808, val); - - flag = 1; - break; - case 1: /* calculate the PSD point index from freq/offset/span */ - psd_center_freq = psd_scan->psd_band_width / 2 + - offset * (1000000); - - start_p = psd_scan->psd_start_base + (psd_center_freq - - span * (1000000) / 2) / delta_freq_per_point; - psd_scan->psd_start_point = start_p - - psd_scan->psd_start_base; - - stop_p = psd_scan->psd_start_base + (psd_center_freq + - span * (1000000) / 2) / delta_freq_per_point; - psd_scan->psd_stop_point = stop_p - - psd_scan->psd_start_base - 1; - - flag = 2; - break; - case 2: /* set RF channel/BW/Mode */ - - /* set 3-wire off */ - val = btcoexist->btc_read_4byte(btcoexist, 0x88c); - val |= 0x00300000; - btcoexist->btc_write_4byte(btcoexist, 0x88c, val); - - /* CCK off */ - val = btcoexist->btc_read_4byte(btcoexist, 0x800); - val &= 0xfeffffff; - btcoexist->btc_write_4byte(btcoexist, 0x800, val); - - /* Tx-pause on */ - btcoexist->btc_write_1byte(btcoexist, 0x522, 0x6f); - - /* store WiFi original channel */ - wifi_original_channel = btcoexist->btc_get_rf_reg( - btcoexist, BTC_RF_A, 0x18, 0x3ff); - - /* Set RF channel */ - if (cent_freq == 2484) - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, - 0x18, 0x3ff, 0xe); - else - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, - 0x18, 0x3ff, (cent_freq - 2412) / 5 + - 1); /* WiFi TRx Mask on */ - - /* save original RCK value */ - u32tmp1 = btcoexist->btc_get_rf_reg( - btcoexist, BTC_RF_A, 0x1d, 0xfffff); - - /* Enter debug mode */ - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0xde, - 0x2, 0x1); - - /* Set RF Rx filter corner */ - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1d, - 0xfffff, 0x2e); - - - /* Set RF mode = Rx, RF Gain = 0x320a0 */ - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x0, - 0xfffff, 0x320a0); - - while (1) { - if (k++ > BT_8821C_2ANT_ANTDET_SWEEPPOINT_DELAY) - break; - } - flag = 3; - break; - case 3: - psd_scan->psd_gen_count = 0; - for (j = 1; j <= loopcnt; j++) { - - btcoexist->btc_get(btcoexist, - BTC_GET_BL_WIFI_SCAN, &scan); - btcoexist->btc_get(btcoexist, - BTC_GET_BL_WIFI_ROAM, &roam); - - if (scan || roam) { - is_sweep_ok = false; - break; - } - memset(psd_scan->psd_report, 0, - psd_scan->psd_point * sizeof(u32)); - start_p = psd_scan->psd_start_point + - psd_scan->psd_start_base; - stop_p = psd_scan->psd_stop_point + - psd_scan->psd_start_base + 1; - - i = start_p; - point_index = 0; - - while (i < stop_p) { - if (i >= points1) - psd_report = - halbtc8821c2ant_psd_getdata( - btcoexist, i - points1); - else - psd_report = - halbtc8821c2ant_psd_getdata( - btcoexist, i); - - if (psd_report == 0) - tmp = 0; - else - /* tmp = 20*log10((double)psd_report); */ - /* 20*log2(x)/log2(10), log2Base return theresult of the psd_report*100 */ - tmp = 6 * halbtc8821c2ant_psd_log2base( - btcoexist, psd_report); - - n = i - psd_scan->psd_start_base; - psd_scan->psd_report[n] = tmp; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "Point=%d, psd_dB_data = %d\n", - i, psd_scan->psd_report[n]); - BTC_TRACE(trace_buf); - - i++; - - } - - halbtc8821c2ant_psd_maxholddata(btcoexist, j); - - psd_scan->psd_gen_count = j; - - /*Accumulate Max PSD value in this loop if the value > threshold */ - if (psd_scan->psd_loop_max_value[j - 1] >= - 4000) { - psd_sum = psd_sum + - psd_scan->psd_loop_max_value[j - - 1]; - avg_cnt++; - } - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "Loop=%d, Max_dB_data = %d\n", - j, psd_scan->psd_loop_max_value[j - - 1]); - BTC_TRACE(trace_buf); - - } - - if (loopcnt == BT_8821C_2ANT_ANTDET_PSD_SWWEEPCOUNT) { - - /* search the Max Value between each-freq-point-max-hold value of all sweep*/ - for (i = 1; - i <= BT_8821C_2ANT_ANTDET_PSD_SWWEEPCOUNT; - i++) { - - if (i == 1) { - i_max = i; - val_max = psd_scan->psd_loop_max_value[i - - 1]; - val_max2 = - psd_scan->psd_loop_max_value[i - - 1]; - } else if ( - psd_scan->psd_loop_max_value[i - - 1] > val_max) { - val_max2 = val_max; - i_max = i; - val_max = psd_scan->psd_loop_max_value[i - - 1]; - } else if ( - psd_scan->psd_loop_max_value[i - - 1] > val_max2) - val_max2 = - psd_scan->psd_loop_max_value[i - - 1]; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "i = %d, val_hold= %d, val_max = %d, val_max2 = %d\n", - i, psd_scan->psd_loop_max_value[i - - 1], - val_max, val_max2); - - BTC_TRACE(trace_buf); - } - - psd_scan->psd_max_value_point = i_max; - psd_scan->psd_max_value = val_max; - psd_scan->psd_max_value2 = val_max2; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "val_max = %d, val_max2 = %d\n", - psd_scan->psd_max_value, - psd_scan->psd_max_value2); - BTC_TRACE(trace_buf); - } - - if (avg_cnt != 0) { - psd_scan->psd_avg_value = (psd_sum / avg_cnt); - if ((psd_sum % avg_cnt) >= (avg_cnt / 2)) - psd_scan->psd_avg_value++; - } else - psd_scan->psd_avg_value = 0; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "AvgLoop=%d, Avg_dB_data = %d\n", - avg_cnt, psd_scan->psd_avg_value); - BTC_TRACE(trace_buf); - - flag = 100; - break; - case 99: /* error */ - - outloop = true; - break; - case 100: /* recovery */ - - /* set 3-wire on */ - val = btcoexist->btc_read_4byte(btcoexist, 0x88c); - val &= 0xffcfffff; - btcoexist->btc_write_4byte(btcoexist, 0x88c, val); - - /* CCK on */ - val = btcoexist->btc_read_4byte(btcoexist, 0x800); - val |= 0x01000000; - btcoexist->btc_write_4byte(btcoexist, 0x800, val); - - /* Tx-pause off */ - btcoexist->btc_write_1byte(btcoexist, 0x522, 0x0); - - /* PSD off */ - val = btcoexist->btc_read_4byte(btcoexist, 0x808); - val &= 0xffbfffff; - btcoexist->btc_write_4byte(btcoexist, 0x808, val); - - /* restore RF Rx filter corner */ - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1d, - 0xfffff, u32tmp1); - - /* Exit debug mode */ - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0xde, - 0x2, 0x0); - - /* restore WiFi original channel */ - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x18, - 0x3ff, wifi_original_channel); - - outloop = true; - break; - - } - - } while (!outloop); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx PSD Sweep Stop!!\n"); - BTC_TRACE(trace_buf); - return is_sweep_ok; - -} - -#pragma optimize("", off) -boolean halbtc8821c2ant_psd_antenna_detection(IN struct btc_coexist - *btcoexist) -{ - u32 i = 0; - u32 wlpsd_cent_freq = 2484, wlpsd_span = 2; - s32 wlpsd_offset = -4; - u32 bt_tx_time, bt_le_channel; - u8 bt_le_ch[13] = {3, 6, 8, 11, 13, 16, 18, 21, 23, 26, 28, 31, 33}; - - u8 h2c_parameter[3] = {0}, u8tmpa, u8tmpb; - - u8 state = 0; - boolean outloop = false, bt_resp = false, ant_det_finish = false; - u32 freq, freq1, freq2, psd_rep1, psd_rep2, delta_freq_per_point, - u32tmp, u32tmp0, u32tmp1, u32tmp2 ; - struct btc_board_info *board_info = &btcoexist->board_info; - - memset(psd_scan->ant_det_peak_val, 0, 16 * sizeof(u8)); - memset(psd_scan->ant_det_peak_freq, 0, 16 * sizeof(u8)); - - psd_scan->ant_det_bt_tx_time = - BT_8821C_2ANT_ANTDET_BTTXTIME; /* 0.42ms*50 = 20ms (0.42ms = 1 PSD sweep) */ - psd_scan->ant_det_bt_le_channel = BT_8821C_2ANT_ANTDET_BTTXCHANNEL; - - bt_tx_time = psd_scan->ant_det_bt_tx_time; - bt_le_channel = psd_scan->ant_det_bt_le_channel; - - if (board_info->tfbga_package) /* for TFBGA */ - psd_scan->ant_det_thres_offset = 5; - else - psd_scan->ant_det_thres_offset = 0; - - do { - switch (state) { - case 0: - if (bt_le_channel == 39) - wlpsd_cent_freq = 2484; - else { - for (i = 1; i <= 13; i++) { - if (bt_le_ch[i - 1] == - bt_le_channel) { - wlpsd_cent_freq = 2412 - + (i - 1) * 5; - break; - } - } - - if (i == 14) { - - BTC_SPRINTF(trace_buf, - BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Abort!!, Invalid LE channel = %d\n ", - bt_le_channel); - BTC_TRACE(trace_buf); - outloop = true; - break; - } - } -#if 0 - wlpsd_sweep_count = bt_tx_time * 238 / - 100; /* bt_tx_time/0.42 */ - wlpsd_sweep_count = wlpsd_sweep_count / 5; - - if (wlpsd_sweep_count % 5 != 0) - wlpsd_sweep_count = (wlpsd_sweep_count / - 5 + 1) * 5; -#endif - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), BT_LETxTime=%d, BT_LECh = %d\n", - bt_tx_time, bt_le_channel); - BTC_TRACE(trace_buf); - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), wlpsd_cent_freq=%d, wlpsd_offset = %d, wlpsd_span = %d, wlpsd_sweep_count = %d\n", - wlpsd_cent_freq, - wlpsd_offset, - wlpsd_span, - BT_8821C_2ANT_ANTDET_PSD_SWWEEPCOUNT); - BTC_TRACE(trace_buf); - - state = 1; - break; - case 1: /* stop coex DM & set antenna path */ - /* Stop Coex DM */ - btcoexist->stop_coex_dm = true; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Stop Coex DM!!\n"); - BTC_TRACE(trace_buf); - - /* Set TDMA off, */ - halbtc8821c2ant_ps_tdma(btcoexist, FORCE_EXEC, - false, 0); - - /* Set coex table */ - halbtc8821c2ant_coex_table_with_type(btcoexist, - FORCE_EXEC, 0); - - if (board_info->btdm_ant_pos == - BTC_ANTENNA_AT_MAIN_PORT) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Antenna at Main Port\n"); - BTC_TRACE(trace_buf); - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Antenna at Aux Port\n"); - BTC_TRACE(trace_buf); - } - - /* Set Antenna path, switch WiFi to un-certain antenna port */ - /* Set Antenna Path, both GNT_WL/GNT_BT = 1, and control by SW */ - halbtc8821c2ant_set_ant_path(btcoexist, - BTC_ANT_PATH_AUTO, FORCE_EXEC, - BT_8821C_2ANT_PHASE_ANTENNA_DET); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Set Antenna to BT!!\n"); - BTC_TRACE(trace_buf); - - /* Set AFH mask on at WiFi channel 2472MHz +/- 10MHz */ - h2c_parameter[0] = 0x1; - h2c_parameter[1] = 0xd; - h2c_parameter[2] = 0x14; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Set AFH on, Cent-Ch= %d, Mask=%d\n", - h2c_parameter[1], - h2c_parameter[2]); - BTC_TRACE(trace_buf); - - btcoexist->btc_fill_h2c(btcoexist, 0x66, 3, - h2c_parameter); - - u32tmp0 = btcoexist->btc_read_4byte(btcoexist, 0x70); - u32tmp1 = halbtc8821c2ant_ltecoex_indirect_read_reg( - btcoexist, 0x38); - u32tmp2 = halbtc8821c2ant_ltecoex_indirect_read_reg( - btcoexist, 0x54); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** 0x70 = 0x%x, 0x38= 0x%x, 0x54= 0x%x (Before Ant Det) **********\n", - u32tmp0, u32tmp1, u32tmp2); - BTC_TRACE(trace_buf); - - state = 2; - break; - case 2: /* Pre-sweep background psd */ - if (!halbtc8821c2ant_psd_sweep_point(btcoexist, - wlpsd_cent_freq, wlpsd_offset, wlpsd_span, - BT_8821C_2ANT_ANTDET_PSD_POINTS, - BT_8821C_2ANT_ANTDET_PSD_AVGNUM, 3)) { - ant_det_finish = false; - board_info->btdm_ant_num_by_ant_det = 1; - psd_scan->ant_det_result = 8; - state = 99; - break; - } - - psd_scan->ant_det_pre_psdscan_peak_val = - psd_scan->psd_max_value; - - if (psd_scan->ant_det_pre_psdscan_peak_val > - (BT_8821C_2ANT_ANTDET_PSDTHRES_BACKGROUND - + psd_scan->ant_det_thres_offset) * 100) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Abort Antenna Detection!! becaus background = %d > thres (%d)\n", - psd_scan->ant_det_pre_psdscan_peak_val / - 100, - BT_8821C_2ANT_ANTDET_PSDTHRES_BACKGROUND - + psd_scan->ant_det_thres_offset); - BTC_TRACE(trace_buf); - ant_det_finish = false; - board_info->btdm_ant_num_by_ant_det = 1; - psd_scan->ant_det_result = 5; - state = 99; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Start Antenna Detection!! becaus background = %d <= thres (%d)\n", - psd_scan->ant_det_pre_psdscan_peak_val / - 100, - BT_8821C_2ANT_ANTDET_PSDTHRES_BACKGROUND - + psd_scan->ant_det_thres_offset); - BTC_TRACE(trace_buf); - state = 3; - } - break; - case 3: - bt_resp = btcoexist->btc_set_bt_ant_detection( - btcoexist, (u8)(bt_tx_time & 0xff), - (u8)(bt_le_channel & 0xff)); - - /* Sync WL Rx PSD with BT Tx time because H2C->Mailbox delay */ - delay_ms(20); - - if (!halbtc8821c2ant_psd_sweep_point(btcoexist, - wlpsd_cent_freq, wlpsd_offset, - wlpsd_span, - BT_8821C_2ANT_ANTDET_PSD_POINTS, - BT_8821C_2ANT_ANTDET_PSD_AVGNUM, - BT_8821C_2ANT_ANTDET_PSD_SWWEEPCOUNT)) { - ant_det_finish = false; - board_info->btdm_ant_num_by_ant_det = 1; - psd_scan->ant_det_result = 8; - state = 99; - break; - } - -#if 1 - psd_scan->ant_det_psd_scan_peak_val = - psd_scan->psd_max_value; -#endif -#if 0 - psd_scan->ant_det_psd_scan_peak_val = - ((psd_scan->psd_max_value - psd_scan->psd_avg_value) < - 800) ? - psd_scan->psd_max_value : (( - psd_scan->psd_max_value - - psd_scan->psd_max_value2 <= 300) ? - psd_scan->psd_avg_value : - psd_scan->psd_max_value2); -#endif - psd_scan->ant_det_psd_scan_peak_freq = - psd_scan->psd_max_value_point; - state = 4; - break; - case 4: - - if (psd_scan->psd_point == 0) - delta_freq_per_point = 0; - else - delta_freq_per_point = - psd_scan->psd_band_width / - psd_scan->psd_point; - - psd_rep1 = psd_scan->ant_det_psd_scan_peak_val / 100; - psd_rep2 = psd_scan->ant_det_psd_scan_peak_val - - psd_rep1 * - 100; - - freq = ((psd_scan->real_cent_freq - 20) * - 1000000 + psd_scan->psd_max_value_point - * delta_freq_per_point); - freq1 = freq / 1000000; - freq2 = freq / 1000 - freq1 * 1000; - - if (freq2 < 100) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Max Value: Freq = %d.0%d MHz", - freq1, freq2); - BTC_TRACE(trace_buf); - CL_SPRINTF(psd_scan->ant_det_peak_freq, - BT_8821C_2ANT_ANTDET_BUF_LEN, - "%d.0%d", freq1, freq2); - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Max Value: Freq = %d.%d MHz", - freq1, freq2); - BTC_TRACE(trace_buf); - CL_SPRINTF(psd_scan->ant_det_peak_freq, - BT_8821C_2ANT_ANTDET_BUF_LEN, - "%d.%d", freq1, freq2); - } - - if (psd_rep2 < 10) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - ", Value = %d.0%d dB\n", - psd_rep1, psd_rep2); - BTC_TRACE(trace_buf); - CL_SPRINTF(psd_scan->ant_det_peak_val, - BT_8821C_2ANT_ANTDET_BUF_LEN, - "%d.0%d", psd_rep1, psd_rep2); - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - ", Value = %d.%d dB\n", - psd_rep1, psd_rep2); - BTC_TRACE(trace_buf); - CL_SPRINTF(psd_scan->ant_det_peak_val, - BT_8821C_2ANT_ANTDET_BUF_LEN, - "%d.%d", psd_rep1, psd_rep2); - } - - psd_scan->ant_det_is_btreply_available = true; - - if (bt_resp == false) { - psd_scan->ant_det_is_btreply_available = - false; - psd_scan->ant_det_result = 0; - ant_det_finish = false; - board_info->btdm_ant_num_by_ant_det = 1; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), BT Response = Fail\n "); - BTC_TRACE(trace_buf); - } else if (psd_scan->ant_det_psd_scan_peak_val > - (BT_8821C_2ANT_ANTDET_PSDTHRES_2ANT_BADISOLATION) - * 100) { - psd_scan->ant_det_result = 1; - ant_det_finish = true; - board_info->btdm_ant_num_by_ant_det = 2; - coex_sta->isolation_btween_wb = (u8)(85 - - psd_scan->ant_det_psd_scan_peak_val / - 100) & 0xff; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Detect Result = 2-Ant, Bad-Isolation!!\n"); - BTC_TRACE(trace_buf); - } else if (psd_scan->ant_det_psd_scan_peak_val > - (BT_8821C_2ANT_ANTDET_PSDTHRES_2ANT_GOODISOLATION - + psd_scan->ant_det_thres_offset) * 100) { - psd_scan->ant_det_result = 2; - ant_det_finish = true; - board_info->btdm_ant_num_by_ant_det = 2; - coex_sta->isolation_btween_wb = (u8)(85 - - psd_scan->ant_det_psd_scan_peak_val / - 100) & 0xff; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Detect Result = 2-Ant, Good-Isolation!!\n"); - BTC_TRACE(trace_buf); - } else if (psd_scan->ant_det_psd_scan_peak_val > - (BT_8821C_2ANT_ANTDET_PSDTHRES_1ANT) * - 100) { - psd_scan->ant_det_result = 3; - ant_det_finish = true; - board_info->btdm_ant_num_by_ant_det = 1; - coex_sta->isolation_btween_wb = (u8)(85 - - psd_scan->ant_det_psd_scan_peak_val / - 100) & 0xff; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Detect Result = 1-Ant!!\n"); - BTC_TRACE(trace_buf); - } else { - psd_scan->ant_det_result = 4; - ant_det_finish = false; - board_info->btdm_ant_num_by_ant_det = 1; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Detect Result = 1-Ant, un-certainity!!\n"); - BTC_TRACE(trace_buf); - } - - state = 99; - break; - case 99: /* restore setup */ - - /* Set AFH mask off at WiFi channel 2472MHz +/- 10MHz */ - h2c_parameter[0] = 0x0; - h2c_parameter[1] = 0x0; - h2c_parameter[2] = 0x0; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Set AFH on, Cent-Ch= %d, Mask=%d\n", - h2c_parameter[1], h2c_parameter[2]); - BTC_TRACE(trace_buf); - - btcoexist->btc_fill_h2c(btcoexist, 0x66, 3, - h2c_parameter); - - /* Set Antenna Path, GNT_WL/GNT_BT control by PTA */ - /* Set Antenna path, switch WiFi to certain antenna port */ - halbtc8821c2ant_set_ant_path(btcoexist, - BTC_ANT_PATH_AUTO, FORCE_EXEC, - BT_8821C_2ANT_PHASE_2G_RUNTIME); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Set Antenna to PTA\n!!"); - BTC_TRACE(trace_buf); - - btcoexist->stop_coex_dm = false; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Resume Coex DM\n!!"); - BTC_TRACE(trace_buf); - - outloop = true; - break; - } - - } while (!outloop); - - return ant_det_finish; - -} - -#pragma optimize("", off) -boolean halbtc8821c2ant_psd_antenna_detection_check(IN struct btc_coexist - *btcoexist) -{ - static u32 ant_det_count = 0, ant_det_fail_count = 0; - struct btc_board_info *board_info = &btcoexist->board_info; - - boolean scan, roam, ant_det_finish = false; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam); - - ant_det_count++; - - psd_scan->ant_det_try_count = ant_det_count; - - if (scan || roam) { - ant_det_finish = false; - psd_scan->ant_det_result = 6; - } else if (coex_sta->bt_disabled) { - ant_det_finish = false; - psd_scan->ant_det_result = 11; - } else if (coex_sta->num_of_profile >= 1) { - ant_det_finish = false; - psd_scan->ant_det_result = 7; - } else if ( - !psd_scan->ant_det_is_ant_det_available) { /* Antenna initial setup is not ready */ - ant_det_finish = false; - psd_scan->ant_det_result = 9; - } else if (coex_sta->c2h_bt_inquiry_page) { - ant_det_finish = false; - psd_scan->ant_det_result = 10; - } else { - - ant_det_finish = halbtc8821c2ant_psd_antenna_detection( - btcoexist); - - delay_ms(psd_scan->ant_det_bt_tx_time); - } - - - if (!ant_det_finish) - ant_det_fail_count++; - - psd_scan->ant_det_fail_count = ant_det_fail_count; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), result = %d, fail_count = %d, finish = %s\n", - psd_scan->ant_det_result, - psd_scan->ant_det_fail_count, - ant_det_finish == true ? "Yes" : "No"); - BTC_TRACE(trace_buf); - - return ant_det_finish; - -} -#endif - -/* ************************************************************ - * work around function start with wa_halbtc8821c2ant_ - * ************************************************************ - * ************************************************************ - * extern function start with ex_halbtc8821c2ant_ - * ************************************************************ */ -void ex_halbtc8821c2ant_power_on_setting(IN struct btc_coexist *btcoexist) -{ - struct btc_board_info *board_info = &btcoexist->board_info; - u8 u8tmp = 0x0; - u16 u16tmp = 0x0; - u32 value = 0; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx Execute 8821c 2-Ant PowerOn Setting xxxxxxxxxxxxxxxx!!\n"); - BTC_TRACE(trace_buf); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "Ant Det Finish = %s, Ant Det Number = %d\n", - (board_info->btdm_ant_det_finish ? "Yes" : "No"), - board_info->btdm_ant_num_by_ant_det); - BTC_TRACE(trace_buf); - - - btcoexist->stop_coex_dm = true; - psd_scan->ant_det_is_ant_det_available = false; - - /* enable BB, REG_SYS_FUNC_EN such that we can write BB Register correctly. */ - u16tmp = btcoexist->btc_read_2byte(btcoexist, 0x2); - btcoexist->btc_write_2byte(btcoexist, 0x2, u16tmp | BIT(0) | BIT(1)); - - - /* Local setting bit define */ - /* BIT0: "0" for no antenna inverse; "1" for antenna inverse */ - /* BIT1: "0" for internal switch; "1" for external switch */ - /* BIT2: "0" for one antenna; "1" for two antenna */ - /* NOTE: here default all internal switch and 1-antenna ==> BIT1=0 and BIT2=0 */ - - /* Check efuse 0xc3[6] for Single Antenna Path */ - if (board_info->single_ant_path == 0) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** Single Antenna, Antenna at Aux Port\n"); - BTC_TRACE(trace_buf); - - board_info->btdm_ant_pos = BTC_ANTENNA_AT_AUX_PORT; - - u8tmp = 7; - } else if (board_info->single_ant_path == 1) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** Single Antenna, Antenna at Main Port\n"); - BTC_TRACE(trace_buf); - - board_info->btdm_ant_pos = BTC_ANTENNA_AT_MAIN_PORT; - - u8tmp = 6; - } - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** (Power On) single_ant_path = %d, btdm_ant_pos = %d\n", - board_info->single_ant_path , board_info->btdm_ant_pos); - BTC_TRACE(trace_buf); - - /* Setup RF front end type */ - halbtc8821c2ant_set_rfe_type(btcoexist); - - /* Set Antenna Path to BT side */ - halbtc8821c2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, FORCE_EXEC, - BT_8821C_2ANT_PHASE_COEX_POWERON); - - /* Save"single antenna position" info in Local register setting for FW reading, because FW may not ready at power on */ - if (btcoexist->chip_interface == BTC_INTF_PCI) - btcoexist->btc_write_local_reg_1byte(btcoexist, 0x3e0, u8tmp); - else if (btcoexist->chip_interface == BTC_INTF_USB) - btcoexist->btc_write_local_reg_1byte(btcoexist, 0xfe08, u8tmp); - else if (btcoexist->chip_interface == BTC_INTF_SDIO) - btcoexist->btc_write_local_reg_1byte(btcoexist, 0x60, u8tmp); - - /* enable GNT_WL/GNT_BT debug signal to GPIO14/15 */ - halbtc8821c2ant_enable_gnt_to_gpio(btcoexist, true); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** LTE coex Reg 0x38 (Power-On) = 0x%x**********\n", - halbtc8821c2ant_ltecoex_indirect_read_reg(btcoexist, 0x38)); - BTC_TRACE(trace_buf); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** MAC Reg 0x70/ BB Reg 0xcb4 (Power-On) = 0x%x / 0x%x\n", - btcoexist->btc_read_4byte(btcoexist, 0x70), - btcoexist->btc_read_4byte(btcoexist, 0xcb4)); - BTC_TRACE(trace_buf); - -} - -void ex_halbtc8821c2ant_pre_load_firmware(IN struct btc_coexist *btcoexist) -{ - struct btc_board_info *board_info = &btcoexist->board_info; - u8 u8tmp = 0x4; /* Set BIT2 by default since it's 2ant case */ - - /* */ - /* S0 or S1 setting and Local register setting(By the setting fw can get ant number, S0/S1, ... info) */ - /* Local setting bit define */ - /* BIT0: "0" for no antenna inverse; "1" for antenna inverse */ - /* BIT1: "0" for internal switch; "1" for external switch */ - /* BIT2: "0" for one antenna; "1" for two antenna */ - /* NOTE: here default all internal switch and 1-antenna ==> BIT1=0 and BIT2=0 */ - if (btcoexist->chip_interface == BTC_INTF_USB) { - /* fixed at S0 for USB interface */ - u8tmp |= 0x1; /* antenna inverse */ - btcoexist->btc_write_local_reg_1byte(btcoexist, 0xfe08, u8tmp); - } else { - /* for PCIE and SDIO interface, we check efuse 0xc3[6] */ - if (board_info->single_ant_path == 0) { - } else if (board_info->single_ant_path == 1) { - /* set to S0 */ - u8tmp |= 0x1; /* antenna inverse */ - } - - if (btcoexist->chip_interface == BTC_INTF_PCI) - btcoexist->btc_write_local_reg_1byte(btcoexist, 0x3e0, - u8tmp); - else if (btcoexist->chip_interface == BTC_INTF_SDIO) - btcoexist->btc_write_local_reg_1byte(btcoexist, 0x60, - u8tmp); - } -} - - -void ex_halbtc8821c2ant_init_hw_config(IN struct btc_coexist *btcoexist, - IN boolean wifi_only) -{ - halbtc8821c2ant_init_hw_config(btcoexist, wifi_only); -} - -void ex_halbtc8821c2ant_init_coex_dm(IN struct btc_coexist *btcoexist) -{ - - halbtc8821c2ant_init_coex_dm(btcoexist); -} - -void ex_halbtc8821c2ant_display_coex_info(IN struct btc_coexist *btcoexist) -{ - struct btc_board_info *board_info = &btcoexist->board_info; - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - - u8 *cli_buf = btcoexist->cli_buf; - u8 u8tmp[4], i, ps_tdma_case = 0; - u32 u32tmp[4]; - u16 u16tmp[4]; - u32 fa_ofdm, fa_cck, cca_ofdm, cca_cck; - u32 fw_ver = 0, bt_patch_ver = 0, bt_coex_ver = 0; - static u8 pop_report_in_10s = 0; - u32 phyver = 0; - boolean lte_coex_on = false; - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n ============[BT Coexist info]============"); - CL_PRINTF(cli_buf); - - if (btcoexist->manual_control) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n ============[Under Manual Control]============"); - CL_PRINTF(cli_buf); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n =========================================="); - CL_PRINTF(cli_buf); - } - - if (psd_scan->ant_det_try_count == 0) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %d/ %d/ %s / %d", - "Ant PG Num/ Mech/ Pos/ RFE", - board_info->pg_ant_num, board_info->btdm_ant_num, - (board_info->btdm_ant_pos == BTC_ANTENNA_AT_MAIN_PORT - ? "Main" : "Aux"), - rfe_type->rfe_module_type); - CL_PRINTF(cli_buf); - } else { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %d/ %d/ %s/ %d (%d/%d/%d)", - "Ant PG Num/ Mech(Ant_Det)/ Pos/ RFE", - board_info->pg_ant_num, - board_info->btdm_ant_num_by_ant_det, - (board_info->btdm_ant_pos == BTC_ANTENNA_AT_MAIN_PORT - ? "Main" : "Aux"), - rfe_type->rfe_module_type, - psd_scan->ant_det_try_count, - psd_scan->ant_det_fail_count, - psd_scan->ant_det_result); - CL_PRINTF(cli_buf); - - - if (board_info->btdm_ant_det_finish) { - - if (psd_scan->ant_det_result != 12) - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s", - "Ant Det PSD Value", - psd_scan->ant_det_peak_val); - else - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %d", - "Ant Det PSD Value", - psd_scan->ant_det_psd_scan_peak_val - / 100); - CL_PRINTF(cli_buf); - } - } - - - bt_patch_ver = btcoexist->bt_info.bt_get_fw_ver; - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, &fw_ver); - phyver = btcoexist->btc_get_bt_phydm_version(btcoexist); - - bt_coex_ver = (coex_sta->bt_coex_supported_version & 0xff); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %d_%02x/ 0x%02x/ 0x%02x (%s)", - "CoexVer WL/ BT_Desired/ BT_Report", - glcoex_ver_date_8821c_2ant, glcoex_ver_8821c_2ant, - glcoex_ver_btdesired_8821c_2ant, - bt_coex_ver, - (bt_coex_ver == 0xff ? "Unknown" : - (bt_coex_ver >= glcoex_ver_btdesired_8821c_2ant ? - "Match" : "Mis-Match"))); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = 0x%x/ 0x%x/ v%d/ %c", - "W_FW/ B_FW/ Phy/ Kt", - fw_ver, bt_patch_ver, phyver, - coex_sta->cut_version + 65); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x ", - "AFH Map to BT", - coex_dm->wifi_chnl_info[0], coex_dm->wifi_chnl_info[1], - coex_dm->wifi_chnl_info[2]); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d / %d ", - "Isolation/WL_Thres/BT_Thres", - coex_sta->isolation_btween_wb, - coex_sta->wifi_coex_thres, - coex_sta->bt_coex_thres); - CL_PRINTF(cli_buf); - - /* wifi status */ - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s", - "============[Wifi Status]============"); - CL_PRINTF(cli_buf); - btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_WIFI_STATUS); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s", - "============[BT Status]============"); - CL_PRINTF(cli_buf); - - pop_report_in_10s++; - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = [%s/ %d dBm/ %d/ %d] ", - "BT [status/ rssi/ retryCnt/ popCnt]", - ((coex_sta->bt_disabled) ? ("disabled") : (( - coex_sta->c2h_bt_inquiry_page) ? ("inquiry/page") - : ((BT_8821C_2ANT_BT_STATUS_NON_CONNECTED_IDLE == - coex_dm->bt_status) ? "non-connected idle" : - ((BT_8821C_2ANT_BT_STATUS_CONNECTED_IDLE == coex_dm->bt_status) - ? "connected-idle" : "busy")))), - coex_sta->bt_rssi - 100, coex_sta->bt_retry_cnt, - coex_sta->pop_event_cnt); - CL_PRINTF(cli_buf); - - if (pop_report_in_10s >= 5) { - coex_sta->pop_event_cnt = 0; - pop_report_in_10s = 0; - } - - - if (coex_sta->num_of_profile != 0) - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %s%s%s%s%s", - "Profiles", - ((bt_link_info->a2dp_exist) ? "A2DP," : ""), - ((bt_link_info->sco_exist) ? "SCO," : ""), - ((bt_link_info->hid_exist) ? - ((coex_sta->hid_busy_num >= 2) ? "HID(4/18)," : - "HID(2/18),") : ""), - ((bt_link_info->pan_exist) ? "PAN," : ""), - ((coex_sta->voice_over_HOGP) ? "Voice" : "")); - else - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = None", "Profiles"); - - CL_PRINTF(cli_buf); - - - if (bt_link_info->a2dp_exist) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %s", - "A2DP Rate/Bitpool/Auto_Slot", - ((coex_sta->is_A2DP_3M) ? "3M" : "No_3M"), - coex_sta->a2dp_bit_pool, - ((coex_sta->is_autoslot) ? "On" : "Off") - ); - CL_PRINTF(cli_buf); - } - - if (bt_link_info->hid_exist) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", - "HID PairNum/Forbid_Slot", - coex_sta->hid_pair_cnt, - coex_sta->forbidden_slot - ); - CL_PRINTF(cli_buf); - } - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s / %s/ 0x%x", - "Role/IgnWlanAct/Feature", - ((bt_link_info->slave_role) ? "Slave" : "Master"), - ((coex_dm->cur_ignore_wlan_act) ? "Yes" : "No"), - coex_sta->bt_coex_supported_feature); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d/ %d", - "ReInit/ReLink/IgnWlact/Page/NameReq", - coex_sta->cnt_ReInit, - coex_sta->cnt_setupLink, - coex_sta->cnt_IgnWlanAct, - coex_sta->cnt_Page, - coex_sta->cnt_RemoteNameReq - ); - CL_PRINTF(cli_buf); - - halbtc8821c2ant_read_score_board(btcoexist, &u16tmp[0]); - - if ((coex_sta->bt_reg_vendor_ae == 0xffff) || - (coex_sta->bt_reg_vendor_ac == 0xffff)) - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = x/ x/ %04x", - "0xae[4]/0xac[1:0]/Scoreboard", u16tmp[0]); - else - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = 0x%x/ 0x%x/ %04x", - "0xae[4]/0xac[1:0]/Scoreboard", - ((coex_sta->bt_reg_vendor_ae & BIT(4)) >> 4), - coex_sta->bt_reg_vendor_ac & 0x3, u16tmp[0]); - CL_PRINTF(cli_buf); - - for (i = 0; i < BT_INFO_SRC_8821C_2ANT_MAX; i++) { - if (coex_sta->bt_info_c2h_cnt[i]) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %02x %02x %02x %02x %02x %02x %02x(%d)", - glbt_info_src_8821c_2ant[i], - coex_sta->bt_info_c2h[i][0], - coex_sta->bt_info_c2h[i][1], - coex_sta->bt_info_c2h[i][2], - coex_sta->bt_info_c2h[i][3], - coex_sta->bt_info_c2h[i][4], - coex_sta->bt_info_c2h[i][5], - coex_sta->bt_info_c2h[i][6], - coex_sta->bt_info_c2h_cnt[i]); - CL_PRINTF(cli_buf); - } - } - - /* Sw mechanism */ - if (btcoexist->manual_control) - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s", - "============[mechanism] (before Manual)============"); - else - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s", - "============[Mechanism]============"); - - CL_PRINTF(cli_buf); - - - ps_tdma_case = coex_dm->cur_ps_tdma; - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %02x %02x %02x %02x %02x (case-%d, %s, %s)", - "TDMA", - coex_dm->ps_tdma_para[0], coex_dm->ps_tdma_para[1], - coex_dm->ps_tdma_para[2], coex_dm->ps_tdma_para[3], - coex_dm->ps_tdma_para[4], ps_tdma_case, - (coex_dm->cur_ps_tdma_on ? "TDMA On" : "TDMA Off"), - (coex_dm->is_switch_to_1dot5_ant ? "1.5Ant" : "2Ant")); - CL_PRINTF(cli_buf); - - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x6c0); - u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x6c4); - u32tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0x6c8); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %d/ 0x%x/ 0x%x/ 0x%x", - "Table/0x6c0/0x6c4/0x6c8", - coex_sta->coex_table_type, u32tmp[0], u32tmp[1], u32tmp[2]); - CL_PRINTF(cli_buf); - - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x778); - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x6cc); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = 0x%x/ 0x%x", - "0x778/0x6cc", - u8tmp[0], u32tmp[0]); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s/ %s", - "AntDiv/ForceLPS/LPRA", - ((board_info->ant_div_cfg) ? "On" : "Off"), - ((coex_sta->force_lps_on) ? "On" : "Off"), - ((coex_dm->cur_low_penalty_ra) ? "On" : "Off")); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", - "WL_DACSwing/ BT_Dec_Pwr", coex_dm->cur_fw_dac_swing_lvl, - coex_dm->cur_bt_dec_pwr_lvl); - CL_PRINTF(cli_buf); - - u32tmp[0] = halbtc8821c2ant_ltecoex_indirect_read_reg(btcoexist, 0x38); - lte_coex_on = ((u32tmp[0] & BIT(7)) >> 7) ? true : false; - - if (lte_coex_on) { - - u32tmp[0] = halbtc8821c2ant_ltecoex_indirect_read_reg(btcoexist, - 0xa0); - u32tmp[1] = halbtc8821c2ant_ltecoex_indirect_read_reg(btcoexist, - 0xa4); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", - "LTE Coex Table W_L/B_L", - u32tmp[0] & 0xffff, u32tmp[1] & 0xffff); - CL_PRINTF(cli_buf); - - - u32tmp[0] = halbtc8821c2ant_ltecoex_indirect_read_reg(btcoexist, - 0xa8); - u32tmp[1] = halbtc8821c2ant_ltecoex_indirect_read_reg(btcoexist, - 0xac); - u32tmp[2] = halbtc8821c2ant_ltecoex_indirect_read_reg(btcoexist, - 0xb0); - u32tmp[3] = halbtc8821c2ant_ltecoex_indirect_read_reg(btcoexist, - 0xb4); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", - "LTE Break Table W_L/B_L/L_W/L_B", - u32tmp[0] & 0xffff, u32tmp[1] & 0xffff, - u32tmp[2] & 0xffff, u32tmp[3] & 0xffff); - CL_PRINTF(cli_buf); - - } - - /* Hw setting */ - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s", - "============[Hw setting]============"); - CL_PRINTF(cli_buf); - /* - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x430); - u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x434); - u16tmp[0] = btcoexist->btc_read_2byte(btcoexist, 0x42a); - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x456); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/0x%x/0x%x/0x%x", - "0x430/0x434/0x42a/0x456", - u32tmp[0], u32tmp[1], u16tmp[0], u8tmp[0]); - CL_PRINTF(cli_buf); - */ - u32tmp[0] = halbtc8821c2ant_ltecoex_indirect_read_reg(btcoexist, 0x38); - u32tmp[1] = halbtc8821c2ant_ltecoex_indirect_read_reg(btcoexist, 0x54); - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x73); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s", - "LTE Coex/Path Owner", - ((lte_coex_on) ? "On" : "Off") , - ((u8tmp[0] & BIT(2)) ? "WL" : "BT")); - CL_PRINTF(cli_buf); - - if (lte_coex_on) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d", - "LTE 3Wire/OPMode/UART/UARTMode", - (int)((u32tmp[0] & BIT(6)) >> 6), - (int)((u32tmp[0] & (BIT(5) | BIT(4))) >> 4), - (int)((u32tmp[0] & BIT(3)) >> 3), - (int)(u32tmp[0] & (BIT(2) | BIT(1) | BIT(0)))); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", - "LTE_Busy/UART_Busy", - (int)((u32tmp[1] & BIT(1)) >> 1), (int)(u32tmp[1] & BIT(0))); - CL_PRINTF(cli_buf); - } - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %s (BB:%s)/ %s (BB:%s)/ %s", - "GNT_WL_Ctrl/GNT_BT_Ctrl/Dbg", - ((u32tmp[0] & BIT(12)) ? "SW" : "HW"), - ((u32tmp[0] & BIT(8)) ? "SW" : "HW"), - ((u32tmp[0] & BIT(14)) ? "SW" : "HW"), - ((u32tmp[0] & BIT(10)) ? "SW" : "HW"), - ((u8tmp[0] & BIT(3)) ? "On" : "Off")); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", - "GNT_WL/GNT_BT", - (int)((u32tmp[1] & BIT(2)) >> 2), - (int)((u32tmp[1] & BIT(3)) >> 3)); - CL_PRINTF(cli_buf); - - - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xcb0); - u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0xcb4); - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0xcba); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = 0x%04x/ 0x%04x/ 0x%02x %s", - "0xcb0/0xcb4/0xcb8[23:16]", - u32tmp[0], u32tmp[1], u8tmp[0], - ((u8tmp[0] & 0x1) == 0x1 ? "(BTG)" : "(WL_A+G)")); - CL_PRINTF(cli_buf); - - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x4c); - u8tmp[2] = btcoexist->btc_read_1byte(btcoexist, 0x64); - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x4c6); - u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0x40); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", - "0x4c[24:23]/0x64[0]/x4c6[4]/0x40[5]", - (u32tmp[0] & (BIT(24) | BIT(23))) >> 23 , u8tmp[2] & 0x1 , - (int)((u8tmp[0] & BIT(4)) >> 4), - (int)((u8tmp[1] & BIT(5)) >> 5)); - CL_PRINTF(cli_buf); - - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x550); - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x522); - u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0x953); - u8tmp[2] = btcoexist->btc_read_1byte(btcoexist, 0xc50); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = 0x%x/ 0x%x/ %s/ 0x%x", - "0x550/0x522/4-RxAGC/0xc50", - u32tmp[0], u8tmp[0], (u8tmp[1] & 0x2) ? "On" : "Off", u8tmp[2]); - CL_PRINTF(cli_buf); - - fa_ofdm = btcoexist->btc_phydm_query_PHY_counter(btcoexist, - PHYDM_INFO_FA_OFDM); - fa_cck = btcoexist->btc_phydm_query_PHY_counter(btcoexist, - PHYDM_INFO_FA_CCK); - cca_ofdm = btcoexist->btc_phydm_query_PHY_counter(btcoexist, - PHYDM_INFO_CCA_OFDM); - cca_cck = btcoexist->btc_phydm_query_PHY_counter(btcoexist, - PHYDM_INFO_CCA_CCK); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", - "CCK-CCA/CCK-FA/OFDM-CCA/OFDM-FA", - cca_cck, fa_cck, cca_ofdm, fa_ofdm); - CL_PRINTF(cli_buf); - -#if 1 - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d", - "CRC_OK CCK/11g/11n/11ac", - coex_sta->crc_ok_cck, coex_sta->crc_ok_11g, - coex_sta->crc_ok_11n, coex_sta->crc_ok_11n_vht); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d", - "CRC_Err CCK/11g/11n/11ac", - coex_sta->crc_err_cck, coex_sta->crc_err_11g, - coex_sta->crc_err_11n, coex_sta->crc_err_11n_vht); - CL_PRINTF(cli_buf); -#endif - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", - "0x770(Hi-pri rx/tx)", - coex_sta->high_priority_rx, coex_sta->high_priority_tx); - CL_PRINTF(cli_buf); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", - "0x774(Lo-pri rx/tx)", - coex_sta->low_priority_rx, coex_sta->low_priority_tx); - CL_PRINTF(cli_buf); - - btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_COEX_STATISTICS); -} - - -void ex_halbtc8821c2ant_ips_notify(IN struct btc_coexist *btcoexist, IN u8 type) -{ - if (btcoexist->manual_control || btcoexist->stop_coex_dm) - return; - - if (BTC_IPS_ENTER == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], IPS ENTER notify\n"); - BTC_TRACE(trace_buf); - coex_sta->under_ips = true; - coex_sta->under_lps = false; - - halbtc8821c2ant_post_state_to_bt(btcoexist, - BT_8821C_2ANT_SCOREBOARD_ACTIVE, false); - - halbtc8821c2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, - FORCE_EXEC, - BT_8821C_2ANT_PHASE_WLAN_OFF); - - halbtc8821c2ant_action_coex_all_off(btcoexist); - } else if (BTC_IPS_LEAVE == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], IPS LEAVE notify\n"); - BTC_TRACE(trace_buf); - coex_sta->under_ips = false; - - halbtc8821c2ant_post_state_to_bt(btcoexist, - BT_8821C_2ANT_SCOREBOARD_ACTIVE, true); - halbtc8821c2ant_init_hw_config(btcoexist, false); - halbtc8821c2ant_init_coex_dm(btcoexist); - halbtc8821c2ant_query_bt_info(btcoexist); - } -} - -void ex_halbtc8821c2ant_lps_notify(IN struct btc_coexist *btcoexist, IN u8 type) -{ - if (btcoexist->manual_control || btcoexist->stop_coex_dm) - return; - - if (BTC_LPS_ENABLE == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], LPS ENABLE notify\n"); - BTC_TRACE(trace_buf); - coex_sta->under_lps = true; - coex_sta->under_ips = false; - - if (coex_sta->force_lps_on == true) { /* LPS No-32K */ - /* Write WL "Active" in Score-board for PS-TDMA */ - halbtc8821c2ant_post_state_to_bt(btcoexist, - BT_8821C_2ANT_SCOREBOARD_ACTIVE, true); - - } else { /* LPS-32K, need check if this h2c 0x71 can work?? (2015/08/28) */ - /* Write WL "Non-Active" in Score-board for Native-PS */ - halbtc8821c2ant_post_state_to_bt(btcoexist, - BT_8821C_2ANT_SCOREBOARD_ACTIVE, false); - } - - - } else if (BTC_LPS_DISABLE == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], LPS DISABLE notify\n"); - BTC_TRACE(trace_buf); - coex_sta->under_lps = false; - - halbtc8821c2ant_post_state_to_bt(btcoexist, - BT_8821C_2ANT_SCOREBOARD_ACTIVE, true); - } -} - -void ex_halbtc8821c2ant_scan_notify(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - boolean wifi_connected = false; - boolean wifi_under_5g = false; - - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCAN notify()\n"); - BTC_TRACE(trace_buf); - - halbtc8821c2ant_post_state_to_bt(btcoexist, - BT_8821C_2ANT_SCOREBOARD_ACTIVE, true); - - if (btcoexist->manual_control || - btcoexist->stop_coex_dm) - return; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - - /* this can't be removed for RF off_on event, or BT would dis-connect */ - halbtc8821c2ant_query_bt_info(btcoexist); - - if (BTC_SCAN_START == type) { - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, - &wifi_under_5g); - - if (wifi_under_5g) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** SCAN START notify (5g)\n"); - BTC_TRACE(trace_buf); - - halbtc8821c2ant_action_wifi_under5g(btcoexist); - return; - } - - coex_sta->wifi_is_high_pri_task = true; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** SCAN START notify (2g)\n"); - BTC_TRACE(trace_buf); - - halbtc8821c2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, - FORCE_EXEC, - BT_8821C_2ANT_PHASE_2G_RUNTIME); - - halbtc8821c2ant_run_coexist_mechanism( - btcoexist); - - return; - } - - - if (BTC_SCAN_START_2G == type) { - - if (!wifi_connected) - coex_sta->wifi_is_high_pri_task = true; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCAN START notify (2G)\n"); - BTC_TRACE(trace_buf); - - halbtc8821c2ant_post_state_to_bt(btcoexist, - BT_8821C_2ANT_SCOREBOARD_SCAN, true); - halbtc8821c2ant_post_state_to_bt(btcoexist, - BT_8821C_2ANT_SCOREBOARD_ACTIVE, true); - - halbtc8821c2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, - FORCE_EXEC, - BT_8821C_2ANT_PHASE_2G_RUNTIME); - - halbtc8821c2ant_run_coexist_mechanism(btcoexist); - - } else if (BTC_SCAN_FINISH == type) { - - coex_sta->wifi_is_high_pri_task = false; - - btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM, - &coex_sta->scan_ap_num); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCAN FINISH notify (Scan-AP = %d)\n", - coex_sta->scan_ap_num); - BTC_TRACE(trace_buf); - - halbtc8821c2ant_post_state_to_bt(btcoexist, - BT_8821C_2ANT_SCOREBOARD_SCAN, false); - - halbtc8821c2ant_run_coexist_mechanism(btcoexist); - } - -} - -void ex_halbtc8821c2ant_switchband_notify(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - - boolean wifi_connected = false, bt_hs_on = false; - u32 wifi_link_status = 0; - u32 num_of_wifi_link = 0; - boolean bt_ctrl_agg_buf_size = false; - u8 agg_buf_size = 5; - - - if (btcoexist->manual_control || - btcoexist->stop_coex_dm) - return; - - if (type == BTC_SWITCH_TO_5G) { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], switchband_notify --- switch to 5G\n"); - BTC_TRACE(trace_buf); - - halbtc8821c2ant_action_wifi_under5g(btcoexist); - - } else if (type == BTC_SWITCH_TO_24G_NOFORSCAN) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** switchband_notify BTC_SWITCH_TO_2G (no for scan)\n"); - BTC_TRACE(trace_buf); - - halbtc8821c2ant_run_coexist_mechanism(btcoexist); - - } else { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], switchband_notify --- switch to 2G\n"); - BTC_TRACE(trace_buf); - - ex_halbtc8821c2ant_scan_notify(btcoexist, - BTC_SCAN_START_2G); - } -} - - -void ex_halbtc8821c2ant_connect_notify(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - - halbtc8821c2ant_post_state_to_bt(btcoexist, - BT_8821C_2ANT_SCOREBOARD_ACTIVE, true); - if (btcoexist->manual_control || - btcoexist->stop_coex_dm) - return; - - if ((BTC_ASSOCIATE_5G_START == type) || - (BTC_ASSOCIATE_5G_FINISH == type)) { - - if (BTC_ASSOCIATE_5G_START == type) - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], connect_notify --- 5G start\n"); - else - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], connect_notify --- 5G finish\n"); - - BTC_TRACE(trace_buf); - - halbtc8821c2ant_action_wifi_under5g(btcoexist); - return; - } - - - if (BTC_ASSOCIATE_START == type) { - - coex_sta->wifi_is_high_pri_task = true; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], CONNECT START notify (2G)\n"); - BTC_TRACE(trace_buf); - - halbtc8821c2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, - FORCE_EXEC, - BT_8821C_2ANT_PHASE_2G_RUNTIME); - - halbtc8821c2ant_action_wifi_link_process(btcoexist); - - /* To keep TDMA case during connect process, - to avoid changed by Btinfo and runcoexmechanism */ - coex_sta->freeze_coexrun_by_btinfo = true; - - coex_dm->arp_cnt = 0; - - } else if (BTC_ASSOCIATE_FINISH == type) { - - coex_sta->wifi_is_high_pri_task = false; - coex_sta->freeze_coexrun_by_btinfo = false; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], CONNECT FINISH notify (2G)\n"); - BTC_TRACE(trace_buf); - - halbtc8821c2ant_run_coexist_mechanism(btcoexist); - } -} - -void ex_halbtc8821c2ant_media_status_notify(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - u8 h2c_parameter[3] = {0}; - u32 wifi_bw; - u8 wifi_central_chnl; - u8 ap_num = 0; - boolean wifi_under_b_mode = false, wifi_under_5g = false; - - - if (btcoexist->manual_control || - btcoexist->stop_coex_dm) - return; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g); - - if (BTC_MEDIA_CONNECT == type) { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], MEDIA connect notify\n"); - BTC_TRACE(trace_buf); - - halbtc8821c2ant_post_state_to_bt(btcoexist, - BT_8821C_2ANT_SCOREBOARD_ACTIVE, true); - - if (wifi_under_5g) { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], WiFi is under 5G!!!\n"); - BTC_TRACE(trace_buf); - - halbtc8821c2ant_action_wifi_under5g(btcoexist); - return; - } - - halbtc8821c2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, - FORCE_EXEC, - BT_8821C_2ANT_PHASE_2G_RUNTIME); - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_B_MODE, - &wifi_under_b_mode); - - /* Set CCK Tx/Rx high Pri except 11b mode */ - if (wifi_under_b_mode) { - btcoexist->btc_write_1byte(btcoexist, 0x6cd, - 0x00); /* CCK Tx */ - btcoexist->btc_write_1byte(btcoexist, 0x6cf, - 0x00); /* CCK Rx */ - } else { - - btcoexist->btc_write_1byte(btcoexist, 0x6cd, - 0x00); /* CCK Tx */ - btcoexist->btc_write_1byte(btcoexist, 0x6cf, - 0x10); /* CCK Rx */ - } - - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], MEDIA disconnect notify\n"); - BTC_TRACE(trace_buf); - - btcoexist->btc_write_1byte(btcoexist, 0x6cd, 0x0); /* CCK Tx */ - btcoexist->btc_write_1byte(btcoexist, 0x6cf, 0x0); /* CCK Rx */ - - halbtc8821c2ant_post_state_to_bt(btcoexist, - BT_8821C_2ANT_SCOREBOARD_ACTIVE, false); - } - - - halbtc8821c2ant_update_wifi_channel_info(btcoexist, type); -} - -void ex_halbtc8821c2ant_specific_packet_notify(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - boolean under_4way = false, wifi_under_5g = false; - - if (btcoexist->manual_control || - btcoexist->stop_coex_dm) - return; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g); - - if (wifi_under_5g) { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], WiFi is under 5G!!!\n"); - BTC_TRACE(trace_buf); - - halbtc8821c2ant_action_wifi_under5g(btcoexist); - return; - } - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS, - &under_4way); - - if (under_4way) { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], specific Packet ---- under_4way!!\n"); - BTC_TRACE(trace_buf); - - coex_sta->wifi_is_high_pri_task = true; - coex_sta->specific_pkt_period_cnt = 2; - - } else if (BTC_PACKET_ARP == type) { - - coex_dm->arp_cnt++; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], specific Packet ARP notify -cnt = %d\n", - coex_dm->arp_cnt); - BTC_TRACE(trace_buf); - - } else { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], specific Packet DHCP or EAPOL notify [Type = %d]\n", - type); - BTC_TRACE(trace_buf); - - coex_sta->wifi_is_high_pri_task = true; - coex_sta->specific_pkt_period_cnt = 2; - } - - if (coex_sta->wifi_is_high_pri_task) - halbtc8821c2ant_run_coexist_mechanism(btcoexist); - -} - -void ex_halbtc8821c2ant_bt_info_notify(IN struct btc_coexist *btcoexist, - IN u8 *tmp_buf, IN u8 length) -{ - u8 i, rsp_source = 0; - boolean wifi_connected = false; - - if (psd_scan->is_AntDet_running == true) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], bt_info_notify return for AntDet is running\n"); - BTC_TRACE(trace_buf); - return; - } - - rsp_source = tmp_buf[0] & 0xf; - if (rsp_source >= BT_INFO_SRC_8821C_2ANT_MAX) - rsp_source = BT_INFO_SRC_8821C_2ANT_WIFI_FW; - coex_sta->bt_info_c2h_cnt[rsp_source]++; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Bt_info[%d], len=%d, data=[", rsp_source, - length); - BTC_TRACE(trace_buf); - - for (i = 0; i < length; i++) { - coex_sta->bt_info_c2h[rsp_source][i] = tmp_buf[i]; - - if (i == length - 1) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "0x%02x]\n", - tmp_buf[i]); - BTC_TRACE(trace_buf); - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "0x%02x, ", - tmp_buf[i]); - BTC_TRACE(trace_buf); - } - } - - coex_sta->bt_info = coex_sta->bt_info_c2h[rsp_source][1]; - coex_sta->bt_info_ext = coex_sta->bt_info_c2h[rsp_source][4]; - coex_sta->bt_info_ext2 = coex_sta->bt_info_c2h[rsp_source][5]; - - if (BT_INFO_SRC_8821C_2ANT_WIFI_FW != rsp_source) { - - /* if 0xff, it means BT is under WHCK test */ - coex_sta->bt_whck_test = ((coex_sta->bt_info == 0xff) ? true : - false); - - coex_sta->bt_create_connection = (( - coex_sta->bt_info_c2h[rsp_source][2] & 0x80) ? true : - false); - - /* unit: %, value-100 to translate to unit: dBm */ - coex_sta->bt_rssi = coex_sta->bt_info_c2h[rsp_source][3] * 2 + - 10; - - coex_sta->c2h_bt_remote_name_req = (( - coex_sta->bt_info_c2h[rsp_source][2] & 0x20) ? true : - false); - - coex_sta->is_A2DP_3M = ((coex_sta->bt_info_c2h[rsp_source][2] & - 0x10) ? true : false); - - coex_sta->acl_busy = ((coex_sta->bt_info_c2h[rsp_source][1] & - 0x9) ? true : false); - - coex_sta->voice_over_HOGP = ((coex_sta->bt_info_ext & 0x10) ? - true : false); - - coex_sta->c2h_bt_inquiry_page = ((coex_sta->bt_info & - BT_INFO_8821C_2ANT_B_INQ_PAGE) ? true : false); - - coex_sta->a2dp_bit_pool = ((( - coex_sta->bt_info_c2h[rsp_source][1] & 0x49) == 0x49) ? - coex_sta->bt_info_c2h[rsp_source][6] : 0); - - coex_sta->bt_retry_cnt = coex_sta->bt_info_c2h[rsp_source][2] & - 0xf; - - coex_sta->is_autoslot = coex_sta->bt_info_ext2 & 0x8; - - coex_sta->forbidden_slot = coex_sta->bt_info_ext2 & 0x7; - - coex_sta->hid_busy_num = (coex_sta->bt_info_ext2 & 0x30) >> 4; - - coex_sta->hid_pair_cnt = (coex_sta->bt_info_ext2 & 0xc0) >> 6; - - if (coex_sta->bt_retry_cnt >= 1) - coex_sta->pop_event_cnt++; - - if (coex_sta->c2h_bt_remote_name_req) - coex_sta->cnt_RemoteNameReq++; - - if (coex_sta->bt_info_ext & BIT(1)) - coex_sta->cnt_ReInit++; - - if (coex_sta->bt_info_ext & BIT(2)) { - coex_sta->cnt_setupLink++; - coex_sta->is_setupLink = true; - } else - coex_sta->is_setupLink = false; - - if (coex_sta->bt_info_ext & BIT(3)) - coex_sta->cnt_IgnWlanAct++; - - if (coex_sta->bt_create_connection) - coex_sta->cnt_Page++; - - /* Here we need to resend some wifi info to BT */ - /* because bt is reset and loss of the info. */ - - if ((!btcoexist->manual_control) && - (!btcoexist->stop_coex_dm)) { - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - - /* Re-Init */ - if ((coex_sta->bt_info_ext & BIT(1))) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT ext info bit1 check, send wifi BW&Chnl to BT!!\n"); - BTC_TRACE(trace_buf); - if (wifi_connected) - halbtc8821c2ant_update_wifi_channel_info( - btcoexist, BTC_MEDIA_CONNECT); - else - halbtc8821c2ant_update_wifi_channel_info( - btcoexist, - BTC_MEDIA_DISCONNECT); - } - - - /* If Ignore_WLanAct && not SetUp_Link */ - if ((coex_sta->bt_info_ext & BIT(3)) && - (!(coex_sta->bt_info_ext & BIT(2)))) { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT ext info bit3 check, set BT NOT to ignore Wlan active!!\n"); - BTC_TRACE(trace_buf); - halbtc8821c2ant_ignore_wlan_act(btcoexist, - FORCE_EXEC, false); - } - } - - } - - - halbtc8821c2ant_update_bt_link_info(btcoexist); - - if (btcoexist->manual_control) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), No run_coexist_mechanism for Manual CTRL\n"); - BTC_TRACE(trace_buf); - return; - } - - if (btcoexist->stop_coex_dm) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), No run_coexist_mechanism for Stop Coex DM\n"); - BTC_TRACE(trace_buf); - return; - } - - coex_sta->c2h_bt_info_req_sent = false; - - halbtc8821c2ant_run_coexist_mechanism(btcoexist); -} - -void ex_halbtc8821c2ant_rf_status_notify(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], RF Status notify\n"); - BTC_TRACE(trace_buf); - - if (BTC_RF_ON == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], RF is turned ON!!\n"); - BTC_TRACE(trace_buf); - - coex_sta->wl_rf_off_on_event = true; - btcoexist->stop_coex_dm = false; - - halbtc8821c2ant_post_state_to_bt(btcoexist, - BT_8821C_2ANT_SCOREBOARD_ACTIVE, true); - halbtc8821c2ant_post_state_to_bt(btcoexist, - BT_8821C_2ANT_SCOREBOARD_ONOFF, true); - } else if (BTC_RF_OFF == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], RF is turned OFF!!\n"); - BTC_TRACE(trace_buf); - - halbtc8821c2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, - FORCE_EXEC, - BT_8821C_2ANT_PHASE_WLAN_OFF); - - halbtc8821c2ant_action_coex_all_off(btcoexist); - - halbtc8821c2ant_post_state_to_bt(btcoexist, - BT_8821C_2ANT_SCOREBOARD_ACTIVE, false); - halbtc8821c2ant_post_state_to_bt(btcoexist, - BT_8821C_2ANT_SCOREBOARD_ONOFF, false); - btcoexist->stop_coex_dm = true; - coex_sta->wl_rf_off_on_event = false; - - } -} - -void ex_halbtc8821c2ant_halt_notify(IN struct btc_coexist *btcoexist) -{ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], Halt notify\n"); - BTC_TRACE(trace_buf); - - halbtc8821c2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, FORCE_EXEC, - BT_8821C_2ANT_PHASE_WLAN_OFF); - - ex_halbtc8821c2ant_media_status_notify(btcoexist, BTC_MEDIA_DISCONNECT); - - halbtc8821c2ant_post_state_to_bt(btcoexist, - BT_8821C_2ANT_SCOREBOARD_ACTIVE, false); - halbtc8821c2ant_post_state_to_bt(btcoexist, - BT_8821C_2ANT_SCOREBOARD_ONOFF, false); -} - -void ex_halbtc8821c2ant_pnp_notify(IN struct btc_coexist *btcoexist, - IN u8 pnp_state) -{ - boolean wifi_under_5g = false; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], Pnp notify\n"); - BTC_TRACE(trace_buf); - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g); - - if ((BTC_WIFI_PNP_SLEEP == pnp_state) || - (BTC_WIFI_PNP_SLEEP_KEEP_ANT == pnp_state)) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Pnp notify to SLEEP\n"); - BTC_TRACE(trace_buf); - - /* Sinda 20150819, workaround for driver skip leave IPS/LPS to speed up sleep time. */ - /* Driver do not leave IPS/LPS when driver is going to sleep, so BTCoexistence think wifi is still under IPS/LPS */ - /* BT should clear UnderIPS/UnderLPS state to avoid mismatch state after wakeup. */ - coex_sta->under_ips = false; - coex_sta->under_lps = false; - - halbtc8821c2ant_post_state_to_bt(btcoexist, - BT_8821C_2ANT_SCOREBOARD_ACTIVE, false); - halbtc8821c2ant_post_state_to_bt(btcoexist, - BT_8821C_2ANT_SCOREBOARD_ONOFF, false); - - - if (BTC_WIFI_PNP_SLEEP_KEEP_ANT == pnp_state) { - - if (wifi_under_5g) - halbtc8821c2ant_set_ant_path(btcoexist, - BTC_ANT_PATH_AUTO, FORCE_EXEC, - BT_8821C_2ANT_PHASE_5G_RUNTIME); - else - halbtc8821c2ant_set_ant_path(btcoexist, - BTC_ANT_PATH_AUTO, FORCE_EXEC, - BT_8821C_2ANT_PHASE_2G_RUNTIME); - } else { - - halbtc8821c2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, - FORCE_EXEC, - BT_8821C_2ANT_PHASE_WLAN_OFF); - } - } else if (BTC_WIFI_PNP_WAKE_UP == pnp_state) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Pnp notify to WAKE UP\n"); - BTC_TRACE(trace_buf); - - halbtc8821c2ant_post_state_to_bt(btcoexist, - BT_8821C_2ANT_SCOREBOARD_ACTIVE, true); - halbtc8821c2ant_post_state_to_bt(btcoexist, - BT_8821C_2ANT_SCOREBOARD_ONOFF, true); - } -} - -void ex_halbtc8821c2ant_periodical(IN struct btc_coexist *btcoexist) -{ - struct btc_board_info *board_info = &btcoexist->board_info; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ************* Periodical *************\n"); - BTC_TRACE(trace_buf); - -#if (BT_AUTO_REPORT_ONLY_8821C_2ANT == 0) - halbtc8821c2ant_query_bt_info(btcoexist); -#endif - - halbtc8821c2ant_monitor_bt_ctr(btcoexist); - halbtc8821c2ant_monitor_wifi_ctr(btcoexist); - halbtc8821c2ant_monitor_bt_enable_disable(btcoexist); - - /* for 4-way, DHCP, EAPOL packet */ - if (coex_sta->specific_pkt_period_cnt > 0) { - - coex_sta->specific_pkt_period_cnt--; - - if ((coex_sta->specific_pkt_period_cnt == 0) && - (coex_sta->wifi_is_high_pri_task)) - coex_sta->wifi_is_high_pri_task = false; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ***************** Hi-Pri Task = %s*****************\n", - (coex_sta->wifi_is_high_pri_task ? "Yes" : - "No")); - BTC_TRACE(trace_buf); - - } - - if (!coex_sta->bt_disabled) { - if (coex_sta->bt_coex_supported_feature == 0) - coex_sta->bt_coex_supported_feature = - btcoexist->btc_get_bt_coex_supported_feature( - btcoexist); - - if ((coex_sta->bt_coex_supported_version == 0) || - (coex_sta->bt_coex_supported_version == 0xffff)) - coex_sta->bt_coex_supported_version = - btcoexist->btc_get_bt_coex_supported_version( - btcoexist); - - /*coex_sta->bt_ble_scan_type = btcoexist->btc_get_ble_scan_type_from_bt(btcoexist);*/ - - if (coex_sta->bt_reg_vendor_ac == 0xffff) - coex_sta->bt_reg_vendor_ac = (u16)( - btcoexist->btc_get_bt_reg(btcoexist, 3, - 0xac) & 0xffff); - - if (coex_sta->bt_reg_vendor_ae == 0xffff) - coex_sta->bt_reg_vendor_ae = (u16)( - btcoexist->btc_get_bt_reg(btcoexist, 3, - 0xae) & 0xffff); - -#if BT_8821C_2ANT_ANTDET_ENABLE - - if (board_info->btdm_ant_det_finish) { - if ((psd_scan->ant_det_result == 12) && - (psd_scan->ant_det_psd_scan_peak_val == 0) - && (!psd_scan->is_AntDet_running)) - psd_scan->ant_det_psd_scan_peak_val = - btcoexist->btc_get_ant_det_val_from_bt( - btcoexist) * 100; - } - -#endif - } - - - if (halbtc8821c2ant_is_wifibt_status_changed(btcoexist)) - halbtc8821c2ant_run_coexist_mechanism(btcoexist); -} - - -/*#pragma optimize( "", off )*/ -void ex_halbtc8821c2ant_antenna_detection(IN struct btc_coexist *btcoexist, - IN u32 cent_freq, IN u32 offset, IN u32 span, IN u32 seconds) -{ -#if 0 - static u32 ant_det_count = 0, ant_det_fail_count = 0; - struct btc_board_info *board_info = &btcoexist->board_info; - u16 u16tmp; - u8 AntDetval = 0; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx Ext Call AntennaDetect()!!\n"); - BTC_TRACE(trace_buf); - -#if BT_8821C_2ANT_ANTDET_ENABLE - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx Call AntennaDetect()!!\n"); - BTC_TRACE(trace_buf); - - if (seconds == 0) { - psd_scan->ant_det_try_count = 0; - psd_scan->ant_det_fail_count = 0; - ant_det_count = 0; - ant_det_fail_count = 0; - board_info->btdm_ant_det_finish = false; - board_info->btdm_ant_num_by_ant_det = 1; - return; - } - - if (!board_info->btdm_ant_det_finish) { - psd_scan->ant_det_inteval_count = - psd_scan->ant_det_inteval_count + 2; - - if (psd_scan->ant_det_inteval_count >= - BT_8821C_2ANT_ANTDET_RETRY_INTERVAL) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Antenna Det Timer is up, Try Detect!!\n"); - BTC_TRACE(trace_buf); - - psd_scan->is_AntDet_running = true; - - halbtc8821c2ant_read_score_board(btcoexist, &u16tmp); - - if (u16tmp & BIT( - 2)) { /* Antenna detection is already done before last WL power on */ - board_info->btdm_ant_det_finish = true; - psd_scan->ant_det_try_count = 1; - psd_scan->ant_det_fail_count = 0; - board_info->btdm_ant_num_by_ant_det = (u16tmp & - BIT(3)) ? 1 : 2; - psd_scan->ant_det_result = 12; - - psd_scan->ant_det_psd_scan_peak_val = - btcoexist->btc_get_ant_det_val_from_bt( - btcoexist) * 100; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Antenna Det Result from BT (%d-Ant)\n", - board_info->btdm_ant_num_by_ant_det); - BTC_TRACE(trace_buf); - } else - board_info->btdm_ant_det_finish = - halbtc8821c2ant_psd_antenna_detection_check( - btcoexist); - - btcoexist->bdontenterLPS = false; - - if (board_info->btdm_ant_det_finish) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Antenna Det Success!!\n"); - BTC_TRACE(trace_buf); - - /*for 8821c, btc_set_bt_trx_mask is just used to - notify BT stop le tx and Ant Det Result , not set BT RF TRx Mask */ - if (psd_scan->ant_det_result != 12) { - - AntDetval = (u8)(( - psd_scan->ant_det_psd_scan_peak_val - / 100) & 0x7f); - - AntDetval = - (board_info->btdm_ant_num_by_ant_det - == 1) ? (AntDetval | 0x80) : - AntDetval; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxx AntennaDetect(), Ant Count = %d, PSD Val = %d\n", - ((AntDetval & - 0x80) ? 1 - : 2), AntDetval - & 0x7f); - BTC_TRACE(trace_buf); - - if (btcoexist->btc_set_bt_trx_mask( - btcoexist, AntDetval)) - BTC_SPRINTF(trace_buf, - BT_TMP_BUF_SIZE, - "xxxxxx AntennaDetect(), Notify BT stop le tx by set_bt_trx_mask ok!\n"); - else - BTC_SPRINTF(trace_buf, - BT_TMP_BUF_SIZE, - "xxxxxx AntennaDetect(), Notify BT stop le tx by set_bt_trx_mask fail!\n"); - - BTC_TRACE(trace_buf); - } - - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Antenna Det Fail!!\n"); - BTC_TRACE(trace_buf); - } - - psd_scan->ant_det_inteval_count = 0; - psd_scan->is_AntDet_running = false; - - /* stimulate coex running */ - halbtc8821c2ant_run_coexist_mechanism( - btcoexist); - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Stimulate Coex running\n!!"); - BTC_TRACE(trace_buf); - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Antenna Det Timer is not up! (%d)\n", - psd_scan->ant_det_inteval_count); - BTC_TRACE(trace_buf); - - if (psd_scan->ant_det_inteval_count == 8) - btcoexist->bdontenterLPS = true; - else - btcoexist->bdontenterLPS = false; - } - - } -#endif -#endif - -} - - -void ex_halbtc8821c2ant_display_ant_detection(IN struct btc_coexist *btcoexist) -{ -#if 0 -#if BT_8821C_2ANT_ANTDET_ENABLE - struct btc_board_info *board_info = &btcoexist->board_info; - - if (psd_scan->ant_det_try_count != 0) { - halbtc8821c2ant_psd_show_antenna_detect_result(btcoexist); - - if (board_info->btdm_ant_det_finish) - halbtc8821c2ant_psd_showdata(btcoexist); - } -#endif -#endif -} - - -#endif - -#endif /* #if (RTL8821C_SUPPORT == 1) */ - diff --git a/hal/btc/halbtc8821c2ant.h b/hal/btc/halbtc8821c2ant.h deleted file mode 100644 index f89b1fa..0000000 --- a/hal/btc/halbtc8821c2ant.h +++ /dev/null @@ -1,478 +0,0 @@ - -#if (BT_SUPPORT == 1 && COEX_SUPPORT == 1) - -#if (RTL8821C_SUPPORT == 1) - -/* ******************************************* - * The following is for 8821C 2Ant BT Co-exist definition - * ******************************************* */ -#define BT_8821C_2ANT_COEX_DBG 0 -#define BT_AUTO_REPORT_ONLY_8821C_2ANT 1 - - -#define BT_INFO_8821C_2ANT_B_FTP BIT(7) -#define BT_INFO_8821C_2ANT_B_A2DP BIT(6) -#define BT_INFO_8821C_2ANT_B_HID BIT(5) -#define BT_INFO_8821C_2ANT_B_SCO_BUSY BIT(4) -#define BT_INFO_8821C_2ANT_B_ACL_BUSY BIT(3) -#define BT_INFO_8821C_2ANT_B_INQ_PAGE BIT(2) -#define BT_INFO_8821C_2ANT_B_SCO_ESCO BIT(1) -#define BT_INFO_8821C_2ANT_B_CONNECTION BIT(0) - -#define BTC_RSSI_COEX_THRESH_TOL_8821C_2ANT 2 - - -#define BT_8821C_2ANT_WIFI_RSSI_COEXSWITCH_THRES1 80 /* unit: % WiFi RSSI Threshold for 2-Ant free-run/2-Ant TDMA translation, default = 42 */ -#define BT_8821C_2ANT_BT_RSSI_COEXSWITCH_THRES1 80 /* unit: % BT RSSI Threshold for 2-Ant free-run/2-Ant TDMA translation, default = 46 */ -#define BT_8821C_2ANT_WIFI_RSSI_COEXSWITCH_THRES2 80 /* unit: % WiFi RSSI Threshold for 1-Ant TDMA/1-Ant PS-TDMA translation, default = 42 */ -#define BT_8821C_2ANT_BT_RSSI_COEXSWITCH_THRES2 80 /* unit: % BT RSSI Threshold for 1-Ant TDMA/1-Ant PS-TDMA translation, default = 46 */ -#define BT_8821C_2ANT_DEFAULT_ISOLATION 15 /* unit: dB */ -#define BT_8821C_2ANT_WIFI_MAX_TX_POWER 15 /* unit: dBm */ -#define BT_8821C_2ANT_BT_MAX_TX_POWER 3 /* unit: dBm */ -#define BT_8821C_2ANT_WIFI_SIR_THRES1 -15 /* unit: dB */ -#define BT_8821C_2ANT_WIFI_SIR_THRES2 -30 /* unit: dB */ -#define BT_8821C_2ANT_BT_SIR_THRES1 -15 /* unit: dB */ -#define BT_8821C_2ANT_BT_SIR_THRES2 -30 /* unit: dB */ - - -/* for Antenna detection */ -#define BT_8821C_2ANT_ANTDET_PSDTHRES_BACKGROUND 50 -#define BT_8821C_2ANT_ANTDET_PSDTHRES_2ANT_BADISOLATION 70 -#define BT_8821C_2ANT_ANTDET_PSDTHRES_2ANT_GOODISOLATION 52 -#define BT_8821C_2ANT_ANTDET_PSDTHRES_1ANT 40 -#define BT_8821C_2ANT_ANTDET_RETRY_INTERVAL 10 /* retry timer if ant det is fail, unit: second */ -#define BT_8821C_2ANT_ANTDET_SWEEPPOINT_DELAY 60000 -#define BT_8821C_2ANT_ANTDET_ENABLE 0 -#define BT_8821C_2ANT_ANTDET_BTTXTIME 100 -#define BT_8821C_2ANT_ANTDET_BTTXCHANNEL 39 -#define BT_8821C_2ANT_ANTDET_PSD_SWWEEPCOUNT 50 - - -#define BT_8821C_2ANT_LTECOEX_INDIRECTREG_ACCESS_TIMEOUT 30000 - -enum bt_8821c_2ant_signal_state { - BT_8821C_2ANT_SIG_STA_SET_TO_LOW = 0x0, - BT_8821C_2ANT_SIG_STA_SET_BY_HW = 0x0, - BT_8821C_2ANT_SIG_STA_SET_TO_HIGH = 0x1, - BT_8821C_2ANT_SIG_STA_MAX -}; - -enum bt_8821c_2ant_path_ctrl_owner { - BT_8821C_2ANT_PCO_BTSIDE = 0x0, - BT_8821C_2ANT_PCO_WLSIDE = 0x1, - BT_8821C_2ANT_PCO_MAX -}; - -enum bt_8821c_2ant_gnt_ctrl_type { - BT_8821C_2ANT_GNT_TYPE_CTRL_BY_PTA = 0x0, - BT_8821C_2ANT_GNT_TYPE_CTRL_BY_SW = 0x1, - BT_8821C_2ANT_GNT_TYPE_MAX -}; - -enum bt_8821c_2ant_gnt_ctrl_block { - BT_8821C_2ANT_GNT_BLOCK_RFC_BB = 0x0, - BT_8821C_2ANT_GNT_BLOCK_RFC = 0x1, - BT_8821C_2ANT_GNT_BLOCK_BB = 0x2, - BT_8821C_2ANT_GNT_BLOCK_MAX -}; - -enum bt_8821c_2ant_lte_coex_table_type { - BT_8821C_2ANT_CTT_WL_VS_LTE = 0x0, - BT_8821C_2ANT_CTT_BT_VS_LTE = 0x1, - BT_8821C_2ANT_CTT_MAX -}; - -enum bt_8821c_2ant_lte_break_table_type { - BT_8821C_2ANT_LBTT_WL_BREAK_LTE = 0x0, - BT_8821C_2ANT_LBTT_BT_BREAK_LTE = 0x1, - BT_8821C_2ANT_LBTT_LTE_BREAK_WL = 0x2, - BT_8821C_2ANT_LBTT_LTE_BREAK_BT = 0x3, - BT_8821C_2ANT_LBTT_MAX -}; - -enum bt_info_src_8821c_2ant { - BT_INFO_SRC_8821C_2ANT_WIFI_FW = 0x0, - BT_INFO_SRC_8821C_2ANT_BT_RSP = 0x1, - BT_INFO_SRC_8821C_2ANT_BT_ACTIVE_SEND = 0x2, - BT_INFO_SRC_8821C_2ANT_MAX -}; - -enum bt_8821c_2ant_bt_status { - BT_8821C_2ANT_BT_STATUS_NON_CONNECTED_IDLE = 0x0, - BT_8821C_2ANT_BT_STATUS_CONNECTED_IDLE = 0x1, - BT_8821C_2ANT_BT_STATUS_INQ_PAGE = 0x2, - BT_8821C_2ANT_BT_STATUS_ACL_BUSY = 0x3, - BT_8821C_2ANT_BT_STATUS_SCO_BUSY = 0x4, - BT_8821C_2ANT_BT_STATUS_ACL_SCO_BUSY = 0x5, - BT_8821C_2ANT_BT_STATUS_MAX -}; - -enum bt_8821c_2ant_coex_algo { - BT_8821C_2ANT_COEX_ALGO_UNDEFINED = 0x0, - BT_8821C_2ANT_COEX_ALGO_SCO = 0x1, - BT_8821C_2ANT_COEX_ALGO_HID = 0x2, - BT_8821C_2ANT_COEX_ALGO_A2DP = 0x3, - BT_8821C_2ANT_COEX_ALGO_A2DP_PANHS = 0x4, - BT_8821C_2ANT_COEX_ALGO_PANEDR = 0x5, - BT_8821C_2ANT_COEX_ALGO_PANHS = 0x6, - BT_8821C_2ANT_COEX_ALGO_PANEDR_A2DP = 0x7, - BT_8821C_2ANT_COEX_ALGO_PANEDR_HID = 0x8, - BT_8821C_2ANT_COEX_ALGO_HID_A2DP_PANEDR = 0x9, - BT_8821C_2ANT_COEX_ALGO_HID_A2DP = 0xa, - BT_8821C_2ANT_COEX_ALGO_NOPROFILEBUSY = 0xb, - BT_8821C_2ANT_COEX_ALGO_MAX -}; - -enum bt_8821c_2ant_ext_ant_switch_type { - BT_8821C_2ANT_EXT_ANT_SWITCH_USE_DPDT = 0x0, - BT_8821C_2ANT_EXT_ANT_SWITCH_USE_SPDT = 0x1, - BT_8821C_2ANT_EXT_ANT_SWITCH_NONE = 0x2, - BT_8821C_2ANT_EXT_ANT_SWITCH_MAX -}; - -enum bt_8821c_2ant_ext_ant_switch_ctrl_type { - BT_8821C_2ANT_EXT_ANT_SWITCH_CTRL_BY_BBSW = 0x0, - BT_8821C_2ANT_EXT_ANT_SWITCH_CTRL_BY_PTA = 0x1, - BT_8821C_2ANT_EXT_ANT_SWITCH_CTRL_BY_ANTDIV = 0x2, - BT_8821C_2ANT_EXT_ANT_SWITCH_CTRL_BY_MAC = 0x3, - BT_8821C_2ANT_EXT_ANT_SWITCH_CTRL_BY_BT = 0x4, - BT_8821C_2ANT_EXT_ANT_SWITCH_CTRL_MAX -}; - -enum bt_8821c_2ant_ext_ant_switch_pos_type { - BT_8821C_2ANT_EXT_ANT_SWITCH_MAIN_TO_BT = 0x0, - BT_8821C_2ANT_EXT_ANT_SWITCH_MAIN_TO_WLG = 0x1, - BT_8821C_2ANT_EXT_ANT_SWITCH_MAIN_TO_WLA = 0x2, - BT_8821C_2ANT_EXT_ANT_SWITCH_MAIN_TO_NOCARE = 0x3, - BT_8821C_2ANT_EXT_ANT_SWITCH_MAIN_TO_MAX -}; - -enum bt_8821c_2ant_ext_band_switch_pos_type { - BT_8821C_2ANT_EXT_BAND_SWITCH_TO_WLG = 0x0, - BT_8821C_2ANT_EXT_BAND_SWITCH_TO_WLA = 0x1, - BT_8821C_2ANT_EXT_BAND_SWITCH_TO_MAX -}; - -enum bt_8821c_2ant_int_block { - BT_8821C_2ANT_INT_BLOCK_SWITCH_TO_WLG_OF_BTG = 0x0, - BT_8821C_2ANT_INT_BLOCK_SWITCH_TO_WLG_OF_WLAG = 0x1, - BT_8821C_2ANT_INT_BLOCK_SWITCH_TO_WLA_OF_WLAG = 0x2, - BT_8821C_2ANT_INT_BLOCK_SWITCH_TO_MAX -}; - -enum bt_8821c_2ant_phase { - BT_8821C_2ANT_PHASE_COEX_INIT = 0x0, - BT_8821C_2ANT_PHASE_WLANONLY_INIT = 0x1, - BT_8821C_2ANT_PHASE_WLAN_OFF = 0x2, - BT_8821C_2ANT_PHASE_2G_RUNTIME = 0x3, - BT_8821C_2ANT_PHASE_5G_RUNTIME = 0x4, - BT_8821C_2ANT_PHASE_BTMPMODE = 0x5, - BT_8821C_2ANT_PHASE_ANTENNA_DET = 0x6, - BT_8821C_2ANT_PHASE_COEX_POWERON = 0x7, - BT_8821C_2ANT_PHASE_2G_RUNTIME_CONCURRENT = 0x8, - BT_8821C_2ANT_PHASE_MAX -}; - -enum bt_8821c_2ant_Scoreboard { - BT_8821C_2ANT_SCOREBOARD_ACTIVE = BIT(0), - BT_8821C_2ANT_SCOREBOARD_ONOFF = BIT(1), - BT_8821C_2ANT_SCOREBOARD_SCAN = BIT(2) -}; - - - -struct coex_dm_8821c_2ant { - /* hw setting */ - u32 pre_ant_pos_type; - u32 cur_ant_pos_type; - /* fw mechanism */ - u8 pre_bt_dec_pwr_lvl; - u8 cur_bt_dec_pwr_lvl; - u8 pre_fw_dac_swing_lvl; - u8 cur_fw_dac_swing_lvl; - boolean cur_ignore_wlan_act; - boolean pre_ignore_wlan_act; - u8 pre_ps_tdma; - u8 cur_ps_tdma; - u8 ps_tdma_para[5]; - u8 ps_tdma_du_adj_type; - boolean reset_tdma_adjust; - boolean pre_ps_tdma_on; - boolean cur_ps_tdma_on; - boolean pre_bt_auto_report; - boolean cur_bt_auto_report; - - /* sw mechanism */ - boolean pre_rf_rx_lpf_shrink; - boolean cur_rf_rx_lpf_shrink; - u32 bt_rf_0x1e_backup; - boolean pre_low_penalty_ra; - boolean cur_low_penalty_ra; - boolean pre_dac_swing_on; - u32 pre_dac_swing_lvl; - boolean cur_dac_swing_on; - u32 cur_dac_swing_lvl; - boolean pre_adc_back_off; - boolean cur_adc_back_off; - boolean pre_agc_table_en; - boolean cur_agc_table_en; - u32 pre_val0x6c0; - u32 cur_val0x6c0; - u32 pre_val0x6c4; - u32 cur_val0x6c4; - u32 pre_val0x6c8; - u32 cur_val0x6c8; - u8 pre_val0x6cc; - u8 cur_val0x6cc; - boolean limited_dig; - - /* algorithm related */ - u8 pre_algorithm; - u8 cur_algorithm; - u8 bt_status; - u8 wifi_chnl_info[3]; - - boolean need_recover0x948; - u32 backup0x948; - - u8 pre_lps; - u8 cur_lps; - u8 pre_rpwm; - u8 cur_rpwm; - - boolean is_switch_to_1dot5_ant; - u8 switch_thres_offset; - u32 arp_cnt; - - u32 pre_ext_ant_switch_status; - u32 cur_ext_ant_switch_status; - - u8 pre_ext_band_switch_status; - u8 cur_ext_band_switch_status; - - u8 pre_int_block_status; - u8 cur_int_block_status; -}; - -struct coex_sta_8821c_2ant { - boolean bt_disabled; - boolean bt_link_exist; - boolean sco_exist; - boolean a2dp_exist; - boolean hid_exist; - boolean pan_exist; - - boolean under_lps; - boolean under_ips; - u32 high_priority_tx; - u32 high_priority_rx; - u32 low_priority_tx; - u32 low_priority_rx; - u8 bt_rssi; - boolean bt_tx_rx_mask; - u8 pre_bt_rssi_state; - u8 pre_wifi_rssi_state[4]; - boolean c2h_bt_info_req_sent; - u8 bt_info_c2h[BT_INFO_SRC_8821C_2ANT_MAX][10]; - u32 bt_info_c2h_cnt[BT_INFO_SRC_8821C_2ANT_MAX]; - boolean bt_whck_test; - boolean c2h_bt_inquiry_page; - boolean c2h_bt_remote_name_req; - u8 bt_retry_cnt; - u8 bt_info_ext; - u8 bt_info_ext2; - u32 pop_event_cnt; - u8 scan_ap_num; - - u32 crc_ok_cck; - u32 crc_ok_11g; - u32 crc_ok_11n; - u32 crc_ok_11n_vht; - - u32 crc_err_cck; - u32 crc_err_11g; - u32 crc_err_11n; - u32 crc_err_11n_vht; - - boolean cck_lock; - boolean pre_ccklock; - boolean cck_ever_lock; - - u8 coex_table_type; - boolean force_lps_on; - - u8 dis_ver_info_cnt; - - u8 a2dp_bit_pool; - u8 cut_version; - - boolean concurrent_rx_mode_on; - - u16 score_board; - u8 isolation_btween_wb; /* 0~ 50 */ - u8 wifi_coex_thres; - u8 bt_coex_thres; - u8 wifi_coex_thres2; - u8 bt_coex_thres2; - - u8 num_of_profile; - boolean acl_busy; - boolean wl_rf_off_on_event; - boolean bt_create_connection; - boolean wifi_is_high_pri_task; - u32 specific_pkt_period_cnt; - u32 bt_coex_supported_feature; - u32 bt_coex_supported_version; - - u8 bt_ble_scan_type; - u8 bt_ble_scan_para[3]; - - boolean run_time_state; - boolean freeze_coexrun_by_btinfo; - - boolean is_A2DP_3M; - boolean voice_over_HOGP; - u8 bt_info; - boolean is_autoslot; - u8 forbidden_slot; - u8 hid_busy_num; - u8 hid_pair_cnt; - - u32 cnt_RemoteNameReq; - u32 cnt_setupLink; - u32 cnt_ReInit; - u32 cnt_IgnWlanAct; - u32 cnt_Page; - - u16 bt_reg_vendor_ac; - u16 bt_reg_vendor_ae; - - boolean is_setupLink; -}; - - -#define BT_8821C_2ANT_EXT_BAND_SWITCH_USE_DPDT 0 -#define BT_8821C_2ANT_EXT_BAND_SWITCH_USE_SPDT 1 - - -struct rfe_type_8821c_2ant { - - u8 rfe_module_type; - boolean ext_ant_switch_exist; - u8 ext_ant_switch_type; /* 0:DPDT, 1:SPDT */ - u8 ext_ant_switch_ctrl_polarity; /* iF 0: DPDT_P=0, DPDT_N=1 => BTG to Main, WL_A+G to Aux */ - - boolean ext_band_switch_exist; - u8 ext_band_switch_type; /* 0:DPDT, 1:SPDT */ - u8 ext_band_switch_ctrl_polarity; - - boolean wlg_Locate_at_btg; /* If true: WLG at BTG, If false: WLG at WLAG */ - - boolean ext_ant_switch_diversity; /* If diversity on */ -}; - -#define BT_8821C_2ANT_ANTDET_PSD_POINTS 256 /* MAX:1024 */ -#define BT_8821C_2ANT_ANTDET_PSD_AVGNUM 1 /* MAX:3 */ -#define BT_8821C_2ANT_ANTDET_BUF_LEN 16 - -struct psdscan_sta_8821c_2ant { - - u32 ant_det_bt_le_channel; /* BT LE Channel ex:2412 */ - u32 ant_det_bt_tx_time; - u32 ant_det_pre_psdscan_peak_val; - boolean ant_det_is_ant_det_available; - u32 ant_det_psd_scan_peak_val; - boolean ant_det_is_btreply_available; - u32 ant_det_psd_scan_peak_freq; - - u8 ant_det_result; - u8 ant_det_peak_val[BT_8821C_2ANT_ANTDET_BUF_LEN]; - u8 ant_det_peak_freq[BT_8821C_2ANT_ANTDET_BUF_LEN]; - u32 ant_det_try_count; - u32 ant_det_fail_count; - u32 ant_det_inteval_count; - u32 ant_det_thres_offset; - - u32 real_cent_freq; - s32 real_offset; - u32 real_span; - - u32 psd_band_width; /* unit: Hz */ - u32 psd_point; /* 128/256/512/1024 */ - u32 psd_report[1024]; /* unit:dB (20logx), 0~255 */ - u32 psd_report_max_hold[1024]; /* unit:dB (20logx), 0~255 */ - u32 psd_start_point; - u32 psd_stop_point; - u32 psd_max_value_point; - u32 psd_max_value; - u32 psd_max_value2; - u32 psd_avg_value; /* filter loop_max_value that below BT_8821C_1ANT_ANTDET_PSDTHRES_1ANT, and average the rest*/ - u32 psd_loop_max_value[BT_8821C_2ANT_ANTDET_PSD_SWWEEPCOUNT]; /*max value in each loop */ - u32 psd_start_base; - u32 psd_avg_num; /* 1/8/16/32 */ - u32 psd_gen_count; - boolean is_AntDet_running; - boolean is_psd_show_max_only; -}; - - -/* ******************************************* - * The following is interface which will notify coex module. - * ******************************************* */ -void ex_halbtc8821c2ant_power_on_setting(IN struct btc_coexist *btcoexist); -void ex_halbtc8821c2ant_pre_load_firmware(IN struct btc_coexist *btcoexist); -void ex_halbtc8821c2ant_init_hw_config(IN struct btc_coexist *btcoexist, - IN boolean wifi_only); -void ex_halbtc8821c2ant_init_coex_dm(IN struct btc_coexist *btcoexist); -void ex_halbtc8821c2ant_ips_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8821c2ant_lps_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8821c2ant_scan_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8821c2ant_switchband_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8821c2ant_connect_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8821c2ant_media_status_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8821c2ant_specific_packet_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8821c2ant_bt_info_notify(IN struct btc_coexist *btcoexist, - IN u8 *tmp_buf, IN u8 length); -void ex_halbtc8821c2ant_rf_status_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8821c2ant_halt_notify(IN struct btc_coexist *btcoexist); -void ex_halbtc8821c2ant_pnp_notify(IN struct btc_coexist *btcoexist, - IN u8 pnp_state); -void ex_halbtc8821c2ant_periodical(IN struct btc_coexist *btcoexist); -void ex_halbtc8821c2ant_display_coex_info(IN struct btc_coexist *btcoexist); -void ex_halbtc8821c2ant_antenna_detection(IN struct btc_coexist *btcoexist, - IN u32 cent_freq, IN u32 offset, IN u32 span, IN u32 seconds); -void ex_halbtc8821c2ant_display_ant_detection(IN struct btc_coexist *btcoexist); - - -#else -#define ex_halbtc8821c2ant_power_on_setting(btcoexist) -#define ex_halbtc8821c2ant_pre_load_firmware(btcoexist) -#define ex_halbtc8821c2ant_init_hw_config(btcoexist, wifi_only) -#define ex_halbtc8821c2ant_init_coex_dm(btcoexist) -#define ex_halbtc8821c2ant_ips_notify(btcoexist, type) -#define ex_halbtc8821c2ant_lps_notify(btcoexist, type) -#define ex_halbtc8821c2ant_scan_notify(btcoexist, type) -#define ex_halbtc8821c2ant_switchband_notify(btcoexist,type) -#define ex_halbtc8821c2ant_connect_notify(btcoexist, type) -#define ex_halbtc8821c2ant_media_status_notify(btcoexist, type) -#define ex_halbtc8821c2ant_specific_packet_notify(btcoexist, type) -#define ex_halbtc8821c2ant_bt_info_notify(btcoexist, tmp_buf, length) -#define ex_halbtc8821c2ant_rf_status_notify(btcoexist, type) -#define ex_halbtc8821c2ant_halt_notify(btcoexist) -#define ex_halbtc8821c2ant_pnp_notify(btcoexist, pnp_state) -#define ex_halbtc8821c2ant_periodical(btcoexist) -#define ex_halbtc8821c2ant_display_coex_info(btcoexist) -#define ex_halbtc8821c2ant_display_ant_detection(btcoexist) -#define ex_halbtc8821c2ant_antenna_detection(btcoexist, cent_freq, offset, span, seconds) -#endif - -#endif - diff --git a/hal/btc/halbtc8821cwifionly.c b/hal/btc/halbtc8821cwifionly.c deleted file mode 100755 index 6de8db0..0000000 --- a/hal/btc/halbtc8821cwifionly.c +++ /dev/null @@ -1,186 +0,0 @@ -#include "mp_precomp.h" - -static struct rfe_type_8821c_wifi_only gl_rfe_type_8821c_1ant; -static struct rfe_type_8821c_wifi_only *rfe_type = &gl_rfe_type_8821c_1ant; - - - -VOID hal8821c_wifi_only_switch_antenna( - IN struct wifi_only_cfg *pwifionlycfg, - IN u1Byte is_5g - ) -{ - boolean switch_polatiry_inverse = false; - u8 regval_0xcb7 = 0; - u8 pos_type, ctrl_type; - - if (!rfe_type->ext_ant_switch_exist) - return; - - /* swap control polarity if use different switch control polarity*/ - /* Normal switch polarity for DPDT, 0xcb4[29:28] = 2b'01 => BTG to Main, WLG to Aux, 0xcb4[29:28] = 2b'10 => BTG to Aux, WLG to Main */ - /* Normal switch polarity for SPDT, 0xcb4[29:28] = 2b'01 => Ant to BTG, 0xcb4[29:28] = 2b'10 => Ant to WLG */ - if (rfe_type->ext_ant_switch_ctrl_polarity) - switch_polatiry_inverse = !switch_polatiry_inverse; - - /* swap control polarity if 1-Ant at Aux */ - if (rfe_type->ant_at_main_port == false) - switch_polatiry_inverse = !switch_polatiry_inverse; - - if (is_5g) - pos_type = BT_8821C_WIFI_ONLY_EXT_ANT_SWITCH_TO_WLA; - else - pos_type = BT_8821C_WIFI_ONLY_EXT_ANT_SWITCH_TO_WLG; - - switch (pos_type) { - default: - case BT_8821C_WIFI_ONLY_EXT_ANT_SWITCH_TO_WLA: - - break; - case BT_8821C_WIFI_ONLY_EXT_ANT_SWITCH_TO_WLG: - if (!rfe_type->wlg_Locate_at_btg) - switch_polatiry_inverse = !switch_polatiry_inverse; - break; - } - - if (pwifionlycfg->haldata_info.ant_div_cfg) - ctrl_type = BT_8821C_WIFI_ONLY_EXT_ANT_SWITCH_CTRL_BY_ANTDIV; - else - ctrl_type = BT_8821C_WIFI_ONLY_EXT_ANT_SWITCH_CTRL_BY_BBSW; - - - switch (ctrl_type) { - default: - case BT_8821C_WIFI_ONLY_EXT_ANT_SWITCH_CTRL_BY_BBSW: - halwifionly_phy_set_bb_reg(pwifionlycfg, 0x4c, 0x01800000, 0x2); - - /* BB SW, DPDT use RFE_ctrl8 and RFE_ctrl9 as control pin */ - halwifionly_phy_set_bb_reg(pwifionlycfg, 0xcb4, 0x000000ff, 0x77); - - regval_0xcb7 = (switch_polatiry_inverse == false ? 0x1 : 0x2); - - /* 0xcb4[29:28] = 2b'01 for no switch_polatiry_inverse, DPDT_SEL_N =1, DPDT_SEL_P =0 */ - halwifionly_phy_set_bb_reg(pwifionlycfg, 0xcb4, 0x30000000, regval_0xcb7); - break; - - case BT_8821C_WIFI_ONLY_EXT_ANT_SWITCH_CTRL_BY_ANTDIV: - halwifionly_phy_set_bb_reg(pwifionlycfg, 0x4c, 0x01800000, 0x2); - - /* BB SW, DPDT use RFE_ctrl8 and RFE_ctrl9 as control pin */ - halwifionly_phy_set_bb_reg(pwifionlycfg, 0xcb4, 0x000000ff, 0x88); - - /* no regval_0xcb7 setup required, because antenna switch control value by antenna diversity */ - - break; - - } - -} - - -VOID halbtc8821c_wifi_only_set_rfe_type( - IN struct wifi_only_cfg *pwifionlycfg - ) -{ - - /* the following setup should be got from Efuse in the future */ - rfe_type->rfe_module_type = (pwifionlycfg->haldata_info.rfe_type) & 0x1f; - - rfe_type->ext_ant_switch_ctrl_polarity = 0; - - switch (rfe_type->rfe_module_type) { - case 0: - default: - rfe_type->ext_ant_switch_exist = true; - rfe_type->ext_ant_switch_type = - BT_8821C_WIFI_ONLY_EXT_ANT_SWITCH_USE_DPDT; /*2-Ant, DPDT, WLG*/ - rfe_type->wlg_Locate_at_btg = false; - rfe_type->ant_at_main_port = true; - break; - case 1: - rfe_type->ext_ant_switch_exist = true; - rfe_type->ext_ant_switch_type = - BT_8821C_WIFI_ONLY_EXT_ANT_SWITCH_USE_SPDT; /*1-Ant, Main, DPDT or SPDT, WLG */ - rfe_type->wlg_Locate_at_btg = false; - rfe_type->ant_at_main_port = true; - break; - case 2: - rfe_type->ext_ant_switch_exist = true; - rfe_type->ext_ant_switch_type = - BT_8821C_WIFI_ONLY_EXT_ANT_SWITCH_USE_SPDT; /*1-Ant, Main, DPDT or SPDT, BTG */ - rfe_type->wlg_Locate_at_btg = true; - rfe_type->ant_at_main_port = true; - break; - case 3: - rfe_type->ext_ant_switch_exist = true; - rfe_type->ext_ant_switch_type = - BT_8821C_WIFI_ONLY_EXT_ANT_SWITCH_USE_DPDT; /*1-Ant, Aux, DPDT, WLG */ - rfe_type->wlg_Locate_at_btg = false; - rfe_type->ant_at_main_port = false; - break; - case 4: - rfe_type->ext_ant_switch_exist = true; - rfe_type->ext_ant_switch_type = - BT_8821C_WIFI_ONLY_EXT_ANT_SWITCH_USE_DPDT; /*1-Ant, Aux, DPDT, BTG */ - rfe_type->wlg_Locate_at_btg = true; - rfe_type->ant_at_main_port = false; - break; - case 5: - rfe_type->ext_ant_switch_exist = false; /*2-Ant, no antenna switch, WLG*/ - rfe_type->ext_ant_switch_type = - BT_8821C_WIFI_ONLY_EXT_ANT_SWITCH_NONE; - rfe_type->wlg_Locate_at_btg = false; - rfe_type->ant_at_main_port = true; - break; - case 6: - rfe_type->ext_ant_switch_exist = false; /*2-Ant, no antenna switch, WLG*/ - rfe_type->ext_ant_switch_type = - BT_8821C_WIFI_ONLY_EXT_ANT_SWITCH_NONE; - rfe_type->wlg_Locate_at_btg = false; - rfe_type->ant_at_main_port = true; - break; - case 7: - rfe_type->ext_ant_switch_exist = true; /*2-Ant, DPDT, BTG*/ - rfe_type->ext_ant_switch_type = - BT_8821C_WIFI_ONLY_EXT_ANT_SWITCH_USE_DPDT; - rfe_type->wlg_Locate_at_btg = true; - rfe_type->ant_at_main_port = true; - break; - } - -} - - -VOID -ex_hal8821c_wifi_only_hw_config( - IN struct wifi_only_cfg *pwifionlycfg - ) -{ - halbtc8821c_wifi_only_set_rfe_type(pwifionlycfg); - - /* set gnt_wl, gnt_bt control owner to WL*/ - halwifionly_phy_set_bb_reg(pwifionlycfg, 0x70, 0x400000, 0x1); - - /*gnt_wl=1 , gnt_bt=0*/ - halwifionly_phy_set_bb_reg(pwifionlycfg, 0x1704, 0xffffffff, 0x7700); - halwifionly_phy_set_bb_reg(pwifionlycfg, 0x1700, 0xffffffff, 0xc00f0038); -} - -VOID -ex_hal8821c_wifi_only_scannotify( - IN struct wifi_only_cfg *pwifionlycfg, - IN u1Byte is_5g - ) -{ - hal8821c_wifi_only_switch_antenna(pwifionlycfg, is_5g); -} - -VOID -ex_hal8821c_wifi_only_switchbandnotify( - IN struct wifi_only_cfg *pwifionlycfg, - IN u1Byte is_5g - ) -{ - hal8821c_wifi_only_switch_antenna(pwifionlycfg, is_5g); -} - diff --git a/hal/btc/halbtc8821cwifionly.h b/hal/btc/halbtc8821cwifionly.h deleted file mode 100755 index afa2b2f..0000000 --- a/hal/btc/halbtc8821cwifionly.h +++ /dev/null @@ -1,70 +0,0 @@ -#ifndef __INC_HAL8821CWIFIONLYHWCFG_H -#define __INC_HAL8821CWIFIONLYHWCFG_H - - -struct rfe_type_8821c_wifi_only { - - u8 rfe_module_type; - boolean ext_ant_switch_exist; - u8 ext_ant_switch_type; /* 0:DPDT, 1:SPDT */ - u8 ext_ant_switch_ctrl_polarity; /* iF 0: DPDT_P=0, DPDT_N=1 => BTG to Main, WL_A+G to Aux */ - - boolean ant_at_main_port; - - boolean wlg_Locate_at_btg; /* If true: WLG at BTG, If false: WLG at WLAG */ - - boolean ext_ant_switch_diversity; /* If diversity on */ -}; - -enum bt_8821c_wifi_only_ext_ant_switch_type { - BT_8821C_WIFI_ONLY_EXT_ANT_SWITCH_USE_DPDT = 0x0, - BT_8821C_WIFI_ONLY_EXT_ANT_SWITCH_USE_SPDT = 0x1, - BT_8821C_WIFI_ONLY_EXT_ANT_SWITCH_NONE = 0x2, - BT_8821C_WIFI_ONLY_EXT_ANT_SWITCH_MAX -}; - -enum bt_8821c_wifi_only_ext_ant_switch_ctrl_type { - BT_8821C_WIFI_ONLY_EXT_ANT_SWITCH_CTRL_BY_BBSW = 0x0, - BT_8821C_WIFI_ONLY_EXT_ANT_SWITCH_CTRL_BY_PTA = 0x1, - BT_8821C_WIFI_ONLY_EXT_ANT_SWITCH_CTRL_BY_ANTDIV = 0x2, - BT_8821C_WIFI_ONLY_EXT_ANT_SWITCH_CTRL_BY_MAC = 0x3, - BT_8821C_WIFI_ONLY_EXT_ANT_SWITCH_CTRL_BY_BT = 0x4, - BT_8821C_WIFI_ONLY_EXT_ANT_SWITCH_CTRL_MAX -}; - -enum bt_8821c_wifi_only_ext_ant_switch_pos_type { - BT_8821C_WIFI_ONLY_EXT_ANT_SWITCH_TO_BT = 0x0, - BT_8821C_WIFI_ONLY_EXT_ANT_SWITCH_TO_WLG = 0x1, - BT_8821C_WIFI_ONLY_EXT_ANT_SWITCH_TO_WLA = 0x2, - BT_8821C_WIFI_ONLY_EXT_ANT_SWITCH_TO_NOCARE = 0x3, - BT_8821C_WIFI_ONLY_EXT_ANT_SWITCH_TO_MAX -}; - - -VOID -hal8821c_wifi_only_switch_antenna( - IN struct wifi_only_cfg *pwifionlycfg, - IN u1Byte is_5g - ); - -VOID -halbtc8821c_wifi_only_set_rfe_type( - IN struct wifi_only_cfg *pwifionlycfg - ); - - -VOID -ex_hal8821c_wifi_only_hw_config( - IN struct wifi_only_cfg *pwifionlycfg - ); -VOID -ex_hal8821c_wifi_only_scannotify( - IN struct wifi_only_cfg *pwifionlycfg, - IN u1Byte is_5g - ); -VOID -ex_hal8821c_wifi_only_switchbandnotify( - IN struct wifi_only_cfg *pwifionlycfg, - IN u1Byte is_5g - ); -#endif diff --git a/hal/btc/halbtc8822b1ant.c b/hal/btc/halbtc8822b1ant.c deleted file mode 100644 index 50673e7..0000000 --- a/hal/btc/halbtc8822b1ant.c +++ /dev/null @@ -1,6840 +0,0 @@ -/* ************************************************************ - * Description: - * - * This file is for RTL8822B Co-exist mechanism - * - * History - * 2012/11/15 Cosa first check in. - * - * ************************************************************ */ - -/* ************************************************************ - * include files - * ************************************************************ */ -#include "mp_precomp.h" - - -#if (BT_SUPPORT == 1 && COEX_SUPPORT == 1) - -#if (RTL8822B_SUPPORT == 1) -/* ************************************************************ - * Global variables, these are static variables - * ************************************************************ */ -static u8 *trace_buf = &gl_btc_trace_buf[0]; -static struct coex_dm_8822b_1ant glcoex_dm_8822b_1ant; -static struct coex_dm_8822b_1ant *coex_dm = &glcoex_dm_8822b_1ant; -static struct coex_sta_8822b_1ant glcoex_sta_8822b_1ant; -static struct coex_sta_8822b_1ant *coex_sta = &glcoex_sta_8822b_1ant; -static struct psdscan_sta_8822b_1ant gl_psd_scan_8822b_1ant; -static struct psdscan_sta_8822b_1ant *psd_scan = &gl_psd_scan_8822b_1ant; -static struct rfe_type_8822b_1ant gl_rfe_type_8822b_1ant; -static struct rfe_type_8822b_1ant *rfe_type = &gl_rfe_type_8822b_1ant; - - - -const char *const glbt_info_src_8822b_1ant[] = { - "BT Info[wifi fw]", - "BT Info[bt rsp]", - "BT Info[bt auto report]", -}; - -u32 glcoex_ver_date_8822b_1ant = 20161026; -u32 glcoex_ver_8822b_1ant = 0x34; -u32 glcoex_ver_btdesired_8822b_1ant = 0x28; - - -/* ************************************************************ - * local function proto type if needed - * ************************************************************ - * ************************************************************ - * local function start with halbtc8822b1ant_ - * ************************************************************ */ -u8 halbtc8822b1ant_bt_rssi_state(u8 level_num, u8 rssi_thresh, u8 rssi_thresh1) -{ - s32 bt_rssi = 0; - u8 bt_rssi_state = coex_sta->pre_bt_rssi_state; - - bt_rssi = coex_sta->bt_rssi; - - if (level_num == 2) { - if ((coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_LOW) || - (coex_sta->pre_bt_rssi_state == - BTC_RSSI_STATE_STAY_LOW)) { - if (bt_rssi >= (rssi_thresh + - BTC_RSSI_COEX_THRESH_TOL_8822B_1ANT)) - bt_rssi_state = BTC_RSSI_STATE_HIGH; - else - bt_rssi_state = BTC_RSSI_STATE_STAY_LOW; - } else { - if (bt_rssi < rssi_thresh) - bt_rssi_state = BTC_RSSI_STATE_LOW; - else - bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH; - } - } else if (level_num == 3) { - if (rssi_thresh > rssi_thresh1) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Rssi thresh error!!\n"); - BTC_TRACE(trace_buf); - return coex_sta->pre_bt_rssi_state; - } - - if ((coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_LOW) || - (coex_sta->pre_bt_rssi_state == - BTC_RSSI_STATE_STAY_LOW)) { - if (bt_rssi >= (rssi_thresh + - BTC_RSSI_COEX_THRESH_TOL_8822B_1ANT)) - bt_rssi_state = BTC_RSSI_STATE_MEDIUM; - else - bt_rssi_state = BTC_RSSI_STATE_STAY_LOW; - } else if ((coex_sta->pre_bt_rssi_state == - BTC_RSSI_STATE_MEDIUM) || - (coex_sta->pre_bt_rssi_state == - BTC_RSSI_STATE_STAY_MEDIUM)) { - if (bt_rssi >= (rssi_thresh1 + - BTC_RSSI_COEX_THRESH_TOL_8822B_1ANT)) - bt_rssi_state = BTC_RSSI_STATE_HIGH; - else if (bt_rssi < rssi_thresh) - bt_rssi_state = BTC_RSSI_STATE_LOW; - else - bt_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM; - } else { - if (bt_rssi < rssi_thresh1) - bt_rssi_state = BTC_RSSI_STATE_MEDIUM; - else - bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH; - } - } - - coex_sta->pre_bt_rssi_state = bt_rssi_state; - - return bt_rssi_state; -} - -u8 halbtc8822b1ant_wifi_rssi_state(IN struct btc_coexist *btcoexist, - IN u8 index, IN u8 level_num, IN u8 rssi_thresh, IN u8 rssi_thresh1) -{ - s32 wifi_rssi = 0; - u8 wifi_rssi_state = coex_sta->pre_wifi_rssi_state[index]; - - btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi); - - if (level_num == 2) { - if ((coex_sta->pre_wifi_rssi_state[index] == BTC_RSSI_STATE_LOW) - || - (coex_sta->pre_wifi_rssi_state[index] == - BTC_RSSI_STATE_STAY_LOW)) { - if (wifi_rssi >= (rssi_thresh + - BTC_RSSI_COEX_THRESH_TOL_8822B_1ANT)) - wifi_rssi_state = BTC_RSSI_STATE_HIGH; - else - wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW; - } else { - if (wifi_rssi < rssi_thresh) - wifi_rssi_state = BTC_RSSI_STATE_LOW; - else - wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH; - } - } else if (level_num == 3) { - if (rssi_thresh > rssi_thresh1) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], wifi RSSI thresh error!!\n"); - BTC_TRACE(trace_buf); - return coex_sta->pre_wifi_rssi_state[index]; - } - - if ((coex_sta->pre_wifi_rssi_state[index] == BTC_RSSI_STATE_LOW) - || - (coex_sta->pre_wifi_rssi_state[index] == - BTC_RSSI_STATE_STAY_LOW)) { - if (wifi_rssi >= (rssi_thresh + - BTC_RSSI_COEX_THRESH_TOL_8822B_1ANT)) - wifi_rssi_state = BTC_RSSI_STATE_MEDIUM; - else - wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW; - } else if ((coex_sta->pre_wifi_rssi_state[index] == - BTC_RSSI_STATE_MEDIUM) || - (coex_sta->pre_wifi_rssi_state[index] == - BTC_RSSI_STATE_STAY_MEDIUM)) { - if (wifi_rssi >= (rssi_thresh1 + - BTC_RSSI_COEX_THRESH_TOL_8822B_1ANT)) - wifi_rssi_state = BTC_RSSI_STATE_HIGH; - else if (wifi_rssi < rssi_thresh) - wifi_rssi_state = BTC_RSSI_STATE_LOW; - else - wifi_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM; - } else { - if (wifi_rssi < rssi_thresh1) - wifi_rssi_state = BTC_RSSI_STATE_MEDIUM; - else - wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH; - } - } - - coex_sta->pre_wifi_rssi_state[index] = wifi_rssi_state; - - return wifi_rssi_state; -} - -void halbtc8822b1ant_update_ra_mask(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u32 dis_rate_mask) -{ - coex_dm->cur_ra_mask = dis_rate_mask; - - if (force_exec || (coex_dm->pre_ra_mask != coex_dm->cur_ra_mask)) - btcoexist->btc_set(btcoexist, BTC_SET_ACT_UPDATE_RAMASK, - &coex_dm->cur_ra_mask); - coex_dm->pre_ra_mask = coex_dm->cur_ra_mask; -} - -void halbtc8822b1ant_auto_rate_fallback_retry(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 type) -{ - boolean wifi_under_b_mode = false; - - coex_dm->cur_arfr_type = type; - - if (force_exec || (coex_dm->pre_arfr_type != coex_dm->cur_arfr_type)) { - switch (coex_dm->cur_arfr_type) { - case 0: /* normal mode */ - btcoexist->btc_write_4byte(btcoexist, 0x430, - coex_dm->backup_arfr_cnt1); - btcoexist->btc_write_4byte(btcoexist, 0x434, - coex_dm->backup_arfr_cnt2); - break; - case 1: - btcoexist->btc_get(btcoexist, - BTC_GET_BL_WIFI_UNDER_B_MODE, - &wifi_under_b_mode); - if (wifi_under_b_mode) { - btcoexist->btc_write_4byte(btcoexist, - 0x430, 0x0); - btcoexist->btc_write_4byte(btcoexist, - 0x434, 0x01010101); - } else { - btcoexist->btc_write_4byte(btcoexist, - 0x430, 0x0); - btcoexist->btc_write_4byte(btcoexist, - 0x434, 0x04030201); - } - break; - default: - break; - } - } - - coex_dm->pre_arfr_type = coex_dm->cur_arfr_type; -} - -void halbtc8822b1ant_retry_limit(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 type) -{ - coex_dm->cur_retry_limit_type = type; - - if (force_exec || - (coex_dm->pre_retry_limit_type != - coex_dm->cur_retry_limit_type)) { - switch (coex_dm->cur_retry_limit_type) { - case 0: /* normal mode */ - btcoexist->btc_write_2byte(btcoexist, 0x42a, - coex_dm->backup_retry_limit); - break; - case 1: /* retry limit=8 */ - btcoexist->btc_write_2byte(btcoexist, 0x42a, - 0x0808); - break; - default: - break; - } - } - - coex_dm->pre_retry_limit_type = coex_dm->cur_retry_limit_type; -} - -void halbtc8822b1ant_ampdu_max_time(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 type) -{ - coex_dm->cur_ampdu_time_type = type; - - if (force_exec || - (coex_dm->pre_ampdu_time_type != coex_dm->cur_ampdu_time_type)) { - switch (coex_dm->cur_ampdu_time_type) { - case 0: /* normal mode */ - btcoexist->btc_write_1byte(btcoexist, 0x456, - coex_dm->backup_ampdu_max_time); - break; - case 1: /* AMPDU timw = 0x38 * 32us */ - btcoexist->btc_write_1byte(btcoexist, 0x456, - 0x38); - break; - default: - break; - } - } - - coex_dm->pre_ampdu_time_type = coex_dm->cur_ampdu_time_type; -} - -void halbtc8822b1ant_limited_tx(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 ra_mask_type, IN u8 arfr_type, - IN u8 retry_limit_type, IN u8 ampdu_time_type) -{ - switch (ra_mask_type) { - case 0: /* normal mode */ - halbtc8822b1ant_update_ra_mask(btcoexist, force_exec, - 0x0); - break; - case 1: /* disable cck 1/2 */ - halbtc8822b1ant_update_ra_mask(btcoexist, force_exec, - 0x00000003); - break; - case 2: /* disable cck 1/2/5.5, ofdm 6/9/12/18/24, mcs 0/1/2/3/4 */ - halbtc8822b1ant_update_ra_mask(btcoexist, force_exec, - 0x0001f1f7); - break; - default: - break; - } - - halbtc8822b1ant_auto_rate_fallback_retry(btcoexist, force_exec, - arfr_type); - halbtc8822b1ant_retry_limit(btcoexist, force_exec, retry_limit_type); - halbtc8822b1ant_ampdu_max_time(btcoexist, force_exec, ampdu_time_type); -} - -/* -rx agg size setting : -1: true / don't care / don't care -max: false / false / don't care -7: false / true / 7 -*/ - -void halbtc8822b1ant_limited_rx(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean rej_ap_agg_pkt, - IN boolean bt_ctrl_agg_buf_size, IN u8 agg_buf_size) -{ - boolean reject_rx_agg = rej_ap_agg_pkt; - boolean bt_ctrl_rx_agg_size = bt_ctrl_agg_buf_size; - u8 rx_agg_size = agg_buf_size; - - /* ============================================ */ - /* Rx Aggregation related setting */ - /* ============================================ */ - btcoexist->btc_set(btcoexist, BTC_SET_BL_TO_REJ_AP_AGG_PKT, - &reject_rx_agg); - /* decide BT control aggregation buf size or not */ - btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_CTRL_AGG_SIZE, - &bt_ctrl_rx_agg_size); - /* aggregation buf size, only work when BT control Rx aggregation size. */ - btcoexist->btc_set(btcoexist, BTC_SET_U1_AGG_BUF_SIZE, &rx_agg_size); - /* real update aggregation setting */ - btcoexist->btc_set(btcoexist, BTC_SET_ACT_AGGREGATE_CTRL, NULL); - - -} - -void halbtc8822b1ant_query_bt_info(IN struct btc_coexist *btcoexist) -{ - u8 h2c_parameter[1] = {0}; - - coex_sta->c2h_bt_info_req_sent = true; - - h2c_parameter[0] |= BIT(0); /* trigger */ - - btcoexist->btc_fill_h2c(btcoexist, 0x61, 1, h2c_parameter); -} - -void halbtc8822b1ant_monitor_bt_ctr(IN struct btc_coexist *btcoexist) -{ - u32 reg_hp_txrx, reg_lp_txrx, u32tmp; - u32 reg_hp_tx = 0, reg_hp_rx = 0, reg_lp_tx = 0, reg_lp_rx = 0; - static u8 num_of_bt_counter_chk = 0, cnt_slave = 0; - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - - /* to avoid 0x76e[3] = 1 (WLAN_Act control by PTA) during IPS */ - /* if (! (btcoexist->btc_read_1byte(btcoexist, 0x76e) & 0x8) ) */ - - if (coex_sta->under_ips) { - /* coex_sta->high_priority_tx = 65535; */ - /* coex_sta->high_priority_rx = 65535; */ - /* coex_sta->low_priority_tx = 65535; */ - /* coex_sta->low_priority_rx = 65535; */ - /* return; */ - } - - reg_hp_txrx = 0x770; - reg_lp_txrx = 0x774; - - u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_hp_txrx); - reg_hp_tx = u32tmp & MASKLWORD; - reg_hp_rx = (u32tmp & MASKHWORD) >> 16; - - u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_lp_txrx); - reg_lp_tx = u32tmp & MASKLWORD; - reg_lp_rx = (u32tmp & MASKHWORD) >> 16; - - coex_sta->high_priority_tx = reg_hp_tx; - coex_sta->high_priority_rx = reg_hp_rx; - coex_sta->low_priority_tx = reg_lp_tx; - coex_sta->low_priority_rx = reg_lp_rx; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Hi-Pri Rx/Tx: %d/%d, Lo-Pri Rx/Tx: %d/%d\n", - reg_hp_rx, reg_hp_tx, reg_lp_rx, reg_lp_tx); - BTC_TRACE(trace_buf); - - /* reset counter */ - btcoexist->btc_write_1byte(btcoexist, 0x76e, 0xc); - - if ((coex_sta->low_priority_tx > 1150) && - (!coex_sta->c2h_bt_inquiry_page)) - coex_sta->pop_event_cnt++; - - if ((coex_sta->low_priority_rx >= 1150) && - (coex_sta->low_priority_rx >= coex_sta->low_priority_tx) - && (!coex_sta->under_ips) && - (!coex_sta->c2h_bt_inquiry_page) && - (coex_sta->bt_link_exist)) { - if (cnt_slave >= 3) { - bt_link_info->slave_role = true; - cnt_slave = 3; - } else - cnt_slave++; - } else { - if (cnt_slave == 0) { - bt_link_info->slave_role = false; - cnt_slave = 0; - } else - cnt_slave--; - - } - - if ((coex_sta->high_priority_tx == 0) && - (coex_sta->high_priority_rx == 0) && - (coex_sta->low_priority_tx == 0) && - (coex_sta->low_priority_rx == 0)) { - num_of_bt_counter_chk++; - - if (num_of_bt_counter_chk >= 3) { - halbtc8822b1ant_query_bt_info( - btcoexist); - num_of_bt_counter_chk = 0; - } - } -#if 0 - /* Add Hi-Pri Tx/Rx counter to avoid false detection */ - if (((coex_sta->hid_exist) || (coex_sta->sco_exist)) && - (coex_sta->high_priority_tx + coex_sta->high_priority_rx - >= 160) - && (!coex_sta->c2h_bt_inquiry_page)) - coex_sta->bt_hi_pri_link_exist = true; - else - coex_sta->bt_hi_pri_link_exist = false; - - if ((coex_sta->acl_busy) && - (coex_sta->num_of_profile == 0)) { - if (coex_sta->low_priority_tx + - coex_sta->low_priority_rx >= 160) { - coex_sta->pan_exist = true; - coex_sta->num_of_profile++; - coex_sta->wrong_profile_notification++; - } - } -#endif - -} - - -void halbtc8822b1ant_monitor_wifi_ctr(IN struct btc_coexist *btcoexist) -{ - s32 wifi_rssi = 0; - boolean wifi_busy = false, wifi_under_b_mode = false; - static u8 cck_lock_counter = 0; - u32 total_cnt; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_B_MODE, - &wifi_under_b_mode); - - if (coex_sta->under_ips) { - coex_sta->crc_ok_cck = 0; - coex_sta->crc_ok_11g = 0; - coex_sta->crc_ok_11n = 0; - coex_sta->crc_ok_11n_agg = 0; - - coex_sta->crc_err_cck = 0; - coex_sta->crc_err_11g = 0; - coex_sta->crc_err_11n = 0; - coex_sta->crc_err_11n_agg = 0; - } else { - coex_sta->crc_ok_cck = btcoexist->btc_read_2byte( - btcoexist, - 0xf04); - coex_sta->crc_ok_11g = btcoexist->btc_read_2byte( - btcoexist, - 0xf14); - coex_sta->crc_ok_11n = btcoexist->btc_read_2byte( - btcoexist, - 0xf10); - coex_sta->crc_ok_11n_agg = btcoexist->btc_read_2byte( - btcoexist, - 0xf0c); - - coex_sta->crc_err_cck = btcoexist->btc_read_2byte( - btcoexist, 0xf00) + btcoexist->btc_read_2byte( - btcoexist, 0xf06); - - coex_sta->crc_err_11g = btcoexist->btc_read_2byte( - btcoexist, - 0xf16); - coex_sta->crc_err_11n = btcoexist->btc_read_2byte( - btcoexist, - 0xf12); - coex_sta->crc_err_11n_agg = btcoexist->btc_read_2byte( - btcoexist, - 0xf0e); - } - - - /* reset counter */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0xb58, 0x1, 0x1); - btcoexist->btc_write_1byte_bitmask(btcoexist, 0xb58, 0x1, 0x0); - - if ((wifi_busy) && (wifi_rssi >= 30) && (!wifi_under_b_mode)) { - total_cnt = coex_sta->crc_ok_cck + coex_sta->crc_ok_11g - + - coex_sta->crc_ok_11n + - coex_sta->crc_ok_11n_agg; - - if ((coex_dm->bt_status == - BT_8822B_1ANT_BT_STATUS_ACL_BUSY) || - (coex_dm->bt_status == - BT_8822B_1ANT_BT_STATUS_ACL_SCO_BUSY) || - (coex_dm->bt_status == - BT_8822B_1ANT_BT_STATUS_SCO_BUSY)) { - if (coex_sta->crc_ok_cck > (total_cnt - - coex_sta->crc_ok_cck)) { - if (cck_lock_counter < 3) - cck_lock_counter++; - } else { - if (cck_lock_counter > 0) - cck_lock_counter--; - } - - } else { - if (cck_lock_counter > 0) - cck_lock_counter--; - } - } else { - if (cck_lock_counter > 0) - cck_lock_counter--; - } - - if (!coex_sta->pre_ccklock) { - - if (cck_lock_counter >= 3) - coex_sta->cck_lock = true; - else - coex_sta->cck_lock = false; - } else { - if (cck_lock_counter == 0) - coex_sta->cck_lock = false; - else - coex_sta->cck_lock = true; - } - - if (coex_sta->cck_lock) - coex_sta->cck_ever_lock = true; - - coex_sta->pre_ccklock = coex_sta->cck_lock; - - -} - - -boolean halbtc8822b1ant_is_wifi_status_changed(IN struct btc_coexist *btcoexist) -{ - static boolean pre_wifi_busy = false, pre_under_4way = false, - pre_bt_hs_on = false, pre_bt_off = false; - boolean wifi_busy = false, under_4way = false, bt_hs_on = false; - boolean wifi_connected = false; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS, - &under_4way); - if (coex_sta->bt_disabled != pre_bt_off) { - pre_bt_off = coex_sta->bt_disabled; - - if (coex_sta->bt_disabled) - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT is disabled !!\n"); - else - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT is enabled !!\n"); - - BTC_TRACE(trace_buf); - - coex_sta->bt_coex_supported_feature = 0; - coex_sta->bt_coex_supported_version = 0; - return true; - } - - if (wifi_connected) { - if (wifi_busy != pre_wifi_busy) { - pre_wifi_busy = wifi_busy; - return true; - } - if (under_4way != pre_under_4way) { - pre_under_4way = under_4way; - return true; - } - if (bt_hs_on != pre_bt_hs_on) { - pre_bt_hs_on = bt_hs_on; - return true; - } - } - - return false; -} - -void halbtc8822b1ant_update_bt_link_info(IN struct btc_coexist *btcoexist) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - boolean bt_hs_on = false; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); - - bt_link_info->bt_link_exist = coex_sta->bt_link_exist; - bt_link_info->sco_exist = coex_sta->sco_exist; - bt_link_info->a2dp_exist = coex_sta->a2dp_exist; - bt_link_info->pan_exist = coex_sta->pan_exist; - bt_link_info->hid_exist = coex_sta->hid_exist; - bt_link_info->bt_hi_pri_link_exist = coex_sta->bt_hi_pri_link_exist; - bt_link_info->acl_busy = coex_sta->acl_busy; - - /* work around for HS mode. */ - if (bt_hs_on) { - bt_link_info->pan_exist = true; - bt_link_info->bt_link_exist = true; - } - - /* check if Sco only */ - if (bt_link_info->sco_exist && - !bt_link_info->a2dp_exist && - !bt_link_info->pan_exist && - !bt_link_info->hid_exist) - bt_link_info->sco_only = true; - else - bt_link_info->sco_only = false; - - /* check if A2dp only */ - if (!bt_link_info->sco_exist && - bt_link_info->a2dp_exist && - !bt_link_info->pan_exist && - !bt_link_info->hid_exist) - bt_link_info->a2dp_only = true; - else - bt_link_info->a2dp_only = false; - - /* check if Pan only */ - if (!bt_link_info->sco_exist && - !bt_link_info->a2dp_exist && - bt_link_info->pan_exist && - !bt_link_info->hid_exist) - bt_link_info->pan_only = true; - else - bt_link_info->pan_only = false; - - /* check if Hid only */ - if (!bt_link_info->sco_exist && - !bt_link_info->a2dp_exist && - !bt_link_info->pan_exist && - bt_link_info->hid_exist) - bt_link_info->hid_only = true; - else - bt_link_info->hid_only = false; -} - -void halbtc8822b1ant_update_wifi_channel_info(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - u8 h2c_parameter[3] = {0}; - u32 wifi_bw; - u8 wifi_central_chnl; - - /* only 2.4G we need to inform bt the chnl mask */ - btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_CENTRAL_CHNL, - &wifi_central_chnl); - if ((BTC_MEDIA_CONNECT == type) && - (wifi_central_chnl <= 14)) { - - h2c_parameter[0] = - 0x1; /* enable BT AFH skip WL channel for 8822b because BT Rx LO interference */ - h2c_parameter[1] = wifi_central_chnl; - - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw); - - if (BTC_WIFI_BW_HT40 == wifi_bw) - h2c_parameter[2] = 0x30; - else - h2c_parameter[2] = 0x20; - } - - coex_dm->wifi_chnl_info[0] = h2c_parameter[0]; - coex_dm->wifi_chnl_info[1] = h2c_parameter[1]; - coex_dm->wifi_chnl_info[2] = h2c_parameter[2]; - - btcoexist->btc_fill_h2c(btcoexist, 0x66, 3, h2c_parameter); - -} - -u8 halbtc8822b1ant_action_algorithm(IN struct btc_coexist *btcoexist) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - boolean bt_hs_on = false; - u8 algorithm = BT_8822B_1ANT_COEX_ALGO_UNDEFINED; - u8 num_of_diff_profile = 0; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); - - if (!bt_link_info->bt_link_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], No BT link exists!!!\n"); - BTC_TRACE(trace_buf); - return algorithm; - } - - if (bt_link_info->sco_exist) - num_of_diff_profile++; - if (bt_link_info->hid_exist) - num_of_diff_profile++; - if (bt_link_info->pan_exist) - num_of_diff_profile++; - if (bt_link_info->a2dp_exist) - num_of_diff_profile++; - - if (num_of_diff_profile == 1) { - if (bt_link_info->sco_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = SCO only\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8822B_1ANT_COEX_ALGO_SCO; - } else { - if (bt_link_info->hid_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = HID only\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8822B_1ANT_COEX_ALGO_HID; - } else if (bt_link_info->a2dp_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = A2DP only\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8822B_1ANT_COEX_ALGO_A2DP; - } else if (bt_link_info->pan_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = PAN(HS) only\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8822B_1ANT_COEX_ALGO_PANHS; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = PAN(EDR) only\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8822B_1ANT_COEX_ALGO_PANEDR; - } - } - } - } else if (num_of_diff_profile == 2) { - if (bt_link_info->sco_exist) { - if (bt_link_info->hid_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = SCO + HID\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8822B_1ANT_COEX_ALGO_HID; - } else if (bt_link_info->a2dp_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = SCO + A2DP ==> SCO\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8822B_1ANT_COEX_ALGO_SCO; - } else if (bt_link_info->pan_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = SCO + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8822B_1ANT_COEX_ALGO_SCO; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = SCO + PAN(EDR)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8822B_1ANT_COEX_ALGO_PANEDR_HID; - } - } - } else { - if (bt_link_info->hid_exist && - bt_link_info->a2dp_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = HID + A2DP\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8822B_1ANT_COEX_ALGO_HID_A2DP; - } else if (bt_link_info->hid_exist && - bt_link_info->pan_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = HID + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8822B_1ANT_COEX_ALGO_HID_A2DP; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = HID + PAN(EDR)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8822B_1ANT_COEX_ALGO_PANEDR_HID; - } - } else if (bt_link_info->pan_exist && - bt_link_info->a2dp_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = A2DP + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8822B_1ANT_COEX_ALGO_A2DP_PANHS; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = A2DP + PAN(EDR)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8822B_1ANT_COEX_ALGO_PANEDR_A2DP; - } - } - } - } else if (num_of_diff_profile == 3) { - if (bt_link_info->sco_exist) { - if (bt_link_info->hid_exist && - bt_link_info->a2dp_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = SCO + HID + A2DP ==> HID\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8822B_1ANT_COEX_ALGO_HID; - } else if (bt_link_info->hid_exist && - bt_link_info->pan_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = SCO + HID + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8822B_1ANT_COEX_ALGO_HID_A2DP; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = SCO + HID + PAN(EDR)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8822B_1ANT_COEX_ALGO_PANEDR_HID; - } - } else if (bt_link_info->pan_exist && - bt_link_info->a2dp_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = SCO + A2DP + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8822B_1ANT_COEX_ALGO_SCO; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = SCO + A2DP + PAN(EDR) ==> HID\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8822B_1ANT_COEX_ALGO_PANEDR_HID; - } - } - } else { - if (bt_link_info->hid_exist && - bt_link_info->pan_exist && - bt_link_info->a2dp_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = HID + A2DP + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8822B_1ANT_COEX_ALGO_HID_A2DP; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = HID + A2DP + PAN(EDR)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8822B_1ANT_COEX_ALGO_HID_A2DP_PANEDR; - } - } - } - } else if (num_of_diff_profile >= 3) { - if (bt_link_info->sco_exist) { - if (bt_link_info->hid_exist && - bt_link_info->pan_exist && - bt_link_info->a2dp_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Error!!! BT Profile = SCO + HID + A2DP + PAN(HS)\n"); - BTC_TRACE(trace_buf); - - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Profile = SCO + HID + A2DP + PAN(EDR)==>PAN(EDR)+HID\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8822B_1ANT_COEX_ALGO_PANEDR_HID; - } - } - } - } - - return algorithm; -} - -void halbtc8822b1ant_set_bt_auto_report(IN struct btc_coexist *btcoexist, - IN boolean enable_auto_report) -{ - u8 h2c_parameter[1] = {0}; - - h2c_parameter[0] = 0; - - if (enable_auto_report) - h2c_parameter[0] |= BIT(0); - - btcoexist->btc_fill_h2c(btcoexist, 0x68, 1, h2c_parameter); -} - -void halbtc8822b1ant_bt_auto_report(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean enable_auto_report) -{ - coex_dm->cur_bt_auto_report = enable_auto_report; - - if (!force_exec) { - if (coex_dm->pre_bt_auto_report == coex_dm->cur_bt_auto_report) - return; - } - halbtc8822b1ant_set_bt_auto_report(btcoexist, - coex_dm->cur_bt_auto_report); - - coex_dm->pre_bt_auto_report = coex_dm->cur_bt_auto_report; -} - - - -void halbtc8822b1ant_set_sw_penalty_tx_rate_adaptive(IN struct btc_coexist - *btcoexist, IN boolean low_penalty_ra) -{ - u8 h2c_parameter[6] = {0}; - - h2c_parameter[0] = 0x6; /* op_code, 0x6= Retry_Penalty */ - - if (low_penalty_ra) { - h2c_parameter[1] |= BIT(0); - h2c_parameter[2] = - 0x00; /* normal rate except MCS7/6/5, OFDM54/48/36 */ - h2c_parameter[3] = 0xf7; /* MCS7 or OFDM54 */ - h2c_parameter[4] = 0xf8; /* MCS6 or OFDM48 */ - h2c_parameter[5] = 0xf9; /* MCS5 or OFDM36 */ - } - - btcoexist->btc_fill_h2c(btcoexist, 0x69, 6, h2c_parameter); -} - -void halbtc8822b1ant_low_penalty_ra(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean low_penalty_ra) -{ -#if 1 - coex_dm->cur_low_penalty_ra = low_penalty_ra; - - if (!force_exec) { - if (coex_dm->pre_low_penalty_ra == - coex_dm->cur_low_penalty_ra) - return; - } - - if (low_penalty_ra) - btcoexist->btc_phydm_modify_RA_PCR_threshold(btcoexist, 0, 25); - else - btcoexist->btc_phydm_modify_RA_PCR_threshold(btcoexist, 0, 0); - - coex_dm->pre_low_penalty_ra = coex_dm->cur_low_penalty_ra; - -#endif -} - -void halbtc8822b1ant_write_score_board( - IN struct btc_coexist *btcoexist, - IN u16 bitpos, - IN boolean state -) -{ - - static u16 originalval = 0x8002; - - if (state) - originalval = originalval | bitpos; - else - originalval = originalval & (~bitpos); - - btcoexist->btc_write_2byte(btcoexist, 0xaa, originalval); -} - -void halbtc8822b1ant_read_score_board( - IN struct btc_coexist *btcoexist, - IN u16 *score_board_val -) -{ - - *score_board_val = (btcoexist->btc_read_2byte(btcoexist, - 0xaa)) & 0x7fff; -} - -void halbtc8822b1ant_post_state_to_bt( - IN struct btc_coexist *btcoexist, - IN u16 type, - IN boolean state -) -{ - - halbtc8822b1ant_write_score_board(btcoexist, (u16) type, state); - -} - - -void halbtc8822b1ant_monitor_bt_enable_disable(IN struct btc_coexist *btcoexist) -{ - static u32 bt_disable_cnt = 0; - boolean bt_active = true, bt_disabled = false, - wifi_under_5g = false; - u16 u16tmp; - - /* This function check if bt is disabled */ -#if 0 - if (coex_sta->high_priority_tx == 0 && - coex_sta->high_priority_rx == 0 && - coex_sta->low_priority_tx == 0 && - coex_sta->low_priority_rx == 0) - bt_active = false; - if (coex_sta->high_priority_tx == 0xffff && - coex_sta->high_priority_rx == 0xffff && - coex_sta->low_priority_tx == 0xffff && - coex_sta->low_priority_rx == 0xffff) - bt_active = false; - - -#else - - /* Read BT on/off status from scoreboard[1], enable this only if BT patch support this feature */ - halbtc8822b1ant_read_score_board(btcoexist, &u16tmp); - - bt_active = u16tmp & BIT(1); - - -#endif - - if (bt_active) { - bt_disable_cnt = 0; - bt_disabled = false; - btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_DISABLE, - &bt_disabled); - } else { - - bt_disable_cnt++; - if (bt_disable_cnt >= 2) { - bt_disabled = true; - bt_disable_cnt = 2; - } - - btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_DISABLE, - &bt_disabled); - } - - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, - &wifi_under_5g); - - if ((wifi_under_5g) || (bt_disabled)) - halbtc8822b1ant_low_penalty_ra(btcoexist, - NORMAL_EXEC, false); - else - halbtc8822b1ant_low_penalty_ra(btcoexist, - NORMAL_EXEC, true); - - - if (coex_sta->bt_disabled != bt_disabled) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT is from %s to %s!!\n", - (coex_sta->bt_disabled ? "disabled" : - "enabled"), - (bt_disabled ? "disabled" : "enabled")); - BTC_TRACE(trace_buf); - coex_sta->bt_disabled = bt_disabled; - } - -} - - - -void halbtc8822b1ant_enable_gnt_to_gpio(IN struct btc_coexist *btcoexist, - boolean isenable) -{ - static u8 bitVal[5] = {0, 0, 0, 0, 0}; - static boolean state = false; - - if (state == isenable) - return; - - state = isenable; - - if (isenable) { - - /* enable GNT_WL, GNT_BT to GPIO for debug */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x73, 0x8, 0x1); - - /* store original value */ - bitVal[0] = (btcoexist->btc_read_1byte(btcoexist, - 0x66) & BIT(4)) >> 4; /*0x66[4] */ - bitVal[1] = (btcoexist->btc_read_1byte(btcoexist, - 0x67) & BIT(0)); /*0x66[8] */ - bitVal[2] = (btcoexist->btc_read_1byte(btcoexist, - 0x42) & BIT(3)) >> 3; /*0x40[19] */ - bitVal[3] = (btcoexist->btc_read_1byte(btcoexist, - 0x65) & BIT(7)) >> 7; /*0x64[15] */ - bitVal[4] = (btcoexist->btc_read_1byte(btcoexist, - 0x72) & BIT(2)) >> 2; /*0x70[18] */ - - /* switch GPIO Mux */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x66, BIT(4), - 0x0); /*0x66[4] = 0 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, BIT(0), - 0x0); /*0x66[8] = 0 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x42, BIT(3), - 0x0); /*0x40[19] = 0 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x65, BIT(7), - 0x0); /*0x64[15] = 0 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x72, BIT(2), - 0x0); /*0x70[18] = 0 */ - - - } else { - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x73, 0x8, 0x0); - - /* Restore original value */ - /* switch GPIO Mux */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x66, BIT(4), - bitVal[0]); /*0x66[4] = 0 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, BIT(0), - bitVal[1]); /*0x66[8] = 0 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x42, BIT(3), - bitVal[2]); /*0x40[19] = 0 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x65, BIT(7), - bitVal[3]); /*0x64[15] = 0 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x72, BIT(2), - bitVal[4]); /*0x70[18] = 0 */ - } - -} - - -u32 halbtc8822b1ant_ltecoex_indirect_read_reg(IN struct btc_coexist *btcoexist, - IN u16 reg_addr) -{ - u32 j = 0; - - - /* wait for ready bit before access 0x1700 */ - btcoexist->btc_write_4byte(btcoexist, 0x1700, 0x800F0000 | reg_addr); - - do { - j++; - } while (((btcoexist->btc_read_1byte(btcoexist, - 0x1703) & BIT(5)) == 0) && - (j < BT_8822B_1ANT_LTECOEX_INDIRECTREG_ACCESS_TIMEOUT)); - - - return btcoexist->btc_read_4byte(btcoexist, - 0x1708); /* get read data */ - -} - -void halbtc8822b1ant_ltecoex_indirect_write_reg(IN struct btc_coexist - *btcoexist, - IN u16 reg_addr, IN u32 bit_mask, IN u32 reg_value) -{ - u32 val, i = 0, j = 0, bitpos = 0; - - - if (bit_mask == 0x0) - return; - if (bit_mask == 0xffffffff) { - btcoexist->btc_write_4byte(btcoexist, 0x1704, - reg_value); /* put write data */ - - /* wait for ready bit before access 0x1700 */ - do { - j++; - } while (((btcoexist->btc_read_1byte(btcoexist, - 0x1703) & BIT(5)) == 0) && - (j < BT_8822B_1ANT_LTECOEX_INDIRECTREG_ACCESS_TIMEOUT)); - - - btcoexist->btc_write_4byte(btcoexist, 0x1700, - 0xc00F0000 | reg_addr); - } else { - for (i = 0; i <= 31; i++) { - if (((bit_mask >> i) & 0x1) == 0x1) { - bitpos = i; - break; - } - } - - /* read back register value before write */ - val = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist, - reg_addr); - val = (val & (~bit_mask)) | (reg_value << bitpos); - - /* put write data value */ - btcoexist->btc_write_4byte(btcoexist, 0x1704, - val); /* put write data */ - - /* wait for ready bit before access 0x1700 */ - do { - j++; - } while (((btcoexist->btc_read_1byte(btcoexist, - 0x1703) & BIT(5)) == 0) && - (j < BT_8822B_1ANT_LTECOEX_INDIRECTREG_ACCESS_TIMEOUT)); - - /* write data add*/ - - btcoexist->btc_write_4byte(btcoexist, 0x1700, - 0xc00F0000 | reg_addr); - - } - -} - -void halbtc8822b1ant_ltecoex_enable(IN struct btc_coexist *btcoexist, - IN boolean enable) -{ - u8 val; - - val = (enable) ? 1 : 0; - /* 0x38[7] */ - halbtc8822b1ant_ltecoex_indirect_write_reg(btcoexist, 0x38, 0x80, - val); /* 0x38[7] */ - -} - - -void halbtc8822b1ant_ltecoex_pathcontrol_owner(IN struct btc_coexist *btcoexist, - IN boolean wifi_control) -{ - u8 val; - - val = (wifi_control) ? 1 : 0; - /* 0x70[26] */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x73, 0x4, - val); /* 0x70[26] */ - -} - -void halbtc8822b1ant_ltecoex_set_gnt_bt(IN struct btc_coexist *btcoexist, - IN u8 control_block, IN boolean sw_control, IN u8 state) -{ - u32 val = 0, bit_mask; - - state = state & 0x1; - /*LTE indirect 0x38=0xccxx (sw : gnt_wl=1,sw gnt_bt=1) - 0x38=0xddxx (sw : gnt_bt=1 , sw gnt_wl=0) - 0x38=0x55xx(hw pta :gnt_wl /gnt_bt ) */ - val = (sw_control) ? ((state << 1) | 0x1) : 0; - - switch (control_block) { - case BT_8822B_1ANT_GNT_BLOCK_RFC_BB: - default: - bit_mask = 0xc000; - halbtc8822b1ant_ltecoex_indirect_write_reg(btcoexist, - 0x38, bit_mask, val); /* 0x38[15:14] */ - bit_mask = 0x0c00; - halbtc8822b1ant_ltecoex_indirect_write_reg(btcoexist, - 0x38, bit_mask, val); /* 0x38[11:10] */ - break; - case BT_8822B_1ANT_GNT_BLOCK_RFC: - bit_mask = 0xc000; - halbtc8822b1ant_ltecoex_indirect_write_reg(btcoexist, - 0x38, bit_mask, val); /* 0x38[15:14] */ - break; - case BT_8822B_1ANT_GNT_BLOCK_BB: - bit_mask = 0x0c00; - halbtc8822b1ant_ltecoex_indirect_write_reg(btcoexist, - 0x38, bit_mask, val); /* 0x38[11:10] */ - break; - - } - -} - -void halbtc8822b1ant_ltecoex_set_gnt_wl(IN struct btc_coexist *btcoexist, - IN u8 control_block, IN boolean sw_control, IN u8 state) -{ - u32 val = 0, bit_mask; - /*LTE indirect 0x38=0xccxx (sw : gnt_wl=1,sw gnt_bt=1) - 0x38=0xddxx (sw : gnt_bt=1 , sw gnt_wl=0) - 0x38=0x55xx(hw pta :gnt_wl /gnt_bt ) */ - - state = state & 0x1; - val = (sw_control) ? ((state << 1) | 0x1) : 0; - - switch (control_block) { - case BT_8822B_1ANT_GNT_BLOCK_RFC_BB: - default: - bit_mask = 0x3000; - halbtc8822b1ant_ltecoex_indirect_write_reg(btcoexist, - 0x38, bit_mask, val); /* 0x38[13:12] */ - bit_mask = 0x0300; - halbtc8822b1ant_ltecoex_indirect_write_reg(btcoexist, - 0x38, bit_mask, val); /* 0x38[9:8] */ - break; - case BT_8822B_1ANT_GNT_BLOCK_RFC: - bit_mask = 0x3000; - halbtc8822b1ant_ltecoex_indirect_write_reg(btcoexist, - 0x38, bit_mask, val); /* 0x38[13:12] */ - break; - case BT_8822B_1ANT_GNT_BLOCK_BB: - bit_mask = 0x0300; - halbtc8822b1ant_ltecoex_indirect_write_reg(btcoexist, - 0x38, bit_mask, val); /* 0x38[9:8] */ - break; - - } - -} - -void halbtc8822b1ant_ltecoex_set_coex_table(IN struct btc_coexist *btcoexist, - IN u8 table_type, IN u16 table_content) -{ - u16 reg_addr = 0x0000; - - switch (table_type) { - case BT_8822B_1ANT_CTT_WL_VS_LTE: - reg_addr = 0xa0; - break; - case BT_8822B_1ANT_CTT_BT_VS_LTE: - reg_addr = 0xa4; - break; - } - - if (reg_addr != 0x0000) - halbtc8822b1ant_ltecoex_indirect_write_reg(btcoexist, reg_addr, - 0xffff, table_content); /* 0xa0[15:0] or 0xa4[15:0] */ - - -} - - -void halbtc8822b1ant_ltcoex_set_break_table(IN struct btc_coexist *btcoexist, - IN u8 table_type, IN u8 table_content) -{ - u16 reg_addr = 0x0000; - - switch (table_type) { - case BT_8822B_1ANT_LBTT_WL_BREAK_LTE: - reg_addr = 0xa8; - break; - case BT_8822B_1ANT_LBTT_BT_BREAK_LTE: - reg_addr = 0xac; - break; - case BT_8822B_1ANT_LBTT_LTE_BREAK_WL: - reg_addr = 0xb0; - break; - case BT_8822B_1ANT_LBTT_LTE_BREAK_BT: - reg_addr = 0xb4; - break; - } - - if (reg_addr != 0x0000) - halbtc8822b1ant_ltecoex_indirect_write_reg(btcoexist, reg_addr, - 0xff, table_content); /* 0xa8[15:0] or 0xb4[15:0] */ - - -} - -void halbtc8822b1ant_set_wltoggle_coex_table(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 interval, - IN u8 val0x6c4_b0, IN u8 val0x6c4_b1, IN u8 val0x6c4_b2, - IN u8 val0x6c4_b3) -{ - static u8 pre_h2c_parameter[6] = {0}; - u8 cur_h2c_parameter[6] = {0}; - u8 i, match_cnt = 0; - - cur_h2c_parameter[0] = 0x7; /* op_code, 0x7= wlan toggle slot*/ - - cur_h2c_parameter[1] = interval; - cur_h2c_parameter[2] = val0x6c4_b0; - cur_h2c_parameter[3] = val0x6c4_b1; - cur_h2c_parameter[4] = val0x6c4_b2; - cur_h2c_parameter[5] = val0x6c4_b3; - - if (!force_exec) { - for (i = 1; i <= 5; i++) { - if (cur_h2c_parameter[i] != pre_h2c_parameter[i]) - break; - - match_cnt++; - } - - if (match_cnt == 5) - return; - } - - for (i = 1; i <= 5; i++) - pre_h2c_parameter[i] = cur_h2c_parameter[i]; - - btcoexist->btc_fill_h2c(btcoexist, 0x69, 6, cur_h2c_parameter); -} - -void halbtc8822b1ant_set_coex_table(IN struct btc_coexist *btcoexist, - IN u32 val0x6c0, IN u32 val0x6c4, IN u32 val0x6c8, IN u8 val0x6cc) -{ - btcoexist->btc_write_4byte(btcoexist, 0x6c0, val0x6c0); - - btcoexist->btc_write_4byte(btcoexist, 0x6c4, val0x6c4); - - btcoexist->btc_write_4byte(btcoexist, 0x6c8, val0x6c8); - - btcoexist->btc_write_1byte(btcoexist, 0x6cc, val0x6cc); -} - -void halbtc8822b1ant_coex_table(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u32 val0x6c0, IN u32 val0x6c4, - IN u32 val0x6c8, IN u8 val0x6cc) -{ - coex_dm->cur_val0x6c0 = val0x6c0; - coex_dm->cur_val0x6c4 = val0x6c4; - coex_dm->cur_val0x6c8 = val0x6c8; - coex_dm->cur_val0x6cc = val0x6cc; - - - - if (!force_exec) { - if ((coex_dm->pre_val0x6c0 == coex_dm->cur_val0x6c0) && - (coex_dm->pre_val0x6c4 == coex_dm->cur_val0x6c4) && - (coex_dm->pre_val0x6c8 == coex_dm->cur_val0x6c8) && - (coex_dm->pre_val0x6cc == coex_dm->cur_val0x6cc)) - return; - } - halbtc8822b1ant_set_coex_table(btcoexist, val0x6c0, val0x6c4, val0x6c8, - val0x6cc); - - coex_dm->pre_val0x6c0 = coex_dm->cur_val0x6c0; - coex_dm->pre_val0x6c4 = coex_dm->cur_val0x6c4; - coex_dm->pre_val0x6c8 = coex_dm->cur_val0x6c8; - coex_dm->pre_val0x6cc = coex_dm->cur_val0x6cc; -} - -void halbtc8822b1ant_coex_table_with_type(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 type) -{ - u32 break_table; - u8 select_table; - - - - coex_sta->coex_table_type = type; - - if (coex_sta->concurrent_rx_mode_on == true) { - break_table = 0xf0ffffff; /* set WL hi-pri can break BT */ - select_table = 0x3; /* set Tx response = Hi-Pri (ex: Transmitting ACK,BA,CTS) */ - } else { - break_table = 0xffffff; - select_table = 0x3; - } - - switch (type) { - case 0: - halbtc8822b1ant_coex_table(btcoexist, force_exec, - 0x55555555, 0x55555555, break_table, - select_table); - break; - case 1: - halbtc8822b1ant_coex_table(btcoexist, force_exec, - 0x55555555, 0x5a5a5a5a, break_table, - select_table); - break; - case 2: - halbtc8822b1ant_coex_table(btcoexist, force_exec, - 0xaa5a5a5a, 0xaa5a5a5a, break_table, - select_table); - break; - case 3: - halbtc8822b1ant_coex_table(btcoexist, force_exec, - 0x55555555, 0xaa5a5a5a, break_table, - select_table); - break; - case 4: - halbtc8822b1ant_coex_table(btcoexist, - force_exec, 0xaa555555, 0xaa5a5a5a, - break_table, select_table); - break; - case 5: - halbtc8822b1ant_coex_table(btcoexist, - force_exec, 0x5a5a5a5a, 0x5a5a5a5a, - break_table, select_table); - break; - case 6: - halbtc8822b1ant_coex_table(btcoexist, force_exec, - 0x55555555, 0xaaaaaaaa, break_table, - select_table); - break; - case 7: - halbtc8822b1ant_coex_table(btcoexist, force_exec, - 0xaaaaaaaa, 0xaaaaaaaa, break_table, - select_table); - break; - case 8: - halbtc8822b1ant_coex_table(btcoexist, force_exec, - 0xffffffff, 0xffffffff, break_table, - select_table); - break; - case 9: - halbtc8822b1ant_coex_table(btcoexist, force_exec, - 0x5a5a5555, 0xaaaa5a5a, break_table, - select_table); - break; - case 10: - halbtc8822b1ant_coex_table(btcoexist, force_exec, - 0xaaaa5aaa, 0xaaaa5aaa, break_table, - select_table); - break; - case 11: - halbtc8822b1ant_coex_table(btcoexist, force_exec, - 0xaaaaa5aa, 0xaaaaaaaa, break_table, - select_table); - break; - case 12: - halbtc8822b1ant_coex_table(btcoexist, force_exec, - 0xaaaaa5aa, 0xaaaaa5aa, break_table, - select_table); - break; - case 13: - halbtc8822b1ant_coex_table(btcoexist, force_exec, - 0x55555555, 0xaaaa5a5a, break_table, - select_table); - break; - case 14: - halbtc8822b1ant_coex_table(btcoexist, force_exec, - 0x5a5a555a, 0xaaaa5a5a, break_table, - select_table); - break; - case 15: - halbtc8822b1ant_coex_table(btcoexist, force_exec, - 0x55555555, 0xaaaa55aa, break_table, - select_table); - break; - case 16: - halbtc8822b1ant_coex_table(btcoexist, force_exec, - 0x5a5a555a, 0x5a5a555a, break_table, - select_table); - break; - - default: - break; - } -} - -void halbtc8822b1ant_set_fw_ignore_wlan_act(IN struct btc_coexist *btcoexist, - IN boolean enable) -{ - - - u8 h2c_parameter[1] = {0}; - - if (enable) - h2c_parameter[0] |= BIT(0); /* function enable */ - - btcoexist->btc_fill_h2c(btcoexist, 0x63, 1, h2c_parameter); -} - -void halbtc8822b1ant_ignore_wlan_act(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean enable) -{ - - coex_dm->cur_ignore_wlan_act = enable; - - if (!force_exec) { - if (coex_dm->pre_ignore_wlan_act == - coex_dm->cur_ignore_wlan_act) { - - coex_dm->pre_ignore_wlan_act = - coex_dm->cur_ignore_wlan_act; - return; - } - } - - halbtc8822b1ant_set_fw_ignore_wlan_act(btcoexist, enable); - - coex_dm->pre_ignore_wlan_act = coex_dm->cur_ignore_wlan_act; -} - -void halbtc8822b1ant_set_lps_rpwm(IN struct btc_coexist *btcoexist, - IN u8 lps_val, IN u8 rpwm_val) -{ - u8 lps = lps_val; - u8 rpwm = rpwm_val; - - btcoexist->btc_set(btcoexist, BTC_SET_U1_LPS_VAL, &lps); - btcoexist->btc_set(btcoexist, BTC_SET_U1_RPWM_VAL, &rpwm); -} - -void halbtc8822b1ant_lps_rpwm(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 lps_val, IN u8 rpwm_val) -{ - coex_dm->cur_lps = lps_val; - coex_dm->cur_rpwm = rpwm_val; - - if (!force_exec) { - if ((coex_dm->pre_lps == coex_dm->cur_lps) && - (coex_dm->pre_rpwm == coex_dm->cur_rpwm)) - return; - } - halbtc8822b1ant_set_lps_rpwm(btcoexist, lps_val, rpwm_val); - - coex_dm->pre_lps = coex_dm->cur_lps; - coex_dm->pre_rpwm = coex_dm->cur_rpwm; -} - -void halbtc8822b1ant_ps_tdma_check_for_power_save_state( - IN struct btc_coexist *btcoexist, IN boolean new_ps_state) -{ - u8 lps_mode = 0x0; - u8 h2c_parameter[5] = {0x8, 0, 0, 0, 0}; - - btcoexist->btc_get(btcoexist, BTC_GET_U1_LPS_MODE, &lps_mode); - - if (lps_mode) { /* already under LPS state */ - if (new_ps_state) { - /* keep state under LPS, do nothing. */ - } else { - /* will leave LPS state, turn off psTdma first */ - - btcoexist->btc_fill_h2c(btcoexist, 0x60, 5, - h2c_parameter); - } - } else { /* NO PS state */ - if (new_ps_state) { - /* will enter LPS state, turn off psTdma first */ - - btcoexist->btc_fill_h2c(btcoexist, 0x60, 5, - h2c_parameter); - } else { - /* keep state under NO PS state, do nothing. */ - } - } -} - - -void halbtc8822b1ant_power_save_state(IN struct btc_coexist *btcoexist, - IN u8 ps_type, IN u8 lps_val, IN u8 rpwm_val) -{ - boolean low_pwr_disable = false; - - switch (ps_type) { - case BTC_PS_WIFI_NATIVE: - /* recover to original 32k low power setting */ - coex_sta->force_lps_on = false; - low_pwr_disable = false; - btcoexist->btc_set(btcoexist, - BTC_SET_ACT_DISABLE_LOW_POWER, - &low_pwr_disable); - btcoexist->btc_set(btcoexist, BTC_SET_ACT_NORMAL_LPS, - NULL); - coex_sta->force_lps_on = false; - break; - case BTC_PS_LPS_ON: - - coex_sta->force_lps_on = true; - halbtc8822b1ant_ps_tdma_check_for_power_save_state( - btcoexist, true); - halbtc8822b1ant_lps_rpwm(btcoexist, NORMAL_EXEC, - lps_val, rpwm_val); - /* when coex force to enter LPS, do not enter 32k low power. */ - low_pwr_disable = true; - btcoexist->btc_set(btcoexist, - BTC_SET_ACT_DISABLE_LOW_POWER, - &low_pwr_disable); - /* power save must executed before psTdma. */ - btcoexist->btc_set(btcoexist, BTC_SET_ACT_ENTER_LPS, - NULL); - coex_sta->force_lps_on = true; - break; - case BTC_PS_LPS_OFF: - - coex_sta->force_lps_on = false; - halbtc8822b1ant_ps_tdma_check_for_power_save_state( - btcoexist, false); - btcoexist->btc_set(btcoexist, BTC_SET_ACT_LEAVE_LPS, - NULL); - coex_sta->force_lps_on = false; - break; - default: - break; - } -} - - -void halbtc8822b1ant_set_fw_pstdma(IN struct btc_coexist *btcoexist, - IN u8 byte1, IN u8 byte2, IN u8 byte3, IN u8 byte4, IN u8 byte5) -{ - u8 h2c_parameter[5] = {0}; - u8 real_byte1 = byte1, real_byte5 = byte5; - boolean ap_enable = false; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, - &ap_enable); - - if (ap_enable) { - if (byte1 & BIT(4) && !(byte1 & BIT(5))) { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], FW for 1Ant AP mode\n"); - BTC_TRACE(trace_buf); - - real_byte1 &= ~BIT(4); - real_byte1 |= BIT(5); - - real_byte5 |= BIT(5); - real_byte5 &= ~BIT(6); - - halbtc8822b1ant_power_save_state(btcoexist, - BTC_PS_WIFI_NATIVE, 0x0, - 0x0); - } - } else if (byte1 & BIT(4) && !(byte1 & BIT(5))) { - - halbtc8822b1ant_power_save_state(btcoexist, - BTC_PS_LPS_ON, 0x50, - 0x4); - } else { - halbtc8822b1ant_power_save_state(btcoexist, - BTC_PS_WIFI_NATIVE, 0x0, - 0x0); - } - - - h2c_parameter[0] = real_byte1; - h2c_parameter[1] = byte2; - h2c_parameter[2] = byte3; - h2c_parameter[3] = byte4; - h2c_parameter[4] = real_byte5; - - coex_dm->ps_tdma_para[0] = real_byte1; - coex_dm->ps_tdma_para[1] = byte2; - coex_dm->ps_tdma_para[2] = byte3; - coex_dm->ps_tdma_para[3] = byte4; - coex_dm->ps_tdma_para[4] = real_byte5; - - btcoexist->btc_fill_h2c(btcoexist, 0x60, 5, h2c_parameter); -} - -void halbtc8822b1ant_ps_tdma(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean turn_on, IN u8 type) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - struct btc_board_info *board_info = &btcoexist->board_info; - boolean wifi_busy = false; - static u8 psTdmaByte4Modify = 0x0, pre_psTdmaByte4Modify = 0x0; - static boolean pre_wifi_busy = false; - - coex_dm->cur_ps_tdma_on = turn_on; - coex_dm->cur_ps_tdma = type; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - - if (wifi_busy != pre_wifi_busy) { - force_exec = true; - pre_wifi_busy = wifi_busy; - } - - /* 0x778 = 0x1 at wifi slot (no blocking BT Low-Pri pkts) */ - if ((bt_link_info->slave_role) && (bt_link_info->a2dp_exist)) - psTdmaByte4Modify = 0x1; - else - psTdmaByte4Modify = 0x0; - - if (pre_psTdmaByte4Modify != psTdmaByte4Modify) { - - force_exec = true; - pre_psTdmaByte4Modify = psTdmaByte4Modify; - } - - if (coex_dm->cur_ps_tdma_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********TDMA(on, %d) **********\n", - coex_dm->cur_ps_tdma); - BTC_TRACE(trace_buf); - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], **********TDMA(off, %d) **********\n", - coex_dm->cur_ps_tdma); - BTC_TRACE(trace_buf); - } - - if (!force_exec) { - if ((coex_dm->pre_ps_tdma_on == coex_dm->cur_ps_tdma_on) && - (coex_dm->pre_ps_tdma == coex_dm->cur_ps_tdma)) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], return for no-TDMA case change\n"); - BTC_TRACE(trace_buf); - - return; - } - } - - - if (turn_on) { - - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x550, 0x8, - 0x1); /* enable TBTT nterrupt */ - - switch (type) { - default: - halbtc8822b1ant_set_fw_pstdma(btcoexist, - 0x51, 0x1a, 0x1a, 0x0, 0x10); - break; - case 1: - halbtc8822b1ant_set_fw_pstdma(btcoexist, - 0x61, 0x3a, 0x03, 0x11, 0x10); - break; - case 3: - halbtc8822b1ant_set_fw_pstdma(btcoexist, - 0x51, 0x3a, 0x03, 0x10, 0x10); - break; - case 4: - halbtc8822b1ant_set_fw_pstdma(btcoexist, - 0x51, 0x21, 0x03, 0x10, 0x10); - break; - case 5: - halbtc8822b1ant_set_fw_pstdma(btcoexist, - 0x61, 0x15, 0x3, 0x11, 0x11); - break; - case 7: - halbtc8822b1ant_set_fw_pstdma(btcoexist, - 0x61, 0x10, 0x03, 0x10, 0x14 | - psTdmaByte4Modify); - break; - case 8: - halbtc8822b1ant_set_fw_pstdma(btcoexist, - 0x51, 0x10, 0x03, 0x10, 0x14 | - psTdmaByte4Modify); - break; - case 13: - halbtc8822b1ant_set_fw_pstdma(btcoexist, - 0x51, 0x25, 0x03, 0x10, 0x10 | - psTdmaByte4Modify); - break; - case 14: - halbtc8822b1ant_set_fw_pstdma(btcoexist, - 0x51, 0x15, 0x03, 0x10, 0x10 | - psTdmaByte4Modify); - break; - case 15: - halbtc8822b1ant_set_fw_pstdma(btcoexist, - 0x51, 0x20, 0x03, 0x10, 0x10 | - psTdmaByte4Modify); - break; - case 17: - halbtc8822b1ant_set_fw_pstdma(btcoexist, - 0x61, 0x10, 0x03, 0x11, 0x14 | - psTdmaByte4Modify); - break; - - case 20: - halbtc8822b1ant_set_fw_pstdma(btcoexist, - 0x61, 0x30, 0x03, 0x11, 0x10); - break; - case 22: - halbtc8822b1ant_set_fw_pstdma(btcoexist, - 0x61, 0x25, 0x03, 0x11, 0x10); - break; - case 32: - halbtc8822b1ant_set_fw_pstdma(btcoexist, - 0x61, 0x35, 0x3, 0x11, 0x11); - break; - case 33: - halbtc8822b1ant_set_fw_pstdma(btcoexist, - 0x61, 0x35, 0x03, 0x11, 0x10); - break; - case 41: - halbtc8822b1ant_set_fw_pstdma(btcoexist, - 0x51, 0x45, 0x3, 0x11, 0x11); - break; - case 42: - halbtc8822b1ant_set_fw_pstdma(btcoexist, - 0x51, 0x1e, 0x3, 0x10, 0x14 | - psTdmaByte4Modify); - break; - case 43: - halbtc8822b1ant_set_fw_pstdma(btcoexist, - 0x51, 0x45, 0x3, 0x10, 0x14); - break; - case 44: - halbtc8822b1ant_set_fw_pstdma(btcoexist, - 0x51, 0x25, 0x3, 0x10, 0x10); - break; - case 45: - halbtc8822b1ant_set_fw_pstdma(btcoexist, - 0x51, 0x29, 0x3, 0x10, 0x10); - break; - case 46: - halbtc8822b1ant_set_fw_pstdma(btcoexist, - 0x51, 0x1a, 0x3, 0x10, 0x10); - break; - case 47: - halbtc8822b1ant_set_fw_pstdma(btcoexist, - 0x51, 0x32, 0x3, 0x10, 0x10); - break; - case 48: - halbtc8822b1ant_set_fw_pstdma(btcoexist, - 0x51, 0x29, 0x3, 0x10, 0x10); - break; - case 49: - halbtc8822b1ant_set_fw_pstdma(btcoexist, - 0x55, 0x1e, 0x3, 0x10, 0x54); - break; - - } - } else { - - switch (type) { - case 0: - default: /* Software control, Antenna at BT side */ - halbtc8822b1ant_set_fw_pstdma(btcoexist, - 0x0, 0x0, 0x0, 0x0, 0x0); - /* - halbtc8822b1ant_set_ant_path(btcoexist, - BTC_ANT_PATH_BT, FORCE_EXEC, false, - false); */ - break; - case 8: /* PTA Control */ - halbtc8822b1ant_set_fw_pstdma(btcoexist, - 0x8, 0x0, 0x0, 0x0, 0x0); - /* - halbtc8822b1ant_set_ant_path(btcoexist, - BTC_ANT_PATH_PTA, FORCE_EXEC, false, - false); */ - break; - case 9: /* Software control, Antenna at WiFi side */ - halbtc8822b1ant_set_fw_pstdma(btcoexist, - 0x0, 0x0, 0x0, 0x0, 0x0); - /* - halbtc8822b1ant_set_ant_path(btcoexist, - BTC_ANT_PATH_WIFI, FORCE_EXEC,false,false); */ - break; - case 10: /* under 5G , 0x778=1*/ - halbtc8822b1ant_set_fw_pstdma(btcoexist, - 0x0, 0x0, 0x0, 0x0, 0x0); - - /* - halbtc8822b1ant_set_ant_path(btcoexist, - BTC_ANT_PATH_WIFI5G, FORCE_EXEC, false, - false); */ - - break; - } - } - - - /* update pre state */ - coex_dm->pre_ps_tdma_on = coex_dm->cur_ps_tdma_on; - coex_dm->pre_ps_tdma = coex_dm->cur_ps_tdma; -} - - -void halbtc8822b1ant_sw_mechanism(IN struct btc_coexist *btcoexist, - IN boolean low_penalty_ra) -{ - halbtc8822b1ant_low_penalty_ra(btcoexist, NORMAL_EXEC, low_penalty_ra); -} -/*rf4 type by efuse , and for ant at main aux inverse use , because is 2x2 ,and control types are the same ,does not need */ - -void halbtc8822b1ant_set_rfe_type(IN struct btc_coexist *btcoexist) -{ - struct btc_board_info *board_info = &btcoexist->board_info; - - /* Ext switch buffer mux */ - btcoexist->btc_write_1byte(btcoexist, 0x974, 0xff); - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x1991, 0x3, 0x0); - btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbe, 0x8, 0x0); - - /* the following setup should be got from Efuse in the future */ - rfe_type->rfe_module_type = board_info->rfe_type; - - rfe_type->ext_ant_switch_ctrl_polarity = 0; - - switch (rfe_type->rfe_module_type) { - case 0: - default: - rfe_type->ext_ant_switch_exist = true; - rfe_type->ext_ant_switch_type = - BT_8822B_1ANT_EXT_ANT_SWITCH_USE_SPDT; - break; - case 1: - rfe_type->ext_ant_switch_exist = true; - rfe_type->ext_ant_switch_type = - BT_8822B_1ANT_EXT_ANT_SWITCH_USE_SPDT; - break; - case 2: - rfe_type->ext_ant_switch_exist = true; - rfe_type->ext_ant_switch_type = - BT_8822B_1ANT_EXT_ANT_SWITCH_USE_SPDT; - break; - case 3: - rfe_type->ext_ant_switch_exist = true; - rfe_type->ext_ant_switch_type = - BT_8822B_1ANT_EXT_ANT_SWITCH_USE_SPDT; - break; - case 4: - rfe_type->ext_ant_switch_exist = true; - rfe_type->ext_ant_switch_type = - BT_8822B_1ANT_EXT_ANT_SWITCH_USE_SP3T; /* SP3T */; - break; - } - - -} - -/*anttenna control by bb mac bt antdiv pta to write 0x4c 0xcb4,0xcbd*/ - -void halbtc8822b1ant_set_ext_ant_switch(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 ctrl_type, IN u8 pos_type) -{ - struct btc_board_info *board_info = &btcoexist->board_info; - boolean switch_polatiry_inverse = false; - u8 regval_0xcbd = 0, regval_0x64; - u32 u32tmp1 = 0, u32tmp2 = 0, u32tmp3 = 0; - /* Ext switch buffer mux */ - btcoexist->btc_write_1byte(btcoexist, 0x974, 0xff); - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x1991, 0x3, 0x0); - btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbe, 0x8, 0x0); - - if (!rfe_type->ext_ant_switch_exist) - return; - - coex_dm->cur_ext_ant_switch_status = (ctrl_type << 8) + pos_type; - - if (!force_exec) { - if (coex_dm->pre_ext_ant_switch_status == - coex_dm->cur_ext_ant_switch_status) - return; - } - - coex_dm->pre_ext_ant_switch_status = coex_dm->cur_ext_ant_switch_status; - - /* swap control polarity if use different switch control polarity*/ - /* Normal switch polarity for SPDT, 0xcbd[1:0] = 2b'01 => Ant to BTG, 0xcbd[1:0] = 2b'10 => Ant to WLG */ - switch_polatiry_inverse = (rfe_type->ext_ant_switch_ctrl_polarity == 1 ? - ~switch_polatiry_inverse : switch_polatiry_inverse); - - - switch (pos_type) { - default: - case BT_8822B_1ANT_EXT_ANT_SWITCH_TO_BT: - case BT_8822B_1ANT_EXT_ANT_SWITCH_TO_NOCARE: - - break; - case BT_8822B_1ANT_EXT_ANT_SWITCH_TO_WLG: - break; - case BT_8822B_1ANT_EXT_ANT_SWITCH_TO_WLA: - break; - } - - - if (rfe_type->ext_ant_switch_type == - BT_8822B_1ANT_EXT_ANT_SWITCH_USE_SPDT) { - switch (ctrl_type) { - default: - case BT_8822B_1ANT_EXT_ANT_SWITCH_CTRL_BY_BBSW: - btcoexist->btc_write_1byte_bitmask( - btcoexist, 0x4e, 0x80, - 0x0); /* 0x4c[23] = 0 */ - btcoexist->btc_write_1byte_bitmask( - btcoexist, 0x4f, 0x01, - 0x1); /* 0x4c[24] = 1 */ - btcoexist->btc_write_1byte_bitmask( - btcoexist, 0xcb4, 0xff, - 0x77); /* BB SW, DPDT use RFE_ctrl8 and RFE_ctrl9 as conctrol pin */ - - regval_0xcbd = (switch_polatiry_inverse - == false ? 0x1 : - 0x2); /* 0xcbd[1:0] = 2b'01 for no switch_polatiry_inverse, ANTSWB =1, ANTSW =0 */ - btcoexist->btc_write_1byte_bitmask( - btcoexist, 0xcbd, 0x3, - regval_0xcbd); - - break; - case BT_8822B_1ANT_EXT_ANT_SWITCH_CTRL_BY_PTA: - btcoexist->btc_write_1byte_bitmask( - btcoexist, 0x4e, 0x80, - 0x0); /* 0x4c[23] = 0 */ - btcoexist->btc_write_1byte_bitmask( - btcoexist, 0x4f, 0x01, - 0x1); /* 0x4c[24] = 1 */ - btcoexist->btc_write_1byte_bitmask( - btcoexist, 0xcb4, 0xff, - 0x66); /* PTA, DPDT use RFE_ctrl8 and RFE_ctrl9 as conctrol pin */ - - regval_0xcbd = (switch_polatiry_inverse - == false ? 0x2 : - 0x1); /* 0xcbd[1:0] = 2b'10 for no switch_polatiry_inverse, ANTSWB =1, ANTSW =0 @ GNT_BT=1 */ - btcoexist->btc_write_1byte_bitmask( - btcoexist, 0xcbd, 0x3, - regval_0xcbd); - - break; - case BT_8822B_1ANT_EXT_ANT_SWITCH_CTRL_BY_ANTDIV - : - btcoexist->btc_write_1byte_bitmask( - btcoexist, 0x4e, 0x80, - 0x0); /* 0x4c[23] = 0 */ - btcoexist->btc_write_1byte_bitmask( - btcoexist, 0x4f, 0x01, - 0x1); /* 0x4c[24] = 1 */ - btcoexist->btc_write_1byte_bitmask( - btcoexist, 0xcb4, 0xff, - 0x88); /* */ - - /* no regval_0xcbd setup required, because antenna switch control value by antenna diversity */ - - break; - case BT_8822B_1ANT_EXT_ANT_SWITCH_CTRL_BY_MAC: - btcoexist->btc_write_1byte_bitmask( - btcoexist, 0x4e, 0x80, - 0x1); /* 0x4c[23] = 1 */ - - regval_0x64 = (switch_polatiry_inverse - == false ? 0x0 : - 0x1); /* 0x64[0] = 1b'0 for no switch_polatiry_inverse, DPDT_SEL_N =1, DPDT_SEL_P =0 */ - btcoexist->btc_write_1byte_bitmask( - btcoexist, 0x64, 0x1, - regval_0x64); - break; - case BT_8822B_1ANT_EXT_ANT_SWITCH_CTRL_BY_BT: - btcoexist->btc_write_1byte_bitmask( - btcoexist, 0x4e, 0x80, - 0x0); /* 0x4c[23] = 0 */ - btcoexist->btc_write_1byte_bitmask( - btcoexist, 0x4f, 0x01, - 0x0); /* 0x4c[24] = 0 */ - - /* no setup required, because antenna switch control value by BT vendor 0xac[1:0] */ - break; - } - } - - u32tmp1 = btcoexist->btc_read_4byte(btcoexist, 0xcbc); - u32tmp2 = btcoexist->btc_read_4byte(btcoexist, 0x4c); - u32tmp3 = btcoexist->btc_read_4byte(btcoexist, 0x64) & 0xff; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** (After Ext Ant switch setup) 0xcbc = 0x%08x, 0x4c = 0x%08x, 0x64= 0x%02x**********\n", - u32tmp1, u32tmp2, u32tmp3); - BTC_TRACE(trace_buf); - - -} - -/*set gnt_wl gnt_bt control by sw high low , or hwpta while in power on,ini,wlan off,wlan only ,wl2g non-currrent ,wl2g current,wl5g*/ - -void halbtc8822b1ant_set_ant_path(IN struct btc_coexist *btcoexist, - IN u8 ant_pos_type, IN boolean force_exec, - IN u8 phase) - -{ - struct btc_board_info *board_info = &btcoexist->board_info; - u8 u8tmp = 0; - u32 u32tmp1 = 0, u32tmp2 = 0, u32tmp3 = 0; - /* Ext switch buffer mux */ - btcoexist->btc_write_1byte(btcoexist, 0x974, 0xff); - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x1991, 0x3, 0x0); - btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbe, 0x8, 0x0); - - coex_dm->cur_ant_pos_type = (ant_pos_type << 8) + phase; - - if (!force_exec) { - if (coex_dm->cur_ant_pos_type == - coex_dm->pre_ant_pos_type) - return; - } - - coex_dm->pre_ant_pos_type = coex_dm->cur_ant_pos_type; - -#if 1 - u32tmp1 = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist, - 0x38); - u32tmp2 = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist, - 0x54); - u32tmp3 = btcoexist->btc_read_4byte(btcoexist, 0xcb4); - - u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x73); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** (Before Ant Setup) 0xcb4 = 0x%x, 0x73 = 0x%x, 0x38= 0x%x, 0x54= 0x%x**********\n", - u32tmp3, u8tmp, u32tmp1, u32tmp2); - BTC_TRACE(trace_buf); -#endif - - switch (phase) { - case BT_8822B_1ANT_PHASE_COEX_INIT: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** (set_ant_path - 1ANT_PHASE_COEX_INIT) **********\n"); - BTC_TRACE(trace_buf); - - /* Disable LTE Coex Function in WiFi side (this should be on if LTE coex is required) */ - halbtc8822b1ant_ltecoex_enable(btcoexist, 0x0); - - /* GNT_WL_LTE always = 1 (this should be config if LTE coex is required) */ - halbtc8822b1ant_ltecoex_set_coex_table(btcoexist, - BT_8822B_1ANT_CTT_WL_VS_LTE, - 0xffff); - - /* GNT_BT_LTE always = 1 (this should be config if LTE coex is required) */ - halbtc8822b1ant_ltecoex_set_coex_table(btcoexist, - BT_8822B_1ANT_CTT_BT_VS_LTE, - 0xffff); - - /* set GNT_BT to SW high */ - halbtc8822b1ant_ltecoex_set_gnt_bt(btcoexist, - BT_8822B_1ANT_GNT_BLOCK_RFC_BB, - BT_8822B_1ANT_GNT_CTRL_BY_SW, - BT_8822B_1ANT_SIG_STA_SET_TO_HIGH); - - /* set GNT_WL to SW low */ - halbtc8822b1ant_ltecoex_set_gnt_wl(btcoexist, - BT_8822B_1ANT_GNT_BLOCK_RFC_BB, - BT_8822B_1ANT_GNT_CTRL_BY_SW, - BT_8822B_1ANT_SIG_STA_SET_TO_LOW); - - /* set Path control owner to WL at initial step */ - halbtc8822b1ant_ltecoex_pathcontrol_owner(btcoexist, - BT_8822B_1ANT_PCO_WLSIDE); - - coex_sta->run_time_state = false; - - /* Ext switch buffer mux */ - btcoexist->btc_write_1byte(btcoexist, 0x974, 0xff); - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x1991, - 0x3, 0x0); - btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbe, - 0x8, 0x0); - - if (BTC_ANT_PATH_AUTO == ant_pos_type) - ant_pos_type = BTC_ANT_PATH_BT; - - break; - case BT_8822B_1ANT_PHASE_WLANONLY_INIT: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** (set_ant_path - 1ANT_PHASE_WLANONLY_INIT) **********\n"); - BTC_TRACE(trace_buf); - - /* Disable LTE Coex Function in WiFi side (this should be on if LTE coex is required) */ - halbtc8822b1ant_ltecoex_enable(btcoexist, 0x0); - - /* GNT_WL_LTE always = 1 (this should be config if LTE coex is required) */ - halbtc8822b1ant_ltecoex_set_coex_table(btcoexist, - BT_8822B_1ANT_CTT_WL_VS_LTE, - 0xffff); - - /* GNT_BT_LTE always = 1 (this should be config if LTE coex is required) */ - halbtc8822b1ant_ltecoex_set_coex_table(btcoexist, - BT_8822B_1ANT_CTT_BT_VS_LTE, - 0xffff); - - /* set GNT_BT to SW Low */ - halbtc8822b1ant_ltecoex_set_gnt_bt(btcoexist, - BT_8822B_1ANT_GNT_BLOCK_RFC_BB, - BT_8822B_1ANT_GNT_CTRL_BY_SW, - BT_8822B_1ANT_SIG_STA_SET_TO_LOW); - - /* Set GNT_WL to SW high */ - halbtc8822b1ant_ltecoex_set_gnt_wl(btcoexist, - BT_8822B_1ANT_GNT_BLOCK_RFC_BB, - BT_8822B_1ANT_GNT_CTRL_BY_SW, - BT_8822B_1ANT_SIG_STA_SET_TO_HIGH); - - /* set Path control owner to WL at initial step */ - halbtc8822b1ant_ltecoex_pathcontrol_owner(btcoexist, - BT_8822B_1ANT_PCO_WLSIDE); - - coex_sta->run_time_state = false; - - /* Ext switch buffer mux */ - btcoexist->btc_write_1byte(btcoexist, 0x974, 0xff); - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x1991, - 0x3, 0x0); - btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbe, - 0x8, 0x0); - - if (BTC_ANT_PATH_AUTO == ant_pos_type) - ant_pos_type = BTC_ANT_PATH_WIFI; - - break; - case BT_8822B_1ANT_PHASE_WLAN_OFF: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** (set_ant_path - 1ANT_PHASE_WLAN_OFF) **********\n"); - BTC_TRACE(trace_buf); - - /* Disable LTE Coex Function in WiFi side */ - halbtc8822b1ant_ltecoex_enable(btcoexist, 0x0); - - /* set Path control owner to BT */ - halbtc8822b1ant_ltecoex_pathcontrol_owner(btcoexist, - BT_8822B_1ANT_PCO_BTSIDE); - - /* Set Ext Ant Switch to BT control at wifi off step */ - halbtc8822b1ant_set_ext_ant_switch(btcoexist, - FORCE_EXEC, - BT_8822B_1ANT_EXT_ANT_SWITCH_CTRL_BY_BT, - BT_8822B_1ANT_EXT_ANT_SWITCH_TO_NOCARE); - - coex_sta->run_time_state = false; - - break; - case BT_8822B_1ANT_PHASE_2G_RUNTIME: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** (set_ant_path - 1ANT_PHASE_2G_RUNTIME) **********\n"); - BTC_TRACE(trace_buf); - - /* set GNT_BT to PTA */ - halbtc8822b1ant_ltecoex_set_gnt_bt(btcoexist, - BT_8822B_1ANT_GNT_BLOCK_RFC_BB, - BT_8822B_1ANT_GNT_CTRL_BY_PTA, - BT_8822B_1ANT_SIG_STA_SET_BY_HW); - - /* Set GNT_WL to PTA */ - halbtc8822b1ant_ltecoex_set_gnt_wl(btcoexist, - BT_8822B_1ANT_GNT_BLOCK_RFC_BB, - BT_8822B_1ANT_GNT_CTRL_BY_PTA, - BT_8822B_1ANT_SIG_STA_SET_BY_HW); - - /* set Path control owner to WL at runtime step */ - halbtc8822b1ant_ltecoex_pathcontrol_owner(btcoexist, - BT_8822B_1ANT_PCO_WLSIDE); - - coex_sta->run_time_state = true; - - if (BTC_ANT_PATH_AUTO == ant_pos_type) - ant_pos_type = BTC_ANT_PATH_PTA; - - break; - case BT_8822B_1ANT_PHASE_5G_RUNTIME: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** (set_ant_path - 1ANT_PHASE_5G_RUNTIME) **********\n"); - BTC_TRACE(trace_buf); - - /* set GNT_BT to SW Hi */ - halbtc8822b1ant_ltecoex_set_gnt_bt(btcoexist, - BT_8822B_1ANT_GNT_BLOCK_RFC_BB, - BT_8822B_1ANT_GNT_CTRL_BY_SW, - BT_8822B_1ANT_SIG_STA_SET_TO_HIGH); - - /* Set GNT_WL to SW Hi */ - halbtc8822b1ant_ltecoex_set_gnt_wl(btcoexist, - BT_8822B_1ANT_GNT_BLOCK_RFC_BB, - BT_8822B_1ANT_GNT_CTRL_BY_SW, - BT_8822B_1ANT_SIG_STA_SET_TO_HIGH); - - /* set Path control owner to WL at runtime step */ - halbtc8822b1ant_ltecoex_pathcontrol_owner(btcoexist, - BT_8822B_1ANT_PCO_WLSIDE); - - coex_sta->run_time_state = true; - - if (BTC_ANT_PATH_AUTO == ant_pos_type) - ant_pos_type = - BTC_ANT_PATH_WIFI5G; - - break; - case BT_8822B_1ANT_PHASE_BTMPMODE: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** (set_ant_path - 1ANT_PHASE_BTMPMODE) **********\n"); - BTC_TRACE(trace_buf); - - /* Disable LTE Coex Function in WiFi side */ - halbtc8822b1ant_ltecoex_enable(btcoexist, 0x0); - - /* set GNT_BT to SW Hi */ - halbtc8822b1ant_ltecoex_set_gnt_bt(btcoexist, - BT_8822B_1ANT_GNT_BLOCK_RFC_BB, - BT_8822B_1ANT_GNT_CTRL_BY_SW, - BT_8822B_1ANT_SIG_STA_SET_TO_HIGH); - - /* Set GNT_WL to SW Lo */ - halbtc8822b1ant_ltecoex_set_gnt_wl(btcoexist, - BT_8822B_1ANT_GNT_BLOCK_RFC_BB, - BT_8822B_1ANT_GNT_CTRL_BY_SW, - BT_8822B_1ANT_SIG_STA_SET_TO_LOW); - - /* set Path control owner to WL */ - halbtc8822b1ant_ltecoex_pathcontrol_owner(btcoexist, - BT_8822B_1ANT_PCO_WLSIDE); - - coex_sta->run_time_state = false; - - /* Set Ext Ant Switch to BT side at BT MP mode */ - if (BTC_ANT_PATH_AUTO == ant_pos_type) - ant_pos_type = BTC_ANT_PATH_BT; - - break; - } - - - if (phase != BT_8822B_1ANT_PHASE_WLAN_OFF) { - switch (ant_pos_type) { - case BTC_ANT_PATH_WIFI: - halbtc8822b1ant_set_ext_ant_switch( - btcoexist, - force_exec, - BT_8822B_1ANT_EXT_ANT_SWITCH_CTRL_BY_BBSW, - BT_8822B_1ANT_EXT_ANT_SWITCH_TO_WLG); - break; - case BTC_ANT_PATH_WIFI5G - : - halbtc8822b1ant_set_ext_ant_switch( - btcoexist, - force_exec, - BT_8822B_1ANT_EXT_ANT_SWITCH_CTRL_BY_BBSW, - BT_8822B_1ANT_EXT_ANT_SWITCH_TO_WLA); - break; - case BTC_ANT_PATH_BT: - halbtc8822b1ant_set_ext_ant_switch( - btcoexist, - force_exec, - BT_8822B_1ANT_EXT_ANT_SWITCH_CTRL_BY_BBSW, - BT_8822B_1ANT_EXT_ANT_SWITCH_TO_BT); - break; - default: - case BTC_ANT_PATH_PTA: - halbtc8822b1ant_set_ext_ant_switch( - btcoexist, - force_exec, - BT_8822B_1ANT_EXT_ANT_SWITCH_CTRL_BY_PTA, - BT_8822B_1ANT_EXT_ANT_SWITCH_TO_NOCARE); - break; - } - - } -#if 1 - u32tmp1 = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist, 0x38); - u32tmp2 = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist, 0x54); - u32tmp3 = btcoexist->btc_read_4byte(btcoexist, 0xcb4); - - u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x73); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** (After Ant Setup) 0xcb4 = 0x%x, 0x73 = 0x%x, 0x38= 0x%x, 0x54= 0x%x**********\n", - u32tmp3, u8tmp, u32tmp1, u32tmp2); - BTC_TRACE(trace_buf); - -#endif - -} - - -void halbtc8822b1ant_coex_all_off(IN struct btc_coexist *btcoexist) -{ - /* sw all off */ - halbtc8822b1ant_sw_mechanism(btcoexist, false); - - /* hw all off */ - halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); -} -boolean halbtc8822b1ant_is_common_action(IN struct btc_coexist *btcoexist) -{ - boolean common = false, wifi_connected = false, wifi_busy = false; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - - if (!wifi_connected && - BT_8822B_1ANT_BT_STATUS_NON_CONNECTED_IDLE == - coex_dm->bt_status) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi non connected-idle + BT non connected-idle!!\n"); - BTC_TRACE(trace_buf); - - /* halbtc8822b1ant_sw_mechanism(btcoexist, false); */ - - common = true; - } else if (wifi_connected && - (BT_8822B_1ANT_BT_STATUS_NON_CONNECTED_IDLE == - coex_dm->bt_status)) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi connected + BT non connected-idle!!\n"); - BTC_TRACE(trace_buf); - - /* halbtc8822b1ant_sw_mechanism(btcoexist, false); */ - - common = true; - } else if (!wifi_connected && - (BT_8822B_1ANT_BT_STATUS_CONNECTED_IDLE == - coex_dm->bt_status)) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi non connected-idle + BT connected-idle!!\n"); - BTC_TRACE(trace_buf); - - /* halbtc8822b1ant_sw_mechanism(btcoexist, false); */ - - common = true; - } else if (wifi_connected && - (BT_8822B_1ANT_BT_STATUS_CONNECTED_IDLE == - coex_dm->bt_status)) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi connected + BT connected-idle!!\n"); - BTC_TRACE(trace_buf); - - /* halbtc8822b1ant_sw_mechanism(btcoexist, false); */ - - common = true; - } else if (!wifi_connected && - (BT_8822B_1ANT_BT_STATUS_CONNECTED_IDLE != - coex_dm->bt_status)) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi non connected-idle + BT Busy!!\n"); - BTC_TRACE(trace_buf); - - /* halbtc8822b1ant_sw_mechanism(btcoexist, false); */ - - common = true; - } else { - if (wifi_busy) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi Connected-Busy + BT Busy!!\n"); - BTC_TRACE(trace_buf); - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi Connected-Idle + BT Busy!!\n"); - BTC_TRACE(trace_buf); - } - - common = false; - } - - return common; -} - -void halbtc8822b1ant_action_wifi_under5g(IN struct btc_coexist *btcoexist) -{ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], under 5g start\n"); - BTC_TRACE(trace_buf); - /* for test : s3 bt disappear , fail rate 1/600*/ -/* - halbtc8822b1ant_ignore_wlan_act(btcoexist, NORMAL_EXEC, true); -*/ -/*set sw gnt wl bt high*/ - halbtc8822b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, FORCE_EXEC, - BT_8822B_1ANT_PHASE_5G_RUNTIME); - - halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8); - halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); -/* - halbtc8822b1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0); - - halbtc8822b1ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 5); -*/ -} - - - -void halbtc8822b1ant_action_wifi_only(IN struct btc_coexist *btcoexist) -{ - boolean wifi_under_5g = false; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g); - if (wifi_under_5g) { - halbtc8822b1ant_action_wifi_under5g(btcoexist); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** (wlan only -- under 5g ) **********\n"); - BTC_TRACE(trace_buf); - return; - } - - halbtc8822b1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 0); - halbtc8822b1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 8); - - halbtc8822b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, FORCE_EXEC, - BT_8822B_1ANT_PHASE_2G_RUNTIME); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** (wlan only -- under 2g ) **********\n"); - BTC_TRACE(trace_buf); - -} - -/* ********************************************* - * - * Software Coex Mechanism start - * - * ********************************************* */ - -/* SCO only or SCO+PAN(HS) */ - -/* -void halbtc8822b1ant_action_sco(IN struct btc_coexist* btcoexist) -{ - halbtc8822b1ant_sw_mechanism(btcoexist, true); -} - - -void halbtc8822b1ant_action_hid(IN struct btc_coexist* btcoexist) -{ - halbtc8822b1ant_sw_mechanism(btcoexist, true); -} - - -void halbtc8822b1ant_action_a2dp(IN struct btc_coexist* btcoexist) -{ - halbtc8822b1ant_sw_mechanism(btcoexist, false); -} - -void halbtc8822b1ant_action_a2dp_pan_hs(IN struct btc_coexist* btcoexist) -{ - halbtc8822b1ant_sw_mechanism(btcoexist, false); -} - -void halbtc8822b1ant_action_pan_edr(IN struct btc_coexist* btcoexist) -{ - halbtc8822b1ant_sw_mechanism(btcoexist, false); -} - - -void halbtc8822b1ant_action_pan_hs(IN struct btc_coexist* btcoexist) -{ - halbtc8822b1ant_sw_mechanism(btcoexist, false); -} - - -void halbtc8822b1ant_action_pan_edr_a2dp(IN struct btc_coexist* btcoexist) -{ - halbtc8822b1ant_sw_mechanism(btcoexist, false); -} - -void halbtc8822b1ant_action_pan_edr_hid(IN struct btc_coexist* btcoexist) -{ - halbtc8822b1ant_sw_mechanism(btcoexist, true); -} - - -void halbtc8822b1ant_action_hid_a2dp_pan_edr(IN struct btc_coexist* btcoexist) -{ - halbtc8822b1ant_sw_mechanism(btcoexist, true); -} - -void halbtc8822b1ant_action_hid_a2dp(IN struct btc_coexist* btcoexist) -{ - halbtc8822b1ant_sw_mechanism(btcoexist, true); -} - -*/ - -/* ********************************************* - * - * Non-Software Coex Mechanism start - * - * ********************************************* */ -void halbtc8822b1ant_action_bt_whck_test(IN struct btc_coexist *btcoexist) -{ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex],action_bt_whck_test\n"); - BTC_TRACE(trace_buf); - - halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8); - - halbtc8822b1ant_set_ant_path(btcoexist, - BTC_ANT_PATH_AUTO, - NORMAL_EXEC, - BT_8822B_1ANT_PHASE_2G_RUNTIME); - - halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); -} - -void halbtc8822b1ant_action_wifi_multi_port(IN struct btc_coexist *btcoexist) -{ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex],action_wifi_multi_port\n"); - BTC_TRACE(trace_buf); - - halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8); - - halbtc8822b1ant_set_ant_path(btcoexist, - BTC_ANT_PATH_AUTO, - NORMAL_EXEC, - BT_8822B_1ANT_PHASE_2G_RUNTIME); - - halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1); -} - -void halbtc8822b1ant_action_hs(IN struct btc_coexist *btcoexist) -{ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], action_hs\n"); - BTC_TRACE(trace_buf); - - halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 5); - - halbtc8822b1ant_set_ant_path(btcoexist, - BTC_ANT_PATH_AUTO, - NORMAL_EXEC, - BT_8822B_1ANT_PHASE_2G_RUNTIME); - - halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 5); -} - -/*"""bt inquiry"""" + wifi any + bt any*/ -void halbtc8822b1ant_action_bt_inquiry(IN struct btc_coexist *btcoexist) -{ - - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - boolean wifi_connected = false, ap_enable = false, wifi_busy = false, - bt_busy = false; - - - boolean wifi_scan = false, link = false, roam = false; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** (bt inquiry) **********\n"); - BTC_TRACE(trace_buf); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, - &ap_enable); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bt_busy); - - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &wifi_scan); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam); - - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** scan = %d, link =%d, roam = %d**********\n", - wifi_scan, link, roam); - BTC_TRACE(trace_buf); - - if ((link) || (roam) || (coex_sta->wifi_is_high_pri_task)) { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** (bt inquiry wifi connect or scan ) **********\n"); - BTC_TRACE(trace_buf); - - halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 1); - - halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 6); - - } else if ((wifi_scan) && (coex_sta->bt_create_connection)) { - - halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 22); - halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 6); - - } else if ((!wifi_connected) && (!wifi_scan)) { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** (bt inquiry wifi non connect) **********\n"); - BTC_TRACE(trace_buf); - - halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8); - - halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - - } else if ((bt_link_info->a2dp_exist) && (bt_link_info->pan_exist)) { - - halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 22); - halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); - } else if (bt_link_info->a2dp_exist) { - - halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32); - - halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 3); - } else if (wifi_scan) { - - halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20); - - halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); - } else if (wifi_busy) { - - /* for BT inquiry/page fail after S4 resume */ - /* halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20); */ - halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32); - - halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, - 6); - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** (bt inquiry wifi connect) **********\n"); - BTC_TRACE(trace_buf); - - halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 22); - - halbtc8822b1ant_set_ant_path(btcoexist, - BTC_ANT_PATH_AUTO, - NORMAL_EXEC, - BT_8822B_1ANT_PHASE_2G_RUNTIME); - - halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, - 4); - } - - /* - if ((wifi_link) || (wifi_roam) || (coex_sta->wifi_is_high_pri_task)) { - - halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 33); - halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 6); - - } else if ((wifi_scan) && (coex_sta->bt_create_connection)) { - - halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 22); - halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 6); - - } else if ((!wifi_connected) && (!wifi_scan)) { - - halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8); - - halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - } else if ((bt_link_info->a2dp_exist) && (bt_link_info->pan_exist)) { - - halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 22); - halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); - - } else if (bt_link_info->a2dp_exist) { - - halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32); - - halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); - } else if (wifi_scan) { - - halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20); - - halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); - - } else if (wifi_busy) { - halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 21); - - halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); - } else { - halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 19); - - halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); - } - */ -} - -void halbtc8822b1ant_action_bt_sco_hid_only_busy(IN struct btc_coexist - *btcoexist, IN u8 wifi_status) -{ - - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x45e, 0x8, 0x1); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** (bt sco hid only busy) **********\n"); - BTC_TRACE(trace_buf); - - /*SCO + wifi connected idle or busy / 0x778=1@wifi slot*/ - if (bt_link_info->sco_exist) { - - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x45e, 0x8, 0x1); - halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 5); - /*case16 for connect SCO first then connect a2sp fail issue*/ - halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 16); - - } else { /* HID + wifi connected idle or busy / 0x778=1@wifi slot */ - - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x45e, 0x8, 0x1); - - halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 5); - /*case16 for connect HID first then connect a2sp fail issue*/ - halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 16); - - } -} - -/*wifi connected + bt acl busy*/ -void halbtc8822b1ant_action_wifi_connected_bt_acl_busy(IN struct btc_coexist - *btcoexist, IN u8 wifi_status) -{ - - u8 bt_rssi_state; - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - boolean wifi_busy = false, wifi_turbo = false; - u32 wifi_bw = 1; - - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, - &wifi_bw); -btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM, - &coex_sta->scan_ap_num); - bt_rssi_state = halbtc8822b1ant_bt_rssi_state(2, 28, 0); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, -"[BTCoex], ********** (wifi connect acl busy) **********\n"); - BTC_TRACE(trace_buf); - - - - if (bt_link_info->hid_only) { /* HID + wifi connected idle or busy / 0x778=1@wifi slot */ - - - - - btcoexist->btc_write_1byte_bitmask( - btcoexist, 0x45e, 0x8, 0x1); - - - - halbtc8822b1ant_action_bt_sco_hid_only_busy(btcoexist, - wifi_status); - return; - } else if ( - bt_link_info->a2dp_only) { /* A2DP + wifi connected idle or busy */ - if (BT_8822B_1ANT_WIFI_STATUS_CONNECTED_IDLE == wifi_status) { - - - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x45e, - 0x8, 0x1); - - halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 32); - halbtc8822b1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 0); - } else { - if (coex_sta->scan_ap_num >= - BT_8822B_1ANT_WIFI_NOISY_THRESH) { - halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, - 17); - } else { - - - - - btcoexist->btc_write_1byte_bitmask( - btcoexist, 0x45e, 0x8, 0x1); - - halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, - 42); - - halbtc8822b1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 1); - } -/* - halbtc8822b1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 1); -*/ - coex_dm->auto_tdma_adjust = true; - } - - /* A2DP+PAN(OPP,FTP), HID+A2DP+PAN(OPP,FTP) */ - } else if (((bt_link_info->a2dp_exist) && (bt_link_info->pan_exist)) || - (bt_link_info->hid_exist && bt_link_info->a2dp_exist && - bt_link_info->pan_exist)) { /* A2DP+PAN(OPP,FTP), HID+A2DP+PAN(OPP,FTP) */ - - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x45e, 0x8, 0x1); - halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 47); - halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, - 6); - } else if (bt_link_info->hid_exist && - bt_link_info->a2dp_exist) { /* HID+A2DP */ - - btcoexist->btc_write_1byte_bitmask( - btcoexist, 0x45e, 0x8, 0x1); - if (!wifi_busy) { -/*a2dp glitch while wl idle , change the 0x6c0=5a5a5a5a->5555or aaaa55aa*/ - halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, - 32); - } else if (wifi_bw == 0) { /* 11bg mode */ - halbtc8822b1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 1); - halbtc8822b1ant_set_wltoggle_coex_table( - btcoexist, - NORMAL_EXEC, - 0x3, 0xaa, - 0x5a, 0xaa, - 0xaa); - halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, - 49); - } else { - /*if in open space , and ask wl tp , 0x60=6135031111,55555555,aaaa55aa*/ - halbtc8822b1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 1); - halbtc8822b1ant_set_wltoggle_coex_table(btcoexist, NORMAL_EXEC, 0x2, 0xaa, 0x5a, 0xaa, 0xaa); - halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 49); -} - /* - halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, - 1); - */ - - - - - } else if ((bt_link_info->pan_only) || (bt_link_info->hid_exist && - bt_link_info->pan_exist)) { /* PAN(OPP,FTP), HID+PAN(OPP,FTP)*/ - /* - if (BT_8723D_1ANT_WIFI_STATUS_CONNECTED_IDLE == wifi_status) - halbtc8723d1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 4); - else - */ - - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x45e, 0x8, 0x1); - halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 47); - halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, - 1); - } else { - /* BT no-profile busy (0x9) */ - - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x45e, 0x8, 0x1); - halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 33); - halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, - 1); - } -} - -/*wifi not connected + bt action*/ -void halbtc8822b1ant_action_wifi_not_connected(IN struct btc_coexist *btcoexist) -{ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** (wifi not connect) **********\n"); - BTC_TRACE(trace_buf); - - /* tdma and coex table */ - halbtc8822b1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 8); - - halbtc8822b1ant_set_ant_path(btcoexist, - BTC_ANT_PATH_AUTO, - NORMAL_EXEC, - BT_8822B_1ANT_PHASE_2G_RUNTIME); - - halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); -} - -/*""""wl not connected scan"""" + bt action*/ -void halbtc8822b1ant_action_wifi_not_connected_scan(IN struct btc_coexist - *btcoexist) -{ - - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - boolean wifi_connected = false, bt_hs_on = false; - u32 wifi_link_status = 0; - u32 num_of_wifi_link = 0; - boolean bt_ctrl_agg_buf_size = false; - u8 agg_buf_size = 5; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** (wifi non connect scan) **********\n"); - BTC_TRACE(trace_buf); - - btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS, - &wifi_link_status); - - num_of_wifi_link = wifi_link_status >> 16; - - if (num_of_wifi_link >= 2) { - halbtc8822b1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0); - halbtc8822b1ant_limited_rx(btcoexist, NORMAL_EXEC, false, - bt_ctrl_agg_buf_size, agg_buf_size); - - if (coex_sta->c2h_bt_inquiry_page) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "############# [BTCoex], BT Is Inquirying\n"); - BTC_TRACE(trace_buf); - halbtc8822b1ant_action_bt_inquiry(btcoexist); - } else - halbtc8822b1ant_action_wifi_multi_port(btcoexist); - return; - } - - if (coex_sta->c2h_bt_inquiry_page) { - halbtc8822b1ant_action_bt_inquiry(btcoexist); - return; - } else if (bt_hs_on) { - halbtc8822b1ant_action_hs(btcoexist); - return; - } - - /* tdma and coex table */ - if (BT_8822B_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) { - if (bt_link_info->a2dp_exist) { - halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 32); - halbtc8822b1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 1); - } else if (bt_link_info->a2dp_exist && - bt_link_info->pan_exist) { - halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 22); - halbtc8822b1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 1); - } else { - halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 20); - halbtc8822b1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 1); - } - } else if ((BT_8822B_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) || - (BT_8822B_1ANT_BT_STATUS_ACL_SCO_BUSY == - coex_dm->bt_status)) { - halbtc8822b1ant_action_bt_sco_hid_only_busy(btcoexist, - BT_8822B_1ANT_WIFI_STATUS_CONNECTED_SCAN); - } else { - - halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8); - - halbtc8822b1ant_set_ant_path(btcoexist, - BTC_ANT_PATH_AUTO, - NORMAL_EXEC, - BT_8822B_1ANT_PHASE_2G_RUNTIME); - - halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, - 5); - } -} - -/*""""wl not connected asso"""" + bt action*/ -void halbtc8822b1ant_action_wifi_not_connected_asso_auth( - IN struct btc_coexist *btcoexist) -{ - - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - boolean wifi_connected = false, bt_hs_on = false; - u32 wifi_link_status = 0; - u32 num_of_wifi_link = 0; - boolean bt_ctrl_agg_buf_size = false; - u8 agg_buf_size = 5; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** (wifi non connect asso_auth) **********\n"); - BTC_TRACE(trace_buf); - - btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS, - &wifi_link_status); - - num_of_wifi_link = wifi_link_status >> 16; - - if (num_of_wifi_link >= 2) { - - halbtc8822b1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0); - halbtc8822b1ant_limited_rx(btcoexist, NORMAL_EXEC, false, - bt_ctrl_agg_buf_size, - agg_buf_size); - - if (coex_sta->c2h_bt_inquiry_page) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "############# [BTCoex], BT Is Inquirying\n"); - BTC_TRACE(trace_buf); - halbtc8822b1ant_action_bt_inquiry(btcoexist); - } else - halbtc8822b1ant_action_wifi_multi_port( - btcoexist); - return; - } - - if (coex_sta->c2h_bt_inquiry_page) { - halbtc8822b1ant_action_bt_inquiry(btcoexist); - return; - } else if (bt_hs_on) { - halbtc8822b1ant_action_hs(btcoexist); - return; - } - - - /* tdma and coex table */ - if ((bt_link_info->sco_exist) || (bt_link_info->hid_exist) || - (bt_link_info->a2dp_exist)) { - - halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32); - halbtc8822b1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 4); - } else if (bt_link_info->pan_exist) { - halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20); - halbtc8822b1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 4); - } else { - - halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8); - - halbtc8822b1ant_set_ant_path(btcoexist, - BTC_ANT_PATH_AUTO, - NORMAL_EXEC, - BT_8822B_1ANT_PHASE_2G_RUNTIME); - - halbtc8822b1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 2); - } -} - -/*""""wl connected scan"""" + bt action*/ -void halbtc8822b1ant_action_wifi_connected_scan(IN struct btc_coexist - *btcoexist) -{ - - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - boolean wifi_connected = false, bt_hs_on = false; - u32 wifi_link_status = 0; - u32 num_of_wifi_link = 0; - boolean bt_ctrl_agg_buf_size = false; - u8 agg_buf_size = 5; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** (wifi connect scan) **********\n"); - BTC_TRACE(trace_buf); - - btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS, - &wifi_link_status); - - num_of_wifi_link = wifi_link_status >> 16; - - if (num_of_wifi_link >= 2) { - halbtc8822b1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0); - halbtc8822b1ant_limited_rx(btcoexist, NORMAL_EXEC, false, - bt_ctrl_agg_buf_size, agg_buf_size); - - if (coex_sta->c2h_bt_inquiry_page) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "############# [BTCoex], BT Is Inquirying\n"); - BTC_TRACE(trace_buf); - halbtc8822b1ant_action_bt_inquiry(btcoexist); - } else - halbtc8822b1ant_action_wifi_multi_port(btcoexist); - return; - } - - if (coex_sta->c2h_bt_inquiry_page) { - halbtc8822b1ant_action_bt_inquiry(btcoexist); - return; - } else if (bt_hs_on) { - halbtc8822b1ant_action_hs(btcoexist); - return; - } - - /* tdma and coex table */ - if (BT_8822B_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) { - if (bt_link_info->a2dp_exist) { - halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 32); - halbtc8822b1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 1); - } else if (bt_link_info->a2dp_exist && - bt_link_info->pan_exist) { - halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 22); - halbtc8822b1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 1); - } else { - halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 20); - halbtc8822b1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 1); - } - } else if ((BT_8822B_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) || - (BT_8822B_1ANT_BT_STATUS_ACL_SCO_BUSY == - coex_dm->bt_status)) { - halbtc8822b1ant_action_bt_sco_hid_only_busy(btcoexist, - BT_8822B_1ANT_WIFI_STATUS_CONNECTED_SCAN); - } else { - - halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8); - - halbtc8822b1ant_set_ant_path(btcoexist, - BTC_ANT_PATH_AUTO, - NORMAL_EXEC, - BT_8822B_1ANT_PHASE_2G_RUNTIME); - - halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, - 6); - } -} - -/*""""wl connected specific packet"""" + bt action*/ -void halbtc8822b1ant_action_wifi_connected_specific_packet( - IN struct btc_coexist *btcoexist) -{ - - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - boolean wifi_connected = false, bt_hs_on = false; - u32 wifi_link_status = 0; - u32 num_of_wifi_link = 0; - boolean bt_ctrl_agg_buf_size = false; - u8 agg_buf_size = 5; - boolean wifi_busy = false; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** (wifi connect specific packet) **********\n"); - BTC_TRACE(trace_buf); - - btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS, - &wifi_link_status); - - num_of_wifi_link = wifi_link_status >> 16; - - if (num_of_wifi_link >= 2) { - halbtc8822b1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0); - halbtc8822b1ant_limited_rx(btcoexist, NORMAL_EXEC, false, - bt_ctrl_agg_buf_size, agg_buf_size); - - if (coex_sta->c2h_bt_inquiry_page) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "############# [BTCoex], BT Is Inquirying\n"); - BTC_TRACE(trace_buf); - halbtc8822b1ant_action_bt_inquiry(btcoexist); - } else - halbtc8822b1ant_action_wifi_multi_port(btcoexist); - return; - } - - if (coex_sta->c2h_bt_inquiry_page) { - halbtc8822b1ant_action_bt_inquiry(btcoexist); - return; - } else if (bt_hs_on) { - halbtc8822b1ant_action_hs(btcoexist); - return; - } - - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - - /* no specific packet process for both WiFi and BT very busy */ - if ((wifi_busy) && ((bt_link_info->pan_exist) || - (coex_sta->num_of_profile >= 2))) - return; - - /* tdma and coex table */ - if ((bt_link_info->sco_exist) || (bt_link_info->hid_exist)) { - halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32); - halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 5); - } else if (bt_link_info->a2dp_exist) { - halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32); - /*for a2dp glitch,change from 1 to 15*/ - halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, - 15); - } else if (bt_link_info->pan_exist) { - halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20); - halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, - 1); - } else { - - halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8); - - halbtc8822b1ant_set_ant_path(btcoexist, - BTC_ANT_PATH_AUTO, - NORMAL_EXEC, - BT_8822B_1ANT_PHASE_2G_RUNTIME); - - halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, - 5); - } -} - -/*wifi connected input point : to set different ps and tdma case (+bt different case)*/ -void halbtc8822b1ant_action_wifi_connected(IN struct btc_coexist *btcoexist) -{ - - boolean wifi_busy = false; - boolean scan = false, link = false, roam = false; - boolean under_4way = false, ap_enable = false, wifi_under_5g = false; - u8 wifi_rssi_state; - - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], CoexForWifiConnect()===>\n"); - BTC_TRACE(trace_buf); - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g); - - if (wifi_under_5g) { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], CoexForWifiConnect(), return for wifi is under 5g<===\n"); - BTC_TRACE(trace_buf); - - halbtc8822b1ant_action_wifi_under5g(btcoexist); - - return; - } - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], CoexForWifiConnect(), return for wifi is under 2g<===\n"); - BTC_TRACE(trace_buf); - - halbtc8822b1ant_set_ant_path(btcoexist, - BTC_ANT_PATH_AUTO, - NORMAL_EXEC, - BT_8822B_1ANT_PHASE_2G_RUNTIME); - - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS, - &under_4way); - - if (under_4way) { - halbtc8822b1ant_action_wifi_connected_specific_packet( - btcoexist); - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], CoexForWifiConnect(), return for wifi is under 4way<===\n"); - BTC_TRACE(trace_buf); - return; - } - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam); - if (scan || link || roam) { - if (scan) - halbtc8822b1ant_action_wifi_connected_scan(btcoexist); - else - halbtc8822b1ant_action_wifi_connected_specific_packet( - btcoexist); - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], CoexForWifiConnect(), return for wifi is under scan<===\n"); - BTC_TRACE(trace_buf); - return; - } - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, - &ap_enable); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - - /* tdma and coex table */ - if (!wifi_busy) { - if (BT_8822B_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) { - halbtc8822b1ant_action_wifi_connected_bt_acl_busy( - btcoexist, - BT_8822B_1ANT_WIFI_STATUS_CONNECTED_IDLE); - } else if ((BT_8822B_1ANT_BT_STATUS_SCO_BUSY == - coex_dm->bt_status) || - (BT_8822B_1ANT_BT_STATUS_ACL_SCO_BUSY == - coex_dm->bt_status)) { - halbtc8822b1ant_action_bt_sco_hid_only_busy(btcoexist, - BT_8822B_1ANT_WIFI_STATUS_CONNECTED_IDLE); - } else { - - halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, - 8); - - halbtc8822b1ant_set_ant_path(btcoexist, - BTC_ANT_PATH_AUTO, - NORMAL_EXEC, - BT_8822B_1ANT_PHASE_2G_RUNTIME); - - if ((coex_sta->high_priority_tx) + - (coex_sta->high_priority_rx) <= 60) - /*sy modify case16 -> case17*/ - halbtc8822b1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 1); - else - halbtc8822b1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 1); - } - } else { - if (BT_8822B_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) { - halbtc8822b1ant_action_wifi_connected_bt_acl_busy( - btcoexist, - BT_8822B_1ANT_WIFI_STATUS_CONNECTED_BUSY); - } else if ((BT_8822B_1ANT_BT_STATUS_SCO_BUSY == - coex_dm->bt_status) || - (BT_8822B_1ANT_BT_STATUS_ACL_SCO_BUSY == - coex_dm->bt_status)) { - halbtc8822b1ant_action_bt_sco_hid_only_busy(btcoexist, - BT_8822B_1ANT_WIFI_STATUS_CONNECTED_BUSY); - } else { - - - - halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, - 8); - - halbtc8822b1ant_set_ant_path(btcoexist, - BTC_ANT_PATH_AUTO, - NORMAL_EXEC, - BT_8822B_1ANT_PHASE_2G_RUNTIME); - - /* - - halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 32); - - halbtc8822b1ant_set_ant_path(btcoexist, - BTC_ANT_PATH_AUTO, NORMAL_EXEC, BT_8822B_1ANT_PHASE_2G_RUNTIME); - */ - - - - wifi_rssi_state = halbtc8822b1ant_wifi_rssi_state( - btcoexist, 1, 2, 25, 0); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** before **********\n"); - BTC_TRACE(trace_buf); -/* - if ((BT_8822B_1ANT_BT_STATUS_NON_CONNECTED_IDLE == - coex_dm->bt_status) && - (coex_sta->scan_ap_num <= 3) && - (wifi_rssi_state == BTC_RSSI_STATE_LOW || - wifi_rssi_state == BTC_RSSI_STATE_STAY_LOW)) { -*/ - if (BT_8822B_1ANT_BT_STATUS_NON_CONNECTED_IDLE == - coex_dm->bt_status) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** scan ap <3 coex table=0xaaaaaaaa **********\n"); - BTC_TRACE(trace_buf); - - halbtc8822b1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 7); - } else - - halbtc8822b1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 1); - - - - /* - else if ((coex_sta->high_priority_tx + - coex_sta->high_priority_rx) <= 60) - halbtc8822b1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 1); - else - halbtc8822b1ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 4); - */ - } - } -} - -void halbtc8822b1ant_run_sw_coexist_mechanism(IN struct btc_coexist *btcoexist) -{ - - u8 algorithm = 0; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** (runswcoexmech) **********\n"); - BTC_TRACE(trace_buf); - algorithm = halbtc8822b1ant_action_algorithm(btcoexist); - coex_dm->cur_algorithm = algorithm; - - if (halbtc8822b1ant_is_common_action(btcoexist)) { - - } else { - switch (coex_dm->cur_algorithm) { - case BT_8822B_1ANT_COEX_ALGO_SCO: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action algorithm = SCO.\n"); - BTC_TRACE(trace_buf); - /* halbtc8822b1ant_action_sco(btcoexist); */ - break; - case BT_8822B_1ANT_COEX_ALGO_HID: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action algorithm = HID.\n"); - BTC_TRACE(trace_buf); - /* halbtc8822b1ant_action_hid(btcoexist); */ - break; - case BT_8822B_1ANT_COEX_ALGO_A2DP: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action algorithm = A2DP.\n"); - BTC_TRACE(trace_buf); - /* halbtc8822b1ant_action_a2dp(btcoexist); */ - break; - case BT_8822B_1ANT_COEX_ALGO_A2DP_PANHS: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action algorithm = A2DP+PAN(HS).\n"); - BTC_TRACE(trace_buf); - /* halbtc8822b1ant_action_a2dp_pan_hs(btcoexist); */ - break; - case BT_8822B_1ANT_COEX_ALGO_PANEDR: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action algorithm = PAN(EDR).\n"); - BTC_TRACE(trace_buf); - /* halbtc8822b1ant_action_pan_edr(btcoexist); */ - break; - case BT_8822B_1ANT_COEX_ALGO_PANHS: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action algorithm = HS mode.\n"); - BTC_TRACE(trace_buf); - /* halbtc8822b1ant_action_pan_hs(btcoexist); */ - break; - case BT_8822B_1ANT_COEX_ALGO_PANEDR_A2DP: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action algorithm = PAN+A2DP.\n"); - BTC_TRACE(trace_buf); - /* halbtc8822b1ant_action_pan_edr_a2dp(btcoexist); */ - break; - case BT_8822B_1ANT_COEX_ALGO_PANEDR_HID: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action algorithm = PAN(EDR)+HID.\n"); - BTC_TRACE(trace_buf); - /* halbtc8822b1ant_action_pan_edr_hid(btcoexist); */ - break; - case BT_8822B_1ANT_COEX_ALGO_HID_A2DP_PANEDR: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action algorithm = HID+A2DP+PAN.\n"); - BTC_TRACE(trace_buf); - /* halbtc8822b1ant_action_hid_a2dp_pan_edr(btcoexist); */ - break; - case BT_8822B_1ANT_COEX_ALGO_HID_A2DP: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action algorithm = HID+A2DP.\n"); - BTC_TRACE(trace_buf); - /* halbtc8822b1ant_action_hid_a2dp(btcoexist); */ - break; - default: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action algorithm = coexist All Off!!\n"); - BTC_TRACE(trace_buf); - /* halbtc8822b1ant_coex_all_off(btcoexist); */ - break; - } - coex_dm->pre_algorithm = coex_dm->cur_algorithm; - } -} - -void halbtc8822b1ant_run_coexist_mechanism(IN struct btc_coexist *btcoexist) -{ - - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - boolean wifi_connected = false, bt_hs_on = false; - boolean increase_scan_dev_num = false; - boolean bt_ctrl_agg_buf_size = false; - boolean miracast_plus_bt = false; - u8 agg_buf_size = 5; - u32 wifi_link_status = 0; - u32 num_of_wifi_link = 0, wifi_bw; - u8 iot_peer = BTC_IOT_PEER_UNKNOWN; - boolean wifi_under_5g = false; - - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], RunCoexistMechanism()===>\n"); - BTC_TRACE(trace_buf); - - if (btcoexist->manual_control) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], RunCoexistMechanism(), return for Manual CTRL <===\n"); - BTC_TRACE(trace_buf); - return; - } - - if (btcoexist->stop_coex_dm) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], RunCoexistMechanism(), return for Stop Coex DM <===\n"); - BTC_TRACE(trace_buf); - return; - } - - if (coex_sta->under_ips) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], wifi is under IPS !!!\n"); - BTC_TRACE(trace_buf); - return; - } - - if (!coex_sta->run_time_state) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], return for run_time_state = false !!!\n"); - BTC_TRACE(trace_buf); - return; - } - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g); - if (wifi_under_5g) { - halbtc8822b1ant_action_wifi_under5g(btcoexist); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], WiFi is under 5G!!!\n"); - BTC_TRACE(trace_buf); - return; - } - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], WiFi is under 2G!!!\n"); - BTC_TRACE(trace_buf); - - halbtc8822b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, - NORMAL_EXEC, - BT_8822B_1ANT_PHASE_2G_RUNTIME); - - if (coex_sta->bt_whck_test) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT is under WHCK TEST!!!\n"); - BTC_TRACE(trace_buf); - halbtc8822b1ant_action_bt_whck_test(btcoexist); - return; - } - - if (coex_sta->bt_disabled) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT is disabled !!!\n"); - halbtc8822b1ant_action_wifi_only(btcoexist); - return; - } - - if ((BT_8822B_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) || - (BT_8822B_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) || - (BT_8822B_1ANT_BT_STATUS_ACL_SCO_BUSY == coex_dm->bt_status)) - increase_scan_dev_num = true; - - btcoexist->btc_set(btcoexist, BTC_SET_BL_INC_SCAN_DEV_NUM, - &increase_scan_dev_num); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS, - &wifi_link_status); - num_of_wifi_link = wifi_link_status >> 16; - - if ((num_of_wifi_link >= 2) || - (wifi_link_status & WIFI_P2P_GO_CONNECTED)) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "############# [BTCoex], Multi-Port num_of_wifi_link = %d, wifi_link_status = 0x%x\n", - num_of_wifi_link, wifi_link_status); - BTC_TRACE(trace_buf); - - if (bt_link_info->bt_link_exist) { - halbtc8822b1ant_limited_tx(btcoexist, NORMAL_EXEC, 1, 1, - 0, 1); - miracast_plus_bt = true; - } else { - halbtc8822b1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, - 0, 0); - miracast_plus_bt = false; - } - btcoexist->btc_set(btcoexist, BTC_SET_BL_MIRACAST_PLUS_BT, - &miracast_plus_bt); - halbtc8822b1ant_limited_rx(btcoexist, NORMAL_EXEC, false, - bt_ctrl_agg_buf_size, agg_buf_size); - - if ((bt_link_info->a2dp_exist) && - (coex_sta->c2h_bt_inquiry_page)) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "############# [BTCoex], BT Is Inquirying\n"); - BTC_TRACE(trace_buf); - halbtc8822b1ant_action_bt_inquiry(btcoexist); - } else - halbtc8822b1ant_action_wifi_multi_port(btcoexist); - - return; - } - - miracast_plus_bt = false; - btcoexist->btc_set(btcoexist, BTC_SET_BL_MIRACAST_PLUS_BT, - &miracast_plus_bt); - - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw); - - if ((bt_link_info->bt_link_exist) && (wifi_connected)) { - halbtc8822b1ant_limited_tx(btcoexist, NORMAL_EXEC, 1, 1, 0, 1); - - btcoexist->btc_get(btcoexist, BTC_GET_U1_IOT_PEER, &iot_peer); - - if (BTC_IOT_PEER_CISCO != iot_peer) { - if (bt_link_info->sco_exist) /* if (bt_link_info->bt_hi_pri_link_exist) */ - halbtc8822b1ant_limited_rx(btcoexist, - NORMAL_EXEC, true, false, 0x5); - else - halbtc8822b1ant_limited_rx(btcoexist, - NORMAL_EXEC, false, false, 0x5); - } else { - if (bt_link_info->sco_exist) - halbtc8822b1ant_limited_rx(btcoexist, - NORMAL_EXEC, true, false, 0x5); - else { - if (BTC_WIFI_BW_HT40 == wifi_bw) - halbtc8822b1ant_limited_rx(btcoexist, - NORMAL_EXEC, false, true, 0x10); - else - halbtc8822b1ant_limited_rx(btcoexist, - NORMAL_EXEC, false, true, 0x8); - } - } - - halbtc8822b1ant_sw_mechanism(btcoexist, true); - halbtc8822b1ant_run_sw_coexist_mechanism( - btcoexist); /* just print debug message */ - } else { - halbtc8822b1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0); - - halbtc8822b1ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, - 0x5); - - halbtc8822b1ant_sw_mechanism(btcoexist, false); - halbtc8822b1ant_run_sw_coexist_mechanism( - btcoexist); /* just print debug message */ - } - - btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); - if (coex_sta->c2h_bt_inquiry_page) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "############# [BTCoex], BT Is Inquirying\n"); - BTC_TRACE(trace_buf); - halbtc8822b1ant_action_bt_inquiry(btcoexist); - return; - } else if (bt_hs_on) { - halbtc8822b1ant_action_hs(btcoexist); - return; - } - - - if (!wifi_connected) { - boolean scan = false, link = false, roam = false; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], wifi is non connected-idle !!!\n"); - BTC_TRACE(trace_buf); - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam); - - if (scan || link || roam) { - if (scan) - halbtc8822b1ant_action_wifi_not_connected_scan( - btcoexist); - else - halbtc8822b1ant_action_wifi_not_connected_asso_auth( - btcoexist); - } else - halbtc8822b1ant_action_wifi_not_connected(btcoexist); - } else /* wifi LPS/Busy */ - halbtc8822b1ant_action_wifi_connected(btcoexist); -} - -u32 halbtc8822b1ant_psd_log2base(IN struct btc_coexist *btcoexist, IN u32 val) -{ - u8 j; - u32 tmp, tmp2, val_integerd_b = 0, tindex, shiftcount = 0; - u32 result, val_fractiond_b = 0, table_fraction[21] = {0, 432, 332, 274, 232, 200, - 174, 151, 132, 115, 100, 86, 74, 62, 51, 42, - 32, 23, 15, 7, 0 - }; - - if (val == 0) - return 0; - - tmp = val; - - while (1) { - if (tmp == 1) - break; - - tmp = (tmp >> 1); - shiftcount++; - } - - - val_integerd_b = shiftcount + 1; - - tmp2 = 1; - for (j = 1; j <= val_integerd_b; j++) - tmp2 = tmp2 * 2; - - tmp = (val * 100) / tmp2; - tindex = tmp / 5; - - if (tindex > 20) - tindex = 20; - - val_fractiond_b = table_fraction[tindex]; - - result = val_integerd_b * 100 - val_fractiond_b; - - return result; - - -} - -void halbtc8822b1ant_init_coex_dm(IN struct btc_coexist *btcoexist) -{ - /* force to reset coex mechanism */ - - halbtc8822b1ant_low_penalty_ra(btcoexist, NORMAL_EXEC, false); - - /* sw all off */ - halbtc8822b1ant_sw_mechanism(btcoexist, false); - - /* halbtc8822b1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 8); */ - /* halbtc8822b1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 0); */ - - coex_sta->pop_event_cnt = 0; -} - -void halbtc8822b1ant_init_hw_config(IN struct btc_coexist *btcoexist, - IN boolean back_up, IN boolean wifi_only) -{ - - u8 u8tmp = 0; - boolean wifi_under_5g = false; - u32 u32tmp1 = 0, u32tmp2 = 0, u32tmp3 = 0; - - - u32tmp3 = btcoexist->btc_read_4byte(btcoexist, 0xcb4); - u32tmp1 = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist, 0x38); - u32tmp2 = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist, 0x54); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** (Before Init HW config) 0xcb4 = 0x%x, 0x38= 0x%x, 0x54= 0x%x**********\n", - u32tmp3, u32tmp1, u32tmp2); - BTC_TRACE(trace_buf); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], 1Ant Init HW Config!!\n"); - BTC_TRACE(trace_buf); - - coex_sta->bt_coex_supported_feature = 0; - coex_sta->bt_coex_supported_version = 0; - - /* Setup RF front end type */ - halbtc8822b1ant_set_rfe_type(btcoexist); - - /* 0xf0[15:12] --> Chip Cut information */ - coex_sta->cut_version = (btcoexist->btc_read_1byte(btcoexist, - 0xf1) & 0xf0) >> 4; - - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x550, 0x8, - 0x1); /* enable TBTT nterrupt */ - - /* BT report packet sample rate */ - /* 0x790[5:0]=0x5 */ - u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x790); - u8tmp &= 0xc0; - u8tmp |= 0x5; - btcoexist->btc_write_1byte(btcoexist, 0x790, u8tmp); - - /* Enable BT counter statistics */ - btcoexist->btc_write_1byte(btcoexist, 0x778, 0x1); - - /* Enable PTA (3-wire function form BT side) */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x40, 0x20, 0x1); - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x41, 0x02, 0x1); - - /* Enable PTA (tx/rx signal form WiFi side) */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4c6, 0x10, 0x1); - /*GNT_BT=1 while select both */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x763, 0x10, 0x1); - - /* enable GNT_WL/GNT_BT debug signal to GPIO14/15 */ - /*btcoexist->btc_write_1byte_bitmask(btcoexist, 0x73, 0x8, 0x1);*/ - - /* enable GNT_WL */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4e, 0x40, 0x0); - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, 0x1, 0x0); - - if (btcoexist->btc_read_1byte(btcoexist, 0x80) == 0xc6) - halbtc8822b1ant_post_state_to_bt(btcoexist, - BT_8822B_1ANT_SCOREBOARD_ONOFF, true); - - /* Antenna config */ - if (wifi_only) { - - coex_sta->concurrent_rx_mode_on = false; - halbtc8822b1ant_set_ant_path(btcoexist, - BTC_ANT_PATH_WIFI, - FORCE_EXEC, - BT_8822B_1ANT_PHASE_WLANONLY_INIT); - } else { - - coex_sta->concurrent_rx_mode_on = true; - - halbtc8822b1ant_set_ant_path(btcoexist, - BTC_ANT_PATH_AUTO, - FORCE_EXEC, - BT_8822B_1ANT_PHASE_COEX_INIT); - } - - - /* PTA parameter */ - halbtc8822b1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 0); - - halbtc8822b1ant_enable_gnt_to_gpio(btcoexist, true); - -} - - -void halbtc8822b1ant_init_hw_config_without_bt(IN struct btc_coexist *btcoexist, - IN boolean back_up, IN boolean wifi_only) -{ - - u8 u8tmp = 0; - boolean wifi_under_5g = false; - u32 u32tmp1 = 0, u32tmp2 = 0, u32tmp3 = 0; - - - /* 0xf0[15:12] --> Chip Cut information */ - coex_sta->cut_version = (btcoexist->btc_read_1byte(btcoexist, - 0xf1) & 0xf0) >> 4; - - /* enable TBTT interrupt */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x550, 0x8, - 0x1); - - /* enable GNT_WL */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4e, 0x40, 0x0); - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, 0x1, 0x0); - - /* Antenna config */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4e, 0x80, - 0x0); /* 0x4c[23] = 0 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4f, 0x01, - 0x1); /* 0x4c[24] = 1 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb4, 0xff, - 0x77); /* BB SW, DPDT use RFE_ctrl8 and RFE_ctrl9 as conctrol pin */ - - - /* Ext switch buffer mux */ - btcoexist->btc_write_1byte(btcoexist, 0x974, 0xff); - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x1991, 0x3, 0x0); - btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbe, 0x8, 0x0); - - /*enable sw control gnt_wl=1 / gnt_bt=1 */ - btcoexist->btc_write_1byte(btcoexist, 0x73, 0x0e); - - btcoexist->btc_write_4byte(btcoexist, 0x1704, 0x0000ff00); - - btcoexist->btc_write_4byte(btcoexist, 0x1700, 0xc00f0038); - - - /* ant switch WL2G or WL5G*/ - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, - &wifi_under_5g); - if (wifi_under_5g) - - btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbd, - 0x3, 1); - - else - - btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbd, - 0x3, 2); - -} - -void halbtc8822b1ant_psd_showdata(IN struct btc_coexist *btcoexist) -{ - u8 *cli_buf = btcoexist->cli_buf; - u32 delta_freq_per_point; - u32 freq, freq1, freq2, n = 0, i = 0, j = 0, m = 0, psd_rep1, psd_rep2; - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n\n============[PSD info] (%d)============\n", - psd_scan->psd_gen_count); - CL_PRINTF(cli_buf); - - if (psd_scan->psd_gen_count == 0) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n No data !!\n"); - CL_PRINTF(cli_buf); - return; - } - - if (psd_scan->psd_point == 0) - delta_freq_per_point = 0; - else - delta_freq_per_point = psd_scan->psd_band_width / - psd_scan->psd_point; - - /* if (psd_scan->is_psd_show_max_only) */ - if (0) { - psd_rep1 = psd_scan->psd_max_value / 100; - psd_rep2 = psd_scan->psd_max_value - psd_rep1 * 100; - - freq = ((psd_scan->real_cent_freq - 20) * 1000000 + - psd_scan->psd_max_value_point * delta_freq_per_point); - freq1 = freq / 1000000; - freq2 = freq / 1000 - freq1 * 1000; - - if (freq2 < 100) - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n Freq = %d.0%d MHz", - freq1, freq2); - else - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n Freq = %d.%d MHz", - freq1, freq2); - - if (psd_rep2 < 10) - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - ", Value = %d.0%d dB, (%d)\n", - psd_rep1, psd_rep2, psd_scan->psd_max_value); - else - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - ", Value = %d.%d dB, (%d)\n", - psd_rep1, psd_rep2, psd_scan->psd_max_value); - - CL_PRINTF(cli_buf); - } else { - m = psd_scan->psd_start_point; - n = psd_scan->psd_start_point; - i = 1; - j = 1; - - while (1) { - do { - freq = ((psd_scan->real_cent_freq - 20) * - 1000000 + m * - delta_freq_per_point); - freq1 = freq / 1000000; - freq2 = freq / 1000 - freq1 * 1000; - - if (i == 1) { - if (freq2 == 0) - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "\r\n Freq%6d.000", - freq1); - else if (freq2 < 100) - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "\r\n Freq%6d.0%2d", - freq1, - freq2); - else - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "\r\n Freq%6d.%3d", - freq1, - freq2); - } else if ((i % 8 == 0) || - (m == psd_scan->psd_stop_point)) { - if (freq2 == 0) - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "%6d.000\n", freq1); - else if (freq2 < 100) - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "%6d.0%2d\n", freq1, - freq2); - else - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "%6d.%3d\n", freq1, - freq2); - } else { - if (freq2 == 0) - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "%6d.000", freq1); - else if (freq2 < 100) - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "%6d.0%2d", freq1, - freq2); - else - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "%6d.%3d", freq1, - freq2); - } - - i++; - m++; - CL_PRINTF(cli_buf); - - } while ((i <= 8) && (m <= psd_scan->psd_stop_point)); - - - do { - psd_rep1 = psd_scan->psd_report_max_hold[n] / - 100; - psd_rep2 = psd_scan->psd_report_max_hold[n] - - psd_rep1 * - 100; - - if (j == 1) { - if (psd_rep2 < 10) - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "\r\n Val %7d.0%d", - psd_rep1, - psd_rep2); - else - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "\r\n Val %7d.%d", - psd_rep1, - psd_rep2); - } else if ((j % 8 == 0) || - (n == psd_scan->psd_stop_point)) { - if (psd_rep2 < 10) - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "%7d.0%d\n", psd_rep1, - psd_rep2); - else - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "%7d.%d\n", psd_rep1, - psd_rep2); - } else { - if (psd_rep2 < 10) - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "%7d.0%d", psd_rep1, - psd_rep2); - else - CL_SPRINTF(cli_buf, - BT_TMP_BUF_SIZE, - "%7d.%d", psd_rep1, - psd_rep2); - } - - j++; - n++; - CL_PRINTF(cli_buf); - - } while ((j <= 8) && (n <= psd_scan->psd_stop_point)); - - if ((m > psd_scan->psd_stop_point) || - (n > psd_scan->psd_stop_point)) - break; - - i = 1; - j = 1; - - } - } - - -} - -void halbtc8822b1ant_psd_max_holddata(IN struct btc_coexist *btcoexist, - IN u32 gen_count) -{ - u32 i = 0, i_max = 0, val_max = 0; - - if (gen_count == 1) { - memcpy(psd_scan->psd_report_max_hold, - psd_scan->psd_report, - BT_8822B_1ANT_ANTDET_PSD_POINTS * sizeof(u32)); - - for (i = psd_scan->psd_start_point; - i <= psd_scan->psd_stop_point; i++) { - - } - - psd_scan->psd_max_value_point = 0; - psd_scan->psd_max_value = 0; - - } else { - for (i = psd_scan->psd_start_point; - i <= psd_scan->psd_stop_point; i++) { - if (psd_scan->psd_report[i] > - psd_scan->psd_report_max_hold[i]) - psd_scan->psd_report_max_hold[i] = - psd_scan->psd_report[i]; - - /* search Max Value */ - if (i == psd_scan->psd_start_point) { - i_max = i; - val_max = psd_scan->psd_report_max_hold[i]; - } else { - if (psd_scan->psd_report_max_hold[i] > - val_max) { - i_max = i; - val_max = psd_scan->psd_report_max_hold[i]; - } - } - - - - } - - psd_scan->psd_max_value_point = i_max; - psd_scan->psd_max_value = val_max; - - } - - -} - -u32 halbtc8822b1ant_psd_getdata(IN struct btc_coexist *btcoexist, IN u32 point) -{ - /* reg 0x808[9:0]: FFT data x */ - /* reg 0x808[22]: 0-->1 to get 1 FFT data y */ - /* reg 0x8b4[15:0]: FFT data y report */ - - u32 val = 0, psd_report = 0; - - val = btcoexist->btc_read_4byte(btcoexist, 0x808); - - val &= 0xffbffc00; - val |= point; - - btcoexist->btc_write_4byte(btcoexist, 0x808, val); - - val |= 0x00400000; - btcoexist->btc_write_4byte(btcoexist, 0x808, val); - - - val = btcoexist->btc_read_4byte(btcoexist, 0x8b4); - - psd_report = val & 0x0000ffff; - - return psd_report; -} - - -void halbtc8822b1ant_psd_sweep_point(IN struct btc_coexist *btcoexist, - IN u32 cent_freq, IN s32 offset, IN u32 span, IN u32 points, - IN u32 avgnum) -{ - u32 i, val, n, k = 0; - u32 points1 = 0, psd_report = 0; - u32 start_p = 0, stop_p = 0, delta_freq_per_point = 156250; - u32 psd_center_freq = 20 * 10 ^ 6, freq, freq1, freq2; - boolean outloop = false; - u8 flag = 0; - u32 tmp, psd_rep1, psd_rep2; - u32 wifi_original_channel = 1; - - psd_scan->is_psd_running = true; - - do { - switch (flag) { - case 0: /* Get PSD parameters */ - default: - - psd_scan->psd_band_width = 40 * 1000000; - psd_scan->psd_point = points; - psd_scan->psd_start_base = points / 2; - psd_scan->psd_avg_num = avgnum; - psd_scan->real_cent_freq = cent_freq; - psd_scan->real_offset = offset; - psd_scan->real_span = span; - - - points1 = psd_scan->psd_point; - delta_freq_per_point = psd_scan->psd_band_width / - psd_scan->psd_point; - - /* PSD point setup */ - val = btcoexist->btc_read_4byte(btcoexist, 0x808); - val &= 0xffff0fff; - - switch (psd_scan->psd_point) { - case 128: - val |= 0x0; - break; - case 256: - default: - val |= 0x00004000; - break; - case 512: - val |= 0x00008000; - break; - case 1024: - val |= 0x0000c000; - break; - } - - switch (psd_scan->psd_avg_num) { - case 1: - val |= 0x0; - break; - case 8: - val |= 0x00001000; - break; - case 16: - val |= 0x00002000; - break; - case 32: - default: - val |= 0x00003000; - break; - } - btcoexist->btc_write_4byte(btcoexist, 0x808, val); - - flag = 1; - break; - case 1: /* calculate the PSD point index from freq/offset/span */ - psd_center_freq = psd_scan->psd_band_width / 2 + - offset * (1000000); - - start_p = psd_scan->psd_start_base + (psd_center_freq - - span * (1000000) / 2) / delta_freq_per_point; - psd_scan->psd_start_point = start_p - - psd_scan->psd_start_base; - - stop_p = psd_scan->psd_start_base + (psd_center_freq + - span * (1000000) / 2) / delta_freq_per_point; - psd_scan->psd_stop_point = stop_p - - psd_scan->psd_start_base - 1; - - flag = 2; - break; - case 2: /* set RF channel/BW/Mode */ - - /* set 3-wire off */ - val = btcoexist->btc_read_4byte(btcoexist, 0x88c); - val |= 0x00300000; - btcoexist->btc_write_4byte(btcoexist, 0x88c, val); - - /* CCK off */ - val = btcoexist->btc_read_4byte(btcoexist, 0x800); - val &= 0xfeffffff; - btcoexist->btc_write_4byte(btcoexist, 0x800, val); - - /* store WiFi original channel */ - wifi_original_channel = btcoexist->btc_get_rf_reg( - btcoexist, BTC_RF_A, 0x18, 0x3ff); - - /* Set RF channel */ - if (cent_freq == 2484) - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, - 0x18, 0x3ff, 0xe); - else - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, - 0x18, 0x3ff, (cent_freq - 2412) / 5 + - 1); /* WiFi TRx Mask on */ - - /* Set RF mode = Rx, RF Gain = 0x8a0 */ - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x0, - 0xfffff, 0x308a0); - - /* Set RF Rx filter corner */ - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1e, - 0xfffff, 0x3e4); - - /* Set TRx mask off */ - /* un-lock TRx Mask setup */ - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0xdd, - 0x80, 0x1); - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0xdf, - 0x1, 0x1); - - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, - 0xfffff, 0x0); - - flag = 3; - break; - case 3: - memset(psd_scan->psd_report, 0, - psd_scan->psd_point * sizeof(u32)); - start_p = psd_scan->psd_start_point + - psd_scan->psd_start_base; - stop_p = psd_scan->psd_stop_point + - psd_scan->psd_start_base + 1; - - i = start_p; - - while (i < stop_p) { - if (i >= points1) - psd_report = - halbtc8822b1ant_psd_getdata( - btcoexist, i - points1); - else - psd_report = - halbtc8822b1ant_psd_getdata( - btcoexist, i); - - if (psd_report == 0) - tmp = 0; - else - /* tmp = 20*log10((double)psd_report); */ - /* 20*log2(x)/log2(10), log2Base return theresult of the psd_report*100 */ - tmp = 6 * halbtc8822b1ant_psd_log2base( - btcoexist, psd_report); - - n = i - psd_scan->psd_start_base; - psd_scan->psd_report[n] = tmp; - psd_rep1 = psd_scan->psd_report[n] / 100; - psd_rep2 = psd_scan->psd_report[n] - psd_rep1 * - 100; - - freq = ((cent_freq - 20) * 1000000 + n * - delta_freq_per_point); - freq1 = freq / 1000000; - freq2 = freq / 1000 - freq1 * 1000; - - i++; - - k = 0; - - /* Add Delay between PSD point */ - while (1) { - if (k++ > 20000) - break; - } - - } - - flag = 100; - break; - case 99: /* error */ - - outloop = true; - break; - case 100: /* recovery */ - - /* set 3-wire on */ - val = btcoexist->btc_read_4byte(btcoexist, 0x88c); - val &= 0xffcfffff; - btcoexist->btc_write_4byte(btcoexist, 0x88c, val); - - /* CCK on */ - val = btcoexist->btc_read_4byte(btcoexist, 0x800); - val |= 0x01000000; - btcoexist->btc_write_4byte(btcoexist, 0x800, val); - - /* PSD off */ - val = btcoexist->btc_read_4byte(btcoexist, 0x808); - val &= 0xffbfffff; - btcoexist->btc_write_4byte(btcoexist, 0x808, val); - - /* TRx Mask on */ - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, - 0xfffff, 0x780); - - /* lock TRx Mask setup */ - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0xdd, - 0x80, 0x0); - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0xdf, - 0x1, 0x0); - - /* Set RF Rx filter corner */ - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1e, - 0xfffff, 0x0); - - /* restore WiFi original channel */ - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x18, - 0x3ff, wifi_original_channel); - - outloop = true; - break; - - } - - } while (!outloop); - - - - psd_scan->is_psd_running = false; - - -} - -#if (BTC_COEX_OFFLOAD == 1) -void halbtc8822b1ant_wifi_info_notify(IN struct btc_coexist *btcoexist) -{ - u8 h2c_para[4] = {0}; - u8 opcode_ver = 0; - u8 ap_num = 0; - s32 wifi_rssi = 0; - boolean wifi_busy = false; - - btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi); - btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM, &ap_num); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - - h2c_para[0] = ap_num; /* AP number */ - h2c_para[1] = (u8)wifi_busy; /* Busy */ - h2c_para[2] = (u8)wifi_rssi; /* RSSI */ - - btcoexist->btc_coex_h2c_process(btcoexist, COL_OP_WIFI_INFO_NOTIFY, - opcode_ver, &h2c_para[0], 3); -} - -void halbtc8822b1ant_setManual(IN struct btc_coexist *btcoexist, - IN boolean manual) -{ - u8 h2c_para[4] = {0}; - u8 opcode_ver = 0; - u8 set_type = 0; - - if (manual) - set_type = 1; - else - set_type = 0; - - h2c_para[0] = set_type; /* set_type */ - - btcoexist->btc_coex_h2c_process(btcoexist, COL_OP_SET_CONTROL, - opcode_ver, - &h2c_para[0], 1); -} - -/* ************************************************************ - * work around function start with wa_halbtc8822b1ant_ - * ************************************************************ - * ************************************************************ - * extern function start with ex_halbtc8822b1ant_ - * ************************************************************ */ - -void ex_halbtc8822b1ant_power_on_setting(IN struct btc_coexist *btcoexist) -{} -void ex_halbtc8822b1ant_pre_load_firmware(IN struct btc_coexist *btcoexist) -{} -void ex_halbtc8822b1ant_init_hw_config(IN struct btc_coexist *btcoexist, - IN boolean wifi_only) -{} -void ex_halbtc8822b1ant_init_coex_dm(IN struct btc_coexist *btcoexist) -{} -void ex_halbtc8822b1ant_ips_notify(IN struct btc_coexist *btcoexist, IN u8 type) -{ - u8 h2c_para[4] = {0}; - u8 opcode_ver = 0; - u8 ips_notify = 0; - - if (BTC_IPS_ENTER == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], IPS ENTER notify\n"); - BTC_TRACE(trace_buf); - ips_notify = 1; - } else if (BTC_IPS_LEAVE == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], IPS LEAVE notify\n"); - BTC_TRACE(trace_buf); - } - - h2c_para[0] = ips_notify; /* IPS notify */ - h2c_para[1] = 0xff; /* LPS notify */ - h2c_para[2] = 0xff; /* RF state notify */ - h2c_para[3] = 0xff; /* pnp notify */ - - btcoexist->btc_coex_h2c_process(btcoexist, - COL_OP_WIFI_POWER_STATE_NOTIFY, - opcode_ver, &h2c_para[0], 4); -} -void ex_halbtc8822b1ant_lps_notify(IN struct btc_coexist *btcoexist, IN u8 type) -{ - u8 h2c_para[4] = {0}; - u8 opcode_ver = 0; - u8 lps_notify = 0; - - if (BTC_LPS_ENABLE == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], LPS ENABLE notify\n"); - BTC_TRACE(trace_buf); - lps_notify = 1; - } else if (BTC_LPS_DISABLE == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], LPS DISABLE notify\n"); - BTC_TRACE(trace_buf); - } - - h2c_para[0] = 0xff; /* IPS notify */ - h2c_para[1] = lps_notify; /* LPS notify */ - h2c_para[2] = 0xff; /* RF state notify */ - h2c_para[3] = 0xff; /* pnp notify */ - - btcoexist->btc_coex_h2c_process(btcoexist, - COL_OP_WIFI_POWER_STATE_NOTIFY, - opcode_ver, &h2c_para[0], 4); -} - -void ex_halbtc8822b1ant_scan_notify(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - u8 h2c_para[4] = {0}; - u8 opcode_ver = 0; - u8 scan_start = 0; - boolean under_4way = false; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS, - &under_4way); - if (BTC_SCAN_START == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCAN START notify\n"); - BTC_TRACE(trace_buf); - scan_start = 1; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCAN FINISH notify\n"); - BTC_TRACE(trace_buf); - } - - h2c_para[0] = scan_start; /* scan notify */ - h2c_para[1] = 0xff; /* connect notify */ - h2c_para[2] = 0xff; /* specific packet notify */ - if (under_4way) - h2c_para[3] = 1; /* under 4way progress */ - else - h2c_para[3] = 0; - - btcoexist->btc_coex_h2c_process(btcoexist, COL_OP_WIFI_PROGRESS_NOTIFY, - opcode_ver, &h2c_para[0], 4); -} - -void ex_halbtc8822b1ant_connect_notify(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - u8 h2c_para[4] = {0}; - u8 opcode_ver = 0; - u8 connect_start = 0; - boolean under_4way = false; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS, - &under_4way); - if (BTC_ASSOCIATE_START == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], CONNECT START notify\n"); - BTC_TRACE(trace_buf); - connect_start = 1; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], CONNECT FINISH notify\n"); - BTC_TRACE(trace_buf); - } - - h2c_para[0] = 0xff; /* scan notify */ - h2c_para[1] = connect_start; /* connect notify */ - h2c_para[2] = 0xff; /* specific packet notify */ - if (under_4way) - h2c_para[3] = 1; /* under 4way progress */ - else - h2c_para[3] = 0; - - btcoexist->btc_coex_h2c_process(btcoexist, COL_OP_WIFI_PROGRESS_NOTIFY, - opcode_ver, &h2c_para[0], 4); -} - -void ex_halbtc8822b1ant_media_status_notify(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - u32 wifi_bw; - u8 wifi_central_chnl; - u8 h2c_para[5] = {0}; - u8 opcode_ver = 0; - u8 port = 0, connected = 0, freq = 0, bandwidth = 0, iot_peer = 0; - boolean wifi_under_5g = false; - - if (BTC_MEDIA_CONNECT == type) - connected = 1; - - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw); - bandwidth = (u8)wifi_bw; - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g); - if (wifi_under_5g) - freq = 1; - else - freq = 0; - btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_CENTRAL_CHNL, - &wifi_central_chnl); - btcoexist->btc_get(btcoexist, BTC_GET_U1_IOT_PEER, &iot_peer); - - h2c_para[0] = (connected << 4) | - port; /* port need to be implemented in the future (p2p port, ...) */ - h2c_para[1] = (freq << 4) | bandwidth; - h2c_para[2] = wifi_central_chnl; - h2c_para[3] = iot_peer; - btcoexist->btc_coex_h2c_process(btcoexist, COL_OP_WIFI_STATUS_NOTIFY, - opcode_ver, &h2c_para[0], 4); -} - -void ex_halbtc8822b1ant_specific_packet_notify(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - u8 h2c_para[4] = {0}; - u8 opcode_ver = 0; - u8 connect_start = 0; - boolean under_4way = false; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS, - &under_4way); - - h2c_para[0] = 0xff; /* scan notify */ - h2c_para[1] = 0xff; /* connect notify */ - h2c_para[2] = type; /* specific packet notify */ - if (under_4way) - h2c_para[3] = 1; /* under 4way progress */ - else - h2c_para[3] = 0; - - btcoexist->btc_coex_h2c_process(btcoexist, COL_OP_WIFI_PROGRESS_NOTIFY, - opcode_ver, &h2c_para[0], 4); -} - -void ex_halbtc8822b1ant_bt_info_notify(IN struct btc_coexist *btcoexist, - IN u8 *tmp_buf, IN u8 length) -{} -void ex_halbtc8822b1ant_rf_status_notify(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - u8 h2c_para[4] = {0}; - u8 opcode_ver = 0; - u8 rfstate_notify = 0; - - if (BTC_RF_ON == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], RF is turned ON!!\n"); - BTC_TRACE(trace_buf); - rfstate_notify = 1; - } else if (BTC_RF_OFF == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], RF is turned OFF!!\n"); - BTC_TRACE(trace_buf); - } - - h2c_para[0] = 0xff; /* IPS notify */ - h2c_para[1] = 0xff; /* LPS notify */ - h2c_para[2] = rfstate_notify; /* RF state notify */ - h2c_para[3] = 0xff; /* pnp notify */ - - btcoexist->btc_coex_h2c_process(btcoexist, - COL_OP_WIFI_POWER_STATE_NOTIFY, - opcode_ver, &h2c_para[0], 4); -} - -void ex_halbtc8822b1ant_halt_notify(IN struct btc_coexist *btcoexist) -{} -void ex_halbtc8822b1ant_pnp_notify(IN struct btc_coexist *btcoexist, - IN u8 pnp_state) -{ - u8 h2c_para[4] = {0}; - u8 opcode_ver = 0; - u8 pnp_notify = 0; - - if (BTC_WIFI_PNP_SLEEP == pnp_state) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Pnp notify to SLEEP\n"); - BTC_TRACE(trace_buf); - pnp_notify = 1; - } else if (BTC_WIFI_PNP_WAKE_UP == pnp_state) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Pnp notify to WAKE UP\n"); - BTC_TRACE(trace_buf); - } - - h2c_para[0] = 0xff; /* IPS notify */ - h2c_para[1] = 0xff; /* LPS notify */ - h2c_para[2] = 0xff; /* RF state notify */ - h2c_para[3] = pnp_notify; /* pnp notify */ - - btcoexist->btc_coex_h2c_process(btcoexist, - COL_OP_WIFI_POWER_STATE_NOTIFY, - opcode_ver, &h2c_para[0], 4); -} - -void ex_halbtc8822b1ant_coex_dm_reset(IN struct btc_coexist *btcoexist) -{} -void ex_halbtc8822b1ant_periodical(IN struct btc_coexist *btcoexist) -{ - - halbtc8822b1ant_wifi_info_notify(btcoexist); -} - -void ex_halbtc8822b1ant_display_coex_info(IN struct btc_coexist *btcoexist) -{ - struct btc_board_info *board_info = &btcoexist->board_info; - struct btc_stack_info *stack_info = &btcoexist->stack_info; - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - u8 *cli_buf = btcoexist->cli_buf; - u8 u8tmp[4], i, bt_info_ext, ps_tdma_case = 0; - u16 u16tmp[4]; - u32 u32tmp[4]; - u32 fa_ofdm, fa_cck, cca_ofdm, cca_cck; - u32 fw_ver = 0, bt_patch_ver = 0, bt_coex_ver = 0; - static u8 pop_report_in_10s = 0; - u32 phyver = 0; - boolean lte_coex_on = false; - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n ============[BT Coexist info]============"); - CL_PRINTF(cli_buf); - - if (btcoexist->manual_control) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n ============[Under Manual Control]============"); - CL_PRINTF(cli_buf); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n =========================================="); - CL_PRINTF(cli_buf); - } - if (btcoexist->stop_coex_dm) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n ============[Coex is STOPPED]============"); - CL_PRINTF(cli_buf); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n =========================================="); - CL_PRINTF(cli_buf); - } - - if (psd_scan->ant_det_try_count == 0) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %d/ %d/ %s / %d", - "Ant PG Num/ Mech/ Pos/ RFE", - board_info->pg_ant_num, board_info->btdm_ant_num, - (board_info->btdm_ant_pos == BTC_ANTENNA_AT_MAIN_PORT - ? "Main" : "Aux"), - rfe_type->rfe_module_type); - CL_PRINTF(cli_buf); - } else { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %d/ %d/ %s/ %d (%d/%d/%d)", - "Ant PG Num/ Mech(Ant_Det)/ Pos/ RFE", - board_info->pg_ant_num, - board_info->btdm_ant_num_by_ant_det, - (board_info->btdm_ant_pos == BTC_ANTENNA_AT_MAIN_PORT - ? "Main" : "Aux"), - rfe_type->rfe_module_type, - psd_scan->ant_det_try_count, - psd_scan->ant_det_fail_count, - psd_scan->ant_det_result); - CL_PRINTF(cli_buf); - - if (board_info->btdm_ant_det_finish) { - if (psd_scan->ant_det_result != 12) - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s", - "Ant Det PSD Value", - psd_scan->ant_det_peak_val); - else - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %d", - "Ant Det PSD Value", - psd_scan->ant_det_psd_scan_peak_val / 100); - - CL_PRINTF(cli_buf); - } - } - - btcoexist->btc_get(btcoexist, BTC_GET_U4_BT_PATCH_VER, &bt_patch_ver); - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, &fw_ver); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %d_%x/ 0x%x/ 0x%x(%d)", - "CoexVer/ FwVer/ PatchVer", - glcoex_ver_date_8822b_1ant, glcoex_ver_8822b_1ant, fw_ver, - bt_patch_ver, bt_patch_ver); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x ", - "Wifi channel informed to BT", - coex_dm->wifi_chnl_info[0], coex_dm->wifi_chnl_info[1], - coex_dm->wifi_chnl_info[2]); - CL_PRINTF(cli_buf); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s/ %s", - "WifibHiPri/ Ccklock/ CckEverLock", - (coex_sta->wifi_is_high_pri_task ? "Yes" : "No"), - (coex_sta->cck_lock ? "Yes" : "No"), - (coex_sta->cck_ever_lock ? "Yes" : "No")); - CL_PRINTF(cli_buf); - - /* wifi status */ - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s", - "============[Wifi Status]============"); - CL_PRINTF(cli_buf); - btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_WIFI_STATUS); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s", - "============[BT Status]============"); - CL_PRINTF(cli_buf); - - pop_report_in_10s++; - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = [%s/ %d/ %d/ %d] ", - "BT [status/ rssi/ retryCnt/ popCnt]", - ((coex_sta->bt_disabled) ? ("disabled") : (( - coex_sta->c2h_bt_inquiry_page) ? ("inquiry/page scan") - : ((BT_8822B_1ANT_BT_STATUS_NON_CONNECTED_IDLE == - coex_dm->bt_status) ? "non-connected idle" : - ((BT_8822B_1ANT_BT_STATUS_CONNECTED_IDLE == coex_dm->bt_status) - ? "connected-idle" : "busy")))), - coex_sta->bt_rssi - 100, coex_sta->bt_retry_cnt, - coex_sta->pop_event_cnt); - CL_PRINTF(cli_buf); - - if (pop_report_in_10s >= 5) { - coex_sta->pop_event_cnt = 0; - pop_report_in_10s = 0; - } - - if (coex_sta->num_of_profile != 0) - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %s%s%s%s%s", - "Profiles", - ((bt_link_info->a2dp_exist) ? "A2DP," : ""), - ((bt_link_info->sco_exist) ? "SCO," : ""), - ((bt_link_info->hid_exist) ? - ((coex_sta->hid_busy_num >= 2) ? "HID(4/18)," : "HID(2/18),") : ""), - ((bt_link_info->pan_exist) ? "PAN," : ""), - ((coex_sta->voice_over_HOGP) ? "Voice" : "")); - else - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = None", "Profiles"); - - CL_PRINTF(cli_buf); - - if (bt_link_info->a2dp_exist) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %s", - "A2DP Rate/Bitpool/Auto_Slot", - ((coex_sta->is_A2DP_3M) ? "3M" : "No_3M"), - coex_sta->a2dp_bit_pool, - ((coex_sta->is_autoslot) ? "On" : "Off")); - CL_PRINTF(cli_buf); - } - - if (bt_link_info->hid_exist) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", - "HID PairNum/Forbid_Slot", - coex_sta->hid_pair_cnt, - coex_sta->forbidden_slot - ); - CL_PRINTF(cli_buf); - } - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s / %s/ 0x%x/ 0x%x", - "Role/IgnWlanAct/Feature/BLEScan", - ((bt_link_info->slave_role) ? "Slave" : "Master"), - ((coex_dm->cur_ignore_wlan_act) ? "Yes":"No"), - coex_sta->bt_coex_supported_feature, - coex_sta->bt_ble_scan_type); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d/ %d", - "ReInit/ReLink/IgnWlact/Page/NameReq", - coex_sta->cnt_ReInit, - coex_sta->cnt_setupLink, - coex_sta->cnt_IgnWlanAct, - coex_sta->cnt_Page, - coex_sta->cnt_RemoteNameReq - ); - CL_PRINTF(cli_buf); - - halbtc8822b1ant_read_score_board(btcoexist, &u16tmp[0]); - - if ((coex_sta->bt_reg_vendor_ae == 0xffff) || - (coex_sta->bt_reg_vendor_ac == 0xffff)) - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = x/ x/ %04x", - "0xae[4]/0xac[1:0]/Scoreboard", u16tmp[0]); - else - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = 0x%x/ 0x%x/ %04x", - "0xae[4]/0xac[1:0]/Scoreboard", - ((coex_sta->bt_reg_vendor_ae & BIT(4))>>4), - coex_sta->bt_reg_vendor_ac & 0x3, u16tmp[0]); - CL_PRINTF(cli_buf); - - for (i = 0; i < BT_INFO_SRC_8822B_1ANT_MAX; i++) { - if (coex_sta->bt_info_c2h_cnt[i]) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %02x %02x %02x %02x %02x %02x %02x(%d)", - glbt_info_src_8822b_1ant[i], - coex_sta->bt_info_c2h[i][0], - coex_sta->bt_info_c2h[i][1], - coex_sta->bt_info_c2h[i][2], - coex_sta->bt_info_c2h[i][3], - coex_sta->bt_info_c2h[i][4], - coex_sta->bt_info_c2h[i][5], - coex_sta->bt_info_c2h[i][6], - coex_sta->bt_info_c2h_cnt[i]); - CL_PRINTF(cli_buf); - } - } - - - if (btcoexist->manual_control) - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s", - "============[mechanisms] (before Manual)============"); - else - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s", - "============[mechanisms]============"); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d", - "SM[LowPenaltyRA]", - coex_dm->cur_low_penalty_ra); - CL_PRINTF(cli_buf); - - ps_tdma_case = coex_dm->cur_ps_tdma; - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %02x %02x %02x %02x %02x case-%d (%s,%s)", - "PS TDMA", - coex_dm->ps_tdma_para[0], coex_dm->ps_tdma_para[1], - coex_dm->ps_tdma_para[2], coex_dm->ps_tdma_para[3], - coex_dm->ps_tdma_para[4], ps_tdma_case, - (coex_dm->cur_ps_tdma_on ? "On" : "Off"), - (coex_dm->auto_tdma_adjust ? "Adj" : "Fix")); - - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d", - "WL/BT Coex Table Type", - coex_sta->coex_table_type); - CL_PRINTF(cli_buf); - - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x6c0); - u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x6c4); - u32tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0x6c8); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", - "0x6c0/0x6c4/0x6c8(coexTable)", - u32tmp[0], u32tmp[1], u32tmp[2]); - CL_PRINTF(cli_buf); - - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x778); - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x6cc); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", - "0x778/0x6cc/IgnWlanAct", - u8tmp[0], u32tmp[0], coex_dm->cur_ignore_wlan_act); - CL_PRINTF(cli_buf); - - u32tmp[0] = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist, - 0xa0); - u32tmp[1] = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist, - 0xa4); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", - "LTE Coex Table W_L/B_L", - u32tmp[0] & 0xffff, u32tmp[1] & 0xffff); - CL_PRINTF(cli_buf); - - u32tmp[0] = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist, - 0xa8); - u32tmp[1] = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist, - 0xac); - u32tmp[2] = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist, - 0xb0); - u32tmp[3] = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist, - 0xb4); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", - "LTE Break Table W_L/B_L/L_W/L_B", - u32tmp[0] & 0xffff, u32tmp[1] & 0xffff, - u32tmp[2] & 0xffff, u32tmp[3] & 0xffff); - CL_PRINTF(cli_buf); - - /* Hw setting */ - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s", - "============[Hw setting]============"); - CL_PRINTF(cli_buf); -/* - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x430); - u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x434); - u16tmp[0] = btcoexist->btc_read_2byte(btcoexist, 0x42a); - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x456); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/0x%x/0x%x/0x%x", - "0x430/0x434/0x42a/0x456", - u32tmp[0], u32tmp[1], u16tmp[0], u8tmp[0]); - CL_PRINTF(cli_buf); -*/ - - u32tmp[0] = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist, 0x38); - u32tmp[1] = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist, 0x54); - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x73); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %s", - "LTE CoexOn/Path Ctrl Owner", - (int)((u32tmp[0]&BIT(7)) >> 7), - ((u8tmp[0]&BIT(2)) ? "WL" : "BT")); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d", - "LTE 3Wire/OPMode/UART/UARTMode", - (int)((u32tmp[0]&BIT(6)) >> 6), - (int)((u32tmp[0] & (BIT(5) | BIT(4))) >> 4), - (int)((u32tmp[0]&BIT(3)) >> 3), - (int)(u32tmp[0] & (BIT(2) | BIT(1) | BIT(0)))); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %s", - "GNT_WL_SWCtrl/GNT_BT_SWCtrl/Dbg", - (int)((u32tmp[0]&BIT(12)) >> 12), - (int)((u32tmp[0]&BIT(14)) >> 14), - ((u8tmp[0]&BIT(3)) ? "On" : "Off")); - CL_PRINTF(cli_buf); - - u32tmp[0] = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist, 0x54); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d", - "GNT_WL/GNT_BT/LTE_Busy/UART_Busy", - (int)((u32tmp[0]&BIT(2)) >> 2), - (int)((u32tmp[0]&BIT(3)) >> 3), - (int)((u32tmp[0]&BIT(1)) >> 1), (int)(u32tmp[0]&BIT(0))); - CL_PRINTF(cli_buf); - - - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x4c6); - u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0x40); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", - "0x4c6[4]/0x40[5] (WL/BT PTA)", - (int)((u8tmp[0] & BIT(4)) >> 4), - (int)((u8tmp[1] & BIT(5)) >> 5)); - CL_PRINTF(cli_buf); - - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x550); - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x522); - u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0x953); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ %s", - "0x550(bcn ctrl)/0x522/4-RxAGC", - u32tmp[0], u8tmp[0], (u8tmp[1] & 0x2) ? "On" : "Off"); - CL_PRINTF(cli_buf); - - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xda0); - u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0xda4); - u32tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0xda8); - u32tmp[3] = btcoexist->btc_read_4byte(btcoexist, 0xcf0); - - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0xa5b); - u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0xa5c); - - fa_ofdm = ((u32tmp[0] & 0xffff0000) >> 16) + ((u32tmp[1] & 0xffff0000) - >> 16) + (u32tmp[1] & 0xffff) + (u32tmp[2] & 0xffff) + - ((u32tmp[3] & 0xffff0000) >> 16) + (u32tmp[3] & - 0xffff); - fa_cck = (u8tmp[0] << 8) + u8tmp[1]; - - u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0xc50); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", - "0xc50/OFDM-CCA/OFDM-FA/CCK-FA", - u32tmp[1] & 0xff, u32tmp[0] & 0xffff, fa_ofdm, fa_cck); - CL_PRINTF(cli_buf); - - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d", - "CRC_OK CCK/11g/11n/11n-Agg", - coex_sta->crc_ok_cck, coex_sta->crc_ok_11g, - coex_sta->crc_ok_11n, coex_sta->crc_ok_11n_agg); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d", - "CRC_Err CCK/11g/11n/11n-Agg", - coex_sta->crc_err_cck, coex_sta->crc_err_11g, - coex_sta->crc_err_11n, coex_sta->crc_err_11n_agg); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", - "0x770(high-pri rx/tx)", - coex_sta->high_priority_rx, coex_sta->high_priority_tx); - CL_PRINTF(cli_buf); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", - "0x774(low-pri rx/tx)", - coex_sta->low_priority_rx, coex_sta->low_priority_tx); - CL_PRINTF(cli_buf); -#if (BT_AUTO_REPORT_ONLY_8822B_1ANT == 1) - /* halbtc8822b1ant_monitor_bt_ctr(btcoexist); */ -#endif - btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_COEX_STATISTICS); -} -void ex_halbtc8822b1ant_antenna_detection(IN struct btc_coexist *btcoexist, - IN u32 cent_freq, IN u32 offset, IN u32 span, IN u32 seconds) -{} -void ex_halbtc8822b1ant_display_ant_detection(IN struct btc_coexist *btcoexist) -{} -void ex_halbtc8822b1ant_dbg_control(IN struct btc_coexist *btcoexist, - IN u8 op_code, IN u8 op_len, IN u8 *pdata) -{ - switch (op_code) { - case BTC_DBG_SET_COEX_MANUAL_CTRL: { - boolean manual = (boolean) *pdata; - - halbtc8822b1ant_setManual(btcoexist, manual); - } - break; - default: - break; - } -} - -#else -void ex_halbtc8822b1ant_power_on_setting(IN struct btc_coexist *btcoexist) -{ - struct btc_board_info *board_info = &btcoexist->board_info; - u8 u8tmp = 0x0; - u16 u16tmp = 0x0; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx Execute 8822b 1-Ant PowerOn Setting!! xxxxxxxxxxxxxxxx\n"); - BTC_TRACE(trace_buf); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "Ant Det Finish = %s, Ant Det Number = %d\n", - board_info->btdm_ant_det_finish ? "Yes" : "No", - board_info->btdm_ant_num_by_ant_det); - BTC_TRACE(trace_buf); - - btcoexist->stop_coex_dm = true; - - /* enable BB, REG_SYS_FUNC_EN such that we can write 0x948 correctly. */ - u16tmp = btcoexist->btc_read_2byte(btcoexist, 0x2); - btcoexist->btc_write_2byte(btcoexist, 0x2, u16tmp | BIT(0) | BIT(1)); - - /* set Path control owner to WiFi */ - halbtc8822b1ant_ltecoex_pathcontrol_owner(btcoexist, - BT_8822B_1ANT_PCO_WLSIDE); - - /* set GNT_BT to high */ - halbtc8822b1ant_ltecoex_set_gnt_bt(btcoexist, - BT_8822B_1ANT_GNT_BLOCK_RFC_BB, - BT_8822B_1ANT_GNT_CTRL_BY_SW, - BT_8822B_1ANT_SIG_STA_SET_TO_HIGH); - /* Set GNT_WL to low */ - halbtc8822b1ant_ltecoex_set_gnt_wl(btcoexist, - BT_8822B_1ANT_GNT_BLOCK_RFC_BB, - BT_8822B_1ANT_GNT_CTRL_BY_SW, - BT_8822B_1ANT_SIG_STA_SET_TO_LOW); - - /* set WLAN_ACT = 0 */ - /* btcoexist->btc_write_1byte(btcoexist, 0x76e, 0x4); */ - - /* SD1 Chunchu red x issue */ - btcoexist->btc_write_1byte(btcoexist, 0xff1a, 0x0); - - halbtc8822b1ant_enable_gnt_to_gpio(btcoexist, true); - - /* */ - /* S0 or S1 setting and Local register setting(By the setting fw can get ant number, S0/S1, ... info) */ - /* Local setting bit define */ - /* BIT0: "0" for no antenna inverse; "1" for antenna inverse */ - /* BIT1: "0" for internal switch; "1" for external switch */ - /* BIT2: "0" for one antenna; "1" for two antenna */ - /* NOTE: here default all internal switch and 1-antenna ==> BIT1=0 and BIT2=0 */ - - u8tmp = 0; - board_info->btdm_ant_pos = BTC_ANTENNA_AT_MAIN_PORT; - - if (btcoexist->chip_interface == BTC_INTF_USB) - btcoexist->btc_write_local_reg_1byte(btcoexist, 0xfe08, u8tmp); - else if (btcoexist->chip_interface == BTC_INTF_SDIO) - btcoexist->btc_write_local_reg_1byte(btcoexist, 0x60, u8tmp); - - BTC_TRACE(trace_buf); - - -} - -void ex_halbtc8822b1ant_power_on_setting_without_bt(IN struct btc_coexist - *btcoexist) -{ - struct btc_board_info *board_info = &btcoexist->board_info; - u8 u8tmp = 0x0; - u16 u16tmp = 0x0; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - " 8822b 1-Ant PowerOn Setting without bt\n"); - BTC_TRACE(trace_buf); - - btcoexist->stop_coex_dm = true; - - /* enable BB, REG_SYS_FUNC_EN such that we can write 0x948 correctly. */ - u16tmp = btcoexist->btc_read_2byte(btcoexist, 0x2); - btcoexist->btc_write_2byte(btcoexist, 0x2, u16tmp | BIT(0) | BIT(1)); - - - /* SD1 Chunchu red x issue */ - btcoexist->btc_write_1byte(btcoexist, 0xff1a, 0x0); - - u8tmp = 0; - board_info->btdm_ant_pos = BTC_ANTENNA_AT_MAIN_PORT; - - if (btcoexist->chip_interface == BTC_INTF_USB) - btcoexist->btc_write_local_reg_1byte(btcoexist, 0xfe08, u8tmp); - else if (btcoexist->chip_interface == BTC_INTF_SDIO) - btcoexist->btc_write_local_reg_1byte(btcoexist, 0x60, u8tmp); - - - -} - - -void ex_halbtc8822b1ant_pre_load_firmware(IN struct btc_coexist *btcoexist) -{ -} - -void ex_halbtc8822b1ant_init_hw_config(IN struct btc_coexist *btcoexist, - IN boolean wifi_only) -{ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** (ini hw config) **********\n"); - - halbtc8822b1ant_init_hw_config(btcoexist, true, wifi_only); - btcoexist->stop_coex_dm = false; -} - -void ex_halbtc8822b1ant_init_hw_config_without_bt(IN struct btc_coexist - *btcoexist, - IN boolean wifi_only) -{ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** (ini hw config) **********\n"); - - halbtc8822b1ant_init_hw_config_without_bt(btcoexist, true, wifi_only); - btcoexist->stop_coex_dm = true; -} - -void ex_halbtc8822b1ant_antenna_switch_without_bt(IN struct btc_coexist - *btcoexist) -{ - - boolean wifi_under_5g = false; - - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g); - - if (wifi_under_5g) - - btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbd, - 0x3, 1); - - else - btcoexist->btc_write_1byte_bitmask(btcoexist, - 0xcbd, 0x3, 2); - - -} - -void ex_halbtc8822b1ant_init_coex_dm(IN struct btc_coexist *btcoexist) -{ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Coex Mechanism Init!!\n"); - BTC_TRACE(trace_buf); - - btcoexist->stop_coex_dm = false; - - halbtc8822b1ant_init_coex_dm(btcoexist); - - halbtc8822b1ant_query_bt_info(btcoexist); -} - -void ex_halbtc8822b1ant_display_coex_info(IN struct btc_coexist *btcoexist) -{ - - struct btc_board_info *board_info = &btcoexist->board_info; - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - u8 *cli_buf = btcoexist->cli_buf; - u8 u8tmp[4], i, bt_info_ext, ps_tdma_case = 0; - u16 u16tmp[4]; - u32 fa_ofdm, fa_cck, cca_ofdm, cca_cck; - u32 u32tmp[4]; - u32 fa_of_dm; - u32 fw_ver = 0, bt_patch_ver = 0; - static u8 pop_report_in_10s = 0; - u32 phyver = 0; - /*u32 pnp_wake_cnt=0;*/ - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** (display coexinfo) **********\n"); - BTC_TRACE(trace_buf); - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** displaycoexinfostart, 0xcb4/0xcbd = 0x%x/0x%x\n", - btcoexist->btc_read_1byte(btcoexist, 0xcb4), - btcoexist->btc_read_1byte(btcoexist, 0xcbd)); - BTC_TRACE(trace_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n ============[BT Coexist info]============"); - CL_PRINTF(cli_buf); - - if (btcoexist->manual_control) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n ============[Under Manual Control]============"); - CL_PRINTF(cli_buf); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n =========================================="); - CL_PRINTF(cli_buf); - } - - if (btcoexist->stop_coex_dm) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n ============[Coex is STOPPED]============"); - CL_PRINTF(cli_buf); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n =========================================="); - CL_PRINTF(cli_buf); - } - - if (psd_scan->ant_det_try_count == 0) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %d/ %d/ %d/ %d", - "Ant PG Num/ Mech/ Pos/ RFE", - board_info->pg_ant_num, board_info->btdm_ant_num, - board_info->btdm_ant_pos, - rfe_type->rfe_module_type); - CL_PRINTF(cli_buf); - } else { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %d/ %d/ %d/ %d (%d/%d/%d)", - "Ant PG Num/ Mech(Ant_Det)/ Pos/ RFE", - board_info->pg_ant_num, - board_info->btdm_ant_num_by_ant_det, - board_info->btdm_ant_pos, - rfe_type->rfe_module_type, - psd_scan->ant_det_try_count, - psd_scan->ant_det_fail_count, - psd_scan->ant_det_result); - CL_PRINTF(cli_buf); - - if (board_info->btdm_ant_det_finish) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s", - "Ant Det PSD Value", - psd_scan->ant_det_peak_val); - CL_PRINTF(cli_buf); - } - } - /*btcoexist->btc_get(btcoexist, BTC_GET_U4_BT_PATCH_VER, &bt_patch_ver);*/ - bt_patch_ver = btcoexist->bt_info.bt_get_fw_ver; - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, &fw_ver); - phyver = btcoexist->btc_get_bt_phydm_version(btcoexist); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %d_%02x/ 0x%02x/ 0x%02x (%s)", - "CoexVer WL/ BT_Desired/ BT_Report", - glcoex_ver_date_8822b_1ant, glcoex_ver_8822b_1ant, - glcoex_ver_btdesired_8822b_1ant, - ((coex_sta->bt_coex_supported_version & 0xff00) >> - 8), - (((coex_sta->bt_coex_supported_version & 0xff00) >> - 8) >= - glcoex_ver_btdesired_8822b_1ant ? "Match" : - "Mis-Match")); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = 0x%x/ 0x%x/ v%d/ %c", - "W_FW/ B_FW/ Phy/ Kt", - fw_ver, bt_patch_ver, phyver, - coex_sta->cut_version + 65); - CL_PRINTF(cli_buf); - - - - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x ", - "Wifi channel informed to BT", - coex_dm->wifi_chnl_info[0], coex_dm->wifi_chnl_info[1], - coex_dm->wifi_chnl_info[2]); - CL_PRINTF(cli_buf); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s/ %s", - "WifibHiPri/ Ccklock/ CckEverLock", - (coex_sta->wifi_is_high_pri_task ? "Yes" : "No"), - (coex_sta->cck_lock ? "Yes" : "No"), - (coex_sta->cck_ever_lock ? "Yes" : "No")); - CL_PRINTF(cli_buf); - - /* wifi status */ - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s", - "============[Wifi Status]============"); - CL_PRINTF(cli_buf); - btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_WIFI_STATUS); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s", - "============[BT Status]============"); - CL_PRINTF(cli_buf); - - pop_report_in_10s++; - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = [%s/ %d/ %d/ %d] ", - "BT [status/ rssi/ retryCnt/ popCnt]", - ((coex_sta->bt_disabled) ? ("disabled") : (( - coex_sta->c2h_bt_inquiry_page) ? ("inquiry/page scan") - : ((BT_8822B_1ANT_BT_STATUS_NON_CONNECTED_IDLE == - coex_dm->bt_status) ? "non-connected idle" : - ((BT_8822B_1ANT_BT_STATUS_CONNECTED_IDLE == coex_dm->bt_status) - ? "connected-idle" : "busy")))), - coex_sta->bt_rssi - 100, coex_sta->bt_retry_cnt, - coex_sta->pop_event_cnt); - CL_PRINTF(cli_buf); - /*bt rssi */ - /*bt pop_even_cnt : bt retry*/ - - if (pop_report_in_10s >= 5) { - coex_sta->pop_event_cnt = 0; - pop_report_in_10s = 0; - } - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %d / %d / %d / %d / %d", - "SCO/HID/PAN/A2DP/Hi-Pri", - bt_link_info->sco_exist, bt_link_info->hid_exist, - bt_link_info->pan_exist, bt_link_info->a2dp_exist, - bt_link_info->bt_hi_pri_link_exist); - CL_PRINTF(cli_buf); - - { - bt_info_ext = coex_sta->bt_info_ext; - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %s / %s / %d/ %x/ %02x", - "Role/A2DP Rate/Bitpool/Feature/Ver", - ((bt_link_info->slave_role) ? "Slave" : "Master"), - (bt_info_ext & BIT(0)) ? "BR" : "EDR", - coex_sta->a2dp_bit_pool, - coex_sta->bt_coex_supported_feature, - ((coex_sta->bt_coex_supported_version & 0xff00) >> 8)); - CL_PRINTF(cli_buf); - } - - /*bt info*/ - for (i = 0; i < BT_INFO_SRC_8822B_1ANT_MAX; i++) { - if (coex_sta->bt_info_c2h_cnt[i]) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %02x %02x %02x %02x %02x %02x %02x(%d)", - glbt_info_src_8822b_1ant[i], - coex_sta->bt_info_c2h[i][0], - coex_sta->bt_info_c2h[i][1], - coex_sta->bt_info_c2h[i][2], - coex_sta->bt_info_c2h[i][3], - coex_sta->bt_info_c2h[i][4], - coex_sta->bt_info_c2h[i][5], - coex_sta->bt_info_c2h[i][6], - coex_sta->bt_info_c2h_cnt[i]); - CL_PRINTF(cli_buf); - } - } - - - if (btcoexist->manual_control) - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s", - "============[mechanisms] (before Manual)============"); - else - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s", - "============[mechanisms]============"); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d", - "SM[LowPenaltyRA]", - coex_dm->cur_low_penalty_ra); - CL_PRINTF(cli_buf); - - /*(ps)tdma*/ - ps_tdma_case = coex_dm->cur_ps_tdma; - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %02x %02x %02x %02x %02x case-%d (%s,%s)", - "PS TDMA", - coex_dm->ps_tdma_para[0], coex_dm->ps_tdma_para[1], - coex_dm->ps_tdma_para[2], coex_dm->ps_tdma_para[3], - coex_dm->ps_tdma_para[4], ps_tdma_case, - (coex_dm->cur_ps_tdma_on ? "On" : "Off"), - (coex_dm->auto_tdma_adjust ? "Adj" : "Fix")); - - CL_PRINTF(cli_buf); - - /*coex table type*/ - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d", - "WL/BT Coex Table Type", - coex_sta->coex_table_type); - CL_PRINTF(cli_buf); - - /*coex table :0x6c0 0x6c4 , break table: 0x6c8*/ - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x6c0); - u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x6c4); - u32tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0x6c8); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", - "0x6c0/0x6c4/0x6c8(coexTable)", - u32tmp[0], u32tmp[1], u32tmp[2]); - CL_PRINTF(cli_buf); - - /*PTA : 0x778=1/3/d , WL BA,RTS,CTS :0x6cc H/L pri */ - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x778); - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x6cc); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", - "0x778/0x6cc/IgnWlanAct", - u8tmp[0], u32tmp[0], coex_dm->cur_ignore_wlan_act); - CL_PRINTF(cli_buf); - - - /*LTE : WL/LTE coex table : 0xa0 */ - - u32tmp[0] = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist, - 0xa0); - - /*LTE : BT/LTE coex table : 0xa4 */ - u32tmp[1] = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist, - 0xa4); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", - "LTE Coex Table W_L/B_L", - u32tmp[0] & 0xffff, u32tmp[1] & 0xffff); - CL_PRINTF(cli_buf); - - /*LTE : WL/LTE break table : 0xa8 */ - u32tmp[0] = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist, - 0xa8); - /*LTE : WL/LTE break table : 0xac */ - u32tmp[1] = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist, - 0xac); - /*LTE : LTE/WL break table : 0xb0 */ - u32tmp[2] = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist, - 0xb0); - /*LTE : LTE/BT break table : 0xb4 */ - u32tmp[3] = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist, - 0xb4); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", - "LTE Break Table W_L/B_L/L_W/L_B", - u32tmp[0] & 0xffff, u32tmp[1] & 0xffff, - u32tmp[2] & 0xffff, u32tmp[3] & 0xffff); - CL_PRINTF(cli_buf); - - /* Hw setting */ - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s", - "============[Hw setting]============"); - CL_PRINTF(cli_buf); - - - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x430); - u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x434); - u16tmp[0] = btcoexist->btc_read_2byte(btcoexist, 0x42a); - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x456); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/0x%x/0x%x/0x%x", - "0x430/0x434/0x42a/0x456", - u32tmp[0], u32tmp[1], u16tmp[0], u8tmp[0]); - CL_PRINTF(cli_buf); - - /*ANT setting*/ - u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0xcb4); - u8tmp[2] = btcoexist->btc_read_1byte(btcoexist, 0xcbd); - u8tmp[3] = btcoexist->btc_read_1byte(btcoexist, 0x1991); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", - "0xcb4/0xcbd/0x1991", - u8tmp[1], u8tmp[2], u8tmp[3]); - CL_PRINTF(cli_buf); - - /*LTE on/off , Path ctrl owner*/ - /*sy add*/ - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x4c); - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x73); - u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0x64); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", - "0x73/ 0x4c/ 0x64[0]", u8tmp[0], - (u32tmp[0] & (BIT(24) | BIT(23))) >> 23, - u8tmp[1] & 0x1); - CL_PRINTF(cli_buf); - - - u32tmp[0] = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist, 0x38); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %s", - "LTE CoexOn/Path Ctrl Owner", - (int)((u32tmp[0]&BIT(7)) >> 7), - ((u8tmp[0]&BIT(2)) ? "WL" : "BT")); - CL_PRINTF(cli_buf); - - /*LTE mode*/ - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d", - "LTE 3Wire/OPMode/UART/UARTMode", - (int)((u32tmp[0]&BIT(6)) >> 6), - (int)((u32tmp[0] & (BIT(5) | BIT(4))) >> 4), - (int)((u32tmp[0]&BIT(3)) >> 3), - (int)(u32tmp[0] & (BIT(2) | BIT(1) | BIT(0)))); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %s", - "GNT_WL_SWCtrl/GNT_BT_SWCtrl/Dbg", - (int)((u32tmp[0]&BIT(12)) >> 12), - (int)((u32tmp[0]&BIT(14)) >> 14), - ((u8tmp[0]&BIT(3)) ? "On" : "Off")); - CL_PRINTF(cli_buf); - - u32tmp[0] = halbtc8822b1ant_ltecoex_indirect_read_reg(btcoexist, 0x54); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d", - "GNT_WL/GNT_BT/LTE_Busy/UART_Busy", - (int)((u32tmp[0]&BIT(2)) >> 2), - (int)((u32tmp[0]&BIT(3)) >> 3), - (int)((u32tmp[0]&BIT(1)) >> 1), (int)(u32tmp[0]&BIT(0))); - CL_PRINTF(cli_buf); - - - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x4c6); - u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0x40); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", - "0x4c6[4]/0x40[5] (WL/BT PTA)", - (int)((u8tmp[0] & BIT(4)) >> 4), - (int)((u8tmp[1] & BIT(5)) >> 5)); - CL_PRINTF(cli_buf); - - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x550); - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x522); - u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0x953); - u8tmp[2] = btcoexist->btc_read_1byte(btcoexist, 0xc50); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = 0x%x/ 0x%x/ %s/ 0x%x", - "0x550/0x522/4-RxAGC/0xc50", - u32tmp[0], u8tmp[0], (u8tmp[1] & 0x2) ? "On" : "Off", u8tmp[2]); - CL_PRINTF(cli_buf); - - fa_ofdm = btcoexist->btc_phydm_query_PHY_counter(btcoexist, - PHYDM_INFO_FA_OFDM); - fa_cck = btcoexist->btc_phydm_query_PHY_counter(btcoexist, - PHYDM_INFO_FA_CCK); - cca_ofdm = btcoexist->btc_phydm_query_PHY_counter(btcoexist, - PHYDM_INFO_CCA_OFDM); - cca_cck = btcoexist->btc_phydm_query_PHY_counter(btcoexist, - PHYDM_INFO_CCA_CCK); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", - "CCK-CCA/CCK-FA/OFDM-CCA/OFDM-FA", - cca_cck, fa_cck, cca_ofdm, fa_ofdm); - CL_PRINTF(cli_buf); - - -#if 1 - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d", - "CRC_OK CCK/11g/11n/11ac", - coex_sta->crc_ok_cck, coex_sta->crc_ok_11g, - coex_sta->crc_ok_11n, coex_sta->crc_ok_11n_vht); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d", - "CRC_Err CCK/11g/11n/11ac", - coex_sta->crc_err_cck, coex_sta->crc_err_11g, - coex_sta->crc_err_11n, coex_sta->crc_err_11n_vht); - CL_PRINTF(cli_buf); -#endif - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s/ %s", - "Wifi-HiPri/ Ccklock/ CckEverLock", - (coex_sta->wifi_is_high_pri_task ? "Yes" : "No"), - (coex_sta->cck_lock ? "Yes" : "No"), - (coex_sta->cck_ever_lock ? "Yes" : "No")); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", - "0x770(high-pri rx/tx)", - coex_sta->high_priority_rx, coex_sta->high_priority_tx); - CL_PRINTF(cli_buf); - /*0x774:bt low pri trx*/ - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", - "0x774(low-pri rx/tx)", - coex_sta->low_priority_rx, coex_sta->low_priority_tx); - CL_PRINTF(cli_buf); - - halbtc8822b1ant_read_score_board(btcoexist, &u16tmp[0]); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %04x", - "ScoreBoard[14:0] (from BT)", u16tmp[0]); - - btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_COEX_STATISTICS); - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** displaycoexinfo end, 0xcb4/0xcbd = 0x%x/0x%x\n", - btcoexist->btc_read_1byte(btcoexist, 0xcb4), - btcoexist->btc_read_1byte(btcoexist, 0xcbd)); - BTC_TRACE(trace_buf); - /* - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** pnp_wake_cnt = %d\n", pnp_wake_cnt); - BTC_TRACE(trace_buf); - */ -} - - -void ex_halbtc8822b1ant_ips_notify(IN struct btc_coexist *btcoexist, IN u8 type) -{ - - if (btcoexist->manual_control || btcoexist->stop_coex_dm) - return; - - - if (BTC_IPS_ENTER == type) { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], IPS ENTER notify\n"); - BTC_TRACE(trace_buf); - coex_sta->under_ips = true; - - /* Write WL "Active" in Score-board for LPS off */ - halbtc8822b1ant_post_state_to_bt(btcoexist, - BT_8822B_1ANT_SCOREBOARD_ACTIVE, false); - - halbtc8822b1ant_post_state_to_bt(btcoexist, - BT_8822B_1ANT_SCOREBOARD_ONOFF, false); - - halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); - - halbtc8822b1ant_set_ant_path(btcoexist, - BTC_ANT_PATH_AUTO, - FORCE_EXEC, - BT_8822B_1ANT_PHASE_WLAN_OFF); - - halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - } else if (BTC_IPS_LEAVE == type) { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], IPS LEAVE notify\n"); - BTC_TRACE(trace_buf); - halbtc8822b1ant_post_state_to_bt(btcoexist, - BT_8822B_1ANT_SCOREBOARD_ACTIVE, true); - - halbtc8822b1ant_post_state_to_bt(btcoexist, - BT_8822B_1ANT_SCOREBOARD_ONOFF, true); - - /*leave IPS : run ini hw config (exclude wifi only)*/ - halbtc8822b1ant_init_hw_config(btcoexist, false, false); - /*sw all off*/ - halbtc8822b1ant_init_coex_dm(btcoexist); - /*leave IPS : Query bt info*/ - halbtc8822b1ant_query_bt_info(btcoexist); - - coex_sta->under_ips = false; - } -} - -void ex_halbtc8822b1ant_lps_notify(IN struct btc_coexist *btcoexist, IN u8 type) -{ - if (btcoexist->manual_control || btcoexist->stop_coex_dm) - return; - - if (BTC_LPS_ENABLE == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], LPS ENABLE notify\n"); - BTC_TRACE(trace_buf); - coex_sta->under_lps = true; - - if (coex_sta->force_lps_on == true) { /* LPS No-32K */ - /* Write WL "Active" in Score-board for PS-TDMA */ - halbtc8822b1ant_post_state_to_bt(btcoexist, - BT_8822B_1ANT_SCOREBOARD_ACTIVE, true); - - } else { /* LPS-32K, need check if this h2c 0x71 can work?? (2015/08/28) */ - /* Write WL "Non-Active" in Score-board for Native-PS */ - halbtc8822b1ant_post_state_to_bt(btcoexist, - BT_8822B_1ANT_SCOREBOARD_ACTIVE, false); - - } - } else if (BTC_LPS_DISABLE == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], LPS DISABLE notify\n"); - BTC_TRACE(trace_buf); - coex_sta->under_lps = false; - - /* Write WL "Active" in Score-board for LPS off */ - halbtc8822b1ant_post_state_to_bt(btcoexist, - BT_8822B_1ANT_SCOREBOARD_ACTIVE, true); - - } -} - - -void ex_halbtc8822b1ant_scan_notify(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - boolean wifi_connected = false; - boolean wifi_under_5g = false; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCAN notify()\n"); - BTC_TRACE(trace_buf); - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - - - - if (btcoexist->manual_control || - btcoexist->stop_coex_dm) - return; - - if (BTC_SCAN_START == type) { - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g); - - if (wifi_under_5g) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** (scan_notify_5g_scan_start) **********\n"); - BTC_TRACE(trace_buf); - halbtc8822b1ant_action_wifi_under5g(btcoexist); - return; - } - - /* under 2.4G */ - coex_sta->wifi_is_high_pri_task = true; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** (scan_notify_2g_scan_start) **********\n"); - BTC_TRACE(trace_buf); - - if (!wifi_connected) { /* non-connected scan */ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** wifi is not connected scan **********\n"); - BTC_TRACE(trace_buf); - halbtc8822b1ant_action_wifi_not_connected_scan( - btcoexist); - } else { /* wifi is connected */ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** wifi is connected scan **********\n"); - BTC_TRACE(trace_buf); - halbtc8822b1ant_action_wifi_connected_scan( - btcoexist); - } - - return; - } - - if (BTC_SCAN_START_2G == type) { - coex_sta->wifi_is_high_pri_task = true; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** (scan_notify_2g_sacn_start_for_switch_band_used) **********\n"); - BTC_TRACE(trace_buf); - - if (!wifi_connected) { /* non-connected scan */ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** wifi is not connected **********\n"); - BTC_TRACE(trace_buf); - - halbtc8822b1ant_action_wifi_not_connected_scan( - btcoexist); - } else { /* wifi is connected */ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** wifi is connected **********\n"); - BTC_TRACE(trace_buf); - halbtc8822b1ant_action_wifi_connected_scan(btcoexist); - } - } else { - coex_sta->wifi_is_high_pri_task = false; - - /*WL scan finish , then get and update sacn ap numbers */ - btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM, - &coex_sta->scan_ap_num); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** (scan_finish_notify) **********\n"); - BTC_TRACE(trace_buf); - - if (!wifi_connected) /* non-connected scan */ - halbtc8822b1ant_action_wifi_not_connected(btcoexist); - else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** scan_finish_notify wifi is connected **********\n"); - BTC_TRACE(trace_buf); - halbtc8822b1ant_action_wifi_connected(btcoexist); - } - } -} - - - -void ex_halbtc8822b1ant_scan_notify_without_bt(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - - boolean wifi_under_5g = false; - - if (BTC_SCAN_START == type) { - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g); - - if (wifi_under_5g) { - btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbd, - 0x3, 1); - return; - } - - /* under 2.4G */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbd, - 0x3, 2); - return; - } - if (BTC_SCAN_START_2G == type) - btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbd, 0x3, 2); -} - -void ex_halbtc8822b1ant_switchband_notify(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - - boolean wifi_connected = false; - - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** (switchband_notify) **********\n"); - BTC_TRACE(trace_buf); - - if (btcoexist->manual_control || - btcoexist->stop_coex_dm) - return; - - - if (type == BTC_SWITCH_TO_5G) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** (switchband_notify BTC_SWITCH_TO_5G) **********\n"); - BTC_TRACE(trace_buf); - - halbtc8822b1ant_action_wifi_under5g(btcoexist); - return; - } else if (type == BTC_SWITCH_TO_24G_NOFORSCAN) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** (switchband_notify BTC_SWITCH_TO_2G (no for scan)) **********\n"); - BTC_TRACE(trace_buf); - - halbtc8822b1ant_run_coexist_mechanism(btcoexist); - - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** (switchband_notify BTC_SWITCH_TO_2G) **********\n"); - BTC_TRACE(trace_buf); - - ex_halbtc8822b1ant_scan_notify(btcoexist, - BTC_SCAN_START_2G); - } - -} - - -void ex_halbtc8822b1ant_switchband_notify_without_bt(IN struct btc_coexist - *btcoexist, - IN u8 type) -{ - boolean wifi_under_5g = false; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g); - - if (type == BTC_SWITCH_TO_5G) { - - btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbd, - 0x3, 1); - return; - } else if (type == BTC_SWITCH_TO_24G_NOFORSCAN) { - - if (wifi_under_5g) - - btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbd, - 0x3, 1); - - else - btcoexist->btc_write_1byte_bitmask(btcoexist, - 0xcbd, 0x3, 2); - } else { - - ex_halbtc8822b1ant_scan_notify_without_bt(btcoexist, - BTC_SCAN_START_2G); - } - -} - -void ex_halbtc8822b1ant_connect_notify(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - boolean wifi_connected = false; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** (connect notify) **********\n"); - BTC_TRACE(trace_buf); - - halbtc8822b1ant_post_state_to_bt(btcoexist, - BT_8822B_1ANT_SCOREBOARD_SCAN, true); - - if (btcoexist->manual_control || - btcoexist->stop_coex_dm) - return; - - - if ((BTC_ASSOCIATE_5G_START == type) || - (BTC_ASSOCIATE_5G_FINISH == type)) { - - if (BTC_ASSOCIATE_5G_START == type) { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** (5G associate start notify) **********\n"); - BTC_TRACE(trace_buf); - - halbtc8822b1ant_action_wifi_under5g(btcoexist); - - } else if (BTC_ASSOCIATE_5G_FINISH == type) { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** (5G associate finish notify) **********\n"); - BTC_TRACE(trace_buf); - - } - - return; - - } - - - if (BTC_ASSOCIATE_START == type) { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], 2G CONNECT START notify\n"); - BTC_TRACE(trace_buf); - - coex_sta->wifi_is_high_pri_task = true; - - halbtc8822b1ant_set_ant_path(btcoexist, - BTC_ANT_PATH_AUTO, - FORCE_EXEC, - BT_8822B_1ANT_PHASE_2G_RUNTIME); - - coex_dm->arp_cnt = 0; - - halbtc8822b1ant_action_wifi_not_connected_asso_auth(btcoexist); - - } else { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], 2G CONNECT Finish notify\n"); - BTC_TRACE(trace_buf); - coex_sta->wifi_is_high_pri_task = false; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - - if (!wifi_connected) /* non-connected scan */ - halbtc8822b1ant_action_wifi_not_connected(btcoexist); - else - halbtc8822b1ant_action_wifi_connected(btcoexist); - } - -} - -void ex_halbtc8822b1ant_media_status_notify(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - boolean wifi_under_b_mode = false; - boolean wifi_under_5g = false; - u32 cnt_bt_cal_chk = 0; - boolean is_in_mp_mode = false; - u8 u8tmp = 0; - u32 u32tmp1 = 0, u32tmp2 = 0; - - - if (btcoexist->manual_control || - btcoexist->stop_coex_dm) - return; - - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g); - - - - - if (BTC_MEDIA_CONNECT == type) { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], 2g media connect notify"); - BTC_TRACE(trace_buf); - - halbtc8822b1ant_post_state_to_bt(btcoexist, - BT_8822B_1ANT_SCOREBOARD_ACTIVE, true); - - if (wifi_under_5g) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], 5g media notify\n"); -BTC_TRACE(trace_buf); - - halbtc8822b1ant_action_wifi_under5g(btcoexist); - return; - } - /* Force antenna setup for no scan result issue */ - halbtc8822b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, - FORCE_EXEC, - BT_8822B_1ANT_PHASE_2G_RUNTIME); - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_B_MODE, - &wifi_under_b_mode); - - /* Set CCK Tx/Rx high Pri except 11b mode */ - if (wifi_under_b_mode) { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** (media status notity under b mode) **********\n"); - BTC_TRACE(trace_buf); - btcoexist->btc_write_1byte(btcoexist, 0x6cd, - 0x00); /* CCK Tx */ - btcoexist->btc_write_1byte(btcoexist, 0x6cf, - 0x00); /* CCK Rx */ - } else { - /* btcoexist->btc_write_1byte(btcoexist, 0x6cd, 0x10); */ /*CCK Tx */ - /* btcoexist->btc_write_1byte(btcoexist, 0x6cf, 0x10); */ /*CCK Rx */ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** (media status notity not under b mode) **********\n"); - BTC_TRACE(trace_buf); - btcoexist->btc_write_1byte(btcoexist, 0x6cd, - 0x00); /* CCK Tx */ - btcoexist->btc_write_1byte(btcoexist, 0x6cf, - 0x10); /* CCK Rx */ - } - - coex_dm->backup_arfr_cnt1 = btcoexist->btc_read_4byte(btcoexist, - 0x430); - coex_dm->backup_arfr_cnt2 = btcoexist->btc_read_4byte(btcoexist, - 0x434); - coex_dm->backup_retry_limit = btcoexist->btc_read_2byte( - btcoexist, 0x42a); - coex_dm->backup_ampdu_max_time = btcoexist->btc_read_1byte( - btcoexist, 0x456); - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], 2g media disconnect notify\n"); - BTC_TRACE(trace_buf); - coex_dm->arp_cnt = 0; - - halbtc8822b1ant_post_state_to_bt(btcoexist, - BT_8822B_1ANT_SCOREBOARD_ACTIVE, false); - - btcoexist->btc_write_1byte(btcoexist, 0x6cd, 0x0); /* CCK Tx */ - btcoexist->btc_write_1byte(btcoexist, 0x6cf, 0x0); /* CCK Rx */ - - coex_sta->cck_ever_lock = false; - } - - halbtc8822b1ant_update_wifi_channel_info(btcoexist, type); - -} - -void ex_halbtc8822b1ant_specific_packet_notify(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - boolean under_4way = false, wifi_under_5g = false; - - if (btcoexist->manual_control || - btcoexist->stop_coex_dm) - return; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g); - if (wifi_under_5g) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], 5g special packet notify\n"); - BTC_TRACE(trace_buf); - - halbtc8822b1ant_action_wifi_under5g(btcoexist); - return; - } - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS, - &under_4way); - - if (under_4way) { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], specific Packet ---- under_4way!!\n"); - BTC_TRACE(trace_buf); - - coex_sta->wifi_is_high_pri_task = true; - coex_sta->specific_pkt_period_cnt = 2; - } else if (BTC_PACKET_ARP == type) { - - coex_dm->arp_cnt++; - - if (coex_sta->wifi_is_high_pri_task) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], specific Packet ARP notify -cnt = %d\n", - coex_dm->arp_cnt); - BTC_TRACE(trace_buf); - } - - } else { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], specific Packet DHCP or EAPOL notify [Type = %d]\n", - type); - BTC_TRACE(trace_buf); - - coex_sta->wifi_is_high_pri_task = true; - coex_sta->specific_pkt_period_cnt = 2; - } - - if (coex_sta->wifi_is_high_pri_task) - halbtc8822b1ant_action_wifi_connected_specific_packet( - btcoexist); - -} - -void ex_halbtc8822b1ant_bt_info_notify(IN struct btc_coexist *btcoexist, - IN u8 *tmp_buf, IN u8 length) -{ - u8 bt_info = 0; - u8 i, rsp_source = 0; - boolean bt_busy = false; - boolean wifi_connected = false; - boolean wifi_under_5g = false; - - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g); - - coex_sta->c2h_bt_info_req_sent = false; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** (BtInfo Notify) **********\n"); - BTC_TRACE(trace_buf); - - rsp_source = tmp_buf[0] & 0xf; - if (rsp_source >= BT_INFO_SRC_8822B_1ANT_MAX) - rsp_source = BT_INFO_SRC_8822B_1ANT_WIFI_FW; - coex_sta->bt_info_c2h_cnt[rsp_source]++; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Bt info[%d], length=%d, hex data=[", rsp_source, - length); - BTC_TRACE(trace_buf); - - for (i = 0; i < length; i++) { - coex_sta->bt_info_c2h[rsp_source][i] = tmp_buf[i]; - if (i == 1) - bt_info = tmp_buf[i]; - if (i == length - 1) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "0x%02x]\n", - tmp_buf[i]); - BTC_TRACE(trace_buf); - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "0x%02x, ", - tmp_buf[i]); - BTC_TRACE(trace_buf); - } - } - - - if (BT_INFO_SRC_8822B_1ANT_WIFI_FW != rsp_source) { - - /* if 0xff, it means BT is under WHCK test */ - if (bt_info == 0xff) - coex_sta->bt_whck_test = true; - else - coex_sta->bt_whck_test = false; - - coex_sta->bt_retry_cnt = /* [3:0] */ - coex_sta->bt_info_c2h[rsp_source][2] & 0xf; - - if (coex_sta->bt_retry_cnt >= 1) - coex_sta->pop_event_cnt++; - - if (coex_sta->bt_info_c2h[rsp_source][2] & 0x20) - coex_sta->c2h_bt_page = true; - else - coex_sta->c2h_bt_page = false; - - if (coex_sta->bt_info_c2h[rsp_source][2] & 0x80) - coex_sta->bt_create_connection = true; - else - coex_sta->bt_create_connection = false; - - /* unit: %, value-100 to translate to unit: dBm */ - coex_sta->bt_rssi = coex_sta->bt_info_c2h[rsp_source][3] * 2 + - 10; - - /* coex_sta->bt_info_c2h[rsp_source][3] * 2 - 90; */ - - if ((coex_sta->bt_info_c2h[rsp_source][1] & 0x49) == 0x49) { - coex_sta->a2dp_bit_pool = - coex_sta->bt_info_c2h[rsp_source][6]; - } else - coex_sta->a2dp_bit_pool = 0; - - if (coex_sta->bt_info_c2h[rsp_source][1] & 0x9) - coex_sta->acl_busy = true; - else - coex_sta->acl_busy = false; - - coex_sta->bt_info_ext = - coex_sta->bt_info_c2h[rsp_source][4]; - - /* Here we need to resend some wifi info to BT */ - /* because bt is reset and loss of the info. */ - - if ((!btcoexist->manual_control) && - (!btcoexist->stop_coex_dm)) { - - /* Re-Init */ - if (coex_sta->bt_info_ext & BIT(1)) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT ext info bit1 check, send wifi BW&Chnl to BT!!\n"); - BTC_TRACE(trace_buf); - btcoexist->btc_get(btcoexist, - BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - if (wifi_connected) - halbtc8822b1ant_update_wifi_channel_info( - btcoexist, - BTC_MEDIA_CONNECT); - else - halbtc8822b1ant_update_wifi_channel_info( - btcoexist, - BTC_MEDIA_DISCONNECT); - } - - /* If Ignore_WLanAct && not SetUp_Link */ - if ((coex_sta->bt_info_ext & BIT(3)) && - (!(coex_sta->bt_info_ext & BIT(2)))) { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT ext info bit3 check, set BT NOT to ignore Wlan active!!\n"); - BTC_TRACE(trace_buf); - halbtc8822b1ant_ignore_wlan_act(btcoexist, - FORCE_EXEC, - false); - } - } - /* check BIT2 first ==> check if bt is under inquiry or page scan */ - if (bt_info & BT_INFO_8822B_1ANT_B_INQ_PAGE) - coex_sta->c2h_bt_inquiry_page = true; - else - coex_sta->c2h_bt_inquiry_page = false; - } - - coex_sta->num_of_profile = 0; - - /* set link exist status */ - if (!(bt_info & BT_INFO_8822B_1ANT_B_CONNECTION)) { - coex_sta->bt_link_exist = false; - coex_sta->pan_exist = false; - coex_sta->a2dp_exist = false; - coex_sta->hid_exist = false; - coex_sta->sco_exist = false; - - coex_sta->bt_hi_pri_link_exist = false; - } else { /* connection exists */ - coex_sta->bt_link_exist = true; - if (bt_info & BT_INFO_8822B_1ANT_B_FTP) { - coex_sta->pan_exist = true; - coex_sta->num_of_profile++; - } else - coex_sta->pan_exist = false; - if (bt_info & BT_INFO_8822B_1ANT_B_A2DP) { - coex_sta->a2dp_exist = true; - coex_sta->num_of_profile++; - } else - coex_sta->a2dp_exist = false; - if (bt_info & BT_INFO_8822B_1ANT_B_HID) { - coex_sta->hid_exist = true; - coex_sta->num_of_profile++; - } else - coex_sta->hid_exist = false; - if (bt_info & BT_INFO_8822B_1ANT_B_SCO_ESCO) { - coex_sta->sco_exist = true; - coex_sta->num_of_profile++; - } else - coex_sta->sco_exist = false; - - } - - halbtc8822b1ant_update_bt_link_info(btcoexist); - - bt_info = bt_info & - 0x1f; /* mask profile bit for connect-ilde identification ( for CSR case: A2DP idle --> 0x41) */ - - if (!(bt_info & BT_INFO_8822B_1ANT_B_CONNECTION)) { - coex_dm->bt_status = BT_8822B_1ANT_BT_STATUS_NON_CONNECTED_IDLE; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), BT Non-Connected idle!!!\n"); - BTC_TRACE(trace_buf); - } else if (bt_info == - BT_INFO_8822B_1ANT_B_CONNECTION) { /* connection exists but no busy */ - coex_dm->bt_status = BT_8822B_1ANT_BT_STATUS_CONNECTED_IDLE; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), BT Connected-idle!!!\n"); - BTC_TRACE(trace_buf); - } else if ((bt_info & BT_INFO_8822B_1ANT_B_SCO_ESCO) || - (bt_info & BT_INFO_8822B_1ANT_B_SCO_BUSY)) { - coex_dm->bt_status = BT_8822B_1ANT_BT_STATUS_SCO_BUSY; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), BT SCO busy!!!\n"); - BTC_TRACE(trace_buf); - } else if (bt_info & BT_INFO_8822B_1ANT_B_ACL_BUSY) { - if (BT_8822B_1ANT_BT_STATUS_ACL_BUSY != coex_dm->bt_status) - coex_dm->bt_status = BT_8822B_1ANT_BT_STATUS_ACL_BUSY; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), BT ACL busy!!!\n"); - BTC_TRACE(trace_buf); - } else { - coex_dm->bt_status = BT_8822B_1ANT_BT_STATUS_MAX; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), BT Non-Defined state!!!\n"); - BTC_TRACE(trace_buf); - } - - if ((BT_8822B_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) || - (BT_8822B_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) || - (BT_8822B_1ANT_BT_STATUS_ACL_SCO_BUSY == coex_dm->bt_status)) - bt_busy = true; - else - bt_busy = false; - - btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bt_busy); - - halbtc8822b1ant_run_coexist_mechanism(btcoexist); -} - -void ex_halbtc8822b1ant_rf_status_notify(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], RF Status notify\n"); - BTC_TRACE(trace_buf); - - if (BTC_RF_ON == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], RF is turned ON!!\n"); - BTC_TRACE(trace_buf); - btcoexist->stop_coex_dm = false; - - halbtc8822b1ant_post_state_to_bt(btcoexist, - BT_8822B_1ANT_SCOREBOARD_ACTIVE, true); - halbtc8822b1ant_post_state_to_bt(btcoexist, - BT_8822B_1ANT_SCOREBOARD_ONOFF, true); - - } else if (BTC_RF_OFF == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], RF is turned OFF!!\n"); - BTC_TRACE(trace_buf); - - halbtc8822b1ant_post_state_to_bt(btcoexist, - BT_8822B_1ANT_SCOREBOARD_ACTIVE, false); - halbtc8822b1ant_post_state_to_bt(btcoexist, - BT_8822B_1ANT_SCOREBOARD_ONOFF, false); - halbtc8822b1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 0); - - halbtc8822b1ant_set_ant_path(btcoexist, - BTC_ANT_PATH_AUTO, - FORCE_EXEC, - BT_8822B_1ANT_PHASE_WLAN_OFF); - /* for test : s3 bt disppear , fail rate 1/600*/ - - halbtc8822b1ant_ignore_wlan_act(btcoexist, FORCE_EXEC, true); - - btcoexist->stop_coex_dm = true; - } -} - -void ex_halbtc8822b1ant_halt_notify(IN struct btc_coexist *btcoexist) -{ - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], Halt notify\n"); - BTC_TRACE(trace_buf); - - halbtc8822b1ant_post_state_to_bt(btcoexist, - BT_8822B_1ANT_SCOREBOARD_ACTIVE, false); - halbtc8822b1ant_post_state_to_bt(btcoexist, - BT_8822B_1ANT_SCOREBOARD_ONOFF, false); - - halbtc8822b1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 0); - - halbtc8822b1ant_set_ant_path(btcoexist, - BTC_ANT_PATH_AUTO, - FORCE_EXEC, - BT_8822B_1ANT_PHASE_WLAN_OFF); - /* for test : s3 bt disppear , fail rate 1/600*/ - - halbtc8822b1ant_ignore_wlan_act(btcoexist, FORCE_EXEC, true); - - ex_halbtc8822b1ant_media_status_notify(btcoexist, BTC_MEDIA_DISCONNECT); - - halbtc8822b1ant_enable_gnt_to_gpio(btcoexist, false); - - btcoexist->stop_coex_dm = true; -} - - -void ex_halbtc8822b1ant_pnp_notify(IN struct btc_coexist *btcoexist, - IN u8 pnp_state) -{ - boolean wifi_under_5g = false; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], Pnp notify\n"); - BTC_TRACE(trace_buf); - -btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g); - if (BTC_WIFI_PNP_SLEEP == pnp_state) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Pnp notify to SLEEP\n"); - BTC_TRACE(trace_buf); - - halbtc8822b1ant_post_state_to_bt(btcoexist, - BT_8822B_1ANT_SCOREBOARD_ACTIVE, false); - halbtc8822b1ant_post_state_to_bt(btcoexist, - BT_8822B_1ANT_SCOREBOARD_ONOFF, false); - /* - halbtc8822b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); - - halbtc8822b1ant_set_ant_path(btcoexist, - BTC_ANT_PATH_AUTO, - FORCE_EXEC, - BT_8822B_1ANT_PHASE_WLAN_OFF); - - halbtc8822b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, - 5); - - halbtc8822b1ant_enable_gnt_to_gpio(btcoexist, false); - */ - btcoexist->stop_coex_dm = true; - } else if (BTC_WIFI_PNP_WAKE_UP == pnp_state) { - /*pnp_wake_cnt++;*/ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Pnp notify to WAKE UP\n"); - BTC_TRACE(trace_buf); - - halbtc8822b1ant_post_state_to_bt(btcoexist, - BT_8822B_1ANT_SCOREBOARD_ACTIVE, true); - halbtc8822b1ant_post_state_to_bt(btcoexist, - BT_8822B_1ANT_SCOREBOARD_ONOFF, true); - - btcoexist->stop_coex_dm = false; - } -} - -void ex_halbtc8822b1ant_coex_dm_reset(IN struct btc_coexist *btcoexist) -{ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], *****************Coex DM Reset*****************\n"); - BTC_TRACE(trace_buf); - - halbtc8822b1ant_init_hw_config(btcoexist, false, false); - halbtc8822b1ant_init_coex_dm(btcoexist); -} - -void ex_halbtc8822b1ant_periodical(IN struct btc_coexist *btcoexist) -{ - - struct btc_board_info *board_info = &btcoexist->board_info; - boolean wifi_busy = false; - u16 bt_scoreboard_val = 0; - u32 bt_patch_ver; - static u8 cnt = 0; - boolean bt_relink_finish = false; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ==========================Periodical===========================\n"); - BTC_TRACE(trace_buf); - -#if (BT_AUTO_REPORT_ONLY_8822B_1ANT == 0) - halbtc8822b1ant_query_bt_info(btcoexist); -#endif - - halbtc8822b1ant_monitor_bt_ctr(btcoexist); - halbtc8822b1ant_monitor_wifi_ctr(btcoexist); - - halbtc8822b1ant_monitor_bt_enable_disable(btcoexist); - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - halbtc8822b1ant_read_score_board(btcoexist, &bt_scoreboard_val); - - if (wifi_busy) { - halbtc8822b1ant_post_state_to_bt(btcoexist, - BT_8822B_1ANT_SCOREBOARD_WLBUSY, true); - if (bt_scoreboard_val & BIT(6)) - halbtc8822b1ant_query_bt_info(btcoexist); - } else { - halbtc8822b1ant_post_state_to_bt(btcoexist, - BT_8822B_1ANT_SCOREBOARD_WLBUSY, false); - } - - /* for 4-way, DHCP, EAPOL packet */ - if (coex_sta->specific_pkt_period_cnt > 0) { - - coex_sta->specific_pkt_period_cnt--; - - if ((coex_sta->specific_pkt_period_cnt == 0) && - (coex_sta->wifi_is_high_pri_task)) - coex_sta->wifi_is_high_pri_task = false; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ***************** Hi-Pri Task = %s*****************\n", - (coex_sta->wifi_is_high_pri_task ? "Yes" : - "No")); - BTC_TRACE(trace_buf); - } - - if (!coex_sta->bt_disabled) { - if (coex_sta->bt_coex_supported_feature == 0) - btcoexist->btc_get(btcoexist, BTC_GET_U4_SUPPORTED_FEATURE, &coex_sta->bt_coex_supported_feature); - - if ((coex_sta->bt_coex_supported_version == 0) || - (coex_sta->bt_coex_supported_version == 0xffff)) - btcoexist->btc_get(btcoexist, BTC_GET_U4_SUPPORTED_VERSION, &coex_sta->bt_coex_supported_version); - - btcoexist->btc_get(btcoexist, BTC_GET_U4_BT_PATCH_VER, &bt_patch_ver); - btcoexist->bt_info.bt_get_fw_ver = bt_patch_ver; - - if (halbtc8822b1ant_is_wifi_status_changed(btcoexist)) - halbtc8822b1ant_run_coexist_mechanism(btcoexist); - - } -} - -void ex_halbtc8822b1ant_antenna_detection(IN struct btc_coexist *btcoexist, - IN u32 cent_freq, IN u32 offset, IN u32 span, IN u32 seconds) -{ -} - -void ex_halbtc8822b1ant_antenna_isolation(IN struct btc_coexist *btcoexist, - IN u32 cent_freq, IN u32 offset, IN u32 span, IN u32 seconds) -{ - - -} - -void ex_halbtc8822b1ant_psd_scan(IN struct btc_coexist *btcoexist, - IN u32 cent_freq, IN u32 offset, IN u32 span, IN u32 seconds) -{ - - -} - -void ex_halbtc8822b1ant_display_ant_detection(IN struct btc_coexist *btcoexist) -{ - -} - -void ex_halbtc8822b1ant_dbg_control(IN struct btc_coexist *btcoexist, - IN u8 op_code, IN u8 op_len, IN u8 *pdata) -{} -#endif /* #if(BTC_COEX_OFFLOAD == 1) */ - -#endif - -#else - -void ex_halbtc8822b1ant_switch_band_without_bt(IN struct btc_coexist *btcoexist, - IN boolean wifi_only_5g) -{ - /* ant switch WL2G or WL5G*/ - if (wifi_only_5g) - - btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbd, 0x3, 1); - - else - - btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbd, 0x3, 2); - -} - -void ex_halbtc8822b1ant_init_hw_config_without_bt(IN struct btc_coexist - *btcoexist) -{ - /* enable GNT_WL */ - - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, 0x1, - 0x0); - - /* Antenna config */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4e, - 0x80, 0x0); /* 0x4c[23] = 0 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4f, - 0x01, 0x1); /* 0x4c[24] = 1 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb4, - 0xff, 0x77); /* BB SW, DPDT use RFE_ctrl8 and RFE_ctrl9 as conctrol pin */ - - - /* Ext switch buffer mux */ - btcoexist->btc_write_1byte(btcoexist, 0x974, 0xff); - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x1991, - 0x3, 0x0); - btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbe, - 0x8, 0x0); - - /*enable sw control gnt_wl=1 / gnt_bt=1 */ - btcoexist->btc_write_1byte(btcoexist, 0x73, 0x0e); - - btcoexist->btc_write_4byte(btcoexist, 0x1704, - 0x0000ff00); - - btcoexist->btc_write_4byte(btcoexist, 0x1700, - 0xc00f0038); -} - -#endif /* #if (BT_SUPPORT == 1 && COEX_SUPPORT == 1) */ - - - diff --git a/hal/btc/halbtc8822b1ant.h b/hal/btc/halbtc8822b1ant.h deleted file mode 100644 index e84a27e..0000000 --- a/hal/btc/halbtc8822b1ant.h +++ /dev/null @@ -1,433 +0,0 @@ - -#if (BT_SUPPORT == 1 && COEX_SUPPORT == 1) - -#if (RTL8822B_SUPPORT == 1) - -/* ******************************************* - * The following is for 8822B 1ANT BT Co-exist definition - * ******************************************* */ -#define BT_AUTO_REPORT_ONLY_8822B_1ANT 1 - -#define BT_INFO_8822B_1ANT_B_FTP BIT(7) -#define BT_INFO_8822B_1ANT_B_A2DP BIT(6) -#define BT_INFO_8822B_1ANT_B_HID BIT(5) -#define BT_INFO_8822B_1ANT_B_SCO_BUSY BIT(4) -#define BT_INFO_8822B_1ANT_B_ACL_BUSY BIT(3) -#define BT_INFO_8822B_1ANT_B_INQ_PAGE BIT(2) -#define BT_INFO_8822B_1ANT_B_SCO_ESCO BIT(1) -#define BT_INFO_8822B_1ANT_B_CONNECTION BIT(0) - -#define BT_INFO_8822B_1ANT_A2DP_BASIC_RATE(_BT_INFO_EXT_) \ - (((_BT_INFO_EXT_&BIT(0))) ? true : false) - -#define BTC_RSSI_COEX_THRESH_TOL_8822B_1ANT 2 - -#define BT_8822B_1ANT_WIFI_NOISY_THRESH 150 /* max: 255 */ - -/* for Antenna detection */ -#define BT_8822B_1ANT_ANTDET_PSDTHRES_BACKGROUND 50 -#define BT_8822B_1ANT_ANTDET_PSDTHRES_2ANT_BADISOLATION 70 -#define BT_8822B_1ANT_ANTDET_PSDTHRES_2ANT_GOODISOLATION 55 -#define BT_8822B_1ANT_ANTDET_PSDTHRES_1ANT 35 -#define BT_8822B_1ANT_ANTDET_RETRY_INTERVAL 10 /* retry timer if ant det is fail, unit: second */ -#define BT_8822B_1ANT_ANTDET_ENABLE 0 -#define BT_8822B_1ANT_ANTDET_COEXMECHANISMSWITCH_ENABLE 0 - -#define BT_8822B_1ANT_LTECOEX_INDIRECTREG_ACCESS_TIMEOUT 30000 - - - -enum bt_8822b_1ant_signal_state { - BT_8822B_1ANT_SIG_STA_SET_TO_LOW = 0x0, - BT_8822B_1ANT_SIG_STA_SET_BY_HW = 0x0, - BT_8822B_1ANT_SIG_STA_SET_TO_HIGH = 0x1, - BT_8822B_1ANT_SIG_STA_MAX -}; - -enum bt_8822b_1ant_path_ctrl_owner { - BT_8822B_1ANT_PCO_BTSIDE = 0x0, - BT_8822B_1ANT_PCO_WLSIDE = 0x1, - BT_8822B_1ANT_PCO_MAX -}; - -enum bt_8822b_1ant_gnt_ctrl_type { - BT_8822B_1ANT_GNT_CTRL_BY_PTA = 0x0, - BT_8822B_1ANT_GNT_CTRL_BY_SW = 0x1, - BT_8822B_1ANT_GNT_CTRL_MAX -}; - -enum bt_8822b_1ant_gnt_ctrl_block { - BT_8822B_1ANT_GNT_BLOCK_RFC_BB = 0x0, - BT_8822B_1ANT_GNT_BLOCK_RFC = 0x1, - BT_8822B_1ANT_GNT_BLOCK_BB = 0x2, - BT_8822B_1ANT_GNT_BLOCK_MAX -}; - -enum bt_8822b_1ant_lte_coex_table_type { - BT_8822B_1ANT_CTT_WL_VS_LTE = 0x0, - BT_8822B_1ANT_CTT_BT_VS_LTE = 0x1, - BT_8822B_1ANT_CTT_MAX -}; - -enum bt_8822b_1ant_lte_break_table_type { - BT_8822B_1ANT_LBTT_WL_BREAK_LTE = 0x0, - BT_8822B_1ANT_LBTT_BT_BREAK_LTE = 0x1, - BT_8822B_1ANT_LBTT_LTE_BREAK_WL = 0x2, - BT_8822B_1ANT_LBTT_LTE_BREAK_BT = 0x3, - BT_8822B_1ANT_LBTT_MAX -}; - -enum bt_info_src_8822b_1ant { - BT_INFO_SRC_8822B_1ANT_WIFI_FW = 0x0, - BT_INFO_SRC_8822B_1ANT_BT_RSP = 0x1, - BT_INFO_SRC_8822B_1ANT_BT_ACTIVE_SEND = 0x2, - BT_INFO_SRC_8822B_1ANT_MAX -}; - -enum bt_8822b_1ant_bt_status { - BT_8822B_1ANT_BT_STATUS_NON_CONNECTED_IDLE = 0x0, - BT_8822B_1ANT_BT_STATUS_CONNECTED_IDLE = 0x1, - BT_8822B_1ANT_BT_STATUS_INQ_PAGE = 0x2, - BT_8822B_1ANT_BT_STATUS_ACL_BUSY = 0x3, - BT_8822B_1ANT_BT_STATUS_SCO_BUSY = 0x4, - BT_8822B_1ANT_BT_STATUS_ACL_SCO_BUSY = 0x5, - BT_8822B_1ANT_BT_STATUS_MAX -}; - -enum bt_8822b_1ant_wifi_status { - BT_8822B_1ANT_WIFI_STATUS_NON_CONNECTED_IDLE = 0x0, - BT_8822B_1ANT_WIFI_STATUS_NON_CONNECTED_ASSO_AUTH_SCAN = 0x1, - BT_8822B_1ANT_WIFI_STATUS_CONNECTED_SCAN = 0x2, - BT_8822B_1ANT_WIFI_STATUS_CONNECTED_SPECIFIC_PKT = 0x3, - BT_8822B_1ANT_WIFI_STATUS_CONNECTED_IDLE = 0x4, - BT_8822B_1ANT_WIFI_STATUS_CONNECTED_BUSY = 0x5, - BT_8822B_1ANT_WIFI_STATUS_MAX -}; - -enum bt_8822b_1ant_coex_algo { - BT_8822B_1ANT_COEX_ALGO_UNDEFINED = 0x0, - BT_8822B_1ANT_COEX_ALGO_SCO = 0x1, - BT_8822B_1ANT_COEX_ALGO_HID = 0x2, - BT_8822B_1ANT_COEX_ALGO_A2DP = 0x3, - BT_8822B_1ANT_COEX_ALGO_A2DP_PANHS = 0x4, - BT_8822B_1ANT_COEX_ALGO_PANEDR = 0x5, - BT_8822B_1ANT_COEX_ALGO_PANHS = 0x6, - BT_8822B_1ANT_COEX_ALGO_PANEDR_A2DP = 0x7, - BT_8822B_1ANT_COEX_ALGO_PANEDR_HID = 0x8, - BT_8822B_1ANT_COEX_ALGO_HID_A2DP_PANEDR = 0x9, - BT_8822B_1ANT_COEX_ALGO_HID_A2DP = 0xa, - BT_8822B_1ANT_COEX_ALGO_MAX = 0xb, -}; - -enum bt_8822b_1ant_ext_ant_switch_type { - BT_8822B_1ANT_EXT_ANT_SWITCH_USE_SPDT = 0x0, - BT_8822B_1ANT_EXT_ANT_SWITCH_USE_SP3T = 0x1, - BT_8822B_1ANT_EXT_ANT_SWITCH_MAX -}; - -enum bt_8822b_1ant_ext_ant_switch_ctrl_type { - BT_8822B_1ANT_EXT_ANT_SWITCH_CTRL_BY_BBSW = 0x0, - BT_8822B_1ANT_EXT_ANT_SWITCH_CTRL_BY_PTA = 0x1, - BT_8822B_1ANT_EXT_ANT_SWITCH_CTRL_BY_ANTDIV = 0x2, - BT_8822B_1ANT_EXT_ANT_SWITCH_CTRL_BY_MAC = 0x3, - BT_8822B_1ANT_EXT_ANT_SWITCH_CTRL_BY_BT = 0x4, - BT_8822B_1ANT_EXT_ANT_SWITCH_CTRL_MAX -}; - -enum bt_8822b_1ant_ext_ant_switch_pos_type { - BT_8822B_1ANT_EXT_ANT_SWITCH_TO_BT = 0x0, - BT_8822B_1ANT_EXT_ANT_SWITCH_TO_WLG = 0x1, - BT_8822B_1ANT_EXT_ANT_SWITCH_TO_WLA = 0x2, - BT_8822B_1ANT_EXT_ANT_SWITCH_TO_NOCARE = 0x3, - BT_8822B_1ANT_EXT_ANT_SWITCH_TO_MAX -}; - -enum bt_8822b_1ant_phase { - BT_8822B_1ANT_PHASE_COEX_INIT = 0x0, - BT_8822B_1ANT_PHASE_WLANONLY_INIT = 0x1, - BT_8822B_1ANT_PHASE_WLAN_OFF = 0x2, - BT_8822B_1ANT_PHASE_2G_RUNTIME = 0x3, - BT_8822B_1ANT_PHASE_5G_RUNTIME = 0x4, - BT_8822B_1ANT_PHASE_BTMPMODE = 0x5, - BT_8822B_1ANT_PHASE_MAX -}; - -/*ADD SCOREBOARD TO FIX BT LPS 32K ISSUE WHILE WL BUSY*/ -enum bt_8822b_1ant_Scoreboard { - BT_8822B_1ANT_SCOREBOARD_ACTIVE = BIT(0), - BT_8822B_1ANT_SCOREBOARD_ONOFF = BIT(1), - BT_8822B_1ANT_SCOREBOARD_SCAN = BIT(2), - BT_8822B_1ANT_SCOREBOARD_UNDERTEST = BIT(3), - BT_8822B_1ANT_SCOREBOARD_WLBUSY = BIT(6) -}; - -struct coex_dm_8822b_1ant { - /* hw setting */ - u32 pre_ant_pos_type; - u32 cur_ant_pos_type; - /* fw mechanism */ - boolean cur_ignore_wlan_act; - boolean pre_ignore_wlan_act; - u8 pre_ps_tdma; - u8 cur_ps_tdma; - u8 ps_tdma_para[5]; - u8 ps_tdma_du_adj_type; - boolean auto_tdma_adjust; - boolean pre_ps_tdma_on; - boolean cur_ps_tdma_on; - boolean pre_bt_auto_report; - boolean cur_bt_auto_report; - u8 pre_lps; - u8 cur_lps; - u8 pre_rpwm; - u8 cur_rpwm; - - /* sw mechanism */ - boolean pre_low_penalty_ra; - boolean cur_low_penalty_ra; - u32 pre_val0x6c0; - u32 cur_val0x6c0; - u32 pre_val0x6c4; - u32 cur_val0x6c4; - u32 pre_val0x6c8; - u32 cur_val0x6c8; - u8 pre_val0x6cc; - u8 cur_val0x6cc; - boolean limited_dig; - - u32 backup_arfr_cnt1; /* Auto Rate Fallback Retry cnt */ - u32 backup_arfr_cnt2; /* Auto Rate Fallback Retry cnt */ - u16 backup_retry_limit; - u8 backup_ampdu_max_time; - - /* algorithm related */ - u8 pre_algorithm; - u8 cur_algorithm; - u8 bt_status; - u8 wifi_chnl_info[3]; - - u32 pre_ra_mask; - u32 cur_ra_mask; - u8 pre_arfr_type; - u8 cur_arfr_type; - u8 pre_retry_limit_type; - u8 cur_retry_limit_type; - u8 pre_ampdu_time_type; - u8 cur_ampdu_time_type; - u32 arp_cnt; - - u32 pre_ext_ant_switch_status; - u32 cur_ext_ant_switch_status; - - u8 error_condition; -}; - -struct coex_sta_8822b_1ant { - boolean bt_disabled; - boolean bt_link_exist; - boolean sco_exist; - boolean a2dp_exist; - boolean hid_exist; - boolean pan_exist; - boolean bt_hi_pri_link_exist; - u8 num_of_profile; - - boolean under_lps; - boolean under_ips; - u32 specific_pkt_period_cnt; - u32 high_priority_tx; - u32 high_priority_rx; - u32 low_priority_tx; - u32 low_priority_rx; - s8 bt_rssi; - boolean bt_tx_rx_mask; - u8 pre_bt_rssi_state; - u8 pre_wifi_rssi_state[4]; - boolean c2h_bt_info_req_sent; - u8 bt_info_c2h[BT_INFO_SRC_8822B_1ANT_MAX][10]; - u32 bt_info_c2h_cnt[BT_INFO_SRC_8822B_1ANT_MAX]; - boolean bt_whck_test; - boolean c2h_bt_inquiry_page; - boolean c2h_bt_page; /* Add for win8.1 page out issue */ - boolean wifi_is_high_pri_task; /* Add for win8.1 page out issue */ - u8 bt_retry_cnt; - u8 bt_info_ext; - u32 pop_event_cnt; - u8 scan_ap_num; - - u32 crc_ok_cck; - u32 crc_ok_11g; - u32 crc_ok_11n; - u32 crc_ok_11n_agg; - u32 crc_ok_11n_vht; - - u32 crc_err_cck; - u32 crc_err_11g; - u32 crc_err_11n; - u32 crc_err_11n_agg; - u32 crc_err_11n_vht; - - boolean cck_lock; - boolean pre_ccklock; - boolean cck_ever_lock; - u8 coex_table_type; - - boolean force_lps_on; - u32 wrong_profile_notification; - - boolean concurrent_rx_mode_on; - - u32 special_pkt_period_cnt; - - u16 score_board; - - u8 a2dp_bit_pool; - u8 cut_version; - boolean acl_busy; - boolean wl_rf_off_on_event; - boolean bt_create_connection; - boolean run_time_state; - - u32 bt_coex_supported_feature; - u32 bt_coex_supported_version; -}; - -struct rfe_type_8822b_1ant { - - u8 rfe_module_type; - boolean ext_ant_switch_exist; - u8 ext_ant_switch_type; - u8 ext_ant_switch_ctrl_polarity; /* iF 0: ANTSW(rfe_sel9)=0, ANTSWB(rfe_sel8)=1 => Ant to BT/5G */ -}; - - -#define BT_8822B_1ANT_ANTDET_PSD_POINTS 256 /* MAX:1024 */ -#define BT_8822B_1ANT_ANTDET_PSD_AVGNUM 1 /* MAX:3 */ -#define BT_8822B_1ANT_ANTDET_BUF_LEN 16 - -struct psdscan_sta_8822b_1ant { - - u32 ant_det_bt_le_channel; /* BT LE Channel ex:2412 */ - u32 ant_det_bt_tx_time; - u32 ant_det_pre_psdscan_peak_val; - boolean ant_det_is_ant_det_available; - u32 ant_det_psd_scan_peak_val; - boolean ant_det_is_btreply_available; - u32 ant_det_psd_scan_peak_freq; - - u8 ant_det_result; - u8 ant_det_peak_val[BT_8822B_1ANT_ANTDET_BUF_LEN]; - u8 ant_det_peak_freq[BT_8822B_1ANT_ANTDET_BUF_LEN]; - u32 ant_det_try_count; - u32 ant_det_fail_count; - u32 ant_det_inteval_count; - u32 ant_det_thres_offset; - - u32 real_cent_freq; - s32 real_offset; - u32 real_span; - - u32 psd_band_width; /* unit: Hz */ - u32 psd_point; /* 128/256/512/1024 */ - u32 psd_report[1024]; /* unit:dB (20logx), 0~255 */ - u32 psd_report_max_hold[1024]; /* unit:dB (20logx), 0~255 */ - u32 psd_start_point; - u32 psd_stop_point; - u32 psd_max_value_point; - u32 psd_max_value; - u32 psd_start_base; - u32 psd_avg_num; /* 1/8/16/32 */ - u32 psd_gen_count; - boolean is_psd_running; - boolean is_psd_show_max_only; -}; - -/* ******************************************* - * The following is interface which will notify coex module. - * ******************************************* */ -void ex_halbtc8822b1ant_power_on_setting(IN struct btc_coexist *btcoexist); -void ex_halbtc8822b1ant_pre_load_firmware(IN struct btc_coexist *btcoexist); -void ex_halbtc8822b1ant_init_hw_config(IN struct btc_coexist *btcoexist, - IN boolean wifi_only); -void ex_halbtc8822b1ant_init_coex_dm(IN struct btc_coexist *btcoexist); -void ex_halbtc8822b1ant_ips_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8822b1ant_lps_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8822b1ant_scan_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8822b1ant_scan_notify_without_bt(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8822b1ant_switchband_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8822b1ant_switchband_notify_without_bt(IN struct btc_coexist - *btcoexist, - IN u8 type); -void ex_halbtc8822b1ant_connect_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8822b1ant_media_status_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8822b1ant_specific_packet_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8822b1ant_bt_info_notify(IN struct btc_coexist *btcoexist, - IN u8 *tmp_buf, IN u8 length); -void ex_halbtc8822b1ant_rf_status_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8822b1ant_halt_notify(IN struct btc_coexist *btcoexist); -void ex_halbtc8822b1ant_pnp_notify(IN struct btc_coexist *btcoexist, - IN u8 pnp_state); -void ex_halbtc8822b1ant_ScoreBoardStatusNotify(IN struct btc_coexist *btcoexist, - IN u8 *tmp_buf, IN u8 length); -void ex_halbtc8822b1ant_coex_dm_reset(IN struct btc_coexist *btcoexist); -void ex_halbtc8822b1ant_periodical(IN struct btc_coexist *btcoexist); -void ex_halbtc8822b1ant_display_coex_info(IN struct btc_coexist *btcoexist); -void ex_halbtc8822b1ant_antenna_detection(IN struct btc_coexist *btcoexist, - IN u32 cent_freq, IN u32 offset, IN u32 span, IN u32 seconds); -void ex_halbtc8822b1ant_antenna_isolation(IN struct btc_coexist *btcoexist, - IN u32 cent_freq, IN u32 offset, IN u32 span, IN u32 seconds); - -void ex_halbtc8822b1ant_psd_scan(IN struct btc_coexist *btcoexist, - IN u32 cent_freq, IN u32 offset, IN u32 span, IN u32 seconds); -void ex_halbtc8822b1ant_display_ant_detection(IN struct btc_coexist *btcoexist); - -void ex_halbtc8822b1ant_dbg_control(IN struct btc_coexist *btcoexist, - IN u8 op_code, IN u8 op_len, IN u8 *pdata); - -#else -#define ex_halbtc8822b1ant_power_on_setting(btcoexist) -#define ex_halbtc8822b1ant_pre_load_firmware(btcoexist) -#define ex_halbtc8822b1ant_init_hw_config(btcoexist, wifi_only) -#define ex_halbtc8822b1ant_init_coex_dm(btcoexist) -#define ex_halbtc8822b1ant_ips_notify(btcoexist, type) -#define ex_halbtc8822b1ant_lps_notify(btcoexist, type) -#define ex_halbtc8822b1ant_scan_notify(btcoexist, type) -#define ex_halbtc8822b1ant_scan_notify_without_bt(btcoexist, type) -#define ex_halbtc8822b1ant_switchband_notify(btcoexist, type) -#define ex_halbtc8822b1ant_switchband_notify_without_bt(btcoexist, type) -#define ex_halbtc8822b1ant_connect_notify(btcoexist, type) -#define ex_halbtc8822b1ant_media_status_notify(btcoexist, type) -#define ex_halbtc8822b1ant_specific_packet_notify(btcoexist, type) -#define ex_halbtc8822b1ant_bt_info_notify(btcoexist, tmp_buf, length) -#define ex_halbtc8822b1ant_rf_status_notify(btcoexist, type) -#define ex_halbtc8822b1ant_halt_notify(btcoexist) -#define ex_halbtc8822b1ant_pnp_notify(btcoexist, pnp_state) -#define ex_halbtc8822b1ant_ScoreBoardStatusNotify(btcoexist, tmp_buf, length) -#define ex_halbtc8822b1ant_coex_dm_reset(btcoexist) -#define ex_halbtc8822b1ant_periodical(btcoexist) -#define ex_halbtc8822b1ant_display_coex_info(btcoexist) -#define ex_halbtc8822b1ant_antenna_detection(btcoexist, cent_freq, offset, span, seconds) -#define ex_halbtc8822b1ant_antenna_isolation(btcoexist, cent_freq, offset, span, seconds) -#define ex_halbtc8822b1ant_psd_scan(btcoexist, cent_freq, offset, span, seconds) -#define ex_halbtc8822b1ant_display_ant_detection(btcoexist) -#define ex_halbtc8822b1ant_dbg_control(btcoexist, op_code, op_len, pdata) -#endif -#else - -void ex_halbtc8822b1ant_init_hw_config_without_bt(IN struct btc_coexist - *btcoexist); -void ex_halbtc8822b1ant_switch_band_without_bt(IN struct btc_coexist *btcoexist, - IN boolean wifi_only_5g); - - -#endif - diff --git a/hal/btc/halbtc8822b2ant.c b/hal/btc/halbtc8822b2ant.c deleted file mode 100644 index 6f3d6b5..0000000 --- a/hal/btc/halbtc8822b2ant.c +++ /dev/null @@ -1,5543 +0,0 @@ -/* ************************************************************ - * Description: - * - * This file is for RTL8822B Co-exist mechanism - * - * History - * 2012/11/15 Cosa first check in. - * - * ************************************************************ */ - -/* ************************************************************ - * include files - * ************************************************************ */ -#include "mp_precomp.h" - -#if (BT_SUPPORT == 1 && COEX_SUPPORT == 1) - -#if (RTL8822B_SUPPORT == 1) -/* ************************************************************ - * Global variables, these are static variables - * ************************************************************ */ -static u8 *trace_buf = &gl_btc_trace_buf[0]; -static struct coex_dm_8822b_2ant glcoex_dm_8822b_2ant; -static struct coex_dm_8822b_2ant *coex_dm = &glcoex_dm_8822b_2ant; -static struct coex_sta_8822b_2ant glcoex_sta_8822b_2ant; -static struct coex_sta_8822b_2ant *coex_sta = &glcoex_sta_8822b_2ant; -static struct psdscan_sta_8822b_2ant gl_psd_scan_8822b_2ant; -static struct psdscan_sta_8822b_2ant *psd_scan = &gl_psd_scan_8822b_2ant; -static struct rfe_type_8822b_2ant gl_rfe_type_8822b_2ant; -static struct rfe_type_8822b_2ant *rfe_type = &gl_rfe_type_8822b_2ant; - -const char *const glbt_info_src_8822b_2ant[] = { - "BT Info[wifi fw]", - "BT Info[bt rsp]", - "BT Info[bt auto report]", -}; - -u32 glcoex_ver_date_8822b_2ant = 20161026; -u32 glcoex_ver_8822b_2ant = 0x34; -u32 glcoex_ver_btdesired_8822b_2ant = 0x28; - -/* ************************************************************ - * local function proto type if needed - * ************************************************************ - * ************************************************************ - * local function start with halbtc8822b2ant_ - * ************************************************************ */ -u8 halbtc8822b2ant_bt_rssi_state(u8 *ppre_bt_rssi_state, u8 level_num, - u8 rssi_thresh, u8 rssi_thresh1) -{ - s32 bt_rssi = 0; - u8 bt_rssi_state = *ppre_bt_rssi_state; - - bt_rssi = coex_sta->bt_rssi; - - if (level_num == 2) { - if ((*ppre_bt_rssi_state == BTC_RSSI_STATE_LOW) || - (*ppre_bt_rssi_state == BTC_RSSI_STATE_STAY_LOW)) { - if (bt_rssi >= (rssi_thresh + - BTC_RSSI_COEX_THRESH_TOL_8822B_2ANT)) - bt_rssi_state = BTC_RSSI_STATE_HIGH; - else - bt_rssi_state = BTC_RSSI_STATE_STAY_LOW; - } else { - if (bt_rssi < rssi_thresh) - bt_rssi_state = BTC_RSSI_STATE_LOW; - else - bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH; - } - } else if (level_num == 3) { - if (rssi_thresh > rssi_thresh1) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT Rssi thresh error!!\n"); - BTC_TRACE(trace_buf); - return *ppre_bt_rssi_state; - } - - if ((*ppre_bt_rssi_state == BTC_RSSI_STATE_LOW) || - (*ppre_bt_rssi_state == BTC_RSSI_STATE_STAY_LOW)) { - if (bt_rssi >= (rssi_thresh + - BTC_RSSI_COEX_THRESH_TOL_8822B_2ANT)) - bt_rssi_state = BTC_RSSI_STATE_MEDIUM; - else - bt_rssi_state = BTC_RSSI_STATE_STAY_LOW; - } else if ((*ppre_bt_rssi_state == BTC_RSSI_STATE_MEDIUM) || - (*ppre_bt_rssi_state == BTC_RSSI_STATE_STAY_MEDIUM)) { - if (bt_rssi >= (rssi_thresh1 + - BTC_RSSI_COEX_THRESH_TOL_8822B_2ANT)) - bt_rssi_state = BTC_RSSI_STATE_HIGH; - else if (bt_rssi < rssi_thresh) - bt_rssi_state = BTC_RSSI_STATE_LOW; - else - bt_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM; - } else { - if (bt_rssi < rssi_thresh1) - bt_rssi_state = BTC_RSSI_STATE_MEDIUM; - else - bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH; - } - } - - *ppre_bt_rssi_state = bt_rssi_state; - - return bt_rssi_state; -} - -u8 halbtc8822b2ant_wifi_rssi_state(IN struct btc_coexist *btcoexist, - IN u8 *pprewifi_rssi_state, IN u8 level_num, IN u8 rssi_thresh, - IN u8 rssi_thresh1) -{ - s32 wifi_rssi = 0; - u8 wifi_rssi_state = *pprewifi_rssi_state; - - btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi); - - if (level_num == 2) { - if ((*pprewifi_rssi_state == BTC_RSSI_STATE_LOW) || - (*pprewifi_rssi_state == BTC_RSSI_STATE_STAY_LOW)) { - if (wifi_rssi >= (rssi_thresh + - BTC_RSSI_COEX_THRESH_TOL_8822B_2ANT)) - wifi_rssi_state = BTC_RSSI_STATE_HIGH; - else - wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW; - } else { - if (wifi_rssi < rssi_thresh) - wifi_rssi_state = BTC_RSSI_STATE_LOW; - else - wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH; - } - } else if (level_num == 3) { - if (rssi_thresh > rssi_thresh1) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], wifi RSSI thresh error!!\n"); - BTC_TRACE(trace_buf); - return *pprewifi_rssi_state; - } - - if ((*pprewifi_rssi_state == BTC_RSSI_STATE_LOW) || - (*pprewifi_rssi_state == BTC_RSSI_STATE_STAY_LOW)) { - if (wifi_rssi >= (rssi_thresh + - BTC_RSSI_COEX_THRESH_TOL_8822B_2ANT)) - wifi_rssi_state = BTC_RSSI_STATE_MEDIUM; - else - wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW; - } else if ((*pprewifi_rssi_state == BTC_RSSI_STATE_MEDIUM) || - (*pprewifi_rssi_state == BTC_RSSI_STATE_STAY_MEDIUM)) { - if (wifi_rssi >= (rssi_thresh1 + - BTC_RSSI_COEX_THRESH_TOL_8822B_2ANT)) - wifi_rssi_state = BTC_RSSI_STATE_HIGH; - else if (wifi_rssi < rssi_thresh) - wifi_rssi_state = BTC_RSSI_STATE_LOW; - else - wifi_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM; - } else { - if (wifi_rssi < rssi_thresh1) - wifi_rssi_state = BTC_RSSI_STATE_MEDIUM; - else - wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH; - } - } - - *pprewifi_rssi_state = wifi_rssi_state; - - return wifi_rssi_state; -} - -void halbtc8822b2ant_coex_switch_threshold(IN struct btc_coexist *btcoexist, - IN u8 isolation_measuared) -{ - s8 interference_wl_tx = 0, interference_bt_tx = 0; - - - interference_wl_tx = BT_8822B_2ANT_WIFI_MAX_TX_POWER - - isolation_measuared; - interference_bt_tx = BT_8822B_2ANT_BT_MAX_TX_POWER - - isolation_measuared; - - - - coex_sta->wifi_coex_thres = BT_8822B_2ANT_WIFI_RSSI_COEXSWITCH_THRES1; - coex_sta->wifi_coex_thres2 = BT_8822B_2ANT_WIFI_RSSI_COEXSWITCH_THRES2; - - coex_sta->bt_coex_thres = BT_8822B_2ANT_BT_RSSI_COEXSWITCH_THRES1; - coex_sta->bt_coex_thres2 = BT_8822B_2ANT_BT_RSSI_COEXSWITCH_THRES2; - - - /* - coex_sta->wifi_coex_thres = interference_wl_tx + BT_8822B_2ANT_WIFI_SIR_THRES1; - coex_sta->wifi_coex_thres2 = interference_wl_tx + BT_8822B_2ANT_WIFI_SIR_THRES2; - - coex_sta->bt_coex_thres = interference_bt_tx + BT_8822B_2ANT_BT_SIR_THRES1; - coex_sta->bt_coex_thres2 = interference_bt_tx + BT_8822B_2ANT_BT_SIR_THRES2; - */ - - - - - - /* - if ( BT_8822B_2ANT_WIFI_RSSI_COEXSWITCH_THRES1 < (isolation_measuared - - BT_8822B_2ANT_DEFAULT_ISOLATION) ) - coex_sta->wifi_coex_thres = BT_8822B_2ANT_WIFI_RSSI_COEXSWITCH_THRES1; - else - coex_sta->wifi_coex_thres = BT_8822B_2ANT_WIFI_RSSI_COEXSWITCH_THRES1 - (isolation_measuared - - BT_8822B_2ANT_DEFAULT_ISOLATION); - - if ( BT_8822B_2ANT_BT_RSSI_COEXSWITCH_THRES1 < (isolation_measuared - - BT_8822B_2ANT_DEFAULT_ISOLATION) ) - coex_sta->bt_coex_thres = BT_8822B_2ANT_BT_RSSI_COEXSWITCH_THRES1; - else - coex_sta->bt_coex_thres = BT_8822B_2ANT_BT_RSSI_COEXSWITCH_THRES1 - (isolation_measuared - - BT_8822B_2ANT_DEFAULT_ISOLATION); - - */ -} - - -void halbtc8822b2ant_limited_rx(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean rej_ap_agg_pkt, - IN boolean bt_ctrl_agg_buf_size, IN u8 agg_buf_size) -{ - boolean reject_rx_agg = rej_ap_agg_pkt; - boolean bt_ctrl_rx_agg_size = bt_ctrl_agg_buf_size; - u8 rx_agg_size = agg_buf_size; - - /* ============================================ */ - /* Rx Aggregation related setting */ - /* ============================================ */ - btcoexist->btc_set(btcoexist, BTC_SET_BL_TO_REJ_AP_AGG_PKT, - &reject_rx_agg); - /* decide BT control aggregation buf size or not */ - btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_CTRL_AGG_SIZE, - &bt_ctrl_rx_agg_size); - /* aggregation buf size, only work when BT control Rx aggregation size. */ - btcoexist->btc_set(btcoexist, BTC_SET_U1_AGG_BUF_SIZE, &rx_agg_size); - /* real update aggregation setting */ - btcoexist->btc_set(btcoexist, BTC_SET_ACT_AGGREGATE_CTRL, NULL); -} - -void halbtc8822b2ant_query_bt_info(IN struct btc_coexist *btcoexist) -{ - u8 h2c_parameter[1] = {0}; - boolean RTL97F_8822B = false; - - if (RTL97F_8822B == true) - return; - - coex_sta->c2h_bt_info_req_sent = true; - - h2c_parameter[0] |= BIT(0); /* trigger */ - - btcoexist->btc_fill_h2c(btcoexist, 0x61, 1, h2c_parameter); -} - -void halbtc8822b2ant_monitor_bt_ctr(IN struct btc_coexist *btcoexist) -{ - u32 reg_hp_txrx, reg_lp_txrx, u32tmp; - u32 reg_hp_tx = 0, reg_hp_rx = 0, reg_lp_tx = 0, reg_lp_rx = 0; - static u8 num_of_bt_counter_chk = 0, cnt_slave = 0; - - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - - reg_hp_txrx = 0x770; - reg_lp_txrx = 0x774; - - u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_hp_txrx); - reg_hp_tx = u32tmp & MASKLWORD; - reg_hp_rx = (u32tmp & MASKHWORD) >> 16; - - u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_lp_txrx); - reg_lp_tx = u32tmp & MASKLWORD; - reg_lp_rx = (u32tmp & MASKHWORD) >> 16; - - coex_sta->high_priority_tx = reg_hp_tx; - coex_sta->high_priority_rx = reg_hp_rx; - coex_sta->low_priority_tx = reg_lp_tx; - coex_sta->low_priority_rx = reg_lp_rx; - - - /* reset counter */ - btcoexist->btc_write_1byte(btcoexist, 0x76e, 0xc); - - if ((coex_sta->low_priority_tx > 1050) && - (!coex_sta->c2h_bt_inquiry_page)) - coex_sta->pop_event_cnt++; - - if ((coex_sta->low_priority_rx >= 950) && - (coex_sta->low_priority_rx >= coex_sta->low_priority_tx) - && (!coex_sta->under_ips) && (!coex_sta->c2h_bt_inquiry_page) && - (coex_sta->bt_link_exist)) { - if (cnt_slave >= 2) { - bt_link_info->slave_role = true; - cnt_slave = 2; - } else - cnt_slave++; - } else { - if (cnt_slave == 0) { - bt_link_info->slave_role = false; - cnt_slave = 0; - } else - cnt_slave--; - - } - - if ((coex_sta->high_priority_tx == 0) && - (coex_sta->high_priority_rx == 0) && - (coex_sta->low_priority_tx == 0) && - (coex_sta->low_priority_rx == 0)) { - num_of_bt_counter_chk++; - if (num_of_bt_counter_chk >= 3) { - halbtc8822b2ant_query_bt_info(btcoexist); - num_of_bt_counter_chk = 0; - } - } - -} - -void halbtc8822b2ant_monitor_wifi_ctr(IN struct btc_coexist *btcoexist) -{ -#if 0 - s32 wifi_rssi = 0; - boolean wifi_busy = false, wifi_under_b_mode = false; - static u8 cck_lock_counter = 0; - u32 total_cnt, reg_val1, reg_val2; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_B_MODE, - &wifi_under_b_mode); - - if (coex_sta->under_ips) { - coex_sta->crc_ok_cck = 0; - coex_sta->crc_ok_11g = 0; - coex_sta->crc_ok_11n = 0; - coex_sta->crc_ok_11n_agg = 0; - - coex_sta->crc_err_cck = 0; - coex_sta->crc_err_11g = 0; - coex_sta->crc_err_11n = 0; - coex_sta->crc_err_11n_agg = 0; - } else { - - reg_val1 = btcoexist->btc_read_4byte(btcoexist, 0xf00); - reg_val2 = btcoexist->btc_read_4byte(btcoexist, 0xf04); - coex_sta->crc_ok_cck = reg_val2 & 0xffff; - coex_sta->crc_err_cck = (reg_val1 & 0xffff) + ((reg_val2 - & 0xffff0000) >> 16); - - reg_val1 = btcoexist->btc_read_4byte(btcoexist, 0xf0c); - coex_sta->crc_ok_11n_agg = reg_val1 & 0xffff; - coex_sta->crc_err_11n_agg = (reg_val1 & 0xffff0000) >> - 16; - - reg_val1 = btcoexist->btc_read_4byte(btcoexist, 0xf10); - coex_sta->crc_ok_11n = reg_val1 & 0xffff; - coex_sta->crc_err_11n = (reg_val1 & 0xffff0000) >> 16; - - reg_val1 = btcoexist->btc_read_4byte(btcoexist, 0xf14); - coex_sta->crc_ok_11g = reg_val1 & 0xffff; - coex_sta->crc_err_11n = (reg_val1 & 0xffff0000) >> 16; - } - - - /* reset counter */ - /*btcoexist->btc_write_1byte_bitmask(btcoexist, 0xb58, 0x1, 0x1);*/ - /*btcoexist->btc_write_1byte_bitmask(btcoexist, 0xb58, 0x1, 0x0);*/ - - if ((wifi_busy) && (wifi_rssi >= 30) && (!wifi_under_b_mode)) { - total_cnt = coex_sta->crc_ok_cck + coex_sta->crc_ok_11g - + - coex_sta->crc_ok_11n + - coex_sta->crc_ok_11n_agg; - - if ((coex_dm->bt_status == - BT_8822B_2ANT_BT_STATUS_ACL_BUSY) || - (coex_dm->bt_status == - BT_8822B_2ANT_BT_STATUS_ACL_SCO_BUSY) || - (coex_dm->bt_status == - BT_8822B_2ANT_BT_STATUS_SCO_BUSY)) { - if (coex_sta->crc_ok_cck > (total_cnt - - coex_sta->crc_ok_cck)) { - if (cck_lock_counter < 3) - cck_lock_counter++; - } else { - if (cck_lock_counter > 0) - cck_lock_counter--; - } - - } else { - if (cck_lock_counter > 0) - cck_lock_counter--; - } - } else { - if (cck_lock_counter > 0) - cck_lock_counter--; - } - - if (!coex_sta->pre_ccklock) { - - if (cck_lock_counter >= 3) - coex_sta->cck_lock = true; - else - coex_sta->cck_lock = false; - } else { - if (cck_lock_counter == 0) - coex_sta->cck_lock = false; - else - coex_sta->cck_lock = true; - } - - if (coex_sta->cck_lock) - coex_sta->cck_ever_lock = true; - - coex_sta->pre_ccklock = coex_sta->cck_lock; - -#endif -} - -boolean halbtc8822b2ant_is_wifibt_status_changed(IN struct btc_coexist - *btcoexist) -{ - static boolean pre_wifi_busy = false, pre_under_4way = false, - pre_bt_hs_on = false, pre_bt_off = false; - static u8 pre_hid_busy_num = 0; - boolean wifi_busy = false, under_4way = false, bt_hs_on = false; - boolean wifi_connected = false; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS, - &under_4way); - - if (coex_sta->bt_disabled != pre_bt_off) { - pre_bt_off = coex_sta->bt_disabled; - - if (coex_sta->bt_disabled) - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT is disabled !!\n"); - else - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT is enabled !!\n"); - - BTC_TRACE(trace_buf); - - coex_sta->bt_coex_supported_feature = 0; - coex_sta->bt_coex_supported_version = 0; - coex_sta->bt_ble_scan_type = 0; - coex_sta->bt_ble_scan_para[0] = 0; - coex_sta->bt_ble_scan_para[1] = 0; - coex_sta->bt_ble_scan_para[2] = 0; - coex_sta->bt_reg_vendor_ac = 0xffff; - coex_sta->bt_reg_vendor_ae = 0xffff; - return true; - } - - - if (wifi_connected) { - if (wifi_busy != pre_wifi_busy) { - pre_wifi_busy = wifi_busy; - return true; - } - if (under_4way != pre_under_4way) { - pre_under_4way = under_4way; - return true; - } - if (bt_hs_on != pre_bt_hs_on) { - pre_bt_hs_on = bt_hs_on; - return true; - } - - if (!coex_sta->bt_disabled) { - - if (coex_sta->hid_busy_num != pre_hid_busy_num) { - pre_hid_busy_num = coex_sta->hid_busy_num; - return true; - } - } - } - - return false; -} - - -void halbtc8822b2ant_update_bt_link_info(IN struct btc_coexist *btcoexist) -{ - - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - boolean bt_hs_on = false; - boolean bt_busy = false; - - coex_sta->num_of_profile = 0; - - /* set link exist status */ - if (!(coex_sta->bt_info & BT_INFO_8822B_1ANT_B_CONNECTION)) { - coex_sta->bt_link_exist = false; - coex_sta->pan_exist = false; - coex_sta->a2dp_exist = false; - coex_sta->hid_exist = false; - coex_sta->sco_exist = false; - } else { /* connection exists */ - coex_sta->bt_link_exist = true; - if (coex_sta->bt_info & BT_INFO_8822B_1ANT_B_FTP) { - coex_sta->pan_exist = true; - coex_sta->num_of_profile++; - } else - coex_sta->pan_exist = false; - - if (coex_sta->bt_info & BT_INFO_8822B_1ANT_B_A2DP) { - coex_sta->a2dp_exist = true; - coex_sta->num_of_profile++; - } else - coex_sta->a2dp_exist = false; - - if (coex_sta->bt_info & BT_INFO_8822B_1ANT_B_HID) { - coex_sta->hid_exist = true; - coex_sta->num_of_profile++; - } else - coex_sta->hid_exist = false; - - if (coex_sta->bt_info & BT_INFO_8822B_1ANT_B_SCO_ESCO) { - coex_sta->sco_exist = true; - coex_sta->num_of_profile++; - } else - coex_sta->sco_exist = false; - - } - - - btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); - - bt_link_info->bt_link_exist = coex_sta->bt_link_exist; - bt_link_info->sco_exist = coex_sta->sco_exist; - bt_link_info->a2dp_exist = coex_sta->a2dp_exist; - bt_link_info->pan_exist = coex_sta->pan_exist; - bt_link_info->hid_exist = coex_sta->hid_exist; - bt_link_info->acl_busy = coex_sta->acl_busy; - - /* work around for HS mode. */ - if (bt_hs_on) { - bt_link_info->pan_exist = true; - bt_link_info->bt_link_exist = true; - } - - /* check if Sco only */ - if (bt_link_info->sco_exist && - !bt_link_info->a2dp_exist && - !bt_link_info->pan_exist && - !bt_link_info->hid_exist) - bt_link_info->sco_only = true; - else - bt_link_info->sco_only = false; - - /* check if A2dp only */ - if (!bt_link_info->sco_exist && - bt_link_info->a2dp_exist && - !bt_link_info->pan_exist && - !bt_link_info->hid_exist) - bt_link_info->a2dp_only = true; - else - bt_link_info->a2dp_only = false; - - /* check if Pan only */ - if (!bt_link_info->sco_exist && - !bt_link_info->a2dp_exist && - bt_link_info->pan_exist && - !bt_link_info->hid_exist) - bt_link_info->pan_only = true; - else - bt_link_info->pan_only = false; - - /* check if Hid only */ - if (!bt_link_info->sco_exist && - !bt_link_info->a2dp_exist && - !bt_link_info->pan_exist && - bt_link_info->hid_exist) - bt_link_info->hid_only = true; - else - bt_link_info->hid_only = false; - - if (!(coex_sta->bt_info & BT_INFO_8822B_2ANT_B_CONNECTION)) { - coex_dm->bt_status = BT_8822B_2ANT_BT_STATUS_NON_CONNECTED_IDLE; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), BT Non-Connected idle!!!\n"); - } else if (coex_sta->bt_info == BT_INFO_8822B_2ANT_B_CONNECTION) { - /* connection exists but no busy */ - coex_dm->bt_status = BT_8822B_2ANT_BT_STATUS_CONNECTED_IDLE; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), BT Connected-idle!!!\n"); - } else if (((coex_sta->bt_info & BT_INFO_8822B_2ANT_B_SCO_ESCO) || - (coex_sta->bt_info & BT_INFO_8822B_2ANT_B_SCO_BUSY)) && - (coex_sta->bt_info & BT_INFO_8822B_2ANT_B_ACL_BUSY)) { - coex_dm->bt_status = BT_8822B_2ANT_BT_STATUS_ACL_SCO_BUSY; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), BT ACL SCO busy!!!\n"); - } else if ((coex_sta->bt_info & BT_INFO_8822B_2ANT_B_SCO_ESCO) || - (coex_sta->bt_info & BT_INFO_8822B_2ANT_B_SCO_BUSY)) { - coex_dm->bt_status = BT_8822B_2ANT_BT_STATUS_SCO_BUSY; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), BT SCO busy!!!\n"); - } else if (coex_sta->bt_info & BT_INFO_8822B_2ANT_B_ACL_BUSY) { - coex_dm->bt_status = BT_8822B_2ANT_BT_STATUS_ACL_BUSY; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), BT ACL busy!!!\n"); - } else { - coex_dm->bt_status = BT_8822B_2ANT_BT_STATUS_MAX; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), BT Non-Defined state!!!\n"); - } - - BTC_TRACE(trace_buf); - - if ((BT_8822B_2ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) || - (BT_8822B_2ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) || - (BT_8822B_2ANT_BT_STATUS_ACL_SCO_BUSY == coex_dm->bt_status)) - bt_busy = true; - else - bt_busy = false; - - btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bt_busy); -} - -void halbtc8822b2ant_update_wifi_channel_info(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - u8 h2c_parameter[3] = {0}; - u32 wifi_bw; - u8 wifi_central_chnl; - u32 RTL97F_8822B = 0; - - if (RTL97F_8822B == true) - return; - - /* only 2.4G we need to inform bt the chnl mask */ - btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_CENTRAL_CHNL, - &wifi_central_chnl); - if ((BTC_MEDIA_CONNECT == type) && - (wifi_central_chnl <= 14)) { - h2c_parameter[0] = - 0x1; /* enable BT AFH skip WL channel for 8822b because BT Rx LO interference */ - /* h2c_parameter[0] = 0x0; */ - h2c_parameter[1] = wifi_central_chnl; - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw); - if (BTC_WIFI_BW_HT40 == wifi_bw) - h2c_parameter[2] = 0x30; - else - h2c_parameter[2] = 0x20; - } - - coex_dm->wifi_chnl_info[0] = h2c_parameter[0]; - coex_dm->wifi_chnl_info[1] = h2c_parameter[1]; - coex_dm->wifi_chnl_info[2] = h2c_parameter[2]; - - btcoexist->btc_fill_h2c(btcoexist, 0x66, 3, h2c_parameter); - -} - -void halbtc8822b2ant_set_fw_dac_swing_level(IN struct btc_coexist *btcoexist, - IN u8 dac_swing_lvl) -{ - u8 h2c_parameter[1] = {0}; - u32 RTL97F_8822B = 0; - - if (RTL97F_8822B == true) - return; - - /* There are several type of dacswing */ - /* 0x18/ 0x10/ 0xc/ 0x8/ 0x4/ 0x6 */ - h2c_parameter[0] = dac_swing_lvl; - - btcoexist->btc_fill_h2c(btcoexist, 0x64, 1, h2c_parameter); -} - -void halbtc8822b2ant_fw_dac_swing_lvl(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 fw_dac_swing_lvl) -{ - u32 RTL97F_8822B = 0; - - if (RTL97F_8822B == true) - return; - - coex_dm->cur_fw_dac_swing_lvl = fw_dac_swing_lvl; - - if (!force_exec) { - if (coex_dm->pre_fw_dac_swing_lvl == - coex_dm->cur_fw_dac_swing_lvl) - return; - } - - halbtc8822b2ant_set_fw_dac_swing_level(btcoexist, - coex_dm->cur_fw_dac_swing_lvl); - - coex_dm->pre_fw_dac_swing_lvl = coex_dm->cur_fw_dac_swing_lvl; -} - -void halbtc8822b2ant_set_fw_dec_bt_pwr(IN struct btc_coexist *btcoexist, - IN u8 dec_bt_pwr_lvl) -{ - u32 RTL97F_8822B = 0; - u8 h2c_parameter[1] = {0}; - - if (RTL97F_8822B == true) - return; - - h2c_parameter[0] = dec_bt_pwr_lvl; - - btcoexist->btc_fill_h2c(btcoexist, 0x62, 1, h2c_parameter); -} - -void halbtc8822b2ant_dec_bt_pwr(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 dec_bt_pwr_lvl) -{ - coex_dm->cur_bt_dec_pwr_lvl = dec_bt_pwr_lvl; - - if (!force_exec) { - if (coex_dm->pre_bt_dec_pwr_lvl == coex_dm->cur_bt_dec_pwr_lvl) - return; - } - halbtc8822b2ant_set_fw_dec_bt_pwr(btcoexist, - coex_dm->cur_bt_dec_pwr_lvl); - - coex_dm->pre_bt_dec_pwr_lvl = coex_dm->cur_bt_dec_pwr_lvl; -} - - -void halbtc8822b2ant_low_penalty_ra(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean low_penalty_ra) -{ - -#if 1 - coex_dm->cur_low_penalty_ra = low_penalty_ra; - - if (!force_exec) { - if (coex_dm->pre_low_penalty_ra == - coex_dm->cur_low_penalty_ra) - return; - } - - if (low_penalty_ra) - btcoexist->btc_phydm_modify_RA_PCR_threshold(btcoexist, 0, 50); - else - btcoexist->btc_phydm_modify_RA_PCR_threshold(btcoexist, 0, 0); - - coex_dm->pre_low_penalty_ra = coex_dm->cur_low_penalty_ra; - -#endif - -} - - -void halbtc8822b2ant_set_bt_auto_report(IN struct btc_coexist *btcoexist, - IN boolean enable_auto_report) -{ - u8 h2c_parameter[1] = {0}; - u32 RTL97F_8822B = 0; - - if (RTL97F_8822B == true) - return; - - h2c_parameter[0] = 0; - - if (enable_auto_report) - h2c_parameter[0] |= BIT(0); - - btcoexist->btc_fill_h2c(btcoexist, 0x68, 1, h2c_parameter); -} - -void halbtc8822b2ant_bt_auto_report(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean enable_auto_report) -{ - coex_dm->cur_bt_auto_report = enable_auto_report; - - if (!force_exec) { - if (coex_dm->pre_bt_auto_report == coex_dm->cur_bt_auto_report) - return; - } - halbtc8822b2ant_set_bt_auto_report(btcoexist, - coex_dm->cur_bt_auto_report); - - coex_dm->pre_bt_auto_report = coex_dm->cur_bt_auto_report; -} - -void halbtc8822b2ant_write_score_board( - IN struct btc_coexist *btcoexist, - IN u16 bitpos, - IN boolean state -) -{ - - static u16 originalval = 0x8002; - - if (state) - originalval = originalval | bitpos; - else - originalval = originalval & (~bitpos); - - - btcoexist->btc_write_2byte(btcoexist, 0xaa, originalval); - -} - -void halbtc8822b2ant_read_score_board( - IN struct btc_coexist *btcoexist, - IN u16 *score_board_val -) -{ - - *score_board_val = (btcoexist->btc_read_2byte(btcoexist, - 0xaa)) & 0x7fff; -} - -void halbtc8822b2ant_post_state_to_bt( - IN struct btc_coexist *btcoexist, - IN u16 type, - IN BOOLEAN state -) -{ - - halbtc8822b2ant_write_score_board(btcoexist, (u16) type, state); - -} - - - -void halbtc8822b2ant_monitor_bt_enable_disable(IN struct btc_coexist *btcoexist) -{ - static u32 bt_disable_cnt = 0; - boolean bt_active = true, bt_disabled = false, wifi_under_5g = false; - u16 u16tmp; - - /* This function check if bt is disabled */ -#if 0 - if (coex_sta->high_priority_tx == 0 && - coex_sta->high_priority_rx == 0 && - coex_sta->low_priority_tx == 0 && - coex_sta->low_priority_rx == 0) - bt_active = false; - if (coex_sta->high_priority_tx == 0xffff && - coex_sta->high_priority_rx == 0xffff && - coex_sta->low_priority_tx == 0xffff && - coex_sta->low_priority_rx == 0xffff) - bt_active = false; - - -#else - - /* Read BT on/off status from scoreboard[1], enable this only if BT patch support this feature */ - halbtc8822b2ant_read_score_board(btcoexist, &u16tmp); - - bt_active = u16tmp & BIT(1); - - -#endif - - if (bt_active) { - bt_disable_cnt = 0; - bt_disabled = false; - btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_DISABLE, - &bt_disabled); - } else { - - bt_disable_cnt++; - if (bt_disable_cnt >= 10) { - bt_disabled = true; - bt_disable_cnt = 10; - } - - btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_DISABLE, - &bt_disabled); - } - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g); - - if ((wifi_under_5g) || (bt_disabled)) - halbtc8822b2ant_low_penalty_ra(btcoexist, NORMAL_EXEC, false); - else - halbtc8822b2ant_low_penalty_ra(btcoexist, NORMAL_EXEC, true); - - - if (coex_sta->bt_disabled != bt_disabled) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT is from %s to %s!!\n", - (coex_sta->bt_disabled ? "disabled" : "enabled"), - (bt_disabled ? "disabled" : "enabled")); - BTC_TRACE(trace_buf); - coex_sta->bt_disabled = bt_disabled; - } - -} - -void halbtc8822b2ant_enable_gnt_to_gpio(IN struct btc_coexist *btcoexist, - boolean isenable) -{ -#if BT_8822B_2ANT_COEX_DBG - static u8 bitVal[5] = {0, 0, 0, 0, 0}; - static boolean state = false; - /* - if (state ==isenable) - return; - else - state = isenable; - */ - if (isenable) { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], enable_gnt_to_gpio!!\n"); - BTC_TRACE(trace_buf); - - /* enable GNT_WL, GNT_BT to GPIO for debug */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x73, 0x8, 0x1); - - /* store original value */ - bitVal[0] = (btcoexist->btc_read_1byte(btcoexist, - 0x66) & BIT(4)) >> 4; /*0x66[4] */ - bitVal[1] = (btcoexist->btc_read_1byte(btcoexist, - 0x67) & BIT(0)); /*0x66[8] */ - bitVal[2] = (btcoexist->btc_read_1byte(btcoexist, - 0x42) & BIT(3)) >> 3; /*0x40[19] */ - bitVal[3] = (btcoexist->btc_read_1byte(btcoexist, - 0x65) & BIT(7)) >> 7; /*0x64[15] */ - bitVal[4] = (btcoexist->btc_read_1byte(btcoexist, - 0x72) & BIT(2)) >> 2; /*0x70[18] */ - - /* switch GPIO Mux */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x66, BIT(4), - 0x0); /*0x66[4] = 0 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, BIT(0), - 0x0); /*0x66[8] = 0 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x42, BIT(3), - 0x0); /*0x40[19] = 0 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x65, BIT(7), - 0x0); /*0x64[15] = 0 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x72, BIT(2), - 0x0); /*0x70[18] = 0 */ - - - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], disable_gnt_to_gpio!!\n"); - BTC_TRACE(trace_buf); - - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x73, 0x8, 0x0); - - /* Restore original value */ - /* switch GPIO Mux */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x66, BIT(4), - bitVal[0]); /*0x66[4] = 0 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, BIT(0), - bitVal[1]); /*0x66[8] = 0 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x42, BIT(3), - bitVal[2]); /*0x40[19] = 0 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x65, BIT(7), - bitVal[3]); /*0x64[15] = 0 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x72, BIT(2), - bitVal[4]); /*0x70[18] = 0 */ - } - -#endif -} - -u32 halbtc8822b2ant_ltecoex_indirect_read_reg(IN struct btc_coexist *btcoexist, - IN u16 reg_addr) -{ - u32 j = 0; - - - /* wait for ready bit before access 0x1700 */ - btcoexist->btc_write_4byte(btcoexist, 0x1700, 0x800F0000 | reg_addr); - - do { - j++; - } while (((btcoexist->btc_read_1byte(btcoexist, - 0x1703)&BIT(5)) == 0) && - (j < BT_8822B_2ANT_LTECOEX_INDIRECTREG_ACCESS_TIMEOUT)); - - - return btcoexist->btc_read_4byte(btcoexist, - 0x1708); /* get read data */ - -} - -void halbtc8822b2ant_ltecoex_indirect_write_reg(IN struct btc_coexist - *btcoexist, - IN u16 reg_addr, IN u32 bit_mask, IN u32 reg_value) -{ - u32 val, i = 0, j = 0, bitpos = 0; - - - if (bit_mask == 0x0) - return; - if (bit_mask == 0xffffffff) { - btcoexist->btc_write_4byte(btcoexist, 0x1704, - reg_value); /* put write data */ - - /* wait for ready bit before access 0x1700 */ - do { - j++; - } while (((btcoexist->btc_read_1byte(btcoexist, - 0x1703)&BIT(5)) == 0) && - (j < BT_8822B_2ANT_LTECOEX_INDIRECTREG_ACCESS_TIMEOUT)); - - - btcoexist->btc_write_4byte(btcoexist, 0x1700, - 0xc00F0000 | reg_addr); - } else { - for (i = 0; i <= 31; i++) { - if (((bit_mask >> i) & 0x1) == 0x1) { - bitpos = i; - break; - } - } - - /* read back register value before write */ - val = halbtc8822b2ant_ltecoex_indirect_read_reg(btcoexist, - reg_addr); - val = (val & (~bit_mask)) | (reg_value << bitpos); - - btcoexist->btc_write_4byte(btcoexist, 0x1704, - val); /* put write data */ - - /* wait for ready bit before access 0x7c0 */ - do { - j++; - } while (((btcoexist->btc_read_1byte(btcoexist, - 0x1703)&BIT(5)) == 0) && - (j < BT_8822B_2ANT_LTECOEX_INDIRECTREG_ACCESS_TIMEOUT)); - - - btcoexist->btc_write_4byte(btcoexist, 0x1700, - 0xc00F0000 | reg_addr); - - } - -} - -void halbtc8822b2ant_ltecoex_enable(IN struct btc_coexist *btcoexist, - IN boolean enable) -{ - u8 val; - - val = (enable) ? 1 : 0; - halbtc8822b2ant_ltecoex_indirect_write_reg(btcoexist, 0x38, 0x80, - val); /* 0x38[7] */ - -} - -void halbtc8822b2ant_ltecoex_pathcontrol_owner(IN struct btc_coexist *btcoexist, - IN boolean wifi_control) -{ - u8 val; - - val = (wifi_control) ? 1 : 0; - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x73, 0x4, - val); /* 0x70[26] */ - -} - -void halbtc8822b2ant_ltecoex_set_gnt_bt(IN struct btc_coexist *btcoexist, - IN u8 control_block, IN boolean sw_control, IN u8 state) -{ - u32 val = 0, bit_mask; - - state = state & 0x1; - val = (sw_control) ? ((state << 1) | 0x1) : 0; - - switch (control_block) { - case BT_8822B_2ANT_GNT_BLOCK_RFC_BB: - default: - bit_mask = 0xc000; - halbtc8822b2ant_ltecoex_indirect_write_reg(btcoexist, - 0x38, bit_mask, val); /* 0x38[15:14] */ - bit_mask = 0x0c00; - halbtc8822b2ant_ltecoex_indirect_write_reg(btcoexist, - 0x38, bit_mask, val); /* 0x38[11:10] */ - break; - case BT_8822B_2ANT_GNT_BLOCK_RFC: - bit_mask = 0xc000; - halbtc8822b2ant_ltecoex_indirect_write_reg(btcoexist, - 0x38, bit_mask, val); /* 0x38[15:14] */ - break; - case BT_8822B_2ANT_GNT_BLOCK_BB: - bit_mask = 0x0c00; - halbtc8822b2ant_ltecoex_indirect_write_reg(btcoexist, - 0x38, bit_mask, val); /* 0x38[11:10] */ - break; - - } - -} - -void halbtc8822b2ant_ltecoex_set_gnt_wl(IN struct btc_coexist *btcoexist, - IN u8 control_block, IN boolean sw_control, IN u8 state) -{ - u32 val = 0, bit_mask; - - state = state & 0x1; - val = (sw_control) ? ((state << 1) | 0x1) : 0; - - switch (control_block) { - case BT_8822B_2ANT_GNT_BLOCK_RFC_BB: - default: - bit_mask = 0x3000; - halbtc8822b2ant_ltecoex_indirect_write_reg(btcoexist, - 0x38, bit_mask, val); /* 0x38[13:12] */ - bit_mask = 0x0300; - halbtc8822b2ant_ltecoex_indirect_write_reg(btcoexist, - 0x38, bit_mask, val); /* 0x38[9:8] */ - break; - case BT_8822B_2ANT_GNT_BLOCK_RFC: - bit_mask = 0x3000; - halbtc8822b2ant_ltecoex_indirect_write_reg(btcoexist, - 0x38, bit_mask, val); /* 0x38[13:12] */ - break; - case BT_8822B_2ANT_GNT_BLOCK_BB: - bit_mask = 0x0300; - halbtc8822b2ant_ltecoex_indirect_write_reg(btcoexist, - 0x38, bit_mask, val); /* 0x38[9:8] */ - break; - - } - -} - -void halbtc8822b2ant_ltecoex_set_coex_table(IN struct btc_coexist *btcoexist, - IN u8 table_type, IN u16 table_content) -{ - u16 reg_addr = 0x0000; - - switch (table_type) { - case BT_8822B_2ANT_CTT_WL_VS_LTE: - reg_addr = 0xa0; - break; - case BT_8822B_2ANT_CTT_BT_VS_LTE: - reg_addr = 0xa4; - break; - } - - if (reg_addr != 0x0000) - halbtc8822b2ant_ltecoex_indirect_write_reg(btcoexist, reg_addr, - 0xffff, table_content); /* 0xa0[15:0] or 0xa4[15:0] */ - - -} - - -void halbtc8822b2ant_ltecoex_set_break_table(IN struct btc_coexist *btcoexist, - IN u8 table_type, IN u8 table_content) -{ - u16 reg_addr = 0x0000; - - switch (table_type) { - case BT_8822B_2ANT_LBTT_WL_BREAK_LTE: - reg_addr = 0xa8; - break; - case BT_8822B_2ANT_LBTT_BT_BREAK_LTE: - reg_addr = 0xac; - break; - case BT_8822B_2ANT_LBTT_LTE_BREAK_WL: - reg_addr = 0xb0; - break; - case BT_8822B_2ANT_LBTT_LTE_BREAK_BT: - reg_addr = 0xb4; - break; - } - - if (reg_addr != 0x0000) - halbtc8822b2ant_ltecoex_indirect_write_reg(btcoexist, reg_addr, - 0xff, table_content); /* 0xa8[15:0] or 0xb4[15:0] */ - - -} - - -void halbtc8822b2ant_set_coex_table(IN struct btc_coexist *btcoexist, - IN u32 val0x6c0, IN u32 val0x6c4, IN u32 val0x6c8, IN u8 val0x6cc) -{ - btcoexist->btc_write_4byte(btcoexist, 0x6c0, val0x6c0); - - btcoexist->btc_write_4byte(btcoexist, 0x6c4, val0x6c4); - - btcoexist->btc_write_4byte(btcoexist, 0x6c8, val0x6c8); - - btcoexist->btc_write_1byte(btcoexist, 0x6cc, val0x6cc); -} - -void halbtc8822b2ant_coex_table(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u32 val0x6c0, IN u32 val0x6c4, - IN u32 val0x6c8, IN u8 val0x6cc) -{ - coex_dm->cur_val0x6c0 = val0x6c0; - coex_dm->cur_val0x6c4 = val0x6c4; - coex_dm->cur_val0x6c8 = val0x6c8; - coex_dm->cur_val0x6cc = val0x6cc; - - if (!force_exec) { - if ((coex_dm->pre_val0x6c0 == coex_dm->cur_val0x6c0) && - (coex_dm->pre_val0x6c4 == coex_dm->cur_val0x6c4) && - (coex_dm->pre_val0x6c8 == coex_dm->cur_val0x6c8) && - (coex_dm->pre_val0x6cc == coex_dm->cur_val0x6cc)) - return; - } - halbtc8822b2ant_set_coex_table(btcoexist, val0x6c0, val0x6c4, val0x6c8, - val0x6cc); - - coex_dm->pre_val0x6c0 = coex_dm->cur_val0x6c0; - coex_dm->pre_val0x6c4 = coex_dm->cur_val0x6c4; - coex_dm->pre_val0x6c8 = coex_dm->cur_val0x6c8; - coex_dm->pre_val0x6cc = coex_dm->cur_val0x6cc; -} - -void halbtc8822b2ant_coex_table_with_type(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 type) -{ - u32 break_table; - u8 select_table; - - coex_sta->coex_table_type = type; - - if (coex_sta->concurrent_rx_mode_on == true) { - break_table = 0xf0ffffff; /* set WL hi-pri can break BT */ - select_table = - 0x3; /* 0xb/0x3,set Tx response = Hi-Pri/LO-Pri (ex: Transmitting ACK,BA,CTS) */ - } else { - break_table = 0xffffff; - select_table = 0x3; - } - - switch (type) { - case 0: - halbtc8822b2ant_coex_table(btcoexist, force_exec, - 0x55555555, 0x55555555, break_table, select_table); - break; - case 1: - halbtc8822b2ant_coex_table(btcoexist, force_exec, - 0x55555555, 0x5a5a5a5a, break_table, select_table); - break; - case 2: - halbtc8822b2ant_coex_table(btcoexist, force_exec, - 0x5a5a5a5a, 0x5a5a5a5a, break_table, select_table); - break; - case 3: - halbtc8822b2ant_coex_table(btcoexist, force_exec, - 0x5a5a5a5a, 0x5a5a5a5a, break_table, select_table); - break; - case 4: - halbtc8822b2ant_coex_table(btcoexist, force_exec, - 0x55555555, 0x5a5a5a5a, break_table, select_table); - break; - case 5: - halbtc8822b2ant_coex_table(btcoexist, force_exec, - 0x55555555, 0x5a5a5a5a, break_table, select_table); - break; - case 6: - halbtc8822b2ant_coex_table(btcoexist, force_exec, - 0x55555555, 0xaaaa5aaa, break_table, select_table); - break; - case 7: - halbtc8822b2ant_coex_table(btcoexist, force_exec, - 0xa5555555, 0xaa5a5a5a, break_table, select_table); - break; - case 8: - halbtc8822b2ant_coex_table(btcoexist, force_exec, - 0x55555555, 0x5a5a5a5a, break_table, select_table); - break; - case 9: - halbtc8822b2ant_coex_table(btcoexist, force_exec, - 0x55555555, 0xaaaa555a, break_table, select_table); - break; - case 10: - halbtc8822b2ant_coex_table(btcoexist, force_exec, - 0x55555555, 0xaaaa5aaa, break_table, select_table); - break; - case 11: - halbtc8822b2ant_coex_table(btcoexist, force_exec, - 0x55555555, 0xaaaaa5aa, break_table, select_table); - break; - default: - break; - } -} - -void halbtc8822b2ant_set_fw_ignore_wlan_act(IN struct btc_coexist *btcoexist, - IN boolean enable) -{ - u8 h2c_parameter[1] = {0}; - u32 RTL97F_8822B = 0; - - if (RTL97F_8822B == true) - return; - - if (enable) - h2c_parameter[0] |= BIT(0); /* function enable */ - - btcoexist->btc_fill_h2c(btcoexist, 0x63, 1, h2c_parameter); -} - -void halbtc8822b2ant_ignore_wlan_act(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean enable) -{ - coex_dm->cur_ignore_wlan_act = enable; - - if (!force_exec) { - if (coex_dm->pre_ignore_wlan_act == - coex_dm->cur_ignore_wlan_act) - return; - } - halbtc8822b2ant_set_fw_ignore_wlan_act(btcoexist, enable); - - coex_dm->pre_ignore_wlan_act = coex_dm->cur_ignore_wlan_act; -} - -void halbtc8822b2ant_set_lps_rpwm(IN struct btc_coexist *btcoexist, - IN u8 lps_val, IN u8 rpwm_val) -{ - u8 lps = lps_val; - u8 rpwm = rpwm_val; - - btcoexist->btc_set(btcoexist, BTC_SET_U1_LPS_VAL, &lps); - btcoexist->btc_set(btcoexist, BTC_SET_U1_RPWM_VAL, &rpwm); -} - -void halbtc8822b2ant_lps_rpwm(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 lps_val, IN u8 rpwm_val) -{ - coex_dm->cur_lps = lps_val; - coex_dm->cur_rpwm = rpwm_val; - - if (!force_exec) { - if ((coex_dm->pre_lps == coex_dm->cur_lps) && - (coex_dm->pre_rpwm == coex_dm->cur_rpwm)) - return; - } - halbtc8822b2ant_set_lps_rpwm(btcoexist, lps_val, rpwm_val); - - coex_dm->pre_lps = coex_dm->cur_lps; - coex_dm->pre_rpwm = coex_dm->cur_rpwm; -} - -void halbtc8822b2ant_ps_tdma_check_for_power_save_state( - IN struct btc_coexist *btcoexist, IN boolean new_ps_state) -{ - u8 lps_mode = 0x0; - u8 h2c_parameter[5] = {0, 0, 0, 0x40, 0}; - u32 RTL97F_8822B = 0; - - if (RTL97F_8822B == true) - return; - - btcoexist->btc_get(btcoexist, BTC_GET_U1_LPS_MODE, &lps_mode); - - if (lps_mode) { /* already under LPS state */ - if (new_ps_state) { - /* keep state under LPS, do nothing. */ - } else { - /* will leave LPS state, turn off psTdma first */ - /*halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, - 8); */ - btcoexist->btc_fill_h2c(btcoexist, 0x60, 5, - h2c_parameter); - } - } else { /* NO PS state */ - if (new_ps_state) { - /* will enter LPS state, turn off psTdma first */ - /*halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, - 8);*/ - btcoexist->btc_fill_h2c(btcoexist, 0x60, 5, - h2c_parameter); - } else { - /* keep state under NO PS state, do nothing. */ - } - } -} - -void halbtc8822b2ant_power_save_state(IN struct btc_coexist *btcoexist, - IN u8 ps_type, IN u8 lps_val, IN u8 rpwm_val) -{ - boolean low_pwr_disable = false; - - switch (ps_type) { - case BTC_PS_WIFI_NATIVE: - /* recover to original 32k low power setting */ - low_pwr_disable = false; - btcoexist->btc_set(btcoexist, - BTC_SET_ACT_DISABLE_LOW_POWER, - &low_pwr_disable); - btcoexist->btc_set(btcoexist, BTC_SET_ACT_NORMAL_LPS, - NULL); - coex_sta->force_lps_on = false; - break; - case BTC_PS_LPS_ON: - halbtc8822b2ant_ps_tdma_check_for_power_save_state( - btcoexist, true); - halbtc8822b2ant_lps_rpwm(btcoexist, NORMAL_EXEC, - lps_val, rpwm_val); - /* when coex force to enter LPS, do not enter 32k low power. */ - low_pwr_disable = true; - btcoexist->btc_set(btcoexist, - BTC_SET_ACT_DISABLE_LOW_POWER, - &low_pwr_disable); - /* power save must executed before psTdma. */ - btcoexist->btc_set(btcoexist, BTC_SET_ACT_ENTER_LPS, - NULL); - coex_sta->force_lps_on = true; - break; - case BTC_PS_LPS_OFF: - halbtc8822b2ant_ps_tdma_check_for_power_save_state( - btcoexist, false); - btcoexist->btc_set(btcoexist, BTC_SET_ACT_LEAVE_LPS, - NULL); - coex_sta->force_lps_on = false; - break; - default: - break; - } -} - - - -void halbtc8822b2ant_set_fw_pstdma(IN struct btc_coexist *btcoexist, - IN u8 byte1, IN u8 byte2, IN u8 byte3, IN u8 byte4, IN u8 byte5) -{ - u8 h2c_parameter[5] = {0}; - u8 real_byte1 = byte1, real_byte5 = byte5; - boolean ap_enable = false; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, - &ap_enable); - - if (ap_enable) { - if (byte1 & BIT(4) && !(byte1 & BIT(5))) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], FW for AP mode\n"); - BTC_TRACE(trace_buf); - real_byte1 &= ~BIT(4); - real_byte1 |= BIT(5); - - real_byte5 |= BIT(5); - real_byte5 &= ~BIT(6); - - halbtc8822b2ant_power_save_state(btcoexist, - BTC_PS_WIFI_NATIVE, 0x0, - 0x0); - } - } else if (byte1 & BIT(4) && !(byte1 & BIT(5))) { - - halbtc8822b2ant_power_save_state( - btcoexist, BTC_PS_LPS_ON, 0x50, - 0x4); - } else { - halbtc8822b2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, - 0x0, - 0x0); - } - - - h2c_parameter[0] = real_byte1; - h2c_parameter[1] = byte2; - h2c_parameter[2] = byte3; - h2c_parameter[3] = byte4; - h2c_parameter[4] = real_byte5; - - coex_dm->ps_tdma_para[0] = real_byte1; - coex_dm->ps_tdma_para[1] = byte2; - coex_dm->ps_tdma_para[2] = byte3; - coex_dm->ps_tdma_para[3] = byte4; - coex_dm->ps_tdma_para[4] = real_byte5; - - btcoexist->btc_fill_h2c(btcoexist, 0x60, 5, h2c_parameter); -} - -void halbtc8822b2ant_ps_tdma(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN boolean turn_on, IN u8 type) -{ - - static u8 psTdmaByte4Modify = 0x0, pre_psTdmaByte4Modify = 0x0; - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - - - coex_dm->cur_ps_tdma_on = turn_on; - coex_dm->cur_ps_tdma = type; - - /* 0x778 = 0x1 at wifi slot (no blocking BT Low-Pri pkts) */ - if ((bt_link_info->slave_role) && (bt_link_info->a2dp_exist)) - psTdmaByte4Modify = 0x1; - else - psTdmaByte4Modify = 0x0; - - if (pre_psTdmaByte4Modify != psTdmaByte4Modify) { - - force_exec = true; - pre_psTdmaByte4Modify = psTdmaByte4Modify; - } - - if (!force_exec) { - if ((coex_dm->pre_ps_tdma_on == coex_dm->cur_ps_tdma_on) && - (coex_dm->pre_ps_tdma == coex_dm->cur_ps_tdma)) - return; - } - - if (coex_dm->cur_ps_tdma_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** TDMA(on, %d) **********\n", - coex_dm->cur_ps_tdma); - BTC_TRACE(trace_buf); - - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x550, 0x8, - 0x1); /* enable TBTT nterrupt */ - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** TDMA(off, %d) **********\n", - coex_dm->cur_ps_tdma); - BTC_TRACE(trace_buf); - } - - - if (turn_on) { - switch (type) { - case 1: - halbtc8822b2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x10, 0x03, 0xf1, - 0x54 | psTdmaByte4Modify); - break; - case 2: - default: - halbtc8822b2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x35, 0x03, 0x71, - 0x11 | psTdmaByte4Modify); - break; - case 3: - halbtc8822b2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x3a, 0x3, 0xf1, - 0x10 | psTdmaByte4Modify); - break; - case 4: - halbtc8822b2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x21, 0x3, 0xf1, - 0x10 | psTdmaByte4Modify); - break; - case 5: - halbtc8822b2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x25, 0x3, 0xf1, - 0x10 | psTdmaByte4Modify); - break; - case 6: - halbtc8822b2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x10, 0x3, 0xf1, - 0x10 | psTdmaByte4Modify); - break; - case 7: - halbtc8822b2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x20, 0x3, 0xf1, - 0x10 | psTdmaByte4Modify); - break; - case 11: - halbtc8822b2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x30, 0x03, 0x71, - 0x10 | psTdmaByte4Modify); - break; - case 12: - halbtc8822b2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x21, 0x03, 0x71, - 0x11 | psTdmaByte4Modify); - break; - case 13: - halbtc8822b2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x1c, 0x03, 0x71, - 0x10 | psTdmaByte4Modify); - break; - case 14: - halbtc8822b2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x30, 0x03, 0x71, - 0x11); - break; - case 51: - halbtc8822b2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x10, 0x03, 0xf1, - 0x10 | psTdmaByte4Modify); - break; - case 101: - halbtc8822b2ant_set_fw_pstdma(btcoexist, 0xd3, - 0x10, 0x03, 0x70, - 0x54 | psTdmaByte4Modify); - break; - case 102: - halbtc8822b2ant_set_fw_pstdma(btcoexist, 0xe3, - 0x35, 0x03, 0x71, - 0x11 | psTdmaByte4Modify); - break; - case 103: - halbtc8822b2ant_set_fw_pstdma(btcoexist, 0xd3, - 0x3a, 0x3, 0x70, - 0x50 | psTdmaByte4Modify); - break; - case 104: - halbtc8822b2ant_set_fw_pstdma(btcoexist, 0xd3, - 0x21, 0x3, 0x70, - 0x50 | psTdmaByte4Modify); - break; - case 105: - halbtc8822b2ant_set_fw_pstdma(btcoexist, 0xd3, - 0x25, 0x3, 0x70, - 0x50 | psTdmaByte4Modify); - break; - case 106: - halbtc8822b2ant_set_fw_pstdma(btcoexist, 0xd3, - 0x10, 0x3, 0x70, - 0x50 | psTdmaByte4Modify); - break; - case 107: - halbtc8822b2ant_set_fw_pstdma(btcoexist, 0xd3, - 0x20, 0x3, 0x70, - 0x50 | psTdmaByte4Modify); - break; - case 151: - halbtc8822b2ant_set_fw_pstdma(btcoexist, 0xd3, - 0x10, 0x03, 0x70, - 0x50 | psTdmaByte4Modify); - break; - } - } else { - /* disable PS tdma */ - switch (type) { - case 0: - halbtc8822b2ant_set_fw_pstdma(btcoexist, 0x0, - 0x0, 0x0, 0x40, 0x0); - break; - case 1: - halbtc8822b2ant_set_fw_pstdma(btcoexist, 0x0, - 0x0, 0x0, 0x48, 0x0); - break; - default: - halbtc8822b2ant_set_fw_pstdma(btcoexist, 0x0, - 0x0, 0x0, 0x40, 0x0); - break; - } - } - - /* update pre state */ - coex_dm->pre_ps_tdma_on = coex_dm->cur_ps_tdma_on; - coex_dm->pre_ps_tdma = coex_dm->cur_ps_tdma; -} - -void halbtc8822b2ant_set_ext_band_switch(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 pos_type) -{ - -#if 0 - boolean switch_polatiry_inverse = false; - u8 regval_0xcb6; - u32 u32tmp1 = 0, u32tmp2 = 0; - - if (!rfe_type->ext_band_switch_exist) - return; - - coex_dm->cur_ext_band_switch_status = pos_type; - - if (!force_exec) { - if (coex_dm->pre_ext_band_switch_status == - coex_dm->cur_ext_band_switch_status) - return; - } - - coex_dm->pre_ext_band_switch_status = - coex_dm->cur_ext_band_switch_status; - - /* swap control polarity if use different switch control polarity*/ - switch_polatiry_inverse = (rfe_type->ext_band_switch_ctrl_polarity == 1 - ? ~switch_polatiry_inverse : switch_polatiry_inverse); - - /*swap control polarity for WL_A, default polarity 0xcb4[21] = 0 && 0xcb4[23] = 1 is for WL_G */ - switch_polatiry_inverse = (pos_type == - BT_8822B_2ANT_EXT_BAND_SWITCH_TO_WLA ? ~switch_polatiry_inverse - : switch_polatiry_inverse); - - regval_0xcb6 = btcoexist->btc_read_1byte(btcoexist, 0xcb6); - - /* for normal switch polrity, 0xcb4[21] =1 && 0xcb4[23] = 0 for WL_A, vice versa */ - regval_0xcb6 = (switch_polatiry_inverse == 1 ? ((regval_0xcb6 & (~(BIT( - 7)))) | BIT(5)) : ((regval_0xcb6 & (~(BIT(5)))) | BIT(7))); - - btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb6, 0xff, - regval_0xcb6); - - u32tmp1 = btcoexist->btc_read_4byte(btcoexist, 0xcb0); - u32tmp2 = btcoexist->btc_read_4byte(btcoexist, 0xcb4); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** (After Ext Band switch setup) 0xcb0 = 0x%08x, 0xcb4 = 0x%08x**********\n", - u32tmp1, u32tmp2); - BTC_TRACE(trace_buf); -#endif - -} - -/*anttenna control by bb mac bt antdiv pta to write 0x4c 0xcb4,0xcbd*/ -void halbtc8822b2ant_set_ext_ant_switch(IN struct btc_coexist *btcoexist, - IN boolean force_exec, IN u8 ctrl_type, IN u8 pos_type) -{ - - struct btc_board_info *board_info = &btcoexist->board_info; - boolean switch_polatiry_inverse = false; - u8 regval_0xcbc = 0, regval_0x64; - u32 u32tmp1 = 0, u32tmp2 = 0, u32tmp3 = 0; - - if (!rfe_type->ext_ant_switch_exist) - return; - - coex_dm->cur_ext_ant_switch_status = (ctrl_type << 8) + pos_type; - - if (!force_exec) { - if (coex_dm->pre_ext_ant_switch_status == - coex_dm->cur_ext_ant_switch_status) - return; -} - coex_dm->pre_ext_ant_switch_status = coex_dm->cur_ext_ant_switch_status; - /* - switch (pos_type) { - default: - case BT_8822B_2ANT_EXT_ANT_SWITCH_MAIN_TO_BT: - case BT_8822B_2ANT_EXT_ANT_SWITCH_MAIN_TO_NOCARE: - break; - case BT_8822B_2ANT_EXT_ANT_SWITCH_MAIN_TO_WLG: - break; - case BT_8822B_2ANT_EXT_ANT_SWITCH_MAIN_TO_WLA: - break; - } -*/ - if (board_info->ant_div_cfg) - /*ctrl_type = BT_8822B_2ANT_EXT_ANT_SWITCH_CTRL_BY_ANTDIV;*/ - - /* Ext switch buffer mux */ - btcoexist->btc_write_1byte(btcoexist, 0x974, 0xff); - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x1991, 0x3, 0x0); - btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbe, 0x8, 0x0); - - - switch (ctrl_type) { - default: - case BT_8822B_2ANT_EXT_ANT_SWITCH_CTRL_BY_BBSW: - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4e, - 0x80, 0x0); /* 0x4c[23] = 0 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4f, - 0x01, 0x1); /* 0x4c[24] = 1 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb4, - 0xff, 0x77); /* BB SW, DPDT use RFE_ctrl8 and RFE_ctrl9 as conctrol pin */ - - btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbd, - 0x03, 01); - - break; - case BT_8822B_2ANT_EXT_ANT_SWITCH_CTRL_BY_PTA: - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4e, - 0x80, 0x0); /* 0x4c[23] = 0 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4f, - 0x01, 0x1); /* 0x4c[24] = 1 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb4, - 0xff, 0x66); /* PTA, DPDT use RFE_ctrl8 and RFE_ctrl9 as conctrol pin */ - - regval_0xcbc = (switch_polatiry_inverse == false ? - 0x2 : 0x1); /* 0xcb4[29:28] = 2b'10 for no switch_polatiry_inverse, DPDT_SEL_N =1, DPDT_SEL_P =0 @ GNT_BT=1 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbc, - 0x03, regval_0xcbc); - - break; - case BT_8822B_2ANT_EXT_ANT_SWITCH_CTRL_BY_ANTDIV: - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4e, - 0x80, 0x0); /* 0x4c[23] = 0 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4f, - 0x01, 0x1);/* 0x4c[24] = 1 */ -btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb4, 0xff, 0x88); -break; - case BT_8822B_2ANT_EXT_ANT_SWITCH_CTRL_BY_MAC: - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4e, - 0x80, 0x1); /* 0x4c[23] = 1 */ - - regval_0x64 = (switch_polatiry_inverse == false ? 0x0 : - 0x1); /* 0x64[0] = 1b'0 for no switch_polatiry_inverse, DPDT_SEL_N =1, DPDT_SEL_P =0 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x64, 0x1, - regval_0x64); - break; - case BT_8822B_2ANT_EXT_ANT_SWITCH_CTRL_BY_BT: - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4e, - 0x80, 0x0); /* 0x4c[23] = 0 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4f, - 0x01, 0x0); /* 0x4c[24] = 0 */ - - /* no setup required, because antenna switch control value by BT vendor 0x1c[1:0] */ - break; - } - - /* PAPE, LNA_ON control by BT while WLAN off for current leakage issue */ - if (ctrl_type == BT_8822B_2ANT_EXT_ANT_SWITCH_CTRL_BY_BT) { - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, 0x20, - 0x0); /* PAPE 0x64[29] = 0 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, 0x10, - 0x0); /* LNA_ON 0x64[28] = 0 */ - } else { - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, 0x20, - 0x1); /* PAPE 0x64[29] = 1 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, 0x10, - 0x1); /* LNA_ON 0x64[28] = 1 */ - } - -#if BT_8822B_2ANT_COEX_DBG - - u32tmp1 = btcoexist->btc_read_4byte(btcoexist, 0xcb4); - u32tmp2 = btcoexist->btc_read_4byte(btcoexist, 0x4c); - u32tmp3 = btcoexist->btc_read_4byte(btcoexist, 0x64) & 0xff; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], (After Ext Ant switch setup) 0xcb4 = 0x%08x, 0x4c = 0x%08x, 0x64= 0x%02x\n", - u32tmp1, u32tmp2, u32tmp3); - BTC_TRACE(trace_buf); -#endif - - - -} -/*rf4 type by efuse , and for ant at main aux inverse use , because is 2x2 ,and control types are the same ,does not need */ -void halbtc8822b2ant_set_rfe_type(IN struct btc_coexist *btcoexist) -{ - - struct btc_board_info *board_info = &btcoexist->board_info; - - - rfe_type->ext_band_switch_exist = false; - rfe_type->ext_band_switch_type = - BT_8822B_2ANT_EXT_BAND_SWITCH_USE_SPDT; /* SPDT; */ - rfe_type->ext_band_switch_ctrl_polarity = 0; - /* Ext switch buffer mux */ - btcoexist->btc_write_1byte(btcoexist, 0x974, 0xff); - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x1991, 0x3, 0x0); - btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbe, 0x8, 0x0); - - if (rfe_type->ext_band_switch_exist) { - - /* band switch use RFE_ctrl1 (pin name: PAPE_A) and RFE_ctrl3 (pin name: LNAON_A) */ - - /* set RFE_ctrl1 as software control */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb0, 0xf0, 0x7); - - /* set RFE_ctrl3 as software control */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb1, 0xf0, 0x7); - - } - - - /* the following setup should be got from Efuse in the future */ - rfe_type->rfe_module_type = board_info->rfe_type; - - rfe_type->ext_ant_switch_ctrl_polarity = 0; - - switch (rfe_type->rfe_module_type) { - case 0: - default: - rfe_type->ext_ant_switch_exist = true; - rfe_type->ext_ant_switch_type = BT_8822B_2ANT_EXT_ANT_SWITCH_USE_SPDT; - break; - case 1: - rfe_type->ext_ant_switch_exist = true; - rfe_type->ext_ant_switch_type = BT_8822B_2ANT_EXT_ANT_SWITCH_USE_SPDT; - break; - case 2: - rfe_type->ext_ant_switch_exist = true; - rfe_type->ext_ant_switch_type = BT_8822B_2ANT_EXT_ANT_SWITCH_USE_SPDT; - break; - case 3: - rfe_type->ext_ant_switch_exist = true; - rfe_type->ext_ant_switch_type = BT_8822B_2ANT_EXT_ANT_SWITCH_USE_SPDT; - break; - case 4: - rfe_type->ext_ant_switch_exist = true; - rfe_type->ext_ant_switch_type = - BT_8822B_2ANT_EXT_ANT_SWITCH_USE_SPDT; - break; - case 5: - rfe_type->ext_ant_switch_exist = true; - rfe_type->ext_ant_switch_type = BT_8822B_2ANT_EXT_ANT_SWITCH_USE_SPDT; - break; - case 6: - rfe_type->ext_ant_switch_exist = true; - rfe_type->ext_ant_switch_type = BT_8822B_2ANT_EXT_ANT_SWITCH_USE_SPDT; - break; - case 7: - rfe_type->ext_ant_switch_exist = true; -rfe_type->ext_ant_switch_type = BT_8822B_2ANT_EXT_ANT_SWITCH_USE_SPDT; - break; - } - -#if 0 - - if (rfe_type->wlg_Locate_at_btg) - halbtc8822b2ant_set_int_block(btcoexist, FORCE_EXEC, - BT_8822B_2ANT_INT_BLOCK_SWITCH_TO_WLG_OF_BTG); - else - halbtc8822b2ant_set_int_block(btcoexist, FORCE_EXEC, - BT_8822B_2ANT_INT_BLOCK_SWITCH_TO_WLG_OF_WLAG); -#endif - -} - -/*set gnt_wl gnt_bt control by sw high low , or hwpta while in power on,ini,wlan off,wlan only ,wl2g non-currrent ,wl2g current,wl5g*/ -void halbtc8822b2ant_set_ant_path(IN struct btc_coexist *btcoexist, - IN u8 ant_pos_type, IN boolean force_exec, - IN u8 phase) -{ - struct btc_board_info *board_info = &btcoexist->board_info; - u32 cnt_bt_cal_chk = 0; - boolean is_in_mp_mode = false; - u8 u8tmp = 0; - u32 u32tmp1 = 0, u32tmp2 = 0, u32tmp3 = 0; - u16 u16tmp1 = 0; - /* Ext switch buffer mux */ - btcoexist->btc_write_1byte(btcoexist, 0x974, 0xff); - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x1991, 0x3, 0x0); - btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbe, 0x8, 0x0); - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4e, - 0x80, 0x0); /* 0x4c[23] = 0 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4f, - 0x01, 0x1); /* 0x4c[24] = 1 */ - - coex_dm->cur_ant_pos_type = (ant_pos_type << 8) + phase; - - if (!force_exec) { - if (coex_dm->cur_ant_pos_type == coex_dm->pre_ant_pos_type) - return; - } - - coex_dm->pre_ant_pos_type = coex_dm->cur_ant_pos_type; - -#if BT_8822B_2ANT_COEX_DBG - u32tmp1 = halbtc8822b2ant_ltecoex_indirect_read_reg(btcoexist, - 0x38); - u32tmp2 = halbtc8822b2ant_ltecoex_indirect_read_reg(btcoexist, - 0x54); - u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x73); - - u32tmp3 = btcoexist->btc_read_4byte(btcoexist, 0xcb4); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], (Before Ant Setup) 0xcb4 = 0x%x, 0x73 = 0x%x, 0x38= 0x%x, 0x54= 0x%x\n", - u32tmp3, u8tmp, u32tmp1, u32tmp2); - BTC_TRACE(trace_buf); -#endif - - switch (phase) { - case BT_8822B_2ANT_PHASE_COEX_POWERON: - - /* set Path control owner to WL at initial step */ - halbtc8822b2ant_ltecoex_pathcontrol_owner(btcoexist, - BT_8822B_2ANT_PCO_BTSIDE); - - /* set GNT_BT to SW high */ - halbtc8822b2ant_ltecoex_set_gnt_bt(btcoexist, - BT_8822B_2ANT_GNT_BLOCK_RFC_BB, - BT_8822B_2ANT_GNT_TYPE_CTRL_BY_SW, - BT_8822B_2ANT_SIG_STA_SET_TO_HIGH); - /* Set GNT_WL to SW high */ - halbtc8822b2ant_ltecoex_set_gnt_wl(btcoexist, - BT_8822B_2ANT_GNT_BLOCK_RFC_BB, - BT_8822B_2ANT_GNT_TYPE_CTRL_BY_SW, - BT_8822B_2ANT_SIG_STA_SET_TO_HIGH); - - coex_sta->run_time_state = false; - - break; - case BT_8822B_2ANT_PHASE_COEX_INIT: - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4e, - 0x80, 0x0); /* 0x4c[23] = 0 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4f, - 0x01, 0x1); /* 0x4c[24] = 1 */ - /* Disable LTE Coex Function in WiFi side (this should be on if LTE coex is required) */ - halbtc8822b2ant_ltecoex_enable(btcoexist, 0x0); - - /* GNT_WL_LTE always = 1 (this should be config if LTE coex is required) */ - halbtc8822b2ant_ltecoex_set_coex_table( - btcoexist, - BT_8822B_2ANT_CTT_WL_VS_LTE, - 0xffff); - - /* GNT_BT_LTE always = 1 (this should be config if LTE coex is required) */ - halbtc8822b2ant_ltecoex_set_coex_table( - btcoexist, - BT_8822B_2ANT_CTT_BT_VS_LTE, - 0xffff); - - /* set Path control owner to WL at initial step */ - halbtc8822b2ant_ltecoex_pathcontrol_owner( - btcoexist, - BT_8822B_2ANT_PCO_WLSIDE); - - /* set GNT_BT to SW high */ - halbtc8822b2ant_ltecoex_set_gnt_bt(btcoexist, - BT_8822B_2ANT_GNT_BLOCK_RFC_BB, - BT_8822B_2ANT_GNT_TYPE_CTRL_BY_SW, - BT_8822B_2ANT_SIG_STA_SET_TO_HIGH); - /* Set GNT_WL to SW high */ - halbtc8822b2ant_ltecoex_set_gnt_wl(btcoexist, - BT_8822B_2ANT_GNT_BLOCK_RFC_BB, - BT_8822B_2ANT_GNT_TYPE_CTRL_BY_SW, - BT_8822B_2ANT_SIG_STA_SET_TO_HIGH); - - coex_sta->run_time_state = false; - - break; - case BT_8822B_2ANT_PHASE_WLANONLY_INIT: - /* Disable LTE Coex Function in WiFi side (this should be on if LTE coex is required) */ - halbtc8822b2ant_ltecoex_enable(btcoexist, 0x0); - - /* GNT_WL_LTE always = 1 (this should be config if LTE coex is required) */ - halbtc8822b2ant_ltecoex_set_coex_table( - btcoexist, - BT_8822B_2ANT_CTT_WL_VS_LTE, - 0xffff); - - /* GNT_BT_LTE always = 1 (this should be config if LTE coex is required) */ - halbtc8822b2ant_ltecoex_set_coex_table( - btcoexist, - BT_8822B_2ANT_CTT_BT_VS_LTE, - 0xffff); - - /* set Path control owner to WL at initial step */ - halbtc8822b2ant_ltecoex_pathcontrol_owner( - btcoexist, - BT_8822B_2ANT_PCO_WLSIDE); - - /* set GNT_BT to SW Low */ - halbtc8822b2ant_ltecoex_set_gnt_bt(btcoexist, - BT_8822B_2ANT_GNT_BLOCK_RFC_BB, - BT_8822B_2ANT_GNT_TYPE_CTRL_BY_SW, - BT_8822B_2ANT_SIG_STA_SET_TO_LOW); - /* Set GNT_WL to SW high */ - halbtc8822b2ant_ltecoex_set_gnt_wl(btcoexist, - BT_8822B_2ANT_GNT_BLOCK_RFC_BB, - BT_8822B_2ANT_GNT_TYPE_CTRL_BY_SW, - BT_8822B_2ANT_SIG_STA_SET_TO_HIGH); - - coex_sta->run_time_state = false; - - - break; - case BT_8822B_2ANT_PHASE_WLAN_OFF: - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4e, - 0x80, 0x0); /* 0x4c[23] = 0 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4f, - 0x01, 0x0); /* 0x4c[24] = 0 */ - /* Disable LTE Coex Function in WiFi side */ - halbtc8822b2ant_ltecoex_enable(btcoexist, 0x0); - - /* set Path control owner to BT */ - halbtc8822b2ant_ltecoex_pathcontrol_owner( - btcoexist, - BT_8822B_2ANT_PCO_BTSIDE); - - /* Set Ext Ant Switch to BT control at wifi off step */ - halbtc8822b2ant_set_ext_ant_switch(btcoexist, - FORCE_EXEC, - BT_8822B_2ANT_EXT_ANT_SWITCH_CTRL_BY_BT, - BT_8822B_2ANT_EXT_ANT_SWITCH_MAIN_TO_NOCARE); - coex_sta->run_time_state = false; - break; - case BT_8822B_2ANT_PHASE_2G_RUNTIME: - case BT_8822B_2ANT_PHASE_2G_RUNTIME_CONCURRENT: - - /* set Path control owner to WL at runtime step */ - halbtc8822b2ant_ltecoex_pathcontrol_owner( - btcoexist, - BT_8822B_2ANT_PCO_WLSIDE); - - if (phase == - BT_8822B_2ANT_PHASE_2G_RUNTIME_CONCURRENT) { - /* set GNT_BT to PTA */ - halbtc8822b2ant_ltecoex_set_gnt_bt( - btcoexist, - BT_8822B_2ANT_GNT_BLOCK_RFC_BB, - BT_8822B_2ANT_GNT_TYPE_CTRL_BY_PTA, - BT_8822B_2ANT_SIG_STA_SET_BY_HW); - - /* Set GNT_WL to SW High */ - halbtc8822b2ant_ltecoex_set_gnt_wl( - btcoexist, - BT_8822B_2ANT_GNT_BLOCK_RFC_BB, - BT_8822B_2ANT_GNT_TYPE_CTRL_BY_SW, - BT_8822B_2ANT_SIG_STA_SET_TO_HIGH); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ************* under2g 0xcbd setting =2 *************\n"); - BTC_TRACE(trace_buf); - - btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbd, - 0x03, 02); - } else { - /* set GNT_BT to PTA */ - halbtc8822b2ant_ltecoex_set_gnt_bt( - btcoexist, - BT_8822B_2ANT_GNT_BLOCK_RFC_BB, - BT_8822B_2ANT_GNT_TYPE_CTRL_BY_PTA, - BT_8822B_2ANT_SIG_STA_SET_BY_HW); - - /* Set GNT_WL to PTA */ - halbtc8822b2ant_ltecoex_set_gnt_wl( - btcoexist, - BT_8822B_2ANT_GNT_BLOCK_RFC_BB, - BT_8822B_2ANT_GNT_TYPE_CTRL_BY_PTA, - BT_8822B_2ANT_SIG_STA_SET_BY_HW); - } - coex_sta->run_time_state = true; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ************* under2g 0xcbd setting =2 *************\n"); - BTC_TRACE(trace_buf); - -btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbd, 0x03, 02); - break; - case BT_8822B_2ANT_PHASE_5G_RUNTIME: - - /* set Path control owner to WL at runtime step */ - halbtc8822b2ant_ltecoex_pathcontrol_owner( - btcoexist, - BT_8822B_2ANT_PCO_WLSIDE); - - /* set GNT_BT to SW Hi */ - halbtc8822b2ant_ltecoex_set_gnt_bt(btcoexist, - BT_8822B_2ANT_GNT_BLOCK_RFC_BB, - BT_8822B_2ANT_GNT_TYPE_CTRL_BY_SW, - BT_8822B_2ANT_SIG_STA_SET_TO_HIGH); - /* Set GNT_WL to SW Hi */ - halbtc8822b2ant_ltecoex_set_gnt_wl(btcoexist, - BT_8822B_2ANT_GNT_BLOCK_RFC_BB, - BT_8822B_2ANT_GNT_TYPE_CTRL_BY_SW, - BT_8822B_2ANT_SIG_STA_SET_TO_HIGH); - coex_sta->run_time_state = true; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ************* under5g 0xcbd setting =1 *************\n"); - BTC_TRACE(trace_buf); - - btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcbd, - 0x03, 01); - - break; - case BT_8822B_2ANT_PHASE_BTMPMODE: - /* Disable LTE Coex Function in WiFi side */ - halbtc8822b2ant_ltecoex_enable(btcoexist, 0x0); - - /* set Path control owner to WL */ - halbtc8822b2ant_ltecoex_pathcontrol_owner( - btcoexist, - BT_8822B_2ANT_PCO_WLSIDE); - - /* set GNT_BT to SW Hi */ - halbtc8822b2ant_ltecoex_set_gnt_bt(btcoexist, - BT_8822B_2ANT_GNT_BLOCK_RFC_BB, - BT_8822B_2ANT_GNT_TYPE_CTRL_BY_SW, - BT_8822B_2ANT_SIG_STA_SET_TO_HIGH); - - /* Set GNT_WL to SW Lo */ - halbtc8822b2ant_ltecoex_set_gnt_wl(btcoexist, - BT_8822B_2ANT_GNT_BLOCK_RFC_BB, - BT_8822B_2ANT_GNT_TYPE_CTRL_BY_SW, - BT_8822B_2ANT_SIG_STA_SET_TO_LOW); - -coex_sta->run_time_state = false; - break; - } -#if BT_8822B_2ANT_COEX_DBG - u32tmp1 = halbtc8822b2ant_ltecoex_indirect_read_reg(btcoexist, 0x38); - u32tmp2 = halbtc8822b2ant_ltecoex_indirect_read_reg(btcoexist, 0x54); - u32tmp3 = btcoexist->btc_read_4byte(btcoexist, 0xcb4); - u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x73); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], (After Ant-Setup phase---%d) 0xcb4 = 0x%x, 0x73 = 0x%x, 0x38= 0x%x, 0x54= 0x%x\n", - phase, u32tmp3, u8tmp, u32tmp1, u32tmp2); - - BTC_TRACE(trace_buf); -#endif - -} - - -u8 halbtc8822b2ant_action_algorithm(IN struct btc_coexist *btcoexist) -{ - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - boolean bt_hs_on = false; - u8 algorithm = BT_8822B_2ANT_COEX_ALGO_UNDEFINED; - u8 num_of_diff_profile = 0; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); - - if (!bt_link_info->bt_link_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], No BT link exists!!!\n"); - BTC_TRACE(trace_buf); - return algorithm; - } - - if (bt_link_info->sco_exist) - num_of_diff_profile++; - if (bt_link_info->hid_exist) - num_of_diff_profile++; - if (bt_link_info->pan_exist) - num_of_diff_profile++; - if (bt_link_info->a2dp_exist) - num_of_diff_profile++; - - if (num_of_diff_profile == 0) { - - if (bt_link_info->acl_busy) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], No-Profile busy\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8822B_2ANT_COEX_ALGO_NOPROFILEBUSY; - } - } else if (num_of_diff_profile == 1) { - if (bt_link_info->sco_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCO only\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8822B_2ANT_COEX_ALGO_SCO; - } else { - if (bt_link_info->hid_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], HID only\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8822B_2ANT_COEX_ALGO_HID; - } else if (bt_link_info->a2dp_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], A2DP only\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8822B_2ANT_COEX_ALGO_A2DP; - } else if (bt_link_info->pan_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], PAN(HS) only\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8822B_2ANT_COEX_ALGO_PANHS; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], PAN(EDR) only\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8822B_2ANT_COEX_ALGO_PANEDR; - } - } - } - } else if (num_of_diff_profile == 2) { - if (bt_link_info->sco_exist) { - if (bt_link_info->hid_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCO + HID\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8822B_2ANT_COEX_ALGO_SCO; - } else if (bt_link_info->a2dp_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCO + A2DP ==> A2DP\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8822B_2ANT_COEX_ALGO_A2DP; - } else if (bt_link_info->pan_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCO + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8822B_2ANT_COEX_ALGO_SCO; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCO + PAN(EDR)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8822B_2ANT_COEX_ALGO_PANEDR; - } - } - } else { - if (bt_link_info->hid_exist && - bt_link_info->a2dp_exist) { - { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], HID + A2DP\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8822B_2ANT_COEX_ALGO_HID_A2DP; - } - } else if (bt_link_info->hid_exist && - bt_link_info->pan_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], HID + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8822B_2ANT_COEX_ALGO_HID; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], HID + PAN(EDR)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8822B_2ANT_COEX_ALGO_PANEDR_HID; - } - } else if (bt_link_info->pan_exist && - bt_link_info->a2dp_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], A2DP + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8822B_2ANT_COEX_ALGO_A2DP_PANHS; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], A2DP + PAN(EDR)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8822B_2ANT_COEX_ALGO_PANEDR_A2DP; - } - } - } - } else if (num_of_diff_profile == 3) { - if (bt_link_info->sco_exist) { - if (bt_link_info->hid_exist && - bt_link_info->a2dp_exist) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCO + HID + A2DP ==> HID + A2DP\n"); - BTC_TRACE(trace_buf); - algorithm = BT_8822B_2ANT_COEX_ALGO_HID_A2DP; - } else if (bt_link_info->hid_exist && - bt_link_info->pan_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCO + HID + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8822B_2ANT_COEX_ALGO_PANEDR_HID; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCO + HID + PAN(EDR)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8822B_2ANT_COEX_ALGO_PANEDR_HID; - } - } else if (bt_link_info->pan_exist && - bt_link_info->a2dp_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCO + A2DP + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8822B_2ANT_COEX_ALGO_PANEDR_A2DP; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCO + A2DP + PAN(EDR) ==> HID\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8822B_2ANT_COEX_ALGO_PANEDR_A2DP; - } - } - } else { - if (bt_link_info->hid_exist && - bt_link_info->pan_exist && - bt_link_info->a2dp_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], HID + A2DP + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8822B_2ANT_COEX_ALGO_HID_A2DP_PANEDR; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], HID + A2DP + PAN(EDR)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8822B_2ANT_COEX_ALGO_HID_A2DP_PANEDR; - } - } - } - } else if (num_of_diff_profile >= 3) { - if (bt_link_info->sco_exist) { - if (bt_link_info->hid_exist && - bt_link_info->pan_exist && - bt_link_info->a2dp_exist) { - if (bt_hs_on) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Error!!! SCO + HID + A2DP + PAN(HS)\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8822B_2ANT_COEX_ALGO_HID_A2DP_PANEDR; - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCO + HID + A2DP + PAN(EDR)==>PAN(EDR)+HID\n"); - BTC_TRACE(trace_buf); - algorithm = - BT_8822B_2ANT_COEX_ALGO_HID_A2DP_PANEDR; - } - } - } - } - - return algorithm; -} - - - -void halbtc8822b2ant_action_coex_all_off(IN struct btc_coexist *btcoexist) -{ - - halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - - halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, NORMAL_EXEC, - BT_8822B_2ANT_PHASE_2G_RUNTIME_CONCURRENT); - - /* fw all off */ - halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); - - halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8); - halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - -} - -void halbtc8822b2ant_action_wifi_under5g(IN struct btc_coexist *btcoexist) -{ - - /* fw all off */ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ************* under5g *************\n"); - BTC_TRACE(trace_buf); - halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); - halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - - halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8); - halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, FORCE_EXEC, - BT_8822B_2ANT_PHASE_5G_RUNTIME); -} - - -void halbtc8822b2ant_action_bt_inquiry(IN struct btc_coexist *btcoexist) -{ - - boolean wifi_connected = false; - boolean scan = false, link = false, roam = false; - boolean wifi_busy = false; - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam); - - if (link || roam || coex_sta->wifi_is_high_pri_task) { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi link/roam/hi-pri-task process + BT Inq/Page!!\n"); - BTC_TRACE(trace_buf); - - halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, - 8); - halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 11); - - } else if (scan) { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi scan process + BT Inq/Page!!\n"); - BTC_TRACE(trace_buf); - - halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, - 8); - - if (coex_sta->bt_create_connection) - halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 12); - else - halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 11); - - } else if (wifi_connected) { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi connected + BT Inq/Page!!\n"); - BTC_TRACE(trace_buf); - - halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, - 8); - - if (wifi_busy) { - - if ((bt_link_info->a2dp_exist) && - (bt_link_info->acl_busy)) - halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 13); - else - halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 11); - - } else - halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 13); - - } else { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi no-link + BT Inq/Page!!\n"); - BTC_TRACE(trace_buf); - - halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, - NORMAL_EXEC, - BT_8822B_2ANT_PHASE_2G_RUNTIME_CONCURRENT); - - halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); - } - - halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, FORCE_EXEC, 0xd8); - halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); -} - -void halbtc8822b2ant_action_wifi_link_process(IN struct btc_coexist *btcoexist) -{ - u32 u32tmp, u32tmpb; - u8 u8tmpa; - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - - halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, FORCE_EXEC, 0xd8); - halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7); - - if ((bt_link_info->a2dp_exist) && (bt_link_info->acl_busy)) - halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 14); - else - halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 11); - -} - - -void halbtc8822b2ant_action_wifi_nonconnected(IN struct btc_coexist *btcoexist) -{ - halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, NORMAL_EXEC, - BT_8822B_2ANT_PHASE_2G_RUNTIME_CONCURRENT); - - /* fw all off */ - halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); - - halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8); - halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); -} - -void halbtc8822b2ant_action_bt_idle(IN struct btc_coexist *btcoexist) -{ - static u8 prewifi_rssi_state = BTC_RSSI_STATE_LOW; - static u8 pre_bt_rssi_state = BTC_RSSI_STATE_LOW; - u8 wifi_rssi_state, bt_rssi_state; - - static u8 prewifi_rssi_state2 = BTC_RSSI_STATE_LOW; - static u8 pre_bt_rssi_state2 = BTC_RSSI_STATE_LOW; - u8 wifi_rssi_state2, bt_rssi_state2; - - boolean wifi_connected = false; - boolean scan = false, link = false, roam = false; - boolean wifi_busy = false; - - wifi_rssi_state = halbtc8822b2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state, 2, - coex_sta->wifi_coex_thres , 0); - - wifi_rssi_state2 = halbtc8822b2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state2, 2, - coex_sta->wifi_coex_thres2 , 0); - - bt_rssi_state = halbtc8822b2ant_bt_rssi_state(&pre_bt_rssi_state, 2, - coex_sta->bt_coex_thres , 0); - - bt_rssi_state2 = halbtc8822b2ant_bt_rssi_state(&pre_bt_rssi_state2, 2, - coex_sta->bt_coex_thres2 , 0); - - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam); - - if (scan || link || roam) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi link process + BT Idle!!\n"); - BTC_TRACE(trace_buf); - - halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, - 7); - - halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 11); - } else if (wifi_connected) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi connected + BT Idle!!\n"); - BTC_TRACE(trace_buf); - - if (wifi_busy) { - halbtc8822b2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 0); - halbtc8822b2ant_set_ant_path(btcoexist, - BTC_ANT_PATH_AUTO, NORMAL_EXEC, - BT_8822B_2ANT_PHASE_2G_RUNTIME_CONCURRENT); - /* - if (!BTC_RSSI_HIGH(bt_rssi_state2)) - halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2); - else { - halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, NORMAL_EXEC, - BT_8822B_2ANT_PHASE_2G_RUNTIME_CONCURRENT); - - } - */ - } else { - halbtc8822b2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 0); - halbtc8822b2ant_set_ant_path(btcoexist, - BTC_ANT_PATH_AUTO, NORMAL_EXEC, - BT_8822B_2ANT_PHASE_2G_RUNTIME_CONCURRENT); - } - - halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); - - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Wifi no-link + BT Idle!!\n"); - BTC_TRACE(trace_buf); - - halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, - NORMAL_EXEC, - BT_8822B_2ANT_PHASE_2G_RUNTIME_CONCURRENT); - - halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); - } - - halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, FORCE_EXEC, 0xd8); - halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - -} - - -/* SCO only or SCO+PAN(HS) */ -void halbtc8822b2ant_action_sco(IN struct btc_coexist *btcoexist) -{ - static u8 prewifi_rssi_state = BTC_RSSI_STATE_LOW; - static u8 pre_bt_rssi_state = BTC_RSSI_STATE_LOW; - u8 wifi_rssi_state, bt_rssi_state; - - static u8 prewifi_rssi_state2 = BTC_RSSI_STATE_LOW; - static u8 pre_bt_rssi_state2 = BTC_RSSI_STATE_LOW; - u8 wifi_rssi_state2, bt_rssi_state2; - boolean wifi_busy = false; - - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - - wifi_rssi_state = halbtc8822b2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state, 2, - coex_sta->wifi_coex_thres , 0); - - wifi_rssi_state2 = halbtc8822b2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state2, 2, - coex_sta->wifi_coex_thres2 , 0); - - bt_rssi_state = halbtc8822b2ant_bt_rssi_state(&pre_bt_rssi_state, 2, - coex_sta->bt_coex_thres , 0); - - bt_rssi_state2 = halbtc8822b2ant_bt_rssi_state(&pre_bt_rssi_state2, 2, - coex_sta->bt_coex_thres2 , 0); - - - if (BTC_RSSI_HIGH(wifi_rssi_state) && - BTC_RSSI_HIGH(bt_rssi_state)) { - - halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8); - halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - coex_dm->is_switch_to_1dot5_ant = false; - - halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, - NORMAL_EXEC, - BT_8822B_2ANT_PHASE_2G_RUNTIME_CONCURRENT); - - halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); - } else { - - halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8); - halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - coex_dm->is_switch_to_1dot5_ant = false; - - halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 3); - - halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); - } - -} - - -void halbtc8822b2ant_action_hid(IN struct btc_coexist *btcoexist) -{ - static u8 prewifi_rssi_state = BTC_RSSI_STATE_LOW; - static u8 pre_bt_rssi_state = BTC_RSSI_STATE_LOW; - u8 wifi_rssi_state, bt_rssi_state; - - static u8 prewifi_rssi_state2 = BTC_RSSI_STATE_LOW; - static u8 pre_bt_rssi_state2 = BTC_RSSI_STATE_LOW; - u8 wifi_rssi_state2, bt_rssi_state2; - boolean wifi_busy = false; - - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - - wifi_rssi_state = halbtc8822b2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state, 2, - coex_sta->wifi_coex_thres , 0); - - wifi_rssi_state2 = halbtc8822b2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state2, 2, - coex_sta->wifi_coex_thres2 , 0); - - bt_rssi_state = halbtc8822b2ant_bt_rssi_state(&pre_bt_rssi_state, 2, - coex_sta->bt_coex_thres , 0); - - bt_rssi_state2 = halbtc8822b2ant_bt_rssi_state(&pre_bt_rssi_state2, 2, - coex_sta->bt_coex_thres2 , 0); - - - if (BTC_RSSI_HIGH(wifi_rssi_state) && - BTC_RSSI_HIGH(bt_rssi_state)) { - - halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8); - halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - coex_dm->is_switch_to_1dot5_ant = false; - - halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, - NORMAL_EXEC, - BT_8822B_2ANT_PHASE_2G_RUNTIME_CONCURRENT); - - halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); - } else { - - halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8); - halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - coex_dm->is_switch_to_1dot5_ant = false; -/* - halbtc8822b2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 0); - halbtc8822b2ant_set_ant_path(btcoexist, - BTC_ANT_PATH_AUTO, NORMAL_EXEC, - BT_8822B_2ANT_PHASE_2G_RUNTIME_CONCURRENT); -*/ - halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 3); - -/* - halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 10); -*/ - halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); - } - -} - -/* A2DP only / PAN(EDR) only/ A2DP+PAN(HS) */ -void halbtc8822b2ant_action_a2dp(IN struct btc_coexist *btcoexist) -{ - static u8 prewifi_rssi_state = BTC_RSSI_STATE_LOW; - static u8 pre_bt_rssi_state = BTC_RSSI_STATE_LOW; - u8 wifi_rssi_state, bt_rssi_state; - - static u8 prewifi_rssi_state2 = BTC_RSSI_STATE_LOW; - static u8 pre_bt_rssi_state2 = BTC_RSSI_STATE_LOW; - u8 wifi_rssi_state2, bt_rssi_state2; - boolean wifi_busy = false, wifi_turbo = false; - - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM, - &coex_sta->scan_ap_num); - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "############# [BTCoex], scan_ap_num = %d\n", - coex_sta->scan_ap_num); - BTC_TRACE(trace_buf); - -#if 1 - if ((wifi_busy) && (coex_sta->scan_ap_num <= 4)) - wifi_turbo = true; -#endif - - wifi_rssi_state = halbtc8822b2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state, 2, - coex_sta->wifi_coex_thres , 0); - - wifi_rssi_state2 = halbtc8822b2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state2, 2, - coex_sta->wifi_coex_thres2 , 0); - - bt_rssi_state = halbtc8822b2ant_bt_rssi_state(&pre_bt_rssi_state, 2, - coex_sta->bt_coex_thres , 0); - - bt_rssi_state2 = halbtc8822b2ant_bt_rssi_state(&pre_bt_rssi_state2, 2, - coex_sta->bt_coex_thres2 , 0); - - - if (BTC_RSSI_HIGH(wifi_rssi_state) && - BTC_RSSI_HIGH(bt_rssi_state)) { - - halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8); - halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - coex_dm->is_switch_to_1dot5_ant = false; - - halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, - NORMAL_EXEC, - BT_8822B_2ANT_PHASE_2G_RUNTIME_CONCURRENT); - - halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); - } else if (BTC_RSSI_HIGH(wifi_rssi_state2) && - BTC_RSSI_HIGH(bt_rssi_state2)) { - - halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xc8); - halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2); - - coex_dm->is_switch_to_1dot5_ant = false; - - - - halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); - - if (wifi_busy) { - if (coex_sta->is_setupLink) - halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 51); - else { - halbtc8822b2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 0); - halbtc8822b2ant_set_ant_path(btcoexist, - BTC_ANT_PATH_AUTO, NORMAL_EXEC, - BT_8822B_2ANT_PHASE_2G_RUNTIME_CONCURRENT); - halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 1); - } - } else - - halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 2); - } else { - - halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8); - halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - coex_dm->is_switch_to_1dot5_ant = true; - - if (wifi_turbo) - halbtc8822b2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 6); - else - halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, - 7); - - if (wifi_busy) { - if (coex_sta->is_setupLink) - halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 151); - else - halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 101); - } else - halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 102); - - } - -} - -void halbtc8822b2ant_action_pan_edr(IN struct btc_coexist *btcoexist) -{ - static u8 prewifi_rssi_state = BTC_RSSI_STATE_LOW; - static u8 pre_bt_rssi_state = BTC_RSSI_STATE_LOW; - u8 wifi_rssi_state, bt_rssi_state; - - static u8 prewifi_rssi_state2 = BTC_RSSI_STATE_LOW; - static u8 pre_bt_rssi_state2 = BTC_RSSI_STATE_LOW; - u8 wifi_rssi_state2, bt_rssi_state2; - boolean wifi_busy = false, wifi_turbo = false; - - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM, - &coex_sta->scan_ap_num); - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "############# [BTCoex], scan_ap_num = %d\n", - coex_sta->scan_ap_num); - BTC_TRACE(trace_buf); - -#if 1 - if ((wifi_busy) && (coex_sta->scan_ap_num <= 4)) - wifi_turbo = true; -#endif - - wifi_rssi_state = halbtc8822b2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state, 2, - coex_sta->wifi_coex_thres , 0); - - wifi_rssi_state2 = halbtc8822b2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state2, 2, - coex_sta->wifi_coex_thres2 , 0); - - bt_rssi_state = halbtc8822b2ant_bt_rssi_state(&pre_bt_rssi_state, 2, - coex_sta->bt_coex_thres , 0); - - bt_rssi_state2 = halbtc8822b2ant_bt_rssi_state(&pre_bt_rssi_state2, 2, - coex_sta->bt_coex_thres2 , 0); - -#if 0 - halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8); - halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - coex_dm->is_switch_to_1dot5_ant = false; - - halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, FORCE_EXEC, - BT_8822B_2ANT_PHASE_2G_RUNTIME_CONCURRENT); - - halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); -#endif - - -#if 1 - if (BTC_RSSI_HIGH(wifi_rssi_state) && - BTC_RSSI_HIGH(bt_rssi_state)) { - - halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8); - halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - coex_dm->is_switch_to_1dot5_ant = false; - - halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, - NORMAL_EXEC, - BT_8822B_2ANT_PHASE_2G_RUNTIME_CONCURRENT); - - halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); - } else if (BTC_RSSI_HIGH(wifi_rssi_state2) && - BTC_RSSI_HIGH(bt_rssi_state2)) { - - halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xc8); - halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2); - - coex_dm->is_switch_to_1dot5_ant = false; - - halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); - - if (wifi_busy) { - halbtc8822b2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 0); - halbtc8822b2ant_set_ant_path(btcoexist, - BTC_ANT_PATH_AUTO, NORMAL_EXEC, - BT_8822B_2ANT_PHASE_2G_RUNTIME_CONCURRENT); - - halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 3); - } else - halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 4); - } else { - - halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8); - halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - coex_dm->is_switch_to_1dot5_ant = true; - - if (wifi_turbo) - halbtc8822b2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 6); - else - halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, - 7); - - if (wifi_busy) - halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 103); - else - halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 104); - - } - -#endif - -} - - -/* PAN(HS) only */ -void halbtc8822b2ant_action_pan_hs(IN struct btc_coexist *btcoexist) -{ - static u8 prewifi_rssi_state = BTC_RSSI_STATE_LOW; - static u8 pre_bt_rssi_state = BTC_RSSI_STATE_LOW; - u8 wifi_rssi_state, bt_rssi_state; - - static u8 prewifi_rssi_state2 = BTC_RSSI_STATE_LOW; - static u8 pre_bt_rssi_state2 = BTC_RSSI_STATE_LOW; - u8 wifi_rssi_state2, bt_rssi_state2; - boolean wifi_busy = false, wifi_turbo = false; - - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM, - &coex_sta->scan_ap_num); - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "############# [BTCoex], scan_ap_num = %d\n", - coex_sta->scan_ap_num); - BTC_TRACE(trace_buf); - -#if 1 - if ((wifi_busy) && (coex_sta->scan_ap_num <= 4)) - wifi_turbo = true; -#endif - - - wifi_rssi_state = halbtc8822b2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state, 2, - coex_sta->wifi_coex_thres , 0); - - wifi_rssi_state2 = halbtc8822b2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state2, 2, - coex_sta->wifi_coex_thres2 , 0); - - bt_rssi_state = halbtc8822b2ant_bt_rssi_state(&pre_bt_rssi_state, 2, - coex_sta->bt_coex_thres , 0); - - bt_rssi_state2 = halbtc8822b2ant_bt_rssi_state(&pre_bt_rssi_state2, 2, - coex_sta->bt_coex_thres2 , 0); - - if (BTC_RSSI_HIGH(wifi_rssi_state) && - BTC_RSSI_HIGH(bt_rssi_state)) { - - halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8); - halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - coex_dm->is_switch_to_1dot5_ant = false; - - halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, - NORMAL_EXEC, - BT_8822B_2ANT_PHASE_2G_RUNTIME_CONCURRENT); - - halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); - } else if (BTC_RSSI_HIGH(wifi_rssi_state2) && - BTC_RSSI_HIGH(bt_rssi_state2)) { - - halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xc8); - halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2); - - coex_dm->is_switch_to_1dot5_ant = false; - - halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, - NORMAL_EXEC, - BT_8822B_2ANT_PHASE_2G_RUNTIME_CONCURRENT); - - halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); - - - } else { - - halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8); - halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - coex_dm->is_switch_to_1dot5_ant = true; - - halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, - NORMAL_EXEC, - BT_8822B_2ANT_PHASE_2G_RUNTIME_CONCURRENT); - - halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); - } - -} - - -void halbtc8822b2ant_action_hid_a2dp(IN struct btc_coexist *btcoexist) -{ - static u8 prewifi_rssi_state = BTC_RSSI_STATE_LOW; - static u8 pre_bt_rssi_state = BTC_RSSI_STATE_LOW; - u8 wifi_rssi_state, bt_rssi_state; - - static u8 prewifi_rssi_state2 = BTC_RSSI_STATE_LOW; - static u8 pre_bt_rssi_state2 = BTC_RSSI_STATE_LOW; - u8 wifi_rssi_state2, bt_rssi_state2; - boolean wifi_busy = false; - - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - - wifi_rssi_state = halbtc8822b2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state, 2, - coex_sta->wifi_coex_thres , 0); - - wifi_rssi_state2 = halbtc8822b2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state2, 2, - coex_sta->wifi_coex_thres2 , 0); - - bt_rssi_state = halbtc8822b2ant_bt_rssi_state(&pre_bt_rssi_state, 2, - coex_sta->bt_coex_thres , 0); - - bt_rssi_state2 = halbtc8822b2ant_bt_rssi_state(&pre_bt_rssi_state2, 2, - coex_sta->bt_coex_thres2 , 0); - - - if (BTC_RSSI_HIGH(wifi_rssi_state) && - BTC_RSSI_HIGH(bt_rssi_state)) { - - halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8); - halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - coex_dm->is_switch_to_1dot5_ant = false; - - halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, - NORMAL_EXEC, - BT_8822B_2ANT_PHASE_2G_RUNTIME_CONCURRENT); - - halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); - } else if (BTC_RSSI_HIGH(wifi_rssi_state2) && - BTC_RSSI_HIGH(bt_rssi_state2)) { - - halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xc8); - halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2); - - coex_dm->is_switch_to_1dot5_ant = false; - - halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); - - - - - if (wifi_busy) { - if (coex_sta->is_setupLink) - halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 51); - else - halbtc8822b2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 0); - halbtc8822b2ant_set_ant_path(btcoexist, - BTC_ANT_PATH_AUTO, NORMAL_EXEC, - BT_8822B_2ANT_PHASE_2G_RUNTIME_CONCURRENT); - /* - halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 1); - */ - } else - halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 2); - - - } else { - - halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8); - halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - coex_dm->is_switch_to_1dot5_ant = true; - - if ((wifi_busy) && (coex_sta->hid_busy_num >= 2)) - halbtc8822b2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 6); - else - /* - halbtc8822b2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 9); - */ - halbtc8822b2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 4); - - if (wifi_busy) { - if (coex_sta->is_setupLink) - halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 151); - else - halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 101); - } else - halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 102); - - } - -} - - -void halbtc8822b2ant_action_a2dp_pan_hs(IN struct btc_coexist *btcoexist) -{ - static u8 prewifi_rssi_state = BTC_RSSI_STATE_LOW; - static u8 pre_bt_rssi_state = BTC_RSSI_STATE_LOW; - u8 wifi_rssi_state, bt_rssi_state; - - static u8 prewifi_rssi_state2 = BTC_RSSI_STATE_LOW; - static u8 pre_bt_rssi_state2 = BTC_RSSI_STATE_LOW; - u8 wifi_rssi_state2, bt_rssi_state2; - boolean wifi_busy = false, wifi_turbo = false; - - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM, - &coex_sta->scan_ap_num); - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "############# [BTCoex], scan_ap_num = %d\n", - coex_sta->scan_ap_num); - BTC_TRACE(trace_buf); - -#if 1 - if ((wifi_busy) && (coex_sta->scan_ap_num <= 4)) - wifi_turbo = true; -#endif - - - wifi_rssi_state = halbtc8822b2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state, 2, - coex_sta->wifi_coex_thres , 0); - - wifi_rssi_state2 = halbtc8822b2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state2, 2, - coex_sta->wifi_coex_thres2 , 0); - - bt_rssi_state = halbtc8822b2ant_bt_rssi_state(&pre_bt_rssi_state, 2, - coex_sta->bt_coex_thres , 0); - - bt_rssi_state2 = halbtc8822b2ant_bt_rssi_state(&pre_bt_rssi_state2, 2, - coex_sta->bt_coex_thres2 , 0); - - - if (BTC_RSSI_HIGH(wifi_rssi_state) && - BTC_RSSI_HIGH(bt_rssi_state)) { - - halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8); - halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - coex_dm->is_switch_to_1dot5_ant = false; - - halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, - NORMAL_EXEC, - BT_8822B_2ANT_PHASE_2G_RUNTIME_CONCURRENT); - - halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); - } else if (BTC_RSSI_HIGH(wifi_rssi_state2) && - BTC_RSSI_HIGH(bt_rssi_state2)) { - - halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xc8); - halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2); - - coex_dm->is_switch_to_1dot5_ant = false; - - halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); - - if (wifi_busy) { - - if ((coex_sta->a2dp_bit_pool > 40) && - (coex_sta->a2dp_bit_pool < 255)) - halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 7); - else - halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 5); - } else - halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 6); - - } else { - - halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8); - halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - coex_dm->is_switch_to_1dot5_ant = true; - - if (wifi_turbo) - halbtc8822b2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 6); - else - halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, - 7); - - if (wifi_busy) { - - if ((coex_sta->a2dp_bit_pool > 40) && - (coex_sta->a2dp_bit_pool < 255)) - halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 107); - else - halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 105); - } else - halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 106); - - } - -} - - - -/* PAN(EDR)+A2DP */ -void halbtc8822b2ant_action_pan_edr_a2dp(IN struct btc_coexist *btcoexist) -{ - static u8 prewifi_rssi_state = BTC_RSSI_STATE_LOW; - static u8 pre_bt_rssi_state = BTC_RSSI_STATE_LOW; - u8 wifi_rssi_state, bt_rssi_state; - - static u8 prewifi_rssi_state2 = BTC_RSSI_STATE_LOW; - static u8 pre_bt_rssi_state2 = BTC_RSSI_STATE_LOW; - u8 wifi_rssi_state2, bt_rssi_state2; - boolean wifi_busy = false, wifi_turbo = false; - - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM, - &coex_sta->scan_ap_num); - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "############# [BTCoex], scan_ap_num = %d\n", - coex_sta->scan_ap_num); - BTC_TRACE(trace_buf); - -#if 1 - if ((wifi_busy) && (coex_sta->scan_ap_num <= 4)) - wifi_turbo = true; -#endif - - - wifi_rssi_state = halbtc8822b2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state, 2, - coex_sta->wifi_coex_thres , 0); - - wifi_rssi_state2 = halbtc8822b2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state2, 2, - coex_sta->wifi_coex_thres2 , 0); - - bt_rssi_state = halbtc8822b2ant_bt_rssi_state(&pre_bt_rssi_state, 2, - coex_sta->bt_coex_thres , 0); - - bt_rssi_state2 = halbtc8822b2ant_bt_rssi_state(&pre_bt_rssi_state2, 2, - coex_sta->bt_coex_thres2 , 0); - - if (BTC_RSSI_HIGH(wifi_rssi_state) && - BTC_RSSI_HIGH(bt_rssi_state)) { - - halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8); - halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - coex_dm->is_switch_to_1dot5_ant = false; - - halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, - NORMAL_EXEC, - BT_8822B_2ANT_PHASE_2G_RUNTIME_CONCURRENT); - - halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); - } else if (BTC_RSSI_HIGH(wifi_rssi_state2) && - BTC_RSSI_HIGH(bt_rssi_state2)) { - - halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xc8); - halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2); - - coex_dm->is_switch_to_1dot5_ant = false; - - halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); - - if (wifi_busy) { - - if (((coex_sta->a2dp_bit_pool > 40) && - (coex_sta->a2dp_bit_pool < 255)) || - (!coex_sta->is_A2DP_3M)) - halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 7); - else - halbtc8822b2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 0); - halbtc8822b2ant_set_ant_path(btcoexist, - BTC_ANT_PATH_AUTO, NORMAL_EXEC, - BT_8822B_2ANT_PHASE_2G_RUNTIME_CONCURRENT); - halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 5); - } else - halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 6); - } else { - - halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8); - halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - coex_dm->is_switch_to_1dot5_ant = true; - - if (wifi_turbo) - halbtc8822b2ant_coex_table_with_type(btcoexist, - NORMAL_EXEC, 6); - else - halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, - 7); - - if (wifi_busy) { - - if ((coex_sta->a2dp_bit_pool > 40) && - (coex_sta->a2dp_bit_pool < 255)) - halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 107); - else - halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 105); - } else - halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 106); - - } - -} - -void halbtc8822b2ant_action_pan_edr_hid(IN struct btc_coexist *btcoexist) -{ - static u8 prewifi_rssi_state = BTC_RSSI_STATE_LOW; - static u8 pre_bt_rssi_state = BTC_RSSI_STATE_LOW; - u8 wifi_rssi_state, bt_rssi_state; - - static u8 prewifi_rssi_state2 = BTC_RSSI_STATE_LOW; - static u8 pre_bt_rssi_state2 = BTC_RSSI_STATE_LOW; - u8 wifi_rssi_state2, bt_rssi_state2; - boolean wifi_busy = false; - - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - - wifi_rssi_state = halbtc8822b2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state, 2, - coex_sta->wifi_coex_thres , 0); - - wifi_rssi_state2 = halbtc8822b2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state2, 2, - coex_sta->wifi_coex_thres2 , 0); - - bt_rssi_state = halbtc8822b2ant_bt_rssi_state(&pre_bt_rssi_state, 2, - coex_sta->bt_coex_thres , 0); - - bt_rssi_state2 = halbtc8822b2ant_bt_rssi_state(&pre_bt_rssi_state2, 2, - coex_sta->bt_coex_thres2 , 0); - - - if (BTC_RSSI_HIGH(wifi_rssi_state) && - BTC_RSSI_HIGH(bt_rssi_state)) { - - halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8); - halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - coex_dm->is_switch_to_1dot5_ant = false; - - halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, - NORMAL_EXEC, - BT_8822B_2ANT_PHASE_2G_RUNTIME_CONCURRENT); - - halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); - } else if (BTC_RSSI_HIGH(wifi_rssi_state2) && - BTC_RSSI_HIGH(bt_rssi_state2)) { - - halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xc8); - halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2); - - coex_dm->is_switch_to_1dot5_ant = false; - - halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); - - if (wifi_busy) - - halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 3); - else - - halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 4); - - - } else { - - halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8); - halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - coex_dm->is_switch_to_1dot5_ant = true; - - halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1); - - if (wifi_busy) - - halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 103); - else - - halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 104); - - } - -} - -/* HID+A2DP+PAN(EDR) */ -void halbtc8822b2ant_action_hid_a2dp_pan_edr(IN struct btc_coexist *btcoexist) -{ - static u8 prewifi_rssi_state = BTC_RSSI_STATE_LOW; - static u8 pre_bt_rssi_state = BTC_RSSI_STATE_LOW; - u8 wifi_rssi_state, bt_rssi_state; - - static u8 prewifi_rssi_state2 = BTC_RSSI_STATE_LOW; - static u8 pre_bt_rssi_state2 = BTC_RSSI_STATE_LOW; - u8 wifi_rssi_state2, bt_rssi_state2; - boolean wifi_busy = false; - - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - - wifi_rssi_state = halbtc8822b2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state, 2, - coex_sta->wifi_coex_thres , 0); - - wifi_rssi_state2 = halbtc8822b2ant_wifi_rssi_state(btcoexist, - &prewifi_rssi_state2, 2, - coex_sta->wifi_coex_thres2 , 0); - - bt_rssi_state = halbtc8822b2ant_bt_rssi_state(&pre_bt_rssi_state, 2, - coex_sta->bt_coex_thres , 0); - - bt_rssi_state2 = halbtc8822b2ant_bt_rssi_state(&pre_bt_rssi_state2, 2, - coex_sta->bt_coex_thres2 , 0); - - - if (BTC_RSSI_HIGH(wifi_rssi_state) && - BTC_RSSI_HIGH(bt_rssi_state)) { - - halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8); - halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - coex_dm->is_switch_to_1dot5_ant = false; - - halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, - NORMAL_EXEC, - BT_8822B_2ANT_PHASE_2G_RUNTIME_CONCURRENT); - - halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); - } else if (BTC_RSSI_HIGH(wifi_rssi_state2) && - BTC_RSSI_HIGH(bt_rssi_state2)) { - - halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xc8); - halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2); - - coex_dm->is_switch_to_1dot5_ant = false; - - halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4); - - if (wifi_busy) { - - if (((coex_sta->a2dp_bit_pool > 40) && - (coex_sta->a2dp_bit_pool < 255)) || - (!coex_sta->is_A2DP_3M)) - halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 7); - else - halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 5); - } else - halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 6); - } else { - - halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8); - halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - coex_dm->is_switch_to_1dot5_ant = true; - - halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1); - - if (wifi_busy) { - - if ((coex_sta->a2dp_bit_pool > 40) && - (coex_sta->a2dp_bit_pool < 255)) - halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 107); - else - halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, - true, 105); - } else - halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, - 106); - } - -} - - - -void halbtc8822b2ant_action_bt_whck_test(IN struct btc_coexist *btcoexist) -{ - halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8); - halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, NORMAL_EXEC, - BT_8822B_2ANT_PHASE_2G_RUNTIME_CONCURRENT); - - halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); -} - -void halbtc8822b2ant_action_wifi_multi_port(IN struct btc_coexist *btcoexist) -{ - halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8); - halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - /* hw all off */ - halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, NORMAL_EXEC, - BT_8822B_2ANT_PHASE_2G_RUNTIME_CONCURRENT); - - halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); -} - -void halbtc8822b2ant_run_coexist_mechanism(IN struct btc_coexist *btcoexist) -{ - u8 algorithm = 0; - u32 num_of_wifi_link = 0; - u32 wifi_link_status = 0; - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - boolean miracast_plus_bt = false; - boolean scan = false, link = false, roam = false, - wifi_connected = false, wifi_under_5g = false; - - - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], RunCoexistMechanism()===>\n"); - BTC_TRACE(trace_buf); - - if (btcoexist->manual_control) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], RunCoexistMechanism(), return for Manual CTRL <===\n"); - BTC_TRACE(trace_buf); - return; - } - - if (btcoexist->stop_coex_dm) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], RunCoexistMechanism(), return for Stop Coex DM <===\n"); - BTC_TRACE(trace_buf); - return; - } - - if (coex_sta->under_ips) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], wifi is under IPS !!!\n"); - BTC_TRACE(trace_buf); - return; - } - - if (!coex_sta->run_time_state) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], return for run_time_state = false !!!\n"); - BTC_TRACE(trace_buf); - return; - } - - if (coex_sta->freeze_coexrun_by_btinfo) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), return for freeze_coexrun_by_btinfo\n"); - BTC_TRACE(trace_buf); - return; - } - - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g); - - if (wifi_under_5g) { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], WiFi is under 5G!!!\n"); - BTC_TRACE(trace_buf); - - halbtc8822b2ant_action_wifi_under5g(btcoexist); - return; - } - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], WiFi is under 2G!!!\n"); - BTC_TRACE(trace_buf); - - halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, - NORMAL_EXEC, - BT_8822B_2ANT_PHASE_2G_RUNTIME); - - - if (coex_sta->bt_whck_test) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT is under WHCK TEST!!!\n"); - BTC_TRACE(trace_buf); - halbtc8822b2ant_action_bt_whck_test(btcoexist); - return; - } - - if (coex_sta->bt_disabled) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT is disabled!!!\n"); - BTC_TRACE(trace_buf); - halbtc8822b2ant_action_coex_all_off(btcoexist); - return; - } - - if (coex_sta->c2h_bt_inquiry_page) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT is under inquiry/page scan !!\n"); - BTC_TRACE(trace_buf); - halbtc8822b2ant_action_bt_inquiry(btcoexist); - return; - } - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link); - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam); - - if (scan || link || roam) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], WiFi is under Link Process !!\n"); - BTC_TRACE(trace_buf); - halbtc8822b2ant_action_wifi_link_process(btcoexist); - return; - } - - /* for P2P */ - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS, - &wifi_link_status); - num_of_wifi_link = wifi_link_status >> 16; - - if ((num_of_wifi_link >= 2) || - (wifi_link_status & WIFI_P2P_GO_CONNECTED)) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "############# [BTCoex], Multi-Port num_of_wifi_link = %d, wifi_link_status = 0x%x\n", - num_of_wifi_link, wifi_link_status); - BTC_TRACE(trace_buf); - - if (bt_link_info->bt_link_exist) - miracast_plus_bt = true; - else - miracast_plus_bt = false; - - btcoexist->btc_set(btcoexist, BTC_SET_BL_MIRACAST_PLUS_BT, - &miracast_plus_bt); - halbtc8822b2ant_action_wifi_multi_port(btcoexist); - - return; - } - - miracast_plus_bt = false; - btcoexist->btc_set(btcoexist, BTC_SET_BL_MIRACAST_PLUS_BT, - &miracast_plus_bt); - - - algorithm = halbtc8822b2ant_action_algorithm(btcoexist); - coex_dm->cur_algorithm = algorithm; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], Algorithm = %d\n", - coex_dm->cur_algorithm); - BTC_TRACE(trace_buf); - - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - - if (!wifi_connected) { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, wifi non-connected!!.\n"); - BTC_TRACE(trace_buf); - halbtc8822b2ant_action_wifi_nonconnected(btcoexist); - - } else if ((BT_8822B_2ANT_BT_STATUS_NON_CONNECTED_IDLE == - coex_dm->bt_status) || - (BT_8822B_2ANT_BT_STATUS_CONNECTED_IDLE == - coex_dm->bt_status)) { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, bt idle!!.\n"); - BTC_TRACE(trace_buf); - - halbtc8822b2ant_action_bt_idle(btcoexist); - - } else { - - if (coex_dm->cur_algorithm != coex_dm->pre_algorithm) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], pre_algorithm=%d, cur_algorithm=%d\n", - coex_dm->pre_algorithm, coex_dm->cur_algorithm); - BTC_TRACE(trace_buf); - } - - switch (coex_dm->cur_algorithm) { - - case BT_8822B_2ANT_COEX_ALGO_SCO: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, algorithm = SCO.\n"); - BTC_TRACE(trace_buf); - halbtc8822b2ant_action_sco(btcoexist); - break; - case BT_8822B_2ANT_COEX_ALGO_HID: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, algorithm = HID.\n"); - BTC_TRACE(trace_buf); - halbtc8822b2ant_action_hid(btcoexist); - break; - case BT_8822B_2ANT_COEX_ALGO_A2DP: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, algorithm = A2DP.\n"); - BTC_TRACE(trace_buf); - halbtc8822b2ant_action_a2dp(btcoexist); - break; - case BT_8822B_2ANT_COEX_ALGO_A2DP_PANHS: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, algorithm = A2DP+PAN(HS).\n"); - BTC_TRACE(trace_buf); - halbtc8822b2ant_action_a2dp_pan_hs(btcoexist); - break; - case BT_8822B_2ANT_COEX_ALGO_PANEDR: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, algorithm = PAN(EDR).\n"); - BTC_TRACE(trace_buf); - halbtc8822b2ant_action_pan_edr(btcoexist); - break; - case BT_8822B_2ANT_COEX_ALGO_PANHS: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, algorithm = HS mode.\n"); - BTC_TRACE(trace_buf); - halbtc8822b2ant_action_pan_hs(btcoexist); - break; - case BT_8822B_2ANT_COEX_ALGO_PANEDR_A2DP: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, algorithm = PAN+A2DP.\n"); - BTC_TRACE(trace_buf); - halbtc8822b2ant_action_pan_edr_a2dp(btcoexist); - break; - case BT_8822B_2ANT_COEX_ALGO_PANEDR_HID: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, algorithm = PAN(EDR)+HID.\n"); - BTC_TRACE(trace_buf); - halbtc8822b2ant_action_pan_edr_hid(btcoexist); - break; - case BT_8822B_2ANT_COEX_ALGO_HID_A2DP_PANEDR: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, algorithm = HID+A2DP+PAN.\n"); - BTC_TRACE(trace_buf); - halbtc8822b2ant_action_hid_a2dp_pan_edr( - btcoexist); - break; - case BT_8822B_2ANT_COEX_ALGO_HID_A2DP: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, algorithm = HID+A2DP.\n"); - BTC_TRACE(trace_buf); - halbtc8822b2ant_action_hid_a2dp(btcoexist); - break; - case BT_8822B_2ANT_COEX_ALGO_NOPROFILEBUSY: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, algorithm = No-Profile busy.\n"); - BTC_TRACE(trace_buf); - halbtc8822b2ant_action_bt_idle(btcoexist); - break; - default: - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Action 2-Ant, algorithm = coexist All Off!!\n"); - BTC_TRACE(trace_buf); - halbtc8822b2ant_action_coex_all_off(btcoexist); - break; - } - coex_dm->pre_algorithm = coex_dm->cur_algorithm; - } -} - -void halbtc8822b2ant_init_coex_dm(IN struct btc_coexist *btcoexist) -{ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Coex Mechanism Init!!\n"); - BTC_TRACE(trace_buf); - - halbtc8822b2ant_low_penalty_ra(btcoexist, NORMAL_EXEC, false); - - halbtc8822b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); - halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, NORMAL_EXEC, - BT_8822B_2ANT_PHASE_2G_RUNTIME_CONCURRENT); - - /* fw all off */ - halbtc8822b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); - - halbtc8822b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 0xd8); - halbtc8822b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); - - coex_sta->pop_event_cnt = 0; - coex_sta->cnt_RemoteNameReq = 0; - coex_sta->cnt_ReInit = 0; - coex_sta->cnt_setupLink = 0; - coex_sta->cnt_IgnWlanAct = 0; - coex_sta->cnt_Page = 0; - - halbtc8822b2ant_query_bt_info(btcoexist); -} - - -void halbtc8822b2ant_init_hw_config(IN struct btc_coexist *btcoexist, - IN boolean wifi_only) -{ - u8 u8tmp = 0; - u32 vendor; - u32 u32tmp0 = 0, u32tmp1 = 0, u32tmp2 = 0, u32tmp3 = 0; - u32 RTL97F_8822B = 0; - - - u32tmp3 = btcoexist->btc_read_4byte(btcoexist, 0xcb4); - u32tmp1 = halbtc8822b2ant_ltecoex_indirect_read_reg(btcoexist, 0x38); - u32tmp2 = halbtc8822b2ant_ltecoex_indirect_read_reg(btcoexist, 0x54); - - if (RTL97F_8822B == true) { - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x66, 0x04, 0x0); - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x41, 0x02, 0x0); - - /* set GNT_BT to SW high */ - halbtc8822b2ant_ltecoex_set_gnt_bt(btcoexist, - BT_8822B_2ANT_GNT_BLOCK_RFC_BB, - BT_8822B_2ANT_GNT_TYPE_CTRL_BY_SW, - BT_8822B_2ANT_SIG_STA_SET_TO_HIGH); - /* Set GNT_WL to SW high */ - halbtc8822b2ant_ltecoex_set_gnt_wl(btcoexist, - BT_8822B_2ANT_GNT_BLOCK_RFC_BB, - BT_8822B_2ANT_GNT_TYPE_CTRL_BY_SW, - BT_8822B_2ANT_SIG_STA_SET_TO_HIGH); - return; - } - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], (Before Init HW config) 0xcb4 = 0x%x, 0x38= 0x%x, 0x54= 0x%x\n", - u32tmp3, u32tmp1, u32tmp2); - BTC_TRACE(trace_buf); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], 2Ant Init HW Config!!\n"); - BTC_TRACE(trace_buf); - - coex_sta->bt_coex_supported_feature = 0; - coex_sta->bt_coex_supported_version = 0; - coex_sta->bt_ble_scan_type = 0; - coex_sta->bt_ble_scan_para[0] = 0; - coex_sta->bt_ble_scan_para[1] = 0; - coex_sta->bt_ble_scan_para[2] = 0; - coex_sta->bt_reg_vendor_ac = 0xffff; - coex_sta->bt_reg_vendor_ae = 0xffff; - coex_sta->isolation_btween_wb = BT_8822B_2ANT_DEFAULT_ISOLATION; - - /* 0xf0[15:12] --> Chip Cut information */ - coex_sta->cut_version = (btcoexist->btc_read_1byte(btcoexist, - 0xf1) & 0xf0) >> 4; - - coex_sta->dis_ver_info_cnt = 0; - - halbtc8822b2ant_coex_switch_threshold(btcoexist, - coex_sta->isolation_btween_wb); - - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x550, 0x8, - 0x1); /* enable TBTT nterrupt */ - - /* BT report packet sample rate */ - btcoexist->btc_write_1byte(btcoexist, 0x790, 0x5); - - /* Init 0x778 = 0x1 for 2-Ant */ - btcoexist->btc_write_1byte(btcoexist, 0x778, 0x1); - - /* Enable PTA (3-wire function form BT side) */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x40, 0x20, 0x1); - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x41, 0x02, 0x1); - - /* Enable PTA (tx/rx signal form WiFi side) */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x4c6, 0x10, 0x1); - - halbtc8822b2ant_enable_gnt_to_gpio(btcoexist, true); - - /*GNT_BT=1 while select both */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x763, 0x10, 0x1); - - - /* check if WL firmware download ok */ - /*if (btcoexist->btc_read_1byte(btcoexist, 0x80) == 0xc6)*/ - halbtc8822b2ant_post_state_to_bt(btcoexist, - BT_8822B_2ANT_SCOREBOARD_ONOFF, true); - - /* Enable counter statistics */ - btcoexist->btc_write_1byte(btcoexist, 0x76e, - 0x4); /* 0x76e[3] =1, WLAN_Act control by PTA */ - - /* WLAN_Tx by GNT_WL 0x950[29] = 0 */ - /* btcoexist->btc_write_1byte_bitmask(btcoexist, 0x953, 0x20, 0x0); */ - - halbtc8822b2ant_coex_table_with_type(btcoexist, FORCE_EXEC, 0); - - halbtc8822b2ant_ps_tdma(btcoexist, FORCE_EXEC, false, 0); - - psd_scan->ant_det_is_ant_det_available = true; - - if (wifi_only) { - coex_sta->concurrent_rx_mode_on = false; - /* Path config */ - /* Set Antenna Path */ - halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, - FORCE_EXEC, - BT_8822B_2ANT_PHASE_WLANONLY_INIT); - - btcoexist->stop_coex_dm = true; - } else { - /*Set BT polluted packet on for Tx rate adaptive not including Tx retry break by PTA, 0x45c[19] =1 */ - btcoexist->btc_write_1byte_bitmask(btcoexist, 0x45e, 0x8, 0x1); - - coex_sta->concurrent_rx_mode_on = true; - /* btcoexist->btc_write_1byte_bitmask(btcoexist, 0x953, 0x2, 0x1); */ - - /* RF 0x1[1] = 0->Set GNT_WL_RF_Rx always = 1 for con-current Rx, mask Tx only */ - btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0x2, 0x0); - - /* Set Antenna Path */ - halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, - FORCE_EXEC, - BT_8822B_2ANT_PHASE_COEX_INIT); - - btcoexist->stop_coex_dm = false; - } -} - - - -/* ************************************************************ - * work around function start with wa_halbtc8822b2ant_ - * ************************************************************ - * ************************************************************ - * extern function start with ex_halbtc8822b2ant_ - * ************************************************************ */ -void ex_halbtc8822b2ant_power_on_setting(IN struct btc_coexist *btcoexist) -{ - struct btc_board_info *board_info = &btcoexist->board_info; - u8 u8tmp = 0x0; - u16 u16tmp = 0x0; - u32 value = 0; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx Execute 8822b 2-Ant PowerOn Setting xxxxxxxxxxxxxxxx!!\n"); - BTC_TRACE(trace_buf); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "Ant Det Finish = %s, Ant Det Number = %d\n", - (board_info->btdm_ant_det_finish ? "Yes" : "No"), - board_info->btdm_ant_num_by_ant_det); - BTC_TRACE(trace_buf); - - - btcoexist->stop_coex_dm = true; - psd_scan->ant_det_is_ant_det_available = false; - - /* enable BB, REG_SYS_FUNC_EN such that we can write BB Register correctly. */ - u16tmp = btcoexist->btc_read_2byte(btcoexist, 0x2); - btcoexist->btc_write_2byte(btcoexist, 0x2, u16tmp | BIT(0) | BIT(1)); - - - /* Local setting bit define */ - /* BIT0: "0" for no antenna inverse; "1" for antenna inverse */ - /* BIT1: "0" for internal switch; "1" for external switch */ - /* BIT2: "0" for one antenna; "1" for two antenna */ - /* NOTE: here default all internal switch and 1-antenna ==> BIT1=0 and BIT2=0 */ - - /* Check efuse 0xc3[6] for Single Antenna Path */ - if (board_info->single_ant_path == 0) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** Single Antenna, Antenna at Aux Port\n"); - BTC_TRACE(trace_buf); - - board_info->btdm_ant_pos = BTC_ANTENNA_AT_AUX_PORT; - - u8tmp = 7; - } else if (board_info->single_ant_path == 1) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** Single Antenna, Antenna at Main Port\n"); - BTC_TRACE(trace_buf); - - board_info->btdm_ant_pos = BTC_ANTENNA_AT_MAIN_PORT; - - u8tmp = 6; - } - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** (Power On) single_ant_path = %d, btdm_ant_pos = %d\n", - board_info->single_ant_path , board_info->btdm_ant_pos); - BTC_TRACE(trace_buf); - - /* Setup RF front end type */ - halbtc8822b2ant_set_rfe_type(btcoexist); - - /* Set Antenna Path to BT side */ - halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, FORCE_EXEC, - BT_8822B_2ANT_PHASE_COEX_POWERON); - - /* Save"single antenna position" info in Local register setting for FW reading, because FW may not ready at power on */ - if (btcoexist->chip_interface == BTC_INTF_PCI) - btcoexist->btc_write_local_reg_1byte(btcoexist, 0x3e0, u8tmp); - else if (btcoexist->chip_interface == BTC_INTF_USB) - btcoexist->btc_write_local_reg_1byte(btcoexist, 0xfe08, u8tmp); - else if (btcoexist->chip_interface == BTC_INTF_SDIO) - btcoexist->btc_write_local_reg_1byte(btcoexist, 0x60, u8tmp); - - /* enable GNT_WL/GNT_BT debug signal to GPIO14/15 */ - halbtc8822b2ant_enable_gnt_to_gpio(btcoexist, true); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** LTE coex Reg 0x38 (Power-On) = 0x%x**********\n", - halbtc8822b2ant_ltecoex_indirect_read_reg(btcoexist, 0x38)); - BTC_TRACE(trace_buf); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** MAC Reg 0x70/ BB Reg 0xcb4 (Power-On) = 0x%x / 0x%x\n", - btcoexist->btc_read_4byte(btcoexist, 0x70), - btcoexist->btc_read_4byte(btcoexist, 0xcb4)); - BTC_TRACE(trace_buf); - -} - -void ex_halbtc8822b2ant_pre_load_firmware(IN struct btc_coexist *btcoexist) -{ - struct btc_board_info *board_info = &btcoexist->board_info; - u8 u8tmp = 0x4; /* Set BIT2 by default since it's 2ant case */ - - /* */ - /* S0 or S1 setting and Local register setting(By the setting fw can get ant number, S0/S1, ... info) */ - /* Local setting bit define */ - /* BIT0: "0" for no antenna inverse; "1" for antenna inverse */ - /* BIT1: "0" for internal switch; "1" for external switch */ - /* BIT2: "0" for one antenna; "1" for two antenna */ - /* NOTE: here default all internal switch and 1-antenna ==> BIT1=0 and BIT2=0 */ - if (btcoexist->chip_interface == BTC_INTF_USB) { - /* fixed at S0 for USB interface */ - u8tmp |= 0x1; /* antenna inverse */ - btcoexist->btc_write_local_reg_1byte(btcoexist, 0xfe08, u8tmp); - } else { - /* for PCIE and SDIO interface, we check efuse 0xc3[6] */ - if (board_info->single_ant_path == 0) { - } else if (board_info->single_ant_path == 1) { - /* set to S0 */ - u8tmp |= 0x1; /* antenna inverse */ - } - - if (btcoexist->chip_interface == BTC_INTF_PCI) - btcoexist->btc_write_local_reg_1byte(btcoexist, 0x3e0, - u8tmp); - else if (btcoexist->chip_interface == BTC_INTF_SDIO) - btcoexist->btc_write_local_reg_1byte(btcoexist, 0x60, - u8tmp); - } -} - - -void ex_halbtc8822b2ant_init_hw_config(IN struct btc_coexist *btcoexist, - IN boolean wifi_only) -{ - halbtc8822b2ant_init_hw_config(btcoexist, wifi_only); -} - -void ex_halbtc8822b2ant_init_coex_dm(IN struct btc_coexist *btcoexist) -{ - - halbtc8822b2ant_init_coex_dm(btcoexist); -} - -void ex_halbtc8822b2ant_display_coex_info(IN struct btc_coexist *btcoexist) -{ - struct btc_board_info *board_info = &btcoexist->board_info; - struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; - - u8 *cli_buf = btcoexist->cli_buf; - u8 u8tmp[4], i, ps_tdma_case = 0; - u32 u32tmp[4]; - u16 u16tmp[4]; - u32 fa_ofdm, fa_cck, cca_ofdm, cca_cck; - u32 fw_ver = 0, bt_patch_ver = 0, bt_coex_ver = 0; - static u8 pop_report_in_10s = 0; - u32 phyver = 0; - boolean lte_coex_on = false; - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n ============[BT Coexist info]============"); - CL_PRINTF(cli_buf); - - if (btcoexist->manual_control) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n ============[Under Manual Control]============"); - CL_PRINTF(cli_buf); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n =========================================="); - CL_PRINTF(cli_buf); - } - - if (psd_scan->ant_det_try_count == 0) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %d/ %d/ %s / %d", - "Ant PG Num/ Mech/ Pos/ RFE", - board_info->pg_ant_num, board_info->btdm_ant_num, - (board_info->btdm_ant_pos == BTC_ANTENNA_AT_MAIN_PORT - ? "Main" : "Aux"), - rfe_type->rfe_module_type); - CL_PRINTF(cli_buf); - } else { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %d/ %d/ %s/ %d (%d/%d/%d)", - "Ant PG Num/ Mech(Ant_Det)/ Pos/ RFE", - board_info->pg_ant_num, - board_info->btdm_ant_num_by_ant_det, - (board_info->btdm_ant_pos == BTC_ANTENNA_AT_MAIN_PORT - ? "Main" : "Aux"), - rfe_type->rfe_module_type, - psd_scan->ant_det_try_count, - psd_scan->ant_det_fail_count, - psd_scan->ant_det_result); - CL_PRINTF(cli_buf); - - - if (board_info->btdm_ant_det_finish) { - - if (psd_scan->ant_det_result != 12) - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s", - "Ant Det PSD Value", - psd_scan->ant_det_peak_val); - else - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %d", - "Ant Det PSD Value", - psd_scan->ant_det_psd_scan_peak_val - / 100); - CL_PRINTF(cli_buf); - } - } - - - /*bt_patch_ver = btcoexist->bt_info.bt_get_fw_ver;*/ - bt_patch_ver = btcoexist->bt_info.bt_get_fw_ver; - btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, &fw_ver); - phyver = btcoexist->btc_get_bt_phydm_version(btcoexist); - - bt_coex_ver = (coex_sta->bt_coex_supported_version & 0xff); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %d_%02x/ 0x%02x/ 0x%02x (%s)", - "CoexVer WL/ BT_Desired/ BT_Report", - glcoex_ver_date_8822b_2ant, glcoex_ver_8822b_2ant, - glcoex_ver_btdesired_8822b_2ant, - bt_coex_ver, - (bt_coex_ver == 0xff ? "Unknown" : - (bt_coex_ver >= glcoex_ver_btdesired_8822b_2ant ? - "Match" : "Mis-Match"))); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = 0x%x/ 0x%x/ v%d/ %c", - "W_FW/ B_FW/ Phy/ Kt", - fw_ver, bt_patch_ver, phyver, - coex_sta->cut_version + 65); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x ", - "AFH Map to BT", - coex_dm->wifi_chnl_info[0], coex_dm->wifi_chnl_info[1], - coex_dm->wifi_chnl_info[2]); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d / %d ", - "Isolation/WL_Thres/BT_Thres", - coex_sta->isolation_btween_wb, - coex_sta->wifi_coex_thres, - coex_sta->bt_coex_thres); - CL_PRINTF(cli_buf); - - /* wifi status */ - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s", - "============[Wifi Status]============"); - CL_PRINTF(cli_buf); - btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_WIFI_STATUS); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s", - "============[BT Status]============"); - CL_PRINTF(cli_buf); - - pop_report_in_10s++; - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = [%s/ %d dBm/ %d/ %d] ", - "BT [status/ rssi/ retryCnt/ popCnt]", - ((coex_sta->bt_disabled) ? ("disabled") : (( - coex_sta->c2h_bt_inquiry_page) ? ("inquiry/page") - : ((BT_8822B_2ANT_BT_STATUS_NON_CONNECTED_IDLE == - coex_dm->bt_status) ? "non-connected idle" : - ((BT_8822B_2ANT_BT_STATUS_CONNECTED_IDLE == coex_dm->bt_status) - ? "connected-idle" : "busy")))), - coex_sta->bt_rssi - 100, coex_sta->bt_retry_cnt, - coex_sta->pop_event_cnt); - CL_PRINTF(cli_buf); - - if (pop_report_in_10s >= 5) { - coex_sta->pop_event_cnt = 0; - pop_report_in_10s = 0; - } - - - if (coex_sta->num_of_profile != 0) - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %s%s%s%s%s", - "Profiles", - ((bt_link_info->a2dp_exist) ? "A2DP," : ""), - ((bt_link_info->sco_exist) ? "SCO," : ""), - ((bt_link_info->hid_exist) ? - ((coex_sta->hid_busy_num >= 2) ? "HID(4/18)," : - "HID(2/18),") : ""), - ((bt_link_info->pan_exist) ? "PAN," : ""), - ((coex_sta->voice_over_HOGP) ? "Voice" : "")); - else - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = None", "Profiles"); - - CL_PRINTF(cli_buf); - - - if (bt_link_info->a2dp_exist) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %s", - "A2DP Rate/Bitpool/Auto_Slot", - ((coex_sta->is_A2DP_3M) ? "3M" : "No_3M"), - coex_sta->a2dp_bit_pool, - ((coex_sta->is_autoslot) ? "On" : "Off") - ); - CL_PRINTF(cli_buf); - } - - if (bt_link_info->hid_exist) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", - "HID PairNum/Forbid_Slot", - coex_sta->hid_pair_cnt, - coex_sta->forbidden_slot - ); - CL_PRINTF(cli_buf); - } - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s / %s/ 0x%x", - "Role/IgnWlanAct/Feature", - ((bt_link_info->slave_role) ? "Slave" : "Master"), - ((coex_dm->cur_ignore_wlan_act) ? "Yes" : "No"), - coex_sta->bt_coex_supported_feature); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d/ %d", - "ReInit/ReLink/IgnWlact/Page/NameReq", - coex_sta->cnt_ReInit, - coex_sta->cnt_setupLink, - coex_sta->cnt_IgnWlanAct, - coex_sta->cnt_Page, - coex_sta->cnt_RemoteNameReq - ); - CL_PRINTF(cli_buf); - - halbtc8822b2ant_read_score_board(btcoexist, &u16tmp[0]); - - if ((coex_sta->bt_reg_vendor_ae == 0xffff) || - (coex_sta->bt_reg_vendor_ac == 0xffff)) - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = x/ x/ %04x", - "0xae[4]/0xac[1:0]/Scoreboard", u16tmp[0]); - else - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = 0x%x/ 0x%x/ %04x", - "0xae[4]/0xac[1:0]/Scoreboard", - ((coex_sta->bt_reg_vendor_ae & BIT(4)) >> 4), - coex_sta->bt_reg_vendor_ac & 0x3, u16tmp[0]); - CL_PRINTF(cli_buf); - - for (i = 0; i < BT_INFO_SRC_8822B_2ANT_MAX; i++) { - if (coex_sta->bt_info_c2h_cnt[i]) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %02x %02x %02x %02x %02x %02x %02x(%d)", - glbt_info_src_8822b_2ant[i], - coex_sta->bt_info_c2h[i][0], - coex_sta->bt_info_c2h[i][1], - coex_sta->bt_info_c2h[i][2], - coex_sta->bt_info_c2h[i][3], - coex_sta->bt_info_c2h[i][4], - coex_sta->bt_info_c2h[i][5], - coex_sta->bt_info_c2h[i][6], - coex_sta->bt_info_c2h_cnt[i]); - CL_PRINTF(cli_buf); - } - } - - /* Sw mechanism */ - if (btcoexist->manual_control) - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s", - "============[mechanism] (before Manual)============"); - else - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s", - "============[Mechanism]============"); - - CL_PRINTF(cli_buf); - - - ps_tdma_case = coex_dm->cur_ps_tdma; - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %02x %02x %02x %02x %02x (case-%d, %s, %s)", - "TDMA", - coex_dm->ps_tdma_para[0], coex_dm->ps_tdma_para[1], - coex_dm->ps_tdma_para[2], coex_dm->ps_tdma_para[3], - coex_dm->ps_tdma_para[4], ps_tdma_case, - (coex_dm->cur_ps_tdma_on ? "TDMA On" : "TDMA Off"), - (coex_dm->is_switch_to_1dot5_ant ? "1.5Ant" : "2Ant")); - CL_PRINTF(cli_buf); - - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x6c0); - u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x6c4); - u32tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0x6c8); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %d/ 0x%x/ 0x%x/ 0x%x", - "Table/0x6c0/0x6c4/0x6c8", - coex_sta->coex_table_type, u32tmp[0], u32tmp[1], u32tmp[2]); - CL_PRINTF(cli_buf); - - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x778); - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x6cc); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = 0x%x/ 0x%x", - "0x778/0x6cc", - u8tmp[0], u32tmp[0]); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s/ %s", - "AntDiv/ForceLPS/LPRA", - ((board_info->ant_div_cfg) ? "On" : "Off"), - ((coex_sta->force_lps_on) ? "On" : "Off"), - ((coex_dm->cur_low_penalty_ra) ? "On" : "Off")); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", - "WL_DACSwing/ BT_Dec_Pwr", coex_dm->cur_fw_dac_swing_lvl, - coex_dm->cur_bt_dec_pwr_lvl); - CL_PRINTF(cli_buf); - - u32tmp[0] = halbtc8822b2ant_ltecoex_indirect_read_reg(btcoexist, 0x38); - lte_coex_on = ((u32tmp[0] & BIT(7)) >> 7) ? true : false; - - if (lte_coex_on) { - - u32tmp[0] = halbtc8822b2ant_ltecoex_indirect_read_reg(btcoexist, - 0xa0); - u32tmp[1] = halbtc8822b2ant_ltecoex_indirect_read_reg(btcoexist, - 0xa4); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", - "LTE Coex Table W_L/B_L", - u32tmp[0] & 0xffff, u32tmp[1] & 0xffff); - CL_PRINTF(cli_buf); - - - u32tmp[0] = halbtc8822b2ant_ltecoex_indirect_read_reg(btcoexist, - 0xa8); - u32tmp[1] = halbtc8822b2ant_ltecoex_indirect_read_reg(btcoexist, - 0xac); - u32tmp[2] = halbtc8822b2ant_ltecoex_indirect_read_reg(btcoexist, - 0xb0); - u32tmp[3] = halbtc8822b2ant_ltecoex_indirect_read_reg(btcoexist, - 0xb4); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", - "LTE Break Table W_L/B_L/L_W/L_B", - u32tmp[0] & 0xffff, u32tmp[1] & 0xffff, - u32tmp[2] & 0xffff, u32tmp[3] & 0xffff); - CL_PRINTF(cli_buf); - - } - - /* Hw setting */ - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s", - "============[Hw setting]============"); - CL_PRINTF(cli_buf); - /* - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x430); - u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x434); - u16tmp[0] = btcoexist->btc_read_2byte(btcoexist, 0x42a); - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x456); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/0x%x/0x%x/0x%x", - "0x430/0x434/0x42a/0x456", - u32tmp[0], u32tmp[1], u16tmp[0], u8tmp[0]); - CL_PRINTF(cli_buf); - */ - u32tmp[0] = halbtc8822b2ant_ltecoex_indirect_read_reg(btcoexist, 0x38); - u32tmp[1] = halbtc8822b2ant_ltecoex_indirect_read_reg(btcoexist, 0x54); - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x73); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s", - "LTE Coex/Path Owner", - ((lte_coex_on) ? "On" : "Off") , - ((u8tmp[0] & BIT(2)) ? "WL" : "BT")); - CL_PRINTF(cli_buf); - - if (lte_coex_on) { - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d", - "LTE 3Wire/OPMode/UART/UARTMode", - (int)((u32tmp[0] & BIT(6)) >> 6), - (int)((u32tmp[0] & (BIT(5) | BIT(4))) >> 4), - (int)((u32tmp[0] & BIT(3)) >> 3), - (int)(u32tmp[0] & (BIT(2) | BIT(1) | BIT(0)))); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", - "LTE_Busy/UART_Busy", - (int)((u32tmp[1] & BIT(1)) >> 1), (int)(u32tmp[1] & BIT(0))); - CL_PRINTF(cli_buf); - } - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = %s (BB:%s)/ %s (BB:%s)/ %s", - "GNT_WL_Ctrl/GNT_BT_Ctrl/Dbg", - ((u32tmp[0] & BIT(12)) ? "SW" : "HW"), - ((u32tmp[0] & BIT(8)) ? "SW" : "HW"), - ((u32tmp[0] & BIT(14)) ? "SW" : "HW"), - ((u32tmp[0] & BIT(10)) ? "SW" : "HW"), - ((u8tmp[0] & BIT(3)) ? "On" : "Off")); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", - "GNT_WL/GNT_BT", - (int)((u32tmp[1] & BIT(2)) >> 2), - (int)((u32tmp[1] & BIT(3)) >> 3)); - CL_PRINTF(cli_buf); - - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xcb0); - u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0xcb4); - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0xcbd); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = 0x%04x/ 0x%04x/ 0x%x", - "0xcb0/0xcb4/0xcbd", - u32tmp[0], u32tmp[1], u8tmp[0]); - CL_PRINTF(cli_buf); - - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x4c); - u8tmp[2] = btcoexist->btc_read_1byte(btcoexist, 0x64); - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x4c6); - u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0x40); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", - "0x4c[24:23]/0x64[0]/x4c6[4]/0x40[5]", - (u32tmp[0] & (BIT(24) | BIT(23))) >> 23 , u8tmp[2] & 0x1 , - (int)((u8tmp[0] & BIT(4)) >> 4), - (int)((u8tmp[1] & BIT(5)) >> 5)); - CL_PRINTF(cli_buf); - - u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x550); - u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x522); - u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0x953); - u8tmp[2] = btcoexist->btc_read_1byte(btcoexist, 0xc50); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = 0x%x/ 0x%x/ %s/ 0x%x", - "0x550/0x522/4-RxAGC/0xc50", - u32tmp[0], u8tmp[0], (u8tmp[1] & 0x2) ? "On" : "Off", u8tmp[2]); - CL_PRINTF(cli_buf); - - fa_ofdm = btcoexist->btc_phydm_query_PHY_counter(btcoexist, - PHYDM_INFO_FA_OFDM); - fa_cck = btcoexist->btc_phydm_query_PHY_counter(btcoexist, - PHYDM_INFO_FA_CCK); - cca_ofdm = btcoexist->btc_phydm_query_PHY_counter(btcoexist, - PHYDM_INFO_CCA_OFDM); - cca_cck = btcoexist->btc_phydm_query_PHY_counter(btcoexist, - PHYDM_INFO_CCA_CCK); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, - "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", - "CCK-CCA/CCK-FA/OFDM-CCA/OFDM-FA", - cca_cck, fa_cck, cca_ofdm, fa_ofdm); - CL_PRINTF(cli_buf); - -#if 1 - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d", - "CRC_OK CCK/11g/11n/11ac", - coex_sta->crc_ok_cck, coex_sta->crc_ok_11g, - coex_sta->crc_ok_11n, coex_sta->crc_ok_11n_vht); - CL_PRINTF(cli_buf); - - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d", - "CRC_Err CCK/11g/11n/11ac", - coex_sta->crc_err_cck, coex_sta->crc_err_11g, - coex_sta->crc_err_11n, coex_sta->crc_err_11n_vht); - CL_PRINTF(cli_buf); -#endif - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", - "0x770(Hi-pri rx/tx)", - coex_sta->high_priority_rx, coex_sta->high_priority_tx); - CL_PRINTF(cli_buf); - CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", - "0x774(Lo-pri rx/tx)", - coex_sta->low_priority_rx, coex_sta->low_priority_tx); - CL_PRINTF(cli_buf); - - btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_COEX_STATISTICS); -} - - -void ex_halbtc8822b2ant_ips_notify(IN struct btc_coexist *btcoexist, IN u8 type) -{ - if (btcoexist->manual_control || btcoexist->stop_coex_dm) - return; - - if (BTC_IPS_ENTER == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], IPS ENTER notify\n"); - BTC_TRACE(trace_buf); - coex_sta->under_ips = true; - coex_sta->under_lps = false; - - halbtc8822b2ant_post_state_to_bt(btcoexist, - BT_8822B_2ANT_SCOREBOARD_ACTIVE, false); - - halbtc8822b2ant_post_state_to_bt(btcoexist, - BT_8822B_2ANT_SCOREBOARD_ONOFF, false); - - halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, - FORCE_EXEC, - BT_8822B_2ANT_PHASE_WLAN_OFF); - - halbtc8822b2ant_action_coex_all_off(btcoexist); - } else if (BTC_IPS_LEAVE == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], IPS LEAVE notify\n"); - BTC_TRACE(trace_buf); - coex_sta->under_ips = false; - - halbtc8822b2ant_post_state_to_bt(btcoexist, - BT_8822B_2ANT_SCOREBOARD_ACTIVE, true); - halbtc8822b2ant_post_state_to_bt(btcoexist, - BT_8822B_2ANT_SCOREBOARD_ONOFF, true); - halbtc8822b2ant_init_hw_config(btcoexist, false); - halbtc8822b2ant_init_coex_dm(btcoexist); - halbtc8822b2ant_query_bt_info(btcoexist); - } -} - -void ex_halbtc8822b2ant_lps_notify(IN struct btc_coexist *btcoexist, IN u8 type) -{ - if (btcoexist->manual_control || btcoexist->stop_coex_dm) - return; - - if (BTC_LPS_ENABLE == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], LPS ENABLE notify\n"); - BTC_TRACE(trace_buf); - coex_sta->under_lps = true; - coex_sta->under_ips = false; - - if (coex_sta->force_lps_on == true) { /* LPS No-32K */ - /* Write WL "Active" in Score-board for PS-TDMA */ - halbtc8822b2ant_post_state_to_bt(btcoexist, - BT_8822B_2ANT_SCOREBOARD_ACTIVE, true); - - } else { /* LPS-32K, need check if this h2c 0x71 can work?? (2015/08/28) */ - /* Write WL "Non-Active" in Score-board for Native-PS */ - halbtc8822b2ant_post_state_to_bt(btcoexist, - BT_8822B_2ANT_SCOREBOARD_ACTIVE, false); - } - - - } else if (BTC_LPS_DISABLE == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], LPS DISABLE notify\n"); - BTC_TRACE(trace_buf); - coex_sta->under_lps = false; - - halbtc8822b2ant_post_state_to_bt(btcoexist, - BT_8822B_2ANT_SCOREBOARD_ACTIVE, true); - } -} - -void ex_halbtc8822b2ant_scan_notify(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - boolean wifi_connected = false; - boolean wifi_under_5g = false; - - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCAN notify()\n"); - BTC_TRACE(trace_buf); - - halbtc8822b2ant_post_state_to_bt(btcoexist, - BT_8822B_2ANT_SCOREBOARD_ACTIVE, true); - - if (btcoexist->manual_control || - btcoexist->stop_coex_dm) - return; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - - /* this can't be removed for RF off_on event, or BT would dis-connect */ - halbtc8822b2ant_query_bt_info(btcoexist); - - if (BTC_SCAN_START == type) { - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, - &wifi_under_5g); - - if (wifi_under_5g) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** SCAN START notify (5g)\n"); - BTC_TRACE(trace_buf); - - halbtc8822b2ant_action_wifi_under5g(btcoexist); - return; - } - - coex_sta->wifi_is_high_pri_task = true; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** SCAN START notify (2g)\n"); - BTC_TRACE(trace_buf); - - halbtc8822b2ant_run_coexist_mechanism( - btcoexist); - - return; - } - - - if (BTC_SCAN_START_2G == type) { - - if (!wifi_connected) - coex_sta->wifi_is_high_pri_task = true; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCAN START notify (2G)\n"); - BTC_TRACE(trace_buf); - - halbtc8822b2ant_post_state_to_bt(btcoexist, - BT_8822B_2ANT_SCOREBOARD_SCAN, true); - halbtc8822b2ant_post_state_to_bt(btcoexist, - BT_8822B_2ANT_SCOREBOARD_ACTIVE, true); - - halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, - FORCE_EXEC, - BT_8822B_2ANT_PHASE_2G_RUNTIME); - - halbtc8822b2ant_run_coexist_mechanism(btcoexist); - - } else if (BTC_SCAN_FINISH == type) { - - coex_sta->wifi_is_high_pri_task = false; - - btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM, - &coex_sta->scan_ap_num); - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], SCAN FINISH notify (Scan-AP = %d)\n", - coex_sta->scan_ap_num); - BTC_TRACE(trace_buf); - - halbtc8822b2ant_post_state_to_bt(btcoexist, - BT_8822B_2ANT_SCOREBOARD_SCAN, false); - - halbtc8822b2ant_run_coexist_mechanism(btcoexist); - } - -} - -void ex_halbtc8822b2ant_switchband_notify(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - - boolean wifi_connected = false, bt_hs_on = false; - u32 wifi_link_status = 0; - u32 num_of_wifi_link = 0; - boolean bt_ctrl_agg_buf_size = false; - u8 agg_buf_size = 5; - - - if (btcoexist->manual_control || - btcoexist->stop_coex_dm) - return; - - if (type == BTC_SWITCH_TO_5G) { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], switchband_notify --- switch to 5G\n"); - BTC_TRACE(trace_buf); - - halbtc8822b2ant_action_wifi_under5g(btcoexist); - - } else if (type == BTC_SWITCH_TO_24G_NOFORSCAN) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ********** switchband_notify BTC_SWITCH_TO_2G (no for scan)\n"); - BTC_TRACE(trace_buf); - - halbtc8822b2ant_run_coexist_mechanism(btcoexist); - - } else { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], switchband_notify --- switch to 2G\n"); - BTC_TRACE(trace_buf); - - ex_halbtc8822b2ant_scan_notify(btcoexist, - BTC_SCAN_START_2G); - } -} - - -void ex_halbtc8822b2ant_connect_notify(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - - halbtc8822b2ant_post_state_to_bt(btcoexist, - BT_8822B_2ANT_SCOREBOARD_ACTIVE, true); - if (btcoexist->manual_control || - btcoexist->stop_coex_dm) - return; - - if ((BTC_ASSOCIATE_5G_START == type) || - (BTC_ASSOCIATE_5G_FINISH == type)) { - - if (BTC_ASSOCIATE_5G_START == type) - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], connect_notify --- 5G start\n"); - else - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], connect_notify --- 5G finish\n"); - - BTC_TRACE(trace_buf); - - halbtc8822b2ant_action_wifi_under5g(btcoexist); - return; - } - - - if (BTC_ASSOCIATE_START == type) { - - coex_sta->wifi_is_high_pri_task = true; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], CONNECT START notify (2G)\n"); - BTC_TRACE(trace_buf); - - halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, - FORCE_EXEC, - BT_8822B_2ANT_PHASE_2G_RUNTIME); - - halbtc8822b2ant_action_wifi_link_process(btcoexist); - - /* To keep TDMA case during connect process, - to avoid changed by Btinfo and runcoexmechanism */ - coex_sta->freeze_coexrun_by_btinfo = true; - - coex_dm->arp_cnt = 0; - - } else if (BTC_ASSOCIATE_FINISH == type) { - - coex_sta->wifi_is_high_pri_task = false; - coex_sta->freeze_coexrun_by_btinfo = false; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], CONNECT FINISH notify (2G)\n"); - BTC_TRACE(trace_buf); - - halbtc8822b2ant_run_coexist_mechanism(btcoexist); - } -} - -void ex_halbtc8822b2ant_media_status_notify(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - u8 h2c_parameter[3] = {0}; - u32 wifi_bw; - u8 wifi_central_chnl; - u8 ap_num = 0; - boolean wifi_under_b_mode = false, wifi_under_5g = false; - - - if (btcoexist->manual_control || - btcoexist->stop_coex_dm) - return; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g); - - if (BTC_MEDIA_CONNECT == type) { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], MEDIA connect notify\n"); - BTC_TRACE(trace_buf); - - halbtc8822b2ant_post_state_to_bt(btcoexist, - BT_8822B_2ANT_SCOREBOARD_ACTIVE, true); - - if (wifi_under_5g) { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], WiFi is under 5G!!!\n"); - BTC_TRACE(trace_buf); - - halbtc8822b2ant_action_wifi_under5g(btcoexist); - return; - } - - halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, - FORCE_EXEC, - BT_8822B_2ANT_PHASE_2G_RUNTIME); - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_B_MODE, - &wifi_under_b_mode); - - /* Set CCK Tx/Rx high Pri except 11b mode */ - if (wifi_under_b_mode) { - btcoexist->btc_write_1byte(btcoexist, 0x6cd, - 0x00); /* CCK Tx */ - btcoexist->btc_write_1byte(btcoexist, 0x6cf, - 0x00); /* CCK Rx */ - } else { - - btcoexist->btc_write_1byte(btcoexist, 0x6cd, - 0x00); /* CCK Tx */ - btcoexist->btc_write_1byte(btcoexist, 0x6cf, - 0x10); /* CCK Rx */ - } - - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], MEDIA disconnect notify\n"); - BTC_TRACE(trace_buf); - - btcoexist->btc_write_1byte(btcoexist, 0x6cd, 0x0); /* CCK Tx */ - btcoexist->btc_write_1byte(btcoexist, 0x6cf, 0x0); /* CCK Rx */ - - halbtc8822b2ant_post_state_to_bt(btcoexist, - BT_8822B_2ANT_SCOREBOARD_ACTIVE, false); - } - - - halbtc8822b2ant_update_wifi_channel_info(btcoexist, type); -} - -void ex_halbtc8822b2ant_specific_packet_notify(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - boolean under_4way = false, wifi_under_5g = false; - - if (btcoexist->manual_control || - btcoexist->stop_coex_dm) - return; - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g); - - if (wifi_under_5g) { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], WiFi is under 5G!!!\n"); - BTC_TRACE(trace_buf); - - halbtc8822b2ant_action_wifi_under5g(btcoexist); - return; - } - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS, - &under_4way); - - if (under_4way) { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], specific Packet ---- under_4way!!\n"); - BTC_TRACE(trace_buf); - - coex_sta->wifi_is_high_pri_task = true; - coex_sta->specific_pkt_period_cnt = 2; - - } else if (BTC_PACKET_ARP == type) { - - coex_dm->arp_cnt++; - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], specific Packet ARP notify -cnt = %d\n", - coex_dm->arp_cnt); - BTC_TRACE(trace_buf); - - } else { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], specific Packet DHCP or EAPOL notify [Type = %d]\n", - type); - BTC_TRACE(trace_buf); - - coex_sta->wifi_is_high_pri_task = true; - coex_sta->specific_pkt_period_cnt = 2; - } - - if (coex_sta->wifi_is_high_pri_task) - halbtc8822b2ant_run_coexist_mechanism(btcoexist); - -} - -void ex_halbtc8822b2ant_bt_info_notify(IN struct btc_coexist *btcoexist, - IN u8 *tmp_buf, IN u8 length) -{ - u8 i, rsp_source = 0; - boolean wifi_connected = false; - - if (psd_scan->is_AntDet_running == true) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], bt_info_notify return for AntDet is running\n"); - BTC_TRACE(trace_buf); - return; - } - - rsp_source = tmp_buf[0] & 0xf; - if (rsp_source >= BT_INFO_SRC_8822B_2ANT_MAX) - rsp_source = BT_INFO_SRC_8822B_2ANT_WIFI_FW; - coex_sta->bt_info_c2h_cnt[rsp_source]++; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Bt_info[%d], len=%d, data=[", rsp_source, - length); - BTC_TRACE(trace_buf); - - for (i = 0; i < length; i++) { - coex_sta->bt_info_c2h[rsp_source][i] = tmp_buf[i]; - - if (i == length - 1) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "0x%02x]\n", - tmp_buf[i]); - BTC_TRACE(trace_buf); - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "0x%02x, ", - tmp_buf[i]); - BTC_TRACE(trace_buf); - } - } - - coex_sta->bt_info = coex_sta->bt_info_c2h[rsp_source][1]; - coex_sta->bt_info_ext = coex_sta->bt_info_c2h[rsp_source][4]; - coex_sta->bt_info_ext2 = coex_sta->bt_info_c2h[rsp_source][5]; - - if (BT_INFO_SRC_8822B_2ANT_WIFI_FW != rsp_source) { - - /* if 0xff, it means BT is under WHCK test */ - coex_sta->bt_whck_test = ((coex_sta->bt_info == 0xff) ? true : - false); - - coex_sta->bt_create_connection = (( - coex_sta->bt_info_c2h[rsp_source][2] & 0x80) ? true : - false); - - /* unit: %, value-100 to translate to unit: dBm */ - coex_sta->bt_rssi = coex_sta->bt_info_c2h[rsp_source][3] * 2 + - 10; - - coex_sta->c2h_bt_remote_name_req = (( - coex_sta->bt_info_c2h[rsp_source][2] & 0x20) ? true : - false); - - coex_sta->is_A2DP_3M = ((coex_sta->bt_info_c2h[rsp_source][2] & - 0x10) ? true : false); - - coex_sta->acl_busy = ((coex_sta->bt_info_c2h[rsp_source][1] & - 0x9) ? true : false); - - coex_sta->voice_over_HOGP = ((coex_sta->bt_info_ext & 0x10) ? - true : false); - - coex_sta->c2h_bt_inquiry_page = ((coex_sta->bt_info & - BT_INFO_8822B_2ANT_B_INQ_PAGE) ? true : false); - - coex_sta->a2dp_bit_pool = ((( - coex_sta->bt_info_c2h[rsp_source][1] & 0x49) == 0x49) ? - coex_sta->bt_info_c2h[rsp_source][6] : 0); - - coex_sta->bt_retry_cnt = coex_sta->bt_info_c2h[rsp_source][2] & - 0xf; - - coex_sta->is_autoslot = coex_sta->bt_info_ext2 & 0x8; - - coex_sta->forbidden_slot = coex_sta->bt_info_ext2 & 0x7; - - coex_sta->hid_busy_num = (coex_sta->bt_info_ext2 & 0x30) >> 4; - - coex_sta->hid_pair_cnt = (coex_sta->bt_info_ext2 & 0xc0) >> 6; - - if (coex_sta->bt_retry_cnt >= 1) - coex_sta->pop_event_cnt++; - - if (coex_sta->c2h_bt_remote_name_req) - coex_sta->cnt_RemoteNameReq++; - - if (coex_sta->bt_info_ext & BIT(1)) - coex_sta->cnt_ReInit++; - - if (coex_sta->bt_info_ext & BIT(2)) { - coex_sta->cnt_setupLink++; - coex_sta->is_setupLink = true; - } else - coex_sta->is_setupLink = false; - - if (coex_sta->bt_info_ext & BIT(3)) - coex_sta->cnt_IgnWlanAct++; - - if (coex_sta->bt_create_connection) - coex_sta->cnt_Page++; - - /* Here we need to resend some wifi info to BT */ - /* because bt is reset and loss of the info. */ - - if ((!btcoexist->manual_control) && - (!btcoexist->stop_coex_dm)) { - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, - &wifi_connected); - - /* Re-Init */ - if ((coex_sta->bt_info_ext & BIT(1))) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT ext info bit1 check, send wifi BW&Chnl to BT!!\n"); - BTC_TRACE(trace_buf); - if (wifi_connected) - halbtc8822b2ant_update_wifi_channel_info( - btcoexist, BTC_MEDIA_CONNECT); - else - halbtc8822b2ant_update_wifi_channel_info( - btcoexist, - BTC_MEDIA_DISCONNECT); - } - - - /* If Ignore_WLanAct && not SetUp_Link */ - if ((coex_sta->bt_info_ext & BIT(3)) && - (!(coex_sta->bt_info_ext & BIT(2)))) { - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BT ext info bit3 check, set BT NOT to ignore Wlan active!!\n"); - BTC_TRACE(trace_buf); - halbtc8822b2ant_ignore_wlan_act(btcoexist, - FORCE_EXEC, false); - } - } - - } - - - halbtc8822b2ant_update_bt_link_info(btcoexist); - - if (btcoexist->manual_control) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), No run_coexist_mechanism for Manual CTRL\n"); - BTC_TRACE(trace_buf); - return; - } - - if (btcoexist->stop_coex_dm) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], BtInfoNotify(), No run_coexist_mechanism for Stop Coex DM\n"); - BTC_TRACE(trace_buf); - return; - } - - coex_sta->c2h_bt_info_req_sent = false; - - halbtc8822b2ant_run_coexist_mechanism(btcoexist); -} - -void ex_halbtc8822b2ant_rf_status_notify(IN struct btc_coexist *btcoexist, - IN u8 type) -{ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], RF Status notify\n"); - BTC_TRACE(trace_buf); - - if (BTC_RF_ON == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], RF is turned ON!!\n"); - BTC_TRACE(trace_buf); - - coex_sta->wl_rf_off_on_event = true; - btcoexist->stop_coex_dm = false; - - halbtc8822b2ant_post_state_to_bt(btcoexist, - BT_8822B_2ANT_SCOREBOARD_ACTIVE, true); - halbtc8822b2ant_post_state_to_bt(btcoexist, - BT_8822B_2ANT_SCOREBOARD_ONOFF, true); - } else if (BTC_RF_OFF == type) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], RF is turned OFF!!\n"); - BTC_TRACE(trace_buf); - - halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, - FORCE_EXEC, - BT_8822B_2ANT_PHASE_WLAN_OFF); - - halbtc8822b2ant_action_coex_all_off(btcoexist); - - halbtc8822b2ant_post_state_to_bt(btcoexist, - BT_8822B_2ANT_SCOREBOARD_ACTIVE, false); - halbtc8822b2ant_post_state_to_bt(btcoexist, - BT_8822B_2ANT_SCOREBOARD_ONOFF, false); - btcoexist->stop_coex_dm = true; - coex_sta->wl_rf_off_on_event = false; - - } -} - -void ex_halbtc8822b2ant_halt_notify(IN struct btc_coexist *btcoexist) -{ - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], Halt notify\n"); - BTC_TRACE(trace_buf); - - halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, FORCE_EXEC, - BT_8822B_2ANT_PHASE_WLAN_OFF); - - ex_halbtc8822b2ant_media_status_notify(btcoexist, BTC_MEDIA_DISCONNECT); - - halbtc8822b2ant_post_state_to_bt(btcoexist, - BT_8822B_2ANT_SCOREBOARD_ACTIVE, false); - halbtc8822b2ant_post_state_to_bt(btcoexist, - BT_8822B_2ANT_SCOREBOARD_ONOFF, false); -} - -void ex_halbtc8822b2ant_pnp_notify(IN struct btc_coexist *btcoexist, - IN u8 pnp_state) -{ - boolean wifi_under_5g = false; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], Pnp notify\n"); - BTC_TRACE(trace_buf); - - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g); - - if ((BTC_WIFI_PNP_SLEEP == pnp_state) || - (BTC_WIFI_PNP_SLEEP_KEEP_ANT == pnp_state)) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Pnp notify to SLEEP\n"); - BTC_TRACE(trace_buf); - - /* Sinda 20150819, workaround for driver skip leave IPS/LPS to speed up sleep time. */ - /* Driver do not leave IPS/LPS when driver is going to sleep, so BTCoexistence think wifi is still under IPS/LPS */ - /* BT should clear UnderIPS/UnderLPS state to avoid mismatch state after wakeup. */ - coex_sta->under_ips = false; - coex_sta->under_lps = false; - - halbtc8822b2ant_post_state_to_bt(btcoexist, - BT_8822B_2ANT_SCOREBOARD_ACTIVE, false); - halbtc8822b2ant_post_state_to_bt(btcoexist, - BT_8822B_2ANT_SCOREBOARD_ONOFF, false); - - - if (BTC_WIFI_PNP_SLEEP_KEEP_ANT == pnp_state) { - - if (wifi_under_5g) - halbtc8822b2ant_set_ant_path(btcoexist, - BTC_ANT_PATH_AUTO, FORCE_EXEC, - BT_8822B_2ANT_PHASE_5G_RUNTIME); - else - halbtc8822b2ant_set_ant_path(btcoexist, - BTC_ANT_PATH_AUTO, FORCE_EXEC, - BT_8822B_2ANT_PHASE_2G_RUNTIME); - } else { - - halbtc8822b2ant_set_ant_path(btcoexist, BTC_ANT_PATH_AUTO, - FORCE_EXEC, - BT_8822B_2ANT_PHASE_WLAN_OFF); - } - } else if (BTC_WIFI_PNP_WAKE_UP == pnp_state) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], Pnp notify to WAKE UP\n"); - BTC_TRACE(trace_buf); - - halbtc8822b2ant_post_state_to_bt(btcoexist, - BT_8822B_2ANT_SCOREBOARD_ACTIVE, true); - halbtc8822b2ant_post_state_to_bt(btcoexist, - BT_8822B_2ANT_SCOREBOARD_ONOFF, true); - } -} - -void ex_halbtc8822b2ant_periodical(IN struct btc_coexist *btcoexist) -{ - struct btc_board_info *board_info = &btcoexist->board_info; - boolean wifi_busy = false; - u32 bt_patch_ver; - u16 bt_scoreboard_val = 0; - static u8 cnt = 0; - boolean bt_relink_finish = false; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ************* Periodical *************\n"); - BTC_TRACE(trace_buf); - -#if (BT_AUTO_REPORT_ONLY_8822B_2ANT == 0) - halbtc8822b2ant_query_bt_info(btcoexist); -#endif - - halbtc8822b2ant_monitor_bt_ctr(btcoexist); - halbtc8822b2ant_monitor_wifi_ctr(btcoexist); - halbtc8822b2ant_monitor_bt_enable_disable(btcoexist); - -#if 1 - btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); - halbtc8822b2ant_read_score_board(btcoexist, &bt_scoreboard_val); - - if (wifi_busy) { - halbtc8822b2ant_post_state_to_bt(btcoexist, - BT_8822B_2ANT_SCOREBOARD_UNDERTEST, true); - /*for bt lps32 clock offset*/ - if (bt_scoreboard_val & BIT(6)) - halbtc8822b2ant_query_bt_info(btcoexist); - } else { - halbtc8822b2ant_post_state_to_bt(btcoexist, - BT_8822B_2ANT_SCOREBOARD_UNDERTEST, false); - /* - halbtc8822b2ant_post_state_to_bt(btcoexist, - BT_8822B_2ANT_SCOREBOARD_WLBUSY, - false); */ - } -#endif - - if (coex_sta->bt_relink_downcount != 0) { - coex_sta->bt_relink_downcount--; - - if (coex_sta->bt_relink_downcount == 0) - bt_relink_finish = true; - } - - /* for 4-way, DHCP, EAPOL packet */ - if (coex_sta->specific_pkt_period_cnt > 0) { - - coex_sta->specific_pkt_period_cnt--; - - if ((coex_sta->specific_pkt_period_cnt == 0) && - (coex_sta->wifi_is_high_pri_task)) - coex_sta->wifi_is_high_pri_task = false; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "[BTCoex], ***************** Hi-Pri Task = %s*****************\n", - (coex_sta->wifi_is_high_pri_task ? "Yes" : - "No")); - BTC_TRACE(trace_buf); - - } - - if (!coex_sta->bt_disabled) { - if (coex_sta->bt_coex_supported_feature == 0) - btcoexist->btc_get(btcoexist, BTC_GET_U4_SUPPORTED_FEATURE, &coex_sta->bt_coex_supported_feature); - - if ((coex_sta->bt_coex_supported_version == 0) || - (coex_sta->bt_coex_supported_version == 0xffff)) - btcoexist->btc_get(btcoexist, BTC_GET_U4_SUPPORTED_VERSION, &coex_sta->bt_coex_supported_version); - - /*coex_sta->bt_ble_scan_type = btcoexist->btc_get_ble_scan_type_from_bt(btcoexist);*/ - btcoexist->btc_get(btcoexist, BTC_GET_U4_BT_PATCH_VER, &bt_patch_ver); - btcoexist->bt_info.bt_get_fw_ver = bt_patch_ver; - - if (coex_sta->bt_reg_vendor_ac == 0xffff) - coex_sta->bt_reg_vendor_ac = (u16)( - btcoexist->btc_get_bt_reg(btcoexist, 3, - 0xac) & 0xffff); - - if (coex_sta->bt_reg_vendor_ae == 0xffff) - coex_sta->bt_reg_vendor_ae = (u16)( - btcoexist->btc_get_bt_reg(btcoexist, 3, - 0xae) & 0xffff); - } - if (halbtc8822b2ant_is_wifibt_status_changed(btcoexist)) - halbtc8822b2ant_run_coexist_mechanism(btcoexist); -} - - -/*#pragma optimize( "", off )*/ -void ex_halbtc8822b2ant_antenna_detection(IN struct btc_coexist *btcoexist, - IN u32 cent_freq, IN u32 offset, IN u32 span, IN u32 seconds) -{ -#if 0 - static u32 ant_det_count = 0, ant_det_fail_count = 0; - struct btc_board_info *board_info = &btcoexist->board_info; - u16 u16tmp; - u8 AntDetval = 0; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx Ext Call AntennaDetect()!!\n"); - BTC_TRACE(trace_buf); - -#if BT_8822B_2ANT_ANTDET_ENABLE - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx Call AntennaDetect()!!\n"); - BTC_TRACE(trace_buf); - - if (seconds == 0) { - psd_scan->ant_det_try_count = 0; - psd_scan->ant_det_fail_count = 0; - ant_det_count = 0; - ant_det_fail_count = 0; - board_info->btdm_ant_det_finish = false; - board_info->btdm_ant_num_by_ant_det = 1; - return; - } - - if (!board_info->btdm_ant_det_finish) { - psd_scan->ant_det_inteval_count = - psd_scan->ant_det_inteval_count + 2; - - if (psd_scan->ant_det_inteval_count >= - BT_8822B_2ANT_ANTDET_RETRY_INTERVAL) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Antenna Det Timer is up, Try Detect!!\n"); - BTC_TRACE(trace_buf); - - psd_scan->is_AntDet_running = true; - - halbtc8822b2ant_read_score_board(btcoexist, &u16tmp); - - if (u16tmp & BIT( - 2)) { /* Antenna detection is already done before last WL power on */ - board_info->btdm_ant_det_finish = true; - psd_scan->ant_det_try_count = 1; - psd_scan->ant_det_fail_count = 0; - board_info->btdm_ant_num_by_ant_det = (u16tmp & - BIT(3)) ? 1 : 2; - psd_scan->ant_det_result = 12; - - psd_scan->ant_det_psd_scan_peak_val = - btcoexist->btc_get_ant_det_val_from_bt( - btcoexist) * 100; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Antenna Det Result from BT (%d-Ant)\n", - board_info->btdm_ant_num_by_ant_det); - BTC_TRACE(trace_buf); - } else - board_info->btdm_ant_det_finish = - halbtc8822b2ant_psd_antenna_detection_check( - btcoexist); - - btcoexist->bdontenterLPS = false; - - if (board_info->btdm_ant_det_finish) { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Antenna Det Success!!\n"); - BTC_TRACE(trace_buf); - - /*for 8822b, btc_set_bt_trx_mask is just used to - notify BT stop le tx and Ant Det Result , not set BT RF TRx Mask */ - if (psd_scan->ant_det_result != 12) { - - AntDetval = (u8)(( - psd_scan->ant_det_psd_scan_peak_val - / 100) & 0x7f); - - AntDetval = - (board_info->btdm_ant_num_by_ant_det - == 1) ? (AntDetval | 0x80) : - AntDetval; - - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxx AntennaDetect(), Ant Count = %d, PSD Val = %d\n", - ((AntDetval & - 0x80) ? 1 - : 2), AntDetval - & 0x7f); - BTC_TRACE(trace_buf); - - if (btcoexist->btc_set_bt_trx_mask( - btcoexist, AntDetval)) - BTC_SPRINTF(trace_buf, - BT_TMP_BUF_SIZE, - "xxxxxx AntennaDetect(), Notify BT stop le tx by set_bt_trx_mask ok!\n"); - else - BTC_SPRINTF(trace_buf, - BT_TMP_BUF_SIZE, - "xxxxxx AntennaDetect(), Notify BT stop le tx by set_bt_trx_mask fail!\n"); - - BTC_TRACE(trace_buf); - } - - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Antenna Det Fail!!\n"); - BTC_TRACE(trace_buf); - } - - psd_scan->ant_det_inteval_count = 0; - psd_scan->is_AntDet_running = false; - - /* stimulate coex running */ - halbtc8822b2ant_run_coexist_mechanism( - btcoexist); - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Stimulate Coex running\n!!"); - BTC_TRACE(trace_buf); - } else { - BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, - "xxxxxxxxxxxxxxxx AntennaDetect(), Antenna Det Timer is not up! (%d)\n", - psd_scan->ant_det_inteval_count); - BTC_TRACE(trace_buf); - - if (psd_scan->ant_det_inteval_count == 8) - btcoexist->bdontenterLPS = true; - else - btcoexist->bdontenterLPS = false; - } - - } -#endif -#endif - -} - - -void ex_halbtc8822b2ant_display_ant_detection(IN struct btc_coexist *btcoexist) -{ -#if 0 -#if BT_8822B_2ANT_ANTDET_ENABLE - struct btc_board_info *board_info = &btcoexist->board_info; - - if (psd_scan->ant_det_try_count != 0) { - halbtc8822b2ant_psd_show_antenna_detect_result(btcoexist); - - if (board_info->btdm_ant_det_finish) - halbtc8822b2ant_psd_showdata(btcoexist); - } -#endif -#endif -} - - -#endif - -#endif /* #if (RTL8822B_SUPPORT == 1) */ - diff --git a/hal/btc/halbtc8822b2ant.h b/hal/btc/halbtc8822b2ant.h deleted file mode 100644 index 8757334..0000000 --- a/hal/btc/halbtc8822b2ant.h +++ /dev/null @@ -1,493 +0,0 @@ - -#if (BT_SUPPORT == 1 && COEX_SUPPORT == 1) - -#if (RTL8822B_SUPPORT == 1) - -/* ******************************************* - * The following is for 8822B 2Ant BT Co-exist definition - * ******************************************* */ -#define BT_8822B_2ANT_COEX_DBG 1 -#define BT_AUTO_REPORT_ONLY_8822B_2ANT 1 - - - - -#define BT_INFO_8822B_2ANT_B_FTP BIT(7) -#define BT_INFO_8822B_2ANT_B_A2DP BIT(6) -#define BT_INFO_8822B_2ANT_B_HID BIT(5) -#define BT_INFO_8822B_2ANT_B_SCO_BUSY BIT(4) -#define BT_INFO_8822B_2ANT_B_ACL_BUSY BIT(3) -#define BT_INFO_8822B_2ANT_B_INQ_PAGE BIT(2) -#define BT_INFO_8822B_2ANT_B_SCO_ESCO BIT(1) -#define BT_INFO_8822B_2ANT_B_CONNECTION BIT(0) - -#define BTC_RSSI_COEX_THRESH_TOL_8822B_2ANT 2 - - -#define BT_8822B_2ANT_WIFI_RSSI_COEXSWITCH_THRES1 80 /* unit: % WiFi RSSI Threshold for 2-Ant free-run/2-Ant TDMA translation, default = 42 */ -#define BT_8822B_2ANT_BT_RSSI_COEXSWITCH_THRES1 80 /* unit: % BT RSSI Threshold for 2-Ant free-run/2-Ant TDMA translation, default = 46 */ -#define BT_8822B_2ANT_WIFI_RSSI_COEXSWITCH_THRES2 40 /* unit: % WiFi RSSI Threshold for 1-Ant TDMA/1-Ant PS-TDMA translation, default = 42 */ -#define BT_8822B_2ANT_BT_RSSI_COEXSWITCH_THRES2 35 /* unit: % BT RSSI Threshold for 1-Ant TDMA/1-Ant PS-TDMA translation, default = 46 */ -#define BT_8822B_2ANT_DEFAULT_ISOLATION 15 /* unit: dB */ -#define BT_8822B_2ANT_WIFI_MAX_TX_POWER 15 /* unit: dBm */ -#define BT_8822B_2ANT_BT_MAX_TX_POWER 3 /* unit: dBm */ -#define BT_8822B_2ANT_WIFI_SIR_THRES1 -15 /* unit: dB */ -#define BT_8822B_2ANT_WIFI_SIR_THRES2 -30 /* unit: dB */ -#define BT_8822B_2ANT_BT_SIR_THRES1 -15 /* unit: dB */ -#define BT_8822B_2ANT_BT_SIR_THRES2 -30 /* unit: dB */ - - -/* for Antenna detection */ -#define BT_8822B_2ANT_ANTDET_PSDTHRES_BACKGROUND 50 -#define BT_8822B_2ANT_ANTDET_PSDTHRES_2ANT_BADISOLATION 70 -#define BT_8822B_2ANT_ANTDET_PSDTHRES_2ANT_GOODISOLATION 52 -#define BT_8822B_2ANT_ANTDET_PSDTHRES_1ANT 40 -#define BT_8822B_2ANT_ANTDET_RETRY_INTERVAL 10 /* retry timer if ant det is fail, unit: second */ -#define BT_8822B_2ANT_ANTDET_SWEEPPOINT_DELAY 60000 -#define BT_8822B_2ANT_ANTDET_ENABLE 0 -#define BT_8822B_2ANT_ANTDET_BTTXTIME 100 -#define BT_8822B_2ANT_ANTDET_BTTXCHANNEL 39 -#define BT_8822B_2ANT_ANTDET_PSD_SWWEEPCOUNT 50 - - -#define BT_8822B_2ANT_LTECOEX_INDIRECTREG_ACCESS_TIMEOUT 30000 - -enum bt_8822b_2ant_signal_state { - BT_8822B_2ANT_SIG_STA_SET_TO_LOW = 0x0, - BT_8822B_2ANT_SIG_STA_SET_BY_HW = 0x0, - BT_8822B_2ANT_SIG_STA_SET_TO_HIGH = 0x1, - BT_8822B_2ANT_SIG_STA_MAX -}; - -enum bt_8822b_2ant_path_ctrl_owner { - BT_8822B_2ANT_PCO_BTSIDE = 0x0, - BT_8822B_2ANT_PCO_WLSIDE = 0x1, - BT_8822B_2ANT_PCO_MAX -}; - -enum bt_8822b_2ant_gnt_ctrl_type { - BT_8822B_2ANT_GNT_TYPE_CTRL_BY_PTA = 0x0, - BT_8822B_2ANT_GNT_TYPE_CTRL_BY_SW = 0x1, - BT_8822B_2ANT_GNT_TYPE_MAX -}; - -enum bt_8822b_2ant_gnt_ctrl_block { - BT_8822B_2ANT_GNT_BLOCK_RFC_BB = 0x0, - BT_8822B_2ANT_GNT_BLOCK_RFC = 0x1, - BT_8822B_2ANT_GNT_BLOCK_BB = 0x2, - BT_8822B_2ANT_GNT_BLOCK_MAX -}; - -enum bt_8822b_2ant_lte_coex_table_type { - BT_8822B_2ANT_CTT_WL_VS_LTE = 0x0, - BT_8822B_2ANT_CTT_BT_VS_LTE = 0x1, - BT_8822B_2ANT_CTT_MAX -}; - -enum bt_8822b_2ant_lte_break_table_type { - BT_8822B_2ANT_LBTT_WL_BREAK_LTE = 0x0, - BT_8822B_2ANT_LBTT_BT_BREAK_LTE = 0x1, - BT_8822B_2ANT_LBTT_LTE_BREAK_WL = 0x2, - BT_8822B_2ANT_LBTT_LTE_BREAK_BT = 0x3, - BT_8822B_2ANT_LBTT_MAX -}; - -enum bt_info_src_8822b_2ant { - BT_INFO_SRC_8822B_2ANT_WIFI_FW = 0x0, - BT_INFO_SRC_8822B_2ANT_BT_RSP = 0x1, - BT_INFO_SRC_8822B_2ANT_BT_ACTIVE_SEND = 0x2, - BT_INFO_SRC_8822B_2ANT_MAX -}; - -enum bt_8822b_2ant_bt_status { - BT_8822B_2ANT_BT_STATUS_NON_CONNECTED_IDLE = 0x0, - BT_8822B_2ANT_BT_STATUS_CONNECTED_IDLE = 0x1, - BT_8822B_2ANT_BT_STATUS_INQ_PAGE = 0x2, - BT_8822B_2ANT_BT_STATUS_ACL_BUSY = 0x3, - BT_8822B_2ANT_BT_STATUS_SCO_BUSY = 0x4, - BT_8822B_2ANT_BT_STATUS_ACL_SCO_BUSY = 0x5, - BT_8822B_2ANT_BT_STATUS_MAX -}; - -enum bt_8822b_2ant_coex_algo { - BT_8822B_2ANT_COEX_ALGO_UNDEFINED = 0x0, - BT_8822B_2ANT_COEX_ALGO_SCO = 0x1, - BT_8822B_2ANT_COEX_ALGO_HID = 0x2, - BT_8822B_2ANT_COEX_ALGO_A2DP = 0x3, - BT_8822B_2ANT_COEX_ALGO_A2DP_PANHS = 0x4, - BT_8822B_2ANT_COEX_ALGO_PANEDR = 0x5, - BT_8822B_2ANT_COEX_ALGO_PANHS = 0x6, - BT_8822B_2ANT_COEX_ALGO_PANEDR_A2DP = 0x7, - BT_8822B_2ANT_COEX_ALGO_PANEDR_HID = 0x8, - BT_8822B_2ANT_COEX_ALGO_HID_A2DP_PANEDR = 0x9, - BT_8822B_2ANT_COEX_ALGO_HID_A2DP = 0xa, - BT_8822B_2ANT_COEX_ALGO_NOPROFILEBUSY = 0xb, - BT_8822B_2ANT_COEX_ALGO_MAX -}; - -enum bt_8822b_2ant_ext_ant_switch_type { - BT_8822B_2ANT_EXT_ANT_SWITCH_USE_DPDT = 0x0, - BT_8822B_2ANT_EXT_ANT_SWITCH_USE_SPDT = 0x1, - BT_8822B_2ANT_EXT_ANT_SWITCH_NONE = 0x2, - BT_8822B_2ANT_EXT_ANT_SWITCH_MAX -}; - -enum bt_8822b_2ant_ext_ant_switch_ctrl_type { - BT_8822B_2ANT_EXT_ANT_SWITCH_CTRL_BY_BBSW = 0x0, - BT_8822B_2ANT_EXT_ANT_SWITCH_CTRL_BY_PTA = 0x1, - BT_8822B_2ANT_EXT_ANT_SWITCH_CTRL_BY_ANTDIV = 0x2, - BT_8822B_2ANT_EXT_ANT_SWITCH_CTRL_BY_MAC = 0x3, - BT_8822B_2ANT_EXT_ANT_SWITCH_CTRL_BY_BT = 0x4, - BT_8822B_2ANT_EXT_ANT_SWITCH_CTRL_MAX -}; - -enum bt_8822b_2ant_ext_ant_switch_pos_type { - BT_8822B_2ANT_EXT_ANT_SWITCH_MAIN_TO_BT = 0x0, - BT_8822B_2ANT_EXT_ANT_SWITCH_MAIN_TO_WLG = 0x1, - BT_8822B_2ANT_EXT_ANT_SWITCH_MAIN_TO_WLA = 0x2, - BT_8822B_2ANT_EXT_ANT_SWITCH_MAIN_TO_NOCARE = 0x3, - BT_8822B_2ANT_EXT_ANT_SWITCH_MAIN_TO_MAX -}; - -enum bt_8822b_2ant_ext_band_switch_pos_type { - BT_8822B_2ANT_EXT_BAND_SWITCH_TO_WLG = 0x0, - BT_8822B_2ANT_EXT_BAND_SWITCH_TO_WLA = 0x1, - BT_8822B_2ANT_EXT_BAND_SWITCH_TO_MAX -}; - -enum bt_8822b_2ant_int_block { - BT_8822B_2ANT_INT_BLOCK_SWITCH_TO_WLG_OF_BTG = 0x0, - BT_8822B_2ANT_INT_BLOCK_SWITCH_TO_WLG_OF_WLAG = 0x1, - BT_8822B_2ANT_INT_BLOCK_SWITCH_TO_WLA_OF_WLAG = 0x2, - BT_8822B_2ANT_INT_BLOCK_SWITCH_TO_MAX -}; - -enum bt_8822b_2ant_phase { - BT_8822B_2ANT_PHASE_COEX_INIT = 0x0, - BT_8822B_2ANT_PHASE_WLANONLY_INIT = 0x1, - BT_8822B_2ANT_PHASE_WLAN_OFF = 0x2, - BT_8822B_2ANT_PHASE_2G_RUNTIME = 0x3, - BT_8822B_2ANT_PHASE_5G_RUNTIME = 0x4, - BT_8822B_2ANT_PHASE_BTMPMODE = 0x5, - BT_8822B_2ANT_PHASE_ANTENNA_DET = 0x6, - BT_8822B_2ANT_PHASE_COEX_POWERON = 0x7, - BT_8822B_2ANT_PHASE_2G_RUNTIME_CONCURRENT = 0x8, - BT_8822B_2ANT_PHASE_MAX -}; - -/*ADD SCOREBOARD TO FIX BT LPS 32K ISSUE WHILE WL BUSY*/ - -enum bt_8822b_2ant_Scoreboard { - BT_8822B_2ANT_SCOREBOARD_ACTIVE = BIT(0), - BT_8822B_2ANT_SCOREBOARD_ONOFF = BIT(1), - BT_8822B_2ANT_SCOREBOARD_SCAN = BIT(2), - BT_8822B_2ANT_SCOREBOARD_UNDERTEST = BIT(3), - BT_8822B_2ANT_SCOREBOARD_WLBUSY = BIT(6) -}; - - - - - -struct coex_dm_8822b_2ant { - /* hw setting */ - u32 pre_ant_pos_type; - u32 cur_ant_pos_type; - /* fw mechanism */ - u8 pre_bt_dec_pwr_lvl; - u8 cur_bt_dec_pwr_lvl; - u8 pre_fw_dac_swing_lvl; - u8 cur_fw_dac_swing_lvl; - boolean cur_ignore_wlan_act; - boolean pre_ignore_wlan_act; - u8 pre_ps_tdma; - u8 cur_ps_tdma; - u8 ps_tdma_para[5]; - u8 ps_tdma_du_adj_type; - boolean reset_tdma_adjust; - boolean pre_ps_tdma_on; - boolean cur_ps_tdma_on; - boolean pre_bt_auto_report; - boolean cur_bt_auto_report; - - /* sw mechanism */ - boolean pre_rf_rx_lpf_shrink; - boolean cur_rf_rx_lpf_shrink; - u32 bt_rf_0x1e_backup; - boolean pre_low_penalty_ra; - boolean cur_low_penalty_ra; - boolean pre_dac_swing_on; - u32 pre_dac_swing_lvl; - boolean cur_dac_swing_on; - u32 cur_dac_swing_lvl; - boolean pre_adc_back_off; - boolean cur_adc_back_off; - boolean pre_agc_table_en; - boolean cur_agc_table_en; - u32 pre_val0x6c0; - u32 cur_val0x6c0; - u32 pre_val0x6c4; - u32 cur_val0x6c4; - u32 pre_val0x6c8; - u32 cur_val0x6c8; - u8 pre_val0x6cc; - u8 cur_val0x6cc; - boolean limited_dig; - - /* algorithm related */ - u8 pre_algorithm; - u8 cur_algorithm; - u8 bt_status; - u8 wifi_chnl_info[3]; - - boolean need_recover0x948; - u32 backup0x948; - - u8 pre_lps; - u8 cur_lps; - u8 pre_rpwm; - u8 cur_rpwm; - - boolean is_switch_to_1dot5_ant; - u8 switch_thres_offset; - u32 arp_cnt; - - u32 pre_ext_ant_switch_status; - u32 cur_ext_ant_switch_status; - - u8 pre_ext_band_switch_status; - u8 cur_ext_band_switch_status; - - u8 pre_int_block_status; - u8 cur_int_block_status; -}; - -struct coex_sta_8822b_2ant { - boolean bt_disabled; - boolean bt_link_exist; - boolean sco_exist; - boolean a2dp_exist; - boolean hid_exist; - boolean pan_exist; - - boolean under_lps; - boolean under_ips; - u32 high_priority_tx; - u32 high_priority_rx; - u32 low_priority_tx; - u32 low_priority_rx; - u8 bt_rssi; - boolean bt_tx_rx_mask; - u8 pre_bt_rssi_state; - u8 pre_wifi_rssi_state[4]; - boolean c2h_bt_info_req_sent; - u8 bt_info_c2h[BT_INFO_SRC_8822B_2ANT_MAX][10]; - u32 bt_info_c2h_cnt[BT_INFO_SRC_8822B_2ANT_MAX]; - boolean bt_whck_test; - boolean c2h_bt_inquiry_page; - boolean c2h_bt_remote_name_req; - u8 bt_retry_cnt; - u8 bt_info_ext; - u8 bt_info_ext2; - u32 pop_event_cnt; - u8 scan_ap_num; - - u32 crc_ok_cck; - u32 crc_ok_11g; - u32 crc_ok_11n; - u32 crc_ok_11n_agg; - u32 crc_ok_11n_vht; - - u32 crc_err_cck; - u32 crc_err_11g; - u32 crc_err_11n; - u32 crc_err_11n_agg; - u32 crc_err_11n_vht; - - boolean cck_lock; - boolean pre_ccklock; - boolean cck_ever_lock; - - u8 coex_table_type; - boolean force_lps_on; - - u8 dis_ver_info_cnt; - - u8 a2dp_bit_pool; - u8 cut_version; - - boolean concurrent_rx_mode_on; - - u16 score_board; - u8 isolation_btween_wb; /* 0~ 50 */ - u8 wifi_coex_thres; - u8 bt_coex_thres; - u8 wifi_coex_thres2; - u8 bt_coex_thres2; - - u8 num_of_profile; - boolean acl_busy; - boolean wl_rf_off_on_event; - boolean bt_create_connection; - boolean wifi_is_high_pri_task; - u32 specific_pkt_period_cnt; - u32 bt_coex_supported_feature; - u32 bt_coex_supported_version; - - u8 bt_ble_scan_type; - u8 bt_ble_scan_para[3]; - - boolean run_time_state; - boolean freeze_coexrun_by_btinfo; - - boolean is_A2DP_3M; - boolean voice_over_HOGP; - u8 bt_info; - boolean is_autoslot; - u8 forbidden_slot; - u8 hid_busy_num; - u8 hid_pair_cnt; - - u32 cnt_RemoteNameReq; - u32 cnt_setupLink; - u32 cnt_ReInit; - u32 cnt_IgnWlanAct; - u32 cnt_Page; - - u16 bt_reg_vendor_ac; - u16 bt_reg_vendor_ae; - - boolean is_setupLink; - u8 wl_noisy_level; - u32 gnt_error_cnt; - - u8 bt_afh_map[10]; - u8 bt_relink_downcount; -}; - - -#define BT_8822B_2ANT_EXT_BAND_SWITCH_USE_DPDT 0 -#define BT_8822B_2ANT_EXT_BAND_SWITCH_USE_SPDT 1 - - -struct rfe_type_8822b_2ant { - - u8 rfe_module_type; - boolean ext_ant_switch_exist; - u8 ext_ant_switch_type; /* 0:DPDT, 1:SPDT */ - u8 ext_ant_switch_ctrl_polarity; /* iF 0: DPDT_P=0, DPDT_N=1 => BTG to Main, WL_A+G to Aux */ - - boolean ext_band_switch_exist; - u8 ext_band_switch_type; /* 0:DPDT, 1:SPDT */ - u8 ext_band_switch_ctrl_polarity; - - boolean wlg_Locate_at_btg; /* If true: WLG at BTG, If false: WLG at WLAG */ - - boolean ext_ant_switch_diversity; /* If diversity on */ -}; - -#define BT_8822B_2ANT_ANTDET_PSD_POINTS 256 /* MAX:1024 */ -#define BT_8822B_2ANT_ANTDET_PSD_AVGNUM 1 /* MAX:3 */ -#define BT_8822B_2ANT_ANTDET_BUF_LEN 16 - -struct psdscan_sta_8822b_2ant { - - u32 ant_det_bt_le_channel; /* BT LE Channel ex:2412 */ - u32 ant_det_bt_tx_time; - u32 ant_det_pre_psdscan_peak_val; - boolean ant_det_is_ant_det_available; - u32 ant_det_psd_scan_peak_val; - boolean ant_det_is_btreply_available; - u32 ant_det_psd_scan_peak_freq; - - u8 ant_det_result; - u8 ant_det_peak_val[BT_8822B_2ANT_ANTDET_BUF_LEN]; - u8 ant_det_peak_freq[BT_8822B_2ANT_ANTDET_BUF_LEN]; - u32 ant_det_try_count; - u32 ant_det_fail_count; - u32 ant_det_inteval_count; - u32 ant_det_thres_offset; - - u32 real_cent_freq; - s32 real_offset; - u32 real_span; - - u32 psd_band_width; /* unit: Hz */ - u32 psd_point; /* 128/256/512/1024 */ - u32 psd_report[1024]; /* unit:dB (20logx), 0~255 */ - u32 psd_report_max_hold[1024]; /* unit:dB (20logx), 0~255 */ - u32 psd_start_point; - u32 psd_stop_point; - u32 psd_max_value_point; - u32 psd_max_value; - u32 psd_max_value2; - u32 psd_avg_value; /* filter loop_max_value that below BT_8822B_1ANT_ANTDET_PSDTHRES_1ANT, and average the rest*/ - u32 psd_loop_max_value[BT_8822B_2ANT_ANTDET_PSD_SWWEEPCOUNT]; /*max value in each loop */ - u32 psd_start_base; - u32 psd_avg_num; /* 1/8/16/32 */ - u32 psd_gen_count; - boolean is_AntDet_running; - boolean is_psd_show_max_only; -}; - - -/* ******************************************* - * The following is interface which will notify coex module. - * ******************************************* */ -void ex_halbtc8822b2ant_power_on_setting(IN struct btc_coexist *btcoexist); -void ex_halbtc8822b2ant_pre_load_firmware(IN struct btc_coexist *btcoexist); -void ex_halbtc8822b2ant_init_hw_config(IN struct btc_coexist *btcoexist, - IN boolean wifi_only); -void ex_halbtc8822b2ant_init_coex_dm(IN struct btc_coexist *btcoexist); -void ex_halbtc8822b2ant_ips_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8822b2ant_lps_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8822b2ant_scan_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8822b2ant_switchband_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8822b2ant_connect_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8822b2ant_media_status_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8822b2ant_specific_packet_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8822b2ant_bt_info_notify(IN struct btc_coexist *btcoexist, - IN u8 *tmp_buf, IN u8 length); -void ex_halbtc8822b2ant_rf_status_notify(IN struct btc_coexist *btcoexist, - IN u8 type); -void ex_halbtc8822b2ant_halt_notify(IN struct btc_coexist *btcoexist); -void ex_halbtc8822b2ant_pnp_notify(IN struct btc_coexist *btcoexist, - IN u8 pnp_state); -void ex_halbtc8822b2ant_periodical(IN struct btc_coexist *btcoexist); -void ex_halbtc8822b2ant_display_coex_info(IN struct btc_coexist *btcoexist); -void ex_halbtc8822b2ant_antenna_detection(IN struct btc_coexist *btcoexist, - IN u32 cent_freq, IN u32 offset, IN u32 span, IN u32 seconds); -void ex_halbtc8822b2ant_display_ant_detection(IN struct btc_coexist *btcoexist); - - -#else -#define ex_halbtc8822b2ant_power_on_setting(btcoexist) -#define ex_halbtc8822b2ant_pre_load_firmware(btcoexist) -#define ex_halbtc8822b2ant_init_hw_config(btcoexist, wifi_only) -#define ex_halbtc8822b2ant_init_coex_dm(btcoexist) -#define ex_halbtc8822b2ant_ips_notify(btcoexist, type) -#define ex_halbtc8822b2ant_lps_notify(btcoexist, type) -#define ex_halbtc8822b2ant_scan_notify(btcoexist, type) -#define ex_halbtc8822b2ant_switchband_notify(btcoexist, type) -#define ex_halbtc8822b2ant_connect_notify(btcoexist, type) -#define ex_halbtc8822b2ant_media_status_notify(btcoexist, type) -#define ex_halbtc8822b2ant_specific_packet_notify(btcoexist, type) -#define ex_halbtc8822b2ant_bt_info_notify(btcoexist, tmp_buf, length) -#define ex_halbtc8822b2ant_rf_status_notify(btcoexist, type) -#define ex_halbtc8822b2ant_halt_notify(btcoexist) -#define ex_halbtc8822b2ant_pnp_notify(btcoexist, pnp_state) -#define ex_halbtc8822b2ant_periodical(btcoexist) -#define ex_halbtc8822b2ant_display_coex_info(btcoexist) -#define ex_halbtc8822b2ant_display_ant_detection(btcoexist) -#define ex_halbtc8822b2ant_antenna_detection(btcoexist, cent_freq, offset, span, seconds) -#endif - -#endif - diff --git a/hal/btc/halbtc8822bwifionly.c b/hal/btc/halbtc8822bwifionly.c deleted file mode 100644 index 35004d7..0000000 --- a/hal/btc/halbtc8822bwifionly.c +++ /dev/null @@ -1,54 +0,0 @@ -#include "mp_precomp.h" - - -VOID -ex_hal8822b_wifi_only_hw_config( - IN struct wifi_only_cfg *pwifionlycfg - ) -{ - /*BB control*/ - halwifionly_phy_set_bb_reg(pwifionlycfg, 0x4c, 0x01800000, 0x2); - /*SW control*/ - halwifionly_phy_set_bb_reg(pwifionlycfg, 0xcb4, 0xff, 0x77); - /*antenna mux switch */ - halwifionly_phy_set_bb_reg(pwifionlycfg, 0x974, 0x300, 0x3); - - halwifionly_phy_set_bb_reg(pwifionlycfg, 0x1990, 0x300, 0x0); - - halwifionly_phy_set_bb_reg(pwifionlycfg, 0xcbc, 0x80000, 0x0); - /*switch to WL side controller and gnt_wl gnt_bt debug signal */ - halwifionly_phy_set_bb_reg(pwifionlycfg, 0x70, 0xff000000, 0x0e); - /*gnt_wl=1 , gnt_bt=0*/ - halwifionly_phy_set_bb_reg(pwifionlycfg, 0x1704, 0xffffffff, 0x7700); - halwifionly_phy_set_bb_reg(pwifionlycfg, 0x1700, 0xffffffff, 0xc00f0038); -} - -VOID -ex_hal8822b_wifi_only_scannotify( - IN struct wifi_only_cfg *pwifionlycfg, - IN u1Byte is_5g - ) -{ - hal8822b_wifi_only_switch_antenna(pwifionlycfg, is_5g); -} - -VOID -ex_hal8822b_wifi_only_switchbandnotify( - IN struct wifi_only_cfg *pwifionlycfg, - IN u1Byte is_5g - ) -{ - hal8822b_wifi_only_switch_antenna(pwifionlycfg, is_5g); -} - -VOID -hal8822b_wifi_only_switch_antenna(IN struct wifi_only_cfg *pwifionlycfg, - IN u1Byte is_5g - ) -{ - - if (is_5g) - halwifionly_phy_set_bb_reg(pwifionlycfg, 0xcbc, 0x300, 0x1); - else - halwifionly_phy_set_bb_reg(pwifionlycfg, 0xcbc, 0x300, 0x2); -} diff --git a/hal/btc/halbtc8822bwifionly.h b/hal/btc/halbtc8822bwifionly.h deleted file mode 100644 index 3f5ef3b..0000000 --- a/hal/btc/halbtc8822bwifionly.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef __INC_HAL8822BWIFIONLYHWCFG_H -#define __INC_HAL8822BWIFIONLYHWCFG_H - -VOID -ex_hal8822b_wifi_only_hw_config( - IN struct wifi_only_cfg *pwifionlycfg - ); -VOID -ex_hal8822b_wifi_only_scannotify( - IN struct wifi_only_cfg *pwifionlycfg, - IN u1Byte is_5g - ); -VOID -ex_hal8822b_wifi_only_switchbandnotify( - IN struct wifi_only_cfg *pwifionlycfg, - IN u1Byte is_5g - ); -VOID -hal8822b_wifi_only_switch_antenna(IN struct wifi_only_cfg *pwifionlycfg, - IN u1Byte is_5g - ); -#endif diff --git a/hal/btc/mp_precomp.h b/hal/btc/mp_precomp.h index 3c125ae..2ad03a4 100644 --- a/hal/btc/mp_precomp.h +++ b/hal/btc/mp_precomp.h @@ -61,26 +61,5 @@ extern u4Byte GLBtcDbgType[]; #endif #include "halbtcoutsrc.h" -#include "halbtc8192e1ant.h" -#include "halbtc8192e2ant.h" -#include "halbtc8723b1ant.h" -#include "halbtc8723b2ant.h" -#include "halbtc8812a1ant.h" -#include "halbtc8812a2ant.h" -#include "halbtc8821a1ant.h" -#include "halbtc8821a2ant.h" -#include "halbtc8703b1ant.h" -#include "halbtc8723d1ant.h" -#include "halbtc8723d2ant.h" -#include "halbtc8822b1ant.h" -#include "halbtc8822b2ant.h" -#include "halbtc8821c1ant.h" -#include "halbtc8821c2ant.h" - -/* for wifi only mode */ -#include "hal_btcoex_wifionly.h" -#include "halbtc8723bwifionly.h" -#include "halbtc8822bwifionly.h" -#include "halbtc8821cwifionly.h" #endif /* __MP_PRECOMP_H__ */ diff --git a/hal/hal_btcoex_wifionly.c b/hal/hal_btcoex_wifionly.c index 077c24d..b669ca8 100644 --- a/hal/hal_btcoex_wifionly.c +++ b/hal/hal_btcoex_wifionly.c @@ -94,11 +94,6 @@ void hal_btcoex_wifionly_switchband_notify(PADAPTER padapter) if (pHalData->current_band_type == BAND_ON_5G) is_5g = _TRUE; - - if (IS_HARDWARE_TYPE_8822B(padapter)) - ex_hal8822b_wifi_only_switchbandnotify(&GLBtCoexistWifiOnly, is_5g); - else if (IS_HARDWARE_TYPE_8821C(padapter)) - ex_hal8821c_wifi_only_switchbandnotify(&GLBtCoexistWifiOnly, is_5g); } void hal_btcoex_wifionly_scan_notify(PADAPTER padapter) @@ -108,23 +103,11 @@ void hal_btcoex_wifionly_scan_notify(PADAPTER padapter) if (pHalData->current_band_type == BAND_ON_5G) is_5g = _TRUE; - - if (IS_HARDWARE_TYPE_8822B(padapter)) - ex_hal8822b_wifi_only_scannotify(&GLBtCoexistWifiOnly, is_5g); - else if (IS_HARDWARE_TYPE_8821C(padapter)) - ex_hal8821c_wifi_only_scannotify(&GLBtCoexistWifiOnly, is_5g); } void hal_btcoex_wifionly_hw_config(PADAPTER padapter) { struct wifi_only_cfg *pwifionlycfg = &GLBtCoexistWifiOnly; - - if (IS_HARDWARE_TYPE_8723B(padapter)) - ex_hal8723b_wifi_only_hw_config(pwifionlycfg); - else if (IS_HARDWARE_TYPE_8822B(padapter)) - ex_hal8822b_wifi_only_hw_config(pwifionlycfg); - else if (IS_HARDWARE_TYPE_8821C(padapter)) - ex_hal8821c_wifi_only_hw_config(pwifionlycfg); } void hal_btcoex_wifionly_initlizevariables(PADAPTER padapter) diff --git a/hal/hal_halmac.c b/hal/hal_halmac.c deleted file mode 100644 index 3e1490c..0000000 --- a/hal/hal_halmac.c +++ /dev/null @@ -1,2635 +0,0 @@ -/****************************************************************************** - * - * Copyright(c) 2015 - 2016 Realtek Corporation. All rights reserved. - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of version 2 of the GNU General Public License as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA - * - * - ******************************************************************************/ -#define _HAL_HALMAC_C_ - -#include /* PADAPTER, struct dvobj_priv, SDIO_ERR_VAL8 and etc. */ -#include /* efuse, PHAL_DATA_TYPE and etc. */ -#include "halmac/halmac_api.h" /* HALMAC_FW_SIZE_MAX_88XX and etc. */ -#include "hal_halmac.h" /* dvobj_to_halmac() and ect. */ - -#define DEFAULT_INDICATOR_TIMELMT 1000 /* ms */ -#define FIRMWARE_MAX_SIZE HALMAC_FW_SIZE_MAX_88XX - -/* - * Driver API for HALMAC operations - */ - -#ifdef CONFIG_SDIO_HCI -#include - -static u8 _halmac_mac_reg_page0_chk(const char *func, struct dvobj_priv *dvobj, u32 offset) -{ -#if defined(CONFIG_IO_CHECK_IN_ANA_LOW_CLK) && defined(CONFIG_LPS_LCLK) - struct pwrctrl_priv *pwrpriv = &dvobj->pwrctl_priv; - u32 mac_reg_offset = 0; - - if (pwrpriv->pwr_mode == PS_MODE_ACTIVE) - return _TRUE; - - if (pwrpriv->rpwm >= PS_STATE_S2) - return _TRUE; - - if (offset & (WLAN_IOREG_DEVICE_ID << 13)) { /*WLAN_IOREG_OFFSET*/ - mac_reg_offset = offset & HALMAC_WLAN_MAC_REG_MSK; - if (mac_reg_offset < 0x100) { - RTW_ERR(FUNC_ADPT_FMT "access MAC REG -0x%04x in PS-mode:0x%02x\n", - FUNC_ADPT_ARG(dvobj_get_primary_adapter(dvobj)), mac_reg_offset, pwrpriv->pwr_mode); - rtw_warn_on(1); - return _FALSE; - } - } -#endif - return _TRUE; -} - -static u8 _halmac_sdio_cmd52_read(void *p, u32 offset) -{ - struct dvobj_priv *d; - u8 val; - u8 ret; - - - d = (struct dvobj_priv *)p; - _halmac_mac_reg_page0_chk(__func__, d, offset); - ret = rtw_sdio_read_cmd52(d, offset, &val, 1); - if (_FAIL == ret) { - RTW_INFO("%s: [ERROR] I/O FAIL!\n", __func__); - return SDIO_ERR_VAL8; - } - - return val; -} - -static void _halmac_sdio_cmd52_write(void *p, u32 offset, u8 val) -{ - struct dvobj_priv *d; - u8 ret; - - - d = (struct dvobj_priv *)p; - _halmac_mac_reg_page0_chk(__func__, d, offset); - ret = rtw_sdio_write_cmd52(d, offset, &val, 1); - if (_FAIL == ret) - RTW_INFO("%s: [ERROR] I/O FAIL!\n", __func__); -} - -static u8 _halmac_sdio_reg_read_8(void *p, u32 offset) -{ - struct dvobj_priv *d; - u8 *pbuf; - u8 val; - int err; - - - d = (struct dvobj_priv *)p; - val = SDIO_ERR_VAL8; - _halmac_mac_reg_page0_chk(__func__, d, offset); - pbuf = rtw_zmalloc(1); - if (!pbuf) - return val; - - err = d->intf_ops->read(d, offset, pbuf, 1, 0); - if (err) { - RTW_INFO("%s: [ERROR] I/O FAIL!\n", __func__); - goto exit; - } - - val = *pbuf; - -exit: - rtw_mfree(pbuf, 1); - - return val; -} - -static u16 _halmac_sdio_reg_read_16(void *p, u32 offset) -{ - struct dvobj_priv *d; - u8 *pbuf; - u16 val; - int err; - - - d = (struct dvobj_priv *)p; - val = SDIO_ERR_VAL16; - _halmac_mac_reg_page0_chk(__func__, d, offset); - pbuf = rtw_zmalloc(2); - if (!pbuf) - return val; - - err = d->intf_ops->read(d, offset, pbuf, 2, 0); - if (err) { - RTW_INFO("%s: [ERROR] I/O FAIL!\n", __func__); - goto exit; - } - - val = le16_to_cpu(*(u16 *)pbuf); - -exit: - rtw_mfree(pbuf, 2); - - return val; -} - -static u32 _halmac_sdio_reg_read_32(void *p, u32 offset) -{ - struct dvobj_priv *d; - u8 *pbuf; - u32 val; - int err; - - - d = (struct dvobj_priv *)p; - val = SDIO_ERR_VAL32; - _halmac_mac_reg_page0_chk(__func__, d, offset); - pbuf = rtw_zmalloc(4); - if (!pbuf) - return val; - - err = d->intf_ops->read(d, offset, pbuf, 4, 0); - if (err) { - RTW_INFO("%s: [ERROR] I/O FAIL!\n", __func__); - goto exit; - } - - val = le32_to_cpu(*(u32 *)pbuf); - -exit: - rtw_mfree(pbuf, 4); - - return val; -} - -static u8 _halmac_sdio_reg_read_n(void *p, u32 offset, u32 size, u8 *data) -{ - struct dvobj_priv *d = (struct dvobj_priv *)p; - PSDIO_DATA psdio = &d->intf_data; - - u8 *pbuf; - int err; - u8 rst = _FALSE; - u32 sdio_read_size; - - sdio_read_size = RND4(size); - if (sdio_read_size > psdio->block_transfer_len) - sdio_read_size = _RND(sdio_read_size, psdio->block_transfer_len); - - pbuf = rtw_zmalloc(sdio_read_size); - if ((!pbuf) || (!data)) - return rst; - - err = d->intf_ops->read(d, offset, pbuf, sdio_read_size, 0); - if (err) { - RTW_ERR("%s: [ERROR] I/O FAIL!\n", __func__); - goto exit; - } - - _rtw_memcpy(data, pbuf, size); - rst = _TRUE; -exit: - rtw_mfree(pbuf, sdio_read_size); - - return rst; -} - -static void _halmac_sdio_reg_write_8(void *p, u32 offset, u8 val) -{ - struct dvobj_priv *d; - u8 *pbuf; - int err; - - - d = (struct dvobj_priv *)p; - _halmac_mac_reg_page0_chk(__func__, d, offset); - pbuf = rtw_zmalloc(1); - if (!pbuf) - return; - _rtw_memcpy(pbuf, &val, 1); - - err = d->intf_ops->write(d, offset, pbuf, 1, 0); - if (err) - RTW_INFO("%s: [ERROR] I/O FAIL!\n", __func__); - - rtw_mfree(pbuf, 1); -} - -static void _halmac_sdio_reg_write_16(void *p, u32 offset, u16 val) -{ - struct dvobj_priv *d; - u8 *pbuf; - int err; - - - d = (struct dvobj_priv *)p; - _halmac_mac_reg_page0_chk(__func__, d, offset); - val = cpu_to_le16(val); - pbuf = rtw_zmalloc(2); - if (!pbuf) - return; - _rtw_memcpy(pbuf, &val, 2); - - err = d->intf_ops->write(d, offset, pbuf, 2, 0); - if (err) - RTW_INFO("%s: [ERROR] I/O FAIL!\n", __func__); - - rtw_mfree(pbuf, 2); -} - -static void _halmac_sdio_reg_write_32(void *p, u32 offset, u32 val) -{ - struct dvobj_priv *d; - u8 *pbuf; - int err; - - - d = (struct dvobj_priv *)p; - _halmac_mac_reg_page0_chk(__func__, d, offset); - val = cpu_to_le32(val); - pbuf = rtw_zmalloc(4); - if (!pbuf) - return; - _rtw_memcpy(pbuf, &val, 4); - - err = d->intf_ops->write(d, offset, pbuf, 4, 0); - if (err) - RTW_INFO("%s: [ERROR] I/O FAIL!\n", __func__); - - rtw_mfree(pbuf, 4); -} - -#else /* !CONFIG_SDIO_HCI */ - -static u8 _halmac_reg_read_8(void *p, u32 offset) -{ - struct dvobj_priv *d; - PADAPTER adapter; - - - d = (struct dvobj_priv *)p; - adapter = dvobj_get_primary_adapter(d); - - return rtw_read8(adapter, offset); -} - -static u16 _halmac_reg_read_16(void *p, u32 offset) -{ - struct dvobj_priv *d; - PADAPTER adapter; - - - d = (struct dvobj_priv *)p; - adapter = dvobj_get_primary_adapter(d); - - return rtw_read16(adapter, offset); -} - -static u32 _halmac_reg_read_32(void *p, u32 offset) -{ - struct dvobj_priv *d; - PADAPTER adapter; - - - d = (struct dvobj_priv *)p; - adapter = dvobj_get_primary_adapter(d); - - return rtw_read32(adapter, offset); -} - -static void _halmac_reg_write_8(void *p, u32 offset, u8 val) -{ - struct dvobj_priv *d; - PADAPTER adapter; - int err; - - - d = (struct dvobj_priv *)p; - adapter = dvobj_get_primary_adapter(d); - - err = rtw_write8(adapter, offset, val); - if (err == _FAIL) - RTW_INFO("%s: [ERROR] I/O FAIL!\n", __func__); -} - -static void _halmac_reg_write_16(void *p, u32 offset, u16 val) -{ - struct dvobj_priv *d; - PADAPTER adapter; - int err; - - - d = (struct dvobj_priv *)p; - adapter = dvobj_get_primary_adapter(d); - - err = rtw_write16(adapter, offset, val); - if (err == _FAIL) - RTW_INFO("%s: [ERROR] I/O FAIL!\n", __func__); -} - -static void _halmac_reg_write_32(void *p, u32 offset, u32 val) -{ - struct dvobj_priv *d; - PADAPTER adapter; - int err; - - - d = (struct dvobj_priv *)p; - adapter = dvobj_get_primary_adapter(d); - - err = rtw_write32(adapter, offset, val); - if (err == _FAIL) - RTW_INFO("%s: [ERROR] I/O FAIL!\n", __func__); -} -#endif /* !CONFIG_SDIO_HCI */ - -static u8 _halmac_mfree(void *p, void *buffer, u32 size) -{ - rtw_mfree(buffer, size); - return _TRUE; -} - -static void *_halmac_malloc(void *p, u32 size) -{ - return rtw_zmalloc(size); -} - -static u8 _halmac_memcpy(void *p, void *dest, void *src, u32 size) -{ - _rtw_memcpy(dest, src, size); - return _TRUE; -} - -static u8 _halmac_memset(void *p, void *addr, u8 value, u32 size) -{ - _rtw_memset(addr, value, size); - return _TRUE; -} - -static void _halmac_udelay(void *p, u32 us) -{ - rtw_udelay_os(us); -} - -static u8 _halmac_mutex_init(void *p, HALMAC_MUTEX *pMutex) -{ - _rtw_mutex_init(pMutex); - return _TRUE; -} - -static u8 _halmac_mutex_deinit(void *p, HALMAC_MUTEX *pMutex) -{ - _rtw_mutex_free(pMutex); - return _TRUE; -} - -static u8 _halmac_mutex_lock(void *p, HALMAC_MUTEX *pMutex) -{ - int err; - - err = _enter_critical_mutex(pMutex, NULL); - if (err) - return _FALSE; - - return _TRUE; -} - -static u8 _halmac_mutex_unlock(void *p, HALMAC_MUTEX *pMutex) -{ - _exit_critical_mutex(pMutex, NULL); - return _TRUE; -} - -static u8 _halmac_msg_print(void *p, u32 msg_type, u8 msg_level, s8 *fmt, ...) -{ -#define MSG_LEN 100 -#define MSG_PREFIX "[HALMAC]" - va_list args; - u8 str[MSG_LEN] = {0}; - - - str[0] = '\n'; - va_start(args, fmt); - vsnprintf(str, MSG_LEN, fmt, args); - va_end(args); - - if (msg_level <= HALMAC_DBG_ERR) - RTW_ERR(MSG_PREFIX "%s", str); - else if (msg_level <= HALMAC_DBG_WARN) - RTW_WARN(MSG_PREFIX "%s", str); - else - RTW_DBG(MSG_PREFIX "%s", str); - - return _TRUE; -} - -static u8 _halmac_buff_print(void *p, u32 msg_type, u8 msg_level, s8 *buf, u32 size) -{ -#define MSG_PREFIX "[HALMAC]" - - if (msg_level <= HALMAC_DBG_WARN) - RTW_INFO_DUMP(MSG_PREFIX, buf, size); - else - RTW_DBG_DUMP(MSG_PREFIX, buf, size); - - return _TRUE; -} - - -const char *const RTW_HALMAC_FEATURE_NAME[] = { - "HALMAC_FEATURE_CFG_PARA", - "HALMAC_FEATURE_DUMP_PHYSICAL_EFUSE", - "HALMAC_FEATURE_DUMP_LOGICAL_EFUSE", - "HALMAC_FEATURE_UPDATE_PACKET", - "HALMAC_FEATURE_UPDATE_DATAPACK", - "HALMAC_FEATURE_RUN_DATAPACK", - "HALMAC_FEATURE_CHANNEL_SWITCH", - "HALMAC_FEATURE_IQK", - "HALMAC_FEATURE_POWER_TRACKING", - "HALMAC_FEATURE_PSD", - "HALMAC_FEATURE_ALL" -}; - -static inline u8 is_valid_id_status(HALMAC_FEATURE_ID id, HALMAC_CMD_PROCESS_STATUS status) -{ - switch (id) { - case HALMAC_FEATURE_CFG_PARA: - RTW_INFO("%s: %s\n", __func__, RTW_HALMAC_FEATURE_NAME[id]); - break; - case HALMAC_FEATURE_DUMP_PHYSICAL_EFUSE: - RTW_INFO("%s: %s\n", __func__, RTW_HALMAC_FEATURE_NAME[id]); - if (HALMAC_CMD_PROCESS_DONE != status) - RTW_INFO("%s: id(%d) unspecified status(%d)!\n", - __func__, id, status); - break; - case HALMAC_FEATURE_DUMP_LOGICAL_EFUSE: - RTW_INFO("%s: %s\n", __func__, RTW_HALMAC_FEATURE_NAME[id]); - if (HALMAC_CMD_PROCESS_DONE != status) - RTW_INFO("%s: id(%d) unspecified status(%d)!\n", - __func__, id, status); - break; - case HALMAC_FEATURE_UPDATE_PACKET: - RTW_INFO("%s: %s\n", __func__, RTW_HALMAC_FEATURE_NAME[id]); - break; - case HALMAC_FEATURE_UPDATE_DATAPACK: - RTW_INFO("%s: %s\n", __func__, RTW_HALMAC_FEATURE_NAME[id]); - break; - case HALMAC_FEATURE_RUN_DATAPACK: - RTW_INFO("%s: %s\n", __func__, RTW_HALMAC_FEATURE_NAME[id]); - break; - case HALMAC_FEATURE_CHANNEL_SWITCH: - RTW_INFO("%s: %s\n", __func__, RTW_HALMAC_FEATURE_NAME[id]); - break; - case HALMAC_FEATURE_IQK: - RTW_INFO("%s: %s\n", __func__, RTW_HALMAC_FEATURE_NAME[id]); - break; - case HALMAC_FEATURE_POWER_TRACKING: - RTW_INFO("%s: %s\n", __func__, RTW_HALMAC_FEATURE_NAME[id]); - break; - case HALMAC_FEATURE_PSD: - RTW_INFO("%s: %s\n", __func__, RTW_HALMAC_FEATURE_NAME[id]); - break; - case HALMAC_FEATURE_ALL: - RTW_INFO("%s: %s\n", __func__, RTW_HALMAC_FEATURE_NAME[id]); - break; - default: - RTW_ERR("%s: unknown feature id(%d)\n", __func__, id); - return _FALSE; - } - - return _TRUE; -} - -static int init_halmac_event_with_waittime(struct dvobj_priv *d, HALMAC_FEATURE_ID id, u8 *buf, u32 size, u32 time) -{ - struct submit_ctx *sctx; - - - if (!d->hmpriv.indicator[id].sctx) { - sctx = (struct submit_ctx *)rtw_zmalloc(sizeof(*sctx)); - if (!sctx) - return -1; - } else { - RTW_WARN("%s: id(%d) sctx is not NULL!!\n", __func__, id); - sctx = d->hmpriv.indicator[id].sctx; - d->hmpriv.indicator[id].sctx = NULL; - } - - rtw_sctx_init(sctx, time); - d->hmpriv.indicator[id].buffer = buf; - d->hmpriv.indicator[id].buf_size = size; - d->hmpriv.indicator[id].ret_size = 0; - d->hmpriv.indicator[id].status = 0; - /* fill sctx at least to sure other variables are all ready! */ - d->hmpriv.indicator[id].sctx = sctx; - - return 0; -} - -static inline int init_halmac_event(struct dvobj_priv *d, HALMAC_FEATURE_ID id, u8 *buf, u32 size) -{ - return init_halmac_event_with_waittime(d, id, buf, size, DEFAULT_INDICATOR_TIMELMT); -} - -static void free_halmac_event(struct dvobj_priv *d, HALMAC_FEATURE_ID id) -{ - struct submit_ctx *sctx; - - - if (!d->hmpriv.indicator[id].sctx) - return; - - sctx = d->hmpriv.indicator[id].sctx; - d->hmpriv.indicator[id].sctx = NULL; - rtw_mfree((u8 *)sctx, sizeof(*sctx)); -} - -static int wait_halmac_event(struct dvobj_priv *d, HALMAC_FEATURE_ID id) -{ - PHALMAC_ADAPTER mac; - PHALMAC_API api; - struct submit_ctx *sctx; - int ret; - - - sctx = d->hmpriv.indicator[id].sctx; - if (!sctx) - return -1; - - ret = rtw_sctx_wait(sctx, RTW_HALMAC_FEATURE_NAME[id]); - free_halmac_event(d, id); - if (_SUCCESS == ret) - return 0; - - /* timeout! We have to reset halmac state */ - RTW_ERR("%s: Wait id(%d, %s) TIMEOUT! Reset HALMAC state!\n", - __func__, id, RTW_HALMAC_FEATURE_NAME[id]); - mac = dvobj_to_halmac(d); - api = HALMAC_GET_API(mac); - api->halmac_reset_feature(mac, id); - - return -1; -} - -/* - * Return: - * Always return _TRUE, HALMAC don't care the return value. - */ -static u8 _halmac_event_indication(void *p, HALMAC_FEATURE_ID feature_id, HALMAC_CMD_PROCESS_STATUS process_status, u8 *buf, u32 size) -{ - struct dvobj_priv *d; - PADAPTER adapter; - PHAL_DATA_TYPE hal; - struct halmac_indicator *tbl, *indicator; - struct submit_ctx *sctx; - u32 cpsz; - u8 ret; - - - d = (struct dvobj_priv *)p; - adapter = dvobj_get_primary_adapter(d); - hal = GET_HAL_DATA(adapter); - tbl = d->hmpriv.indicator; - - /* Filter(Skip) middle status indication */ - ret = is_valid_id_status(feature_id, process_status); - if (_FALSE == ret) - goto exit; - - indicator = &tbl[feature_id]; - indicator->status = process_status; - indicator->ret_size = size; - if (!indicator->sctx) { - RTW_WARN("%s: No feature id(%d, %s) waiting!!\n", __func__, feature_id, RTW_HALMAC_FEATURE_NAME[feature_id]); - goto exit; - } - sctx = indicator->sctx; - - if (HALMAC_CMD_PROCESS_ERROR == process_status) { - RTW_ERR("%s: Something wrong id(%d, %s)!!\n", __func__, feature_id, RTW_HALMAC_FEATURE_NAME[feature_id]); - rtw_sctx_done_err(&sctx, RTW_SCTX_DONE_UNKNOWN); - goto exit; - } - - if (size > indicator->buf_size) { - RTW_WARN("%s: id(%d, %s) buffer is not enough(%d<%d), data will be truncated!\n", - __func__, feature_id, RTW_HALMAC_FEATURE_NAME[feature_id], indicator->buf_size, size); - cpsz = indicator->buf_size; - } else { - cpsz = size; - } - if (cpsz && indicator->buffer) - _rtw_memcpy(indicator->buffer, buf, cpsz); - - rtw_sctx_done(&sctx); - -exit: - return _TRUE; -} - -HALMAC_PLATFORM_API rtw_halmac_platform_api = { - /* R/W register */ -#ifdef CONFIG_SDIO_HCI - .SDIO_CMD52_READ = _halmac_sdio_cmd52_read, - .SDIO_CMD53_READ_8 = _halmac_sdio_reg_read_8, - .SDIO_CMD53_READ_16 = _halmac_sdio_reg_read_16, - .SDIO_CMD53_READ_32 = _halmac_sdio_reg_read_32, - .SDIO_CMD53_READ_N = _halmac_sdio_reg_read_n, - .SDIO_CMD52_WRITE = _halmac_sdio_cmd52_write, - .SDIO_CMD53_WRITE_8 = _halmac_sdio_reg_write_8, - .SDIO_CMD53_WRITE_16 = _halmac_sdio_reg_write_16, - .SDIO_CMD53_WRITE_32 = _halmac_sdio_reg_write_32, - -#endif /* CONFIG_SDIO_HCI */ -#if defined(CONFIG_USB_HCI) || defined(CONFIG_PCIE_HCI) - .REG_READ_8 = _halmac_reg_read_8, - .REG_READ_16 = _halmac_reg_read_16, - .REG_READ_32 = _halmac_reg_read_32, - .REG_WRITE_8 = _halmac_reg_write_8, - .REG_WRITE_16 = _halmac_reg_write_16, - .REG_WRITE_32 = _halmac_reg_write_32, -#endif /* CONFIG_USB_HCI || CONFIG_PCIE_HCI */ - - /* Write data */ -#if 0 - /* impletement in HAL-IC level */ - .SEND_RSVD_PAGE = sdio_write_data_rsvd_page, - .SEND_H2C_PKT = sdio_write_data_h2c, -#endif - /* Memory allocate */ - .RTL_FREE = _halmac_mfree, - .RTL_MALLOC = _halmac_malloc, - .RTL_MEMCPY = _halmac_memcpy, - .RTL_MEMSET = _halmac_memset, - - /* Sleep */ - .RTL_DELAY_US = _halmac_udelay, - - /* Process Synchronization */ - .MUTEX_INIT = _halmac_mutex_init, - .MUTEX_DEINIT = _halmac_mutex_deinit, - .MUTEX_LOCK = _halmac_mutex_lock, - .MUTEX_UNLOCK = _halmac_mutex_unlock, - - .MSG_PRINT = _halmac_msg_print, - .BUFF_PRINT = _halmac_buff_print, - .EVENT_INDICATION = _halmac_event_indication, -}; - -u8 rtw_halmac_read8(struct intf_hdl *pintfhdl, u32 addr) -{ - PHALMAC_ADAPTER mac; - PHALMAC_API api; - - - /* WARNING: pintf_dev should not be null! */ - mac = dvobj_to_halmac(pintfhdl->pintf_dev); - api = HALMAC_GET_API(mac); - - return api->halmac_reg_read_8(mac, addr); -} - -u16 rtw_halmac_read16(struct intf_hdl *pintfhdl, u32 addr) -{ - PHALMAC_ADAPTER mac; - PHALMAC_API api; - - - /* WARNING: pintf_dev should not be null! */ - mac = dvobj_to_halmac(pintfhdl->pintf_dev); - api = HALMAC_GET_API(mac); - - return api->halmac_reg_read_16(mac, addr); -} - -u32 rtw_halmac_read32(struct intf_hdl *pintfhdl, u32 addr) -{ - PHALMAC_ADAPTER mac; - PHALMAC_API api; - - - /* WARNING: pintf_dev should not be null! */ - mac = dvobj_to_halmac(pintfhdl->pintf_dev); - api = HALMAC_GET_API(mac); - - return api->halmac_reg_read_32(mac, addr); -} - -void rtw_halmac_read_mem(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *pmem) -{ -#if defined(CONFIG_SDIO_HCI) - PHALMAC_ADAPTER mac; - PHALMAC_API api; - - if (pmem == NULL) { - RTW_ERR("pmem is NULL\n"); - return; - } - /* WARNING: pintf_dev should not be null! */ - mac = dvobj_to_halmac(pintfhdl->pintf_dev); - api = HALMAC_GET_API(mac); - - api->halmac_reg_sdio_cmd53_read_n(mac, addr, cnt, pmem); -#endif -} - -#ifdef CONFIG_SDIO_INDIRECT_ACCESS -u8 rtw_halmac_iread8(struct intf_hdl *pintfhdl, u32 addr) -{ - PHALMAC_ADAPTER mac; - PHALMAC_API api; - - /* WARNING: pintf_dev should not be null! */ - mac = dvobj_to_halmac(pintfhdl->pintf_dev); - api = HALMAC_GET_API(mac); - - /*return api->halmac_reg_read_indirect_8(mac, addr);*/ - return api->halmac_reg_read_8(mac, addr); -} - -u16 rtw_halmac_iread16(struct intf_hdl *pintfhdl, u32 addr) -{ - PHALMAC_ADAPTER mac; - PHALMAC_API api; - u16 val16 = 0; - - /* WARNING: pintf_dev should not be null! */ - mac = dvobj_to_halmac(pintfhdl->pintf_dev); - api = HALMAC_GET_API(mac); - - /*return api->halmac_reg_read_indirect_16(mac, addr);*/ - return api->halmac_reg_read_16(mac, addr); -} - -u32 rtw_halmac_iread32(struct intf_hdl *pintfhdl, u32 addr) -{ - PHALMAC_ADAPTER mac; - PHALMAC_API api; - - - /* WARNING: pintf_dev should not be null! */ - mac = dvobj_to_halmac(pintfhdl->pintf_dev); - api = HALMAC_GET_API(mac); - - return api->halmac_reg_read_indirect_32(mac, addr); -} -#endif - -int rtw_halmac_write8(struct intf_hdl *pintfhdl, u32 addr, u8 value) -{ - PHALMAC_ADAPTER mac; - PHALMAC_API api; - HALMAC_RET_STATUS status; - - - /* WARNING: pintf_dev should not be null! */ - mac = dvobj_to_halmac(pintfhdl->pintf_dev); - api = HALMAC_GET_API(mac); - - status = api->halmac_reg_write_8(mac, addr, value); - - if (status == HALMAC_RET_SUCCESS) - return 0; - - return -1; -} - -int rtw_halmac_write16(struct intf_hdl *pintfhdl, u32 addr, u16 value) -{ - PHALMAC_ADAPTER mac; - PHALMAC_API api; - HALMAC_RET_STATUS status; - - - /* WARNING: pintf_dev should not be null! */ - mac = dvobj_to_halmac(pintfhdl->pintf_dev); - api = HALMAC_GET_API(mac); - - status = api->halmac_reg_write_16(mac, addr, value); - - if (status == HALMAC_RET_SUCCESS) - return 0; - - return -1; -} - -int rtw_halmac_write32(struct intf_hdl *pintfhdl, u32 addr, u32 value) -{ - PHALMAC_ADAPTER mac; - PHALMAC_API api; - HALMAC_RET_STATUS status; - - - /* WARNING: pintf_dev should not be null! */ - mac = dvobj_to_halmac(pintfhdl->pintf_dev); - api = HALMAC_GET_API(mac); - - status = api->halmac_reg_write_32(mac, addr, value); - - if (status == HALMAC_RET_SUCCESS) - return 0; - - return -1; -} - -static int init_priv(struct halmacpriv *priv) -{ - struct halmac_indicator *indicator; - u32 count, size; - - - size = sizeof(*priv); - _rtw_memset(priv, 0, size); - - count = HALMAC_FEATURE_ALL + 1; - size = sizeof(*indicator) * count; - indicator = (struct halmac_indicator *)rtw_zmalloc(size); - if (!indicator) - return -1; - priv->indicator = indicator; - - return 0; -} - -static void deinit_priv(struct halmacpriv *priv) -{ - struct halmac_indicator *indicator; - - - indicator = priv->indicator; - priv->indicator = NULL; - if (indicator) { - u32 count, size; - - count = HALMAC_FEATURE_ALL + 1; -#ifdef CONFIG_RTW_DEBUG - { - struct submit_ctx *sctx; - u32 i; - - for (i = 0; i < count; i++) { - if (!indicator[i].sctx) - continue; - - RTW_INFO("%s: %s id(%d) sctx still exist!!\n", - __func__, RTW_HALMAC_FEATURE_NAME[i], i); - sctx = indicator[i].sctx; - indicator[i].sctx = NULL; - rtw_mfree((u8 *)sctx, sizeof(*sctx)); - } - } -#endif /* !CONFIG_RTW_DEBUG */ - size = sizeof(*indicator) * count; - rtw_mfree((u8 *)indicator, size); - } -} - -void rtw_dump_halmac_info(void *sel) -{ - HALMAC_RET_STATUS status; - HALMAC_VER halmac_version; - - status = halmac_get_version(&halmac_version); - if (status != HALMAC_RET_SUCCESS) - return; - - RTW_PRINT_SEL(sel, "HALMAC VER -%x.%x.%x\n", halmac_version.major_ver, halmac_version.prototype_ver, halmac_version.minor_ver); -} - -int rtw_halmac_init_adapter(struct dvobj_priv *d, PHALMAC_PLATFORM_API pf_api) -{ - PHALMAC_ADAPTER halmac; - PHALMAC_API api; - HALMAC_INTERFACE intf; - HALMAC_RET_STATUS status; - int err = 0; - - - halmac = dvobj_to_halmac(d); - if (halmac) { - err = 0; - goto out; - } - - err = init_priv(&d->hmpriv); - if (err) - goto out; - -#ifdef CONFIG_SDIO_HCI - intf = HALMAC_INTERFACE_SDIO; -#elif defined(CONFIG_USB_HCI) - intf = HALMAC_INTERFACE_USB; -#elif defined(CONFIG_PCIE_HCI) - intf = HALMAC_INTERFACE_PCIE; -#else -#warning "INTERFACE(CONFIG_XXX_HCI) not be defined!!" - intf = HALMAC_INTERFACE_UNDEFINE; -#endif - status = halmac_init_adapter(d, pf_api, intf, &halmac, &api); - if (HALMAC_RET_SUCCESS != status) { - RTW_INFO("%s: halmac_init_adapter fail!(status=%d)\n", __func__, status); - err = -1; - goto out; - } - - dvobj_set_halmac(d, halmac); - -out: - if (err) - rtw_halmac_deinit_adapter(d); - - return err; -} - -int rtw_halmac_deinit_adapter(struct dvobj_priv *d) -{ - PHALMAC_ADAPTER halmac; - HALMAC_RET_STATUS status; - int err = 0; - - - halmac = dvobj_to_halmac(d); - if (!halmac) { - err = 0; - goto out; - } - - deinit_priv(&d->hmpriv); - - status = halmac_deinit_adapter(halmac); - dvobj_set_halmac(d, NULL); - if (status != HALMAC_RET_SUCCESS) { - err = -1; - goto out; - } - -out: - return err; -} - -/* - * Description: - * Power on device hardware. - * [Notice!] If device's power state is on before, - * it would be power off first and turn on power again. - * - * Return: - * 0 power on success - * -1 power on fail - * -2 power state unchange - */ -int rtw_halmac_poweron(struct dvobj_priv *d) -{ - PHALMAC_ADAPTER halmac; - PHALMAC_API api; - HALMAC_RET_STATUS status; - int err = -1; - - - halmac = dvobj_to_halmac(d); - if (!halmac) - goto out; - - api = HALMAC_GET_API(halmac); - - status = api->halmac_pre_init_system_cfg(halmac); - if (status != HALMAC_RET_SUCCESS) - goto out; - -#ifdef CONFIG_SDIO_HCI - status = api->halmac_sdio_cmd53_4byte(halmac, 1); - if (status != HALMAC_RET_SUCCESS) - goto out; -#endif - - status = api->halmac_mac_power_switch(halmac, HALMAC_MAC_POWER_ON); - if (HALMAC_RET_PWR_UNCHANGE == status) { - /* - * Work around for warm reboot but device not power off, - * but it would also fall into this case when auto power on is enabled. - */ - api->halmac_mac_power_switch(halmac, HALMAC_MAC_POWER_OFF); - status = api->halmac_mac_power_switch(halmac, HALMAC_MAC_POWER_ON); - RTW_WARN("%s: Power state abnormal, try to recover...%s\n", - __func__, (HALMAC_RET_SUCCESS == status)?"OK":"FAIL!"); - } - if (HALMAC_RET_SUCCESS != status) { - if (HALMAC_RET_PWR_UNCHANGE == status) - err = -2; - goto out; - } - - status = api->halmac_init_system_cfg(halmac); - if (status != HALMAC_RET_SUCCESS) - goto out; - - err = 0; -out: - return err; -} - -/* - * Description: - * Power off device hardware. - * - * Return: - * 0 Power off success - * -1 Power off fail - */ -int rtw_halmac_poweroff(struct dvobj_priv *d) -{ - PHALMAC_ADAPTER halmac; - PHALMAC_API api; - HALMAC_RET_STATUS status; - int err = -1; - - - halmac = dvobj_to_halmac(d); - if (!halmac) - goto out; - - api = HALMAC_GET_API(halmac); - - status = api->halmac_mac_power_switch(halmac, HALMAC_MAC_POWER_OFF); - if ((HALMAC_RET_SUCCESS != status) - && (HALMAC_RET_PWR_UNCHANGE != status)) - goto out; - - err = 0; -out: - return err; -} - -/* - * Note: - * When this function return, the register REG_RCR may be changed. - */ -int rtw_halmac_config_rx_info(struct dvobj_priv *d, HALMAC_DRV_INFO info) -{ - PHALMAC_ADAPTER halmac; - PHALMAC_API api; - HALMAC_RET_STATUS status; - int err = -1; - - - halmac = dvobj_to_halmac(d); - api = HALMAC_GET_API(halmac); - - status = api->halmac_cfg_drv_info(halmac, info); - if (status != HALMAC_RET_SUCCESS) - goto out; - - err = 0; -out: - return err; -} - -#ifdef CONFIG_SUPPORT_TRX_SHARED -static inline HALMAC_RX_FIFO_EXPANDING_MODE _trx_share_mode_drv2halmac(u8 trx_share_mode) -{ - if (0 == trx_share_mode) - return HALMAC_RX_FIFO_EXPANDING_MODE_DISABLE; - else if (1 == trx_share_mode) - return HALMAC_RX_FIFO_EXPANDING_MODE_1_BLOCK; - else if (2 == trx_share_mode) - return HALMAC_RX_FIFO_EXPANDING_MODE_2_BLOCK; - else if (3 == trx_share_mode) - return HALMAC_RX_FIFO_EXPANDING_MODE_3_BLOCK; - else - return HALMAC_RX_FIFO_EXPANDING_MODE_DISABLE; -} -static HALMAC_RX_FIFO_EXPANDING_MODE _rtw_get_trx_share_mode(_adapter *adapter) -{ - struct registry_priv *registry_par = &adapter->registrypriv; - - return _trx_share_mode_drv2halmac(registry_par->trx_share_mode); -} -void dump_trx_share_mode(void *sel, _adapter *adapter) -{ - struct registry_priv *registry_par = &adapter->registrypriv; - u8 mode = _trx_share_mode_drv2halmac(registry_par->trx_share_mode); - - if (HALMAC_RX_FIFO_EXPANDING_MODE_1_BLOCK == mode) - RTW_PRINT_SEL(sel, "TRx share mode : %s\n", "RX_FIFO_EXPANDING_MODE_1"); - else if (HALMAC_RX_FIFO_EXPANDING_MODE_2_BLOCK == mode) - RTW_PRINT_SEL(sel, "TRx share mode : %s\n", "RX_FIFO_EXPANDING_MODE_2"); - else if (HALMAC_RX_FIFO_EXPANDING_MODE_3_BLOCK == mode) - RTW_PRINT_SEL(sel, "TRx share mode : %s\n", "RX_FIFO_EXPANDING_MODE_3"); - else - RTW_PRINT_SEL(sel, "TRx share mode : %s\n", "DISABLE"); -} -#endif - -static u8 _get_drv_rsvd_page(HALMAC_DRV_RSVD_PG_NUM rsvd_page_number) -{ - if (HALMAC_RSVD_PG_NUM16 == rsvd_page_number) - return 16; - else if (HALMAC_RSVD_PG_NUM24 == rsvd_page_number) - return 24; - else if (HALMAC_RSVD_PG_NUM32 == rsvd_page_number) - return 32; - - RTW_ERR("%s unknown HALMAC_RSVD_PG type :%d\n", __func__, rsvd_page_number); - rtw_warn_on(1); - return 0; -} - -static HALMAC_TRX_MODE _choose_trx_mode(struct dvobj_priv *d) -{ - PADAPTER p; - - - p = dvobj_get_primary_adapter(d); - - if (p->registrypriv.wifi_spec) - return HALMAC_TRX_MODE_WMM; - -#ifdef CONFIG_SUPPORT_TRX_SHARED - if (_rtw_get_trx_share_mode(p)) - return HALMAC_TRX_MODE_TRXSHARE; -#endif - - return HALMAC_TRX_MODE_NORMAL; -} - -static inline HALMAC_RF_TYPE _rf_type_drv2halmac(RT_RF_TYPE_DEF_E rf_drv) -{ - HALMAC_RF_TYPE rf_mac; - - - switch (rf_drv) { - case RF_1T2R: - rf_mac = HALMAC_RF_1T2R; - break; - case RF_2T4R: - rf_mac = HALMAC_RF_2T4R; - break; - case RF_2T2R: - rf_mac = HALMAC_RF_2T2R; - break; - case RF_1T1R: - rf_mac = HALMAC_RF_1T1R; - break; - case RF_2T2R_GREEN: - rf_mac = HALMAC_RF_2T2R_GREEN; - break; - case RF_2T3R: - rf_mac = HALMAC_RF_2T3R; - break; - case RF_3T3R: - rf_mac = HALMAC_RF_3T3R; - break; - case RF_3T4R: - rf_mac = HALMAC_RF_3T4R; - break; - case RF_4T4R: - rf_mac = HALMAC_RF_4T4R; - break; - default: - rf_mac = (HALMAC_RF_TYPE)rf_drv; - break; - } - - return rf_mac; -} - -static int _send_general_info(struct dvobj_priv *d) -{ - PADAPTER adapter; - PHAL_DATA_TYPE hal; - PHALMAC_ADAPTER halmac; - PHALMAC_API api; - HALMAC_GENERAL_INFO info; - HALMAC_RET_STATUS status; - u8 val8; - - - adapter = dvobj_get_primary_adapter(d); - hal = GET_HAL_DATA(adapter); - halmac = dvobj_to_halmac(d); - if (!halmac) - return -1; - api = HALMAC_GET_API(halmac); - - _rtw_memset(&info, 0, sizeof(info)); - info.rfe_type = (u8)hal->rfe_type; - rtw_hal_get_hwreg(adapter, HW_VAR_RF_TYPE, &val8); - info.rf_type = _rf_type_drv2halmac(val8); - - status = api->halmac_send_general_info(halmac, &info); - switch (status) { - case HALMAC_RET_SUCCESS: - break; - case HALMAC_RET_NO_DLFW: - RTW_WARN("%s: halmac_send_general_info() fail because fw not dl!\n", - __func__); - /* go through */ - default: - return -1; - } - - return 0; -} - -/* - * Description: - * Downlaod Firmware Flow - * - * Parameters: - * d pointer of struct dvobj_priv - * fw firmware array - * fwsize firmware size - * re_dl re-download firmware or not - * 0: run in init hal flow, not re-download - * 1: it is a stand alone operation, not in init hal flow - * - * Return: - * 0 Success - * others Fail - */ -static int download_fw(struct dvobj_priv *d, u8 *fw, u32 fwsize, u8 re_dl) -{ - PHALMAC_ADAPTER mac; - PHALMAC_API api; - HALMAC_RET_STATUS status; - int err = 0; - PHAL_DATA_TYPE hal; - HALMAC_FW_VERSION fw_vesion; - - - mac = dvobj_to_halmac(d); - api = HALMAC_GET_API(mac); - hal = GET_HAL_DATA(dvobj_get_primary_adapter(d)); - - if ((!fw) || (!fwsize)) - return -1; - - /* 1. Driver Stop Tx */ - /* ToDo */ - - /* 2. Driver Check Tx FIFO is empty */ - /* ToDo */ - - /* 3. Config MAX download size */ -#ifdef CONFIG_USB_HCI - /* for USB do not exceed MAX_CMDBUF_SZ */ - api->halmac_cfg_max_dl_size(mac, 0x1000); -#elif defined CONFIG_PCIE_HCI - /* required a even length from u32 */ - api->halmac_cfg_max_dl_size(mac, (MAX_CMDBUF_SZ - TXDESC_OFFSET) & 0xFFFFFFFE); -#endif - - /* 4. Download Firmware */ - status = api->halmac_download_firmware(mac, fw, fwsize); - if (HALMAC_RET_SUCCESS != status) - return -1; - - /* 5. Driver resume TX if needed */ - /* ToDo */ - - if (re_dl) { - HALMAC_TRX_MODE mode; - - /* 6. Init TRX Configuration */ - mode = _choose_trx_mode(d); - status = api->halmac_init_trx_cfg(mac, mode); - if (HALMAC_RET_SUCCESS != status) - return -1; - - /* 7. Config RX Aggregation */ - err = rtw_halmac_rx_agg_switch(d, _TRUE); - if (err) - return -1; - - /* 8. Send General Info */ - err = _send_general_info(d); - if (err) - return -1; - } - - /* 9. Reset driver variables if needed */ - hal->LastHMEBoxNum = 0; - - /* 10. Get FW version */ - status = api->halmac_get_fw_version(mac, &fw_vesion); - if (status == HALMAC_RET_SUCCESS) { - hal->firmware_version = fw_vesion.version; - hal->firmware_sub_version = fw_vesion.sub_version; - } - - return err; -} - -static HALMAC_RET_STATUS init_mac_flow(struct dvobj_priv *d) -{ - PADAPTER p; - PHALMAC_ADAPTER halmac; - PHALMAC_API api; - HALMAC_WLAN_ADDR hwa; - HALMAC_TRX_MODE trx_mode; - HALMAC_RET_STATUS status; - u8 nettype; - int err; - PHAL_DATA_TYPE hal; - HALMAC_DRV_RSVD_PG_NUM rsvd_page_number = HALMAC_RSVD_PG_NUM16;/*HALMAC_RSVD_PG_NUM24/HALMAC_RSVD_PG_NUM32*/ - - p = dvobj_get_primary_adapter(d); - hal = GET_HAL_DATA(p); - halmac = dvobj_to_halmac(d); - api = HALMAC_GET_API(halmac); - -#ifdef CONFIG_SUPPORT_TRX_SHARED - status = api->halmac_cfg_rx_fifo_expanding_mode(halmac, _rtw_get_trx_share_mode(p)); - if (status != HALMAC_RET_SUCCESS) - goto out; -#endif - -#ifdef CONFIG_PNO_SUPPORT - rsvd_page_number = HALMAC_RSVD_PG_NUM32; -#endif - status = api->halmac_cfg_drv_rsvd_pg_num(halmac, rsvd_page_number); - if (status != HALMAC_RET_SUCCESS) - goto out; - hal->drv_rsvd_page_number = _get_drv_rsvd_page(rsvd_page_number); - -#ifdef CONFIG_USB_HCI - status = api->halmac_set_bulkout_num(halmac, d->RtNumOutPipes); - if (status != HALMAC_RET_SUCCESS) - goto out; -#endif /* CONFIG_USB_HCI */ - - trx_mode = _choose_trx_mode(d); - status = api->halmac_init_mac_cfg(halmac, trx_mode); - if (status != HALMAC_RET_SUCCESS) - goto out; - - err = rtw_halmac_rx_agg_switch(d, _TRUE); - if (err) - goto out; - - nettype = dvobj_to_regsty(d)->wireless_mode; - if (is_supported_vht(nettype) == _TRUE) - status = api->halmac_cfg_operation_mode(halmac, HALMAC_WIRELESS_MODE_AC); - else if (is_supported_ht(nettype) == _TRUE) - status = api->halmac_cfg_operation_mode(halmac, HALMAC_WIRELESS_MODE_N); - else if (IsSupportedTxOFDM(nettype) == _TRUE) - status = api->halmac_cfg_operation_mode(halmac, HALMAC_WIRELESS_MODE_G); - else - status = api->halmac_cfg_operation_mode(halmac, HALMAC_WIRELESS_MODE_B); - if (status != HALMAC_RET_SUCCESS) - goto out; - -out: - return status; -} - -/* - * Notices: - * Make sure - * 1. rtw_hal_get_hwreg(HW_VAR_RF_TYPE) - * 2. HAL_DATA_TYPE.rfe_type - * already ready for use before calling this function. - */ -static int _halmac_init_hal(struct dvobj_priv *d, u8 *fw, u32 fwsize) -{ - PADAPTER adapter; - PHALMAC_ADAPTER halmac; - PHALMAC_API api; - HALMAC_RET_STATUS status; - u32 ok = _TRUE; - u8 fw_ok = _FALSE; - int err, err_ret = -1; - - - adapter = dvobj_get_primary_adapter(d); - halmac = dvobj_to_halmac(d); - if (!halmac) - goto out; - api = HALMAC_GET_API(halmac); - - /* StatePowerOff */ - - /* SKIP: halmac_init_adapter (Already done before) */ - - /* halmac_pre_Init_system_cfg */ - /* halmac_mac_power_switch(on) */ - /* halmac_Init_system_cfg */ - ok = rtw_hal_power_on(adapter); - if (_FAIL == ok) - goto out; - - /* StatePowerOn */ - - /* DownloadFW */ - if (fw && fwsize) { - err = download_fw(d, fw, fwsize, 0); - if (err) - goto out; - fw_ok = _TRUE; - } - - /* InitMACFlow */ - status = init_mac_flow(d); - if (status != HALMAC_RET_SUCCESS) - goto out; - - /* halmac_send_general_info */ - if (_TRUE == fw_ok) { - err = _send_general_info(d); - if (err) - goto out; - } - - /* Init Phy parameter-MAC */ - ok = rtw_hal_init_mac_register(adapter); - if (_FALSE == ok) - goto out; - - /* StateMacInitialized */ - - /* halmac_cfg_drv_info */ - err = rtw_halmac_config_rx_info(d, HALMAC_DRV_INFO_PHY_STATUS); - if (err) - goto out; - - /* halmac_set_hw_value(HALMAC_HW_EN_BB_RF) */ - /* Init BB, RF */ - ok = rtw_hal_init_phy(adapter); - if (_FALSE == ok) - goto out; - - status = api->halmac_init_interface_cfg(halmac); - if (status != HALMAC_RET_SUCCESS) - goto out; - - /* SKIP: halmac_verify_platform_api */ - /* SKIP: halmac_h2c_lb */ - - /* StateRxIdle */ - - err_ret = 0; -out: - return err_ret; -} - -int rtw_halmac_init_hal(struct dvobj_priv *d) -{ - return _halmac_init_hal(d, NULL, 0); -} - -/* - * Notices: - * Make sure - * 1. rtw_hal_get_hwreg(HW_VAR_RF_TYPE) - * 2. HAL_DATA_TYPE.rfe_type - * already ready for use before calling this function. - */ -int rtw_halmac_init_hal_fw(struct dvobj_priv *d, u8 *fw, u32 fwsize) -{ - return _halmac_init_hal(d, fw, fwsize); -} - -/* - * Notices: - * Make sure - * 1. rtw_hal_get_hwreg(HW_VAR_RF_TYPE) - * 2. HAL_DATA_TYPE.rfe_type - * already ready for use before calling this function. - */ -int rtw_halmac_init_hal_fw_file(struct dvobj_priv *d, u8 *fwpath) -{ - u8 *fw = NULL; - u32 fwmaxsize, size = 0; - int err = 0; - - - fwmaxsize = FIRMWARE_MAX_SIZE; - fw = rtw_zmalloc(fwmaxsize); - if (!fw) - return -1; - - size = rtw_retrieve_from_file(fwpath, fw, fwmaxsize); - if (!size) { - err = -1; - goto exit; - } - - err = _halmac_init_hal(d, fw, size); - -exit: - rtw_mfree(fw, fwmaxsize); - fw = NULL; - - return err; -} - -int rtw_halmac_deinit_hal(struct dvobj_priv *d) -{ - PADAPTER adapter; - PHALMAC_ADAPTER halmac; - PHALMAC_API api; - HALMAC_RET_STATUS status; - int err = -1; - - - adapter = dvobj_get_primary_adapter(d); - halmac = dvobj_to_halmac(d); - if (!halmac) - goto out; - api = HALMAC_GET_API(halmac); - - status = api->halmac_deinit_interface_cfg(halmac); - if (status != HALMAC_RET_SUCCESS) - goto out; - - rtw_hal_power_off(adapter); - - err = 0; -out: - return err; -} - -int rtw_halmac_self_verify(struct dvobj_priv *d) -{ - PHALMAC_ADAPTER mac; - PHALMAC_API api; - HALMAC_RET_STATUS status; - int err = -1; - - - mac = dvobj_to_halmac(d); - api = HALMAC_GET_API(mac); - - status = api->halmac_verify_platform_api(mac); - if (status != HALMAC_RET_SUCCESS) - goto out; - - status = api->halmac_h2c_lb(mac); - if (status != HALMAC_RET_SUCCESS) - goto out; - - err = 0; -out: - return err; -} - -int rtw_halmac_redl_fw(struct dvobj_priv *d, u8 *fw, u32 fwsize) -{ - int err = 0; - - return err; -} - -/* - * Return: - * 0 Success - * -22 Invalid arguemnt - */ -int rtw_halmac_dlfw(struct dvobj_priv *d, u8 *fw, u32 fwsize) -{ - PADAPTER adapter; - HALMAC_RET_STATUS status; - u32 ok = _TRUE; - int err, err_ret = -1; - - - if (!fw || !fwsize) - return -22; - - adapter = dvobj_get_primary_adapter(d); - - /* re-download firmware */ - if (rtw_is_hw_init_completed(adapter)) - return download_fw(d, fw, fwsize, 1); - - /* Download firmware before hal init */ - /* Power on, download firmware and init mac */ - ok = rtw_hal_power_on(adapter); - if (_FAIL == ok) - goto out; - - err = download_fw(d, fw, fwsize, 0); - if (err) { - err_ret = err; - goto out; - } - - status = init_mac_flow(d); - if (status != HALMAC_RET_SUCCESS) - goto out; - - err = _send_general_info(d); - if (err) - goto out; - - err_ret = 0; - -out: - return err_ret; -} - -int rtw_halmac_dlfw_from_file(struct dvobj_priv *d, u8 *fwpath) -{ - u8 *fw = NULL; - u32 fwmaxsize, size = 0; - int err = 0; - - - fwmaxsize = FIRMWARE_MAX_SIZE; - fw = rtw_zmalloc(fwmaxsize); - if (!fw) - return -1; - - size = rtw_retrieve_from_file(fwpath, fw, fwmaxsize); - if (size) - err = rtw_halmac_dlfw(d, fw, size); - else - err = -1; - - rtw_mfree(fw, fwmaxsize); - fw = NULL; - - return err; -} - -/* - * Description: - * Power on/off BB/RF domain. - * - * Parameters: - * enable _TRUE/_FALSE for power on/off - * - * Return: - * 0 Success - * others Fail - */ -int rtw_halmac_phy_power_switch(struct dvobj_priv *d, u8 enable) -{ - PADAPTER adapter; - PHALMAC_ADAPTER halmac; - PHALMAC_API api; - HALMAC_RET_STATUS status; - - - adapter = dvobj_get_primary_adapter(d); - halmac = dvobj_to_halmac(d); - if (!halmac) - return -1; - api = HALMAC_GET_API(halmac); - - status = api->halmac_set_hw_value(halmac, HALMAC_HW_EN_BB_RF, &enable); - if (status != HALMAC_RET_SUCCESS) - return -1; - - return 0; -} - -static u8 _is_fw_read_cmd_down(PADAPTER adapter, u8 msgbox_num) -{ - u8 read_down = _FALSE; - int retry_cnts = 100; - u8 valid; - - /* RTW_INFO("_is_fw_read_cmd_down, reg_1cc(%x), msg_box(%d)...\n", rtw_read8(adapter, REG_HMETFR), msgbox_num); */ - - do { - valid = rtw_read8(adapter, REG_HMETFR) & BIT(msgbox_num); - if (0 == valid) - read_down = _TRUE; - else - rtw_msleep_os(1); - } while ((!read_down) && (retry_cnts--)); - - return read_down; -} - -int rtw_halmac_send_h2c(struct dvobj_priv *d, u8 *h2c) -{ - PADAPTER adapter = dvobj_get_primary_adapter(d); - PHAL_DATA_TYPE hal = GET_HAL_DATA(adapter); - u8 h2c_box_num = 0; - u32 msgbox_addr = 0; - u32 msgbox_ex_addr = 0; - u32 h2c_cmd = 0; - u32 h2c_cmd_ex = 0; - s32 ret = _FAIL; - - if (adapter->bFWReady == _FALSE) { - RTW_INFO("%s: return H2C cmd because fw is not ready\n", __func__); - return ret; - } - - if (!h2c) { - RTW_INFO("%s: pbuf is NULL\n", __func__); - return ret; - } - - if (rtw_is_surprise_removed(adapter)) { - RTW_INFO("%s: surprise removed\n", __func__); - return ret; - } - - _enter_critical_mutex(&d->h2c_fwcmd_mutex, NULL); - - /* pay attention to if race condition happened in H2C cmd setting */ - h2c_box_num = hal->LastHMEBoxNum; - - if (!_is_fw_read_cmd_down(adapter, h2c_box_num)) { - RTW_INFO(" fw read cmd failed...\n"); - goto exit; - } - - /* Write Ext command(byte 4 -7) */ - msgbox_ex_addr = REG_HMEBOX_E0 + (h2c_box_num * EX_MESSAGE_BOX_SIZE); - _rtw_memcpy((u8 *)(&h2c_cmd_ex), h2c + 4, EX_MESSAGE_BOX_SIZE); - h2c_cmd_ex = le32_to_cpu(h2c_cmd_ex); - rtw_write32(adapter, msgbox_ex_addr, h2c_cmd_ex); - - /* Write command (byte 0 -3 ) */ - msgbox_addr = REG_HMEBOX0 + (h2c_box_num * MESSAGE_BOX_SIZE); - _rtw_memcpy((u8 *)(&h2c_cmd), h2c, 4); - h2c_cmd = le32_to_cpu(h2c_cmd); - rtw_write32(adapter, msgbox_addr, h2c_cmd); - - /* update last msg box number */ - hal->LastHMEBoxNum = (h2c_box_num + 1) % MAX_H2C_BOX_NUMS; - ret = _SUCCESS; - -#ifdef DBG_H2C_CONTENT - RTW_INFO_DUMP("[H2C] - ", h2c, RTW_HALMAC_H2C_MAX_SIZE); -#endif -exit: - _exit_critical_mutex(&d->h2c_fwcmd_mutex, NULL); - return ret; -} - -int rtw_halmac_c2h_handle(struct dvobj_priv *d, u8 *c2h, u32 size) -{ - PHALMAC_ADAPTER mac; - PHALMAC_API api; - HALMAC_RET_STATUS status; - - - mac = dvobj_to_halmac(d); - api = HALMAC_GET_API(mac); - - status = api->halmac_get_c2h_info(mac, c2h, size); - if (HALMAC_RET_SUCCESS != status) - return -1; - - return 0; -} - -int rtw_halmac_get_available_efuse_size(struct dvobj_priv *d, u32 *size) -{ - PHALMAC_ADAPTER mac; - PHALMAC_API api; - HALMAC_RET_STATUS status; - u32 val; - - - mac = dvobj_to_halmac(d); - api = HALMAC_GET_API(mac); - - status = api->halmac_get_efuse_available_size(mac, &val); - if (HALMAC_RET_SUCCESS != status) - return -1; - - *size = val; - return 0; -} - -int rtw_halmac_get_physical_efuse_size(struct dvobj_priv *d, u32 *size) -{ - PHALMAC_ADAPTER mac; - PHALMAC_API api; - HALMAC_RET_STATUS status; - u32 val; - - - mac = dvobj_to_halmac(d); - api = HALMAC_GET_API(mac); - - status = api->halmac_get_efuse_size(mac, &val); - if (HALMAC_RET_SUCCESS != status) - return -1; - - *size = val; - return 0; -} - -int rtw_halmac_read_physical_efuse_map(struct dvobj_priv *d, u8 *map, u32 size) -{ - PHALMAC_ADAPTER mac; - PHALMAC_API api; - HALMAC_RET_STATUS status; - HALMAC_FEATURE_ID id; - int ret; - - - mac = dvobj_to_halmac(d); - api = HALMAC_GET_API(mac); - id = HALMAC_FEATURE_DUMP_PHYSICAL_EFUSE; - - ret = init_halmac_event(d, id, map, size); - if (ret) - return -1; - - status = api->halmac_dump_efuse_map(mac, HALMAC_EFUSE_R_AUTO); - if (HALMAC_RET_SUCCESS != status) { - free_halmac_event(d, id); - return -1; - } - - ret = wait_halmac_event(d, id); - if (ret) - return -1; - - return 0; -} - -int rtw_halmac_read_physical_efuse(struct dvobj_priv *d, u32 offset, u32 cnt, u8 *data) -{ - PHALMAC_ADAPTER mac; - PHALMAC_API api; - HALMAC_RET_STATUS status; - u8 v; - u32 i; - - - mac = dvobj_to_halmac(d); - api = HALMAC_GET_API(mac); - - for (i = 0; i < cnt; i++) { - status = api->halmac_read_efuse(mac, offset + i, &v); - if (HALMAC_RET_SUCCESS != status) - return -1; - data[i] = v; - } - - return 0; -} - -int rtw_halmac_write_physical_efuse(struct dvobj_priv *d, u32 offset, u32 cnt, u8 *data) -{ - PHALMAC_ADAPTER mac; - PHALMAC_API api; - HALMAC_RET_STATUS status; - u32 i; - - - mac = dvobj_to_halmac(d); - api = HALMAC_GET_API(mac); - - for (i = 0; i < cnt; i++) { - status = api->halmac_write_efuse(mac, offset + i, data[i]); - if (HALMAC_RET_SUCCESS != status) - return -1; - } - - return 0; -} - -int rtw_halmac_get_logical_efuse_size(struct dvobj_priv *d, u32 *size) -{ - PHALMAC_ADAPTER mac; - PHALMAC_API api; - HALMAC_RET_STATUS status; - u32 val; - - - mac = dvobj_to_halmac(d); - api = HALMAC_GET_API(mac); - - status = api->halmac_get_logical_efuse_size(mac, &val); - if (HALMAC_RET_SUCCESS != status) - return -1; - - *size = val; - return 0; -} - -int rtw_halmac_read_logical_efuse_map(struct dvobj_priv *d, u8 *map, u32 size) -{ - PHALMAC_ADAPTER mac; - PHALMAC_API api; - HALMAC_RET_STATUS status; - HALMAC_FEATURE_ID id; - int ret; - - - mac = dvobj_to_halmac(d); - api = HALMAC_GET_API(mac); - id = HALMAC_FEATURE_DUMP_LOGICAL_EFUSE; - - ret = init_halmac_event(d, id, map, size); - if (ret) - return -1; - - status = api->halmac_dump_logical_efuse_map(mac, HALMAC_EFUSE_R_DRV); - if (HALMAC_RET_SUCCESS != status) { - free_halmac_event(d, id); - return -1; - } - - ret = wait_halmac_event(d, id); - if (ret) - return -1; - - return 0; -} - -int rtw_halmac_write_logical_efuse_map(struct dvobj_priv *d, u8 *map, u32 size, u8 *maskmap, u32 masksize) -{ - PHALMAC_ADAPTER mac; - PHALMAC_API api; - HALMAC_PG_EFUSE_INFO pginfo; - HALMAC_RET_STATUS status; - - - mac = dvobj_to_halmac(d); - api = HALMAC_GET_API(mac); - - pginfo.pEfuse_map = map; - pginfo.efuse_map_size = size; - pginfo.pEfuse_mask = maskmap; - pginfo.efuse_mask_size = masksize; - - status = api->halmac_pg_efuse_by_map(mac, &pginfo, HALMAC_EFUSE_R_AUTO); - if (HALMAC_RET_SUCCESS != status) - return -1; - - return 0; -} - -int rtw_halmac_read_logical_efuse(struct dvobj_priv *d, u32 offset, u32 cnt, u8 *data) -{ - PHALMAC_ADAPTER mac; - PHALMAC_API api; - HALMAC_RET_STATUS status; - u8 v; - u32 i; - - - mac = dvobj_to_halmac(d); - api = HALMAC_GET_API(mac); - - for (i = 0; i < cnt; i++) { - status = api->halmac_read_logical_efuse(mac, offset + i, &v); - if (HALMAC_RET_SUCCESS != status) - return -1; - data[i] = v; - } - - return 0; -} - -int rtw_halmac_write_logical_efuse(struct dvobj_priv *d, u32 offset, u32 cnt, u8 *data) -{ - PHALMAC_ADAPTER mac; - PHALMAC_API api; - HALMAC_RET_STATUS status; - u32 i; - - - mac = dvobj_to_halmac(d); - api = HALMAC_GET_API(mac); - - for (i = 0; i < cnt; i++) { - status = api->halmac_write_logical_efuse(mac, offset + i, data[i]); - if (HALMAC_RET_SUCCESS != status) - return -1; - } - - return 0; -} - -int rtw_halmac_write_bt_physical_efuse(struct dvobj_priv *d, u32 offset, u32 cnt, u8 *data) -{ - PHALMAC_ADAPTER mac; - PHALMAC_API api; - HALMAC_RET_STATUS status; - u32 i; - u8 bank = 1; - - mac = dvobj_to_halmac(d); - api = HALMAC_GET_API(mac); - - for (i = 0; i < cnt; i++) { - status = api->halmac_write_efuse_bt(mac, offset + i, data[i], bank); - if (HALMAC_RET_SUCCESS != status) { - printk("%s: halmac_write_efuse_bt status = %d\n", __func__, status); - return -1; - } - } - printk("%s: halmac_write_efuse_bt status = HALMAC_RET_SUCCESS %d\n", __func__, status); - return 0; -} - - -int rtw_halmac_read_bt_physical_efuse_map(struct dvobj_priv *d, u8 *map, u32 size) -{ - PHALMAC_ADAPTER mac; - PHALMAC_API api; - HALMAC_RET_STATUS status; - HALMAC_FEATURE_ID id; - int ret; - int bank = 1; - - mac = dvobj_to_halmac(d); - api = HALMAC_GET_API(mac); - - status = api->halmac_dump_efuse_map_bt(mac, bank, size, map); - if (HALMAC_RET_SUCCESS != status) { - printk("%s: halmac_dump_efuse_map_bt fail!\n", __func__); - return -1; - } - - printk("%s: OK!\n", __func__); - - return 0; -} - -static inline u8 _hw_port_drv2halmac(enum _hw_port hwport) -{ - u8 port = 0; - - - switch (hwport) { - case HW_PORT0: - port = 0; - break; - case HW_PORT1: - port = 1; - break; - case HW_PORT2: - port = 2; - break; - case HW_PORT3: - port = 3; - break; - case HW_PORT4: - port = 4; - break; - default: - port = hwport; - break; - } - - return port; -} - -int rtw_halmac_set_mac_address(struct dvobj_priv *d, enum _hw_port hwport, u8 *addr) -{ - PHALMAC_ADAPTER halmac; - PHALMAC_API api; - u8 port; - HALMAC_WLAN_ADDR hwa; - HALMAC_RET_STATUS status; - int err = -1; - - - halmac = dvobj_to_halmac(d); - api = HALMAC_GET_API(halmac); - - port = _hw_port_drv2halmac(hwport); - _rtw_memset(&hwa, 0, sizeof(hwa)); - _rtw_memcpy(hwa.Address, addr, 6); - - status = api->halmac_cfg_mac_addr(halmac, port, &hwa); - if (status != HALMAC_RET_SUCCESS) - goto out; - - err = 0; -out: - return err; -} - -int rtw_halmac_set_bssid(struct dvobj_priv *d, enum _hw_port hwport, u8 *addr) -{ - PHALMAC_ADAPTER halmac; - PHALMAC_API api; - u8 port; - HALMAC_WLAN_ADDR hwa; - HALMAC_RET_STATUS status; - int err = -1; - - halmac = dvobj_to_halmac(d); - api = HALMAC_GET_API(halmac); - port = _hw_port_drv2halmac(hwport); - - _rtw_memset(&hwa, 0, sizeof(HALMAC_WLAN_ADDR)); - _rtw_memcpy(hwa.Address, addr, 6); - status = api->halmac_cfg_bssid(halmac, port, &hwa); - if (status != HALMAC_RET_SUCCESS) - goto out; - - err = 0; -out: - return err; -} - -int rtw_halmac_set_bandwidth(struct dvobj_priv *d, u8 channel, u8 pri_ch_idx, u8 bw) -{ - PHALMAC_ADAPTER mac; - PHALMAC_API api; - HALMAC_RET_STATUS status; - - - mac = dvobj_to_halmac(d); - api = HALMAC_GET_API(mac); - - status = api->halmac_cfg_ch_bw(mac, channel, pri_ch_idx, bw); - if (HALMAC_RET_SUCCESS != status) - return -1; - - return 0; -} - -int rtw_halmac_get_hw_value(struct dvobj_priv *d, HALMAC_HW_ID hw_id, VOID *pvalue) -{ - PHALMAC_ADAPTER mac; - PHALMAC_API api; - HALMAC_RET_STATUS status; - - - mac = dvobj_to_halmac(d); - api = HALMAC_GET_API(mac); - - status = api->halmac_get_hw_value(mac, hw_id, pvalue); - if (HALMAC_RET_SUCCESS != status) - return -1; - - return 0; -} - -static HAL_FIFO_SEL _fifo_sel_drv2halmac(u8 fifo_sel) -{ - if (0 == fifo_sel) - return HAL_FIFO_SEL_TX; - else if (1 == fifo_sel) - return HAL_FIFO_SEL_RX; - else if (2 == fifo_sel) - return HAL_FIFO_SEL_RSVD_PAGE; - else if (3 == fifo_sel) - return HAL_FIFO_SEL_REPORT; - else if (4 == fifo_sel) - return HAL_FIFO_SEL_LLT; - else - return HAL_FIFO_SEL_RSVD_PAGE; -} - -#define CONFIG_HALMAC_FIFO_DUMP -int rtw_halmac_dump_fifo(struct dvobj_priv *d, u8 fifo_sel, u32 addr, u32 size, u8 *buffer) -{ - PHALMAC_ADAPTER mac; - PHALMAC_API api; - HALMAC_RET_STATUS status; - u8 *pfifo_map = NULL; - u32 fifo_size = 0; - s8 ret = 0;/* 0:success, -1:error */ - u8 mem_created = _FALSE; - - HAL_FIFO_SEL halmac_fifo_sel; - - mac = dvobj_to_halmac(d); - api = HALMAC_GET_API(mac); - - if ((size != 0) && (buffer == NULL)) - return -1; - - halmac_fifo_sel = _fifo_sel_drv2halmac(fifo_sel); - - if ((size) && (buffer)) { - pfifo_map = buffer; - fifo_size = size; - } else { - fifo_size = api->halmac_get_fifo_size(mac, halmac_fifo_sel); - - if (fifo_size) - pfifo_map = rtw_zvmalloc(fifo_size); - if (pfifo_map == NULL) - return -1; - mem_created = _TRUE; - } - - status = api->halmac_dump_fifo(mac, halmac_fifo_sel, addr, fifo_size, pfifo_map); - if (HALMAC_RET_SUCCESS != status) { - ret = -1; - goto _exit; - } - -#ifdef CONFIG_HALMAC_FIFO_DUMP - { - static const char * const fifo_sel_str[] = { - "TX", "RX", "RSVD_PAGE", "REPORT", "LLT" - }; - - RTW_INFO("%s FIFO DUMP [start_addr:0x%04x , size:%d]\n", fifo_sel_str[halmac_fifo_sel], addr, fifo_size); - RTW_INFO_DUMP("\n", pfifo_map, fifo_size); - RTW_INFO(" ==================================================\n"); - } -#endif - -_exit: - if (mem_created && pfifo_map) - rtw_vmfree(pfifo_map, fifo_size); - return ret; - -} - -int rtw_halmac_rx_agg_switch(struct dvobj_priv *d, u8 enable) -{ - PADAPTER adapter; - PHAL_DATA_TYPE hal; - PHALMAC_ADAPTER halmac; - PHALMAC_API api; - HALMAC_RXAGG_CFG rxaggcfg; - HALMAC_RET_STATUS status; - int err = -1; - - - adapter = dvobj_get_primary_adapter(d); - hal = GET_HAL_DATA(adapter); - halmac = dvobj_to_halmac(d); - api = HALMAC_GET_API(halmac); - _rtw_memset((void *)&rxaggcfg, 0, sizeof(rxaggcfg)); - - if (_TRUE == enable) { -#ifdef CONFIG_SDIO_HCI - rxaggcfg.mode = HALMAC_RX_AGG_MODE_DMA; - rxaggcfg.threshold.drv_define = 0; -#elif defined(CONFIG_USB_HCI) && defined(CONFIG_USB_RX_AGGREGATION) - switch (hal->rxagg_mode) { - case RX_AGG_DISABLE: - rxaggcfg.mode = HALMAC_RX_AGG_MODE_NONE; - break; - - case RX_AGG_DMA: - rxaggcfg.mode = HALMAC_RX_AGG_MODE_DMA; - if (hal->rxagg_dma_size || hal->rxagg_dma_timeout) { - rxaggcfg.threshold.drv_define = 1; - rxaggcfg.threshold.timeout = hal->rxagg_dma_timeout; - rxaggcfg.threshold.size = hal->rxagg_dma_size; - } - break; - - case RX_AGG_USB: - case RX_AGG_MIX: - rxaggcfg.mode = HALMAC_RX_AGG_MODE_USB; - if (hal->rxagg_usb_size || hal->rxagg_usb_timeout) { - rxaggcfg.threshold.drv_define = 1; - rxaggcfg.threshold.timeout = hal->rxagg_usb_timeout; - rxaggcfg.threshold.size = hal->rxagg_usb_size; - } - break; - } -#endif /* CONFIG_USB_HCI */ - } else - rxaggcfg.mode = HALMAC_RX_AGG_MODE_NONE; - - status = api->halmac_cfg_rx_aggregation(halmac, &rxaggcfg); - if (status != HALMAC_RET_SUCCESS) - goto out; - - err = 0; -out: - return err; -} - -/* - * Description: - * Get RX driver info size. RX driver info is a small memory space between - * scriptor and RX payload. - * - * +-------------------------+ - * | RX descriptor | - * | usually 24 bytes | - * +-------------------------+ - * | RX driver info | - * | depends on driver cfg | - * +-------------------------+ - * | RX paylad | - * | | - * +-------------------------+ - * - * Parameter: - * d pointer to struct dvobj_priv of driver - * sz rx driver info size in bytes. - * - * Rteurn: - * 0 Success - * other Fail - */ -int rtw_halmac_get_drv_info_sz(struct dvobj_priv *d, u8 *sz) -{ - HALMAC_RET_STATUS status; - PHALMAC_ADAPTER halmac = dvobj_to_halmac(d); - PHALMAC_API api = HALMAC_GET_API(halmac); - u8 dw = 0; - - status = api->halmac_get_hw_value(halmac, HALMAC_HW_DRV_INFO_SIZE, &dw); - if (status != HALMAC_RET_SUCCESS) - return -1; - - *sz = dw * 8; - return 0; -} -int rtw_halmac_get_rsvd_drv_pg_bndy(struct dvobj_priv *dvobj, u16 *drv_pg) -{ - HALMAC_RET_STATUS status; - PHALMAC_ADAPTER halmac = dvobj_to_halmac(dvobj); - PHALMAC_API api = HALMAC_GET_API(halmac); - - status = api->halmac_get_hw_value(halmac, HALMAC_HW_RSVD_PG_BNDY, drv_pg); - if (status != HALMAC_RET_SUCCESS) - return -1; - - return 0; -} - -int rtw_halmac_download_rsvd_page(struct dvobj_priv *dvobj, u8 pg_offset, u8 *pbuf, u32 size) -{ - HALMAC_RET_STATUS status = HALMAC_RET_SUCCESS; - PHALMAC_ADAPTER halmac = dvobj_to_halmac(dvobj); - PHALMAC_API api = HALMAC_GET_API(halmac); - - status = api->halmac_dl_drv_rsvd_page(halmac, pg_offset, pbuf, size); - if (status != HALMAC_RET_SUCCESS) - return -1; - - return 0; - -} - -/* - * Description - * Fill following spec info from HALMAC API: - * sec_cam_ent_num - * - * Return - * 0 Success - * others Fail - */ -int rtw_halmac_fill_hal_spec(struct dvobj_priv *dvobj, struct hal_spec_t *spec) -{ - HALMAC_RET_STATUS status; - PHALMAC_ADAPTER halmac; - PHALMAC_API api; - u8 cam = 0; /* Security Cam Entry Number */ - - - halmac = dvobj_to_halmac(dvobj); - api = HALMAC_GET_API(halmac); - - /* Prepare data from HALMAC */ - status = api->halmac_get_hw_value(halmac, HALMAC_HW_CAM_ENTRY_NUM, &cam); - if (status != HALMAC_RET_SUCCESS) - return -1; - - /* Fill data to hal_spec_t */ - spec->sec_cam_ent_num = cam; - - return 0; -} - -#ifdef CONFIG_SDIO_HCI - -/* - * Description: - * Update queue allocated page number to driver - * - * Parameter: - * d pointer to struct dvobj_priv of driver - * - * Rteurn: - * 0 Success, "page" is valid. - * others Fail, "page" is invalid. - */ -int rtw_halmac_query_tx_page_num(struct dvobj_priv *d) -{ - PADAPTER adapter; - struct halmacpriv *hmpriv; - PHALMAC_ADAPTER halmac; - PHALMAC_API api; - HALMAC_RQPN_MAP rqpn; - HALMAC_DMA_MAPPING dmaqueue; - HALMAC_TXFF_ALLOCATION fifosize; - HALMAC_RET_STATUS status; - u8 i; - - - adapter = dvobj_get_primary_adapter(d); - hmpriv = &d->hmpriv; - halmac = dvobj_to_halmac(d); - api = HALMAC_GET_API(halmac); - _rtw_memset((void *)&rqpn, 0, sizeof(rqpn)); - _rtw_memset((void *)&fifosize, 0, sizeof(fifosize)); - - status = api->halmac_get_hw_value(halmac, HALMAC_HW_RQPN_MAPPING, &rqpn); - if (status != HALMAC_RET_SUCCESS) - return -1; - status = api->halmac_get_hw_value(halmac, HALMAC_HW_TXFF_ALLOCATION, &fifosize); - if (status != HALMAC_RET_SUCCESS) - return -1; - - for (i = 0; i < HW_QUEUE_ENTRY; i++) { - hmpriv->txpage[i] = 0; - - /* Driver index mapping to HALMAC DMA queue */ - dmaqueue = HALMAC_DMA_MAPPING_UNDEFINE; - switch (i) { - case VO_QUEUE_INX: - dmaqueue = rqpn.dma_map_vo; - break; - case VI_QUEUE_INX: - dmaqueue = rqpn.dma_map_vi; - break; - case BE_QUEUE_INX: - dmaqueue = rqpn.dma_map_be; - break; - case BK_QUEUE_INX: - dmaqueue = rqpn.dma_map_bk; - break; - case MGT_QUEUE_INX: - dmaqueue = rqpn.dma_map_mg; - break; - case HIGH_QUEUE_INX: - dmaqueue = rqpn.dma_map_hi; - break; - case BCN_QUEUE_INX: - case TXCMD_QUEUE_INX: - /* Unlimited */ - hmpriv->txpage[i] = 0xFFFF; - continue; - } - - switch (dmaqueue) { - case HALMAC_DMA_MAPPING_EXTRA: - hmpriv->txpage[i] = fifosize.extra_queue_pg_num; - break; - case HALMAC_DMA_MAPPING_LOW: - hmpriv->txpage[i] = fifosize.low_queue_pg_num; - break; - case HALMAC_DMA_MAPPING_NORMAL: - hmpriv->txpage[i] = fifosize.normal_queue_pg_num; - break; - case HALMAC_DMA_MAPPING_HIGH: - hmpriv->txpage[i] = fifosize.high_queue_pg_num; - break; - case HALMAC_DMA_MAPPING_UNDEFINE: - break; - } - hmpriv->txpage[i] += fifosize.pub_queue_pg_num; - } - - return 0; -} - -/* - * Description: - * Get specific queue allocated page number - * - * Parameter: - * d pointer to struct dvobj_priv of driver - * queue target queue to query, VO/VI/BE/BK/.../TXCMD_QUEUE_INX - * page return allocated page number - * - * Rteurn: - * 0 Success, "page" is valid. - * others Fail, "page" is invalid. - */ -int rtw_halmac_get_tx_queue_page_num(struct dvobj_priv *d, u8 queue, u32 *page) -{ - *page = 0; - if (queue < HW_QUEUE_ENTRY) - *page = d->hmpriv.txpage[queue]; - - return 0; -} - -/* - * Return: - * address for SDIO command - */ -u32 rtw_halmac_sdio_get_tx_addr(struct dvobj_priv *d, u8 *desc, u32 size) -{ - PHALMAC_ADAPTER mac; - PHALMAC_API api; - HALMAC_RET_STATUS status; - u32 addr; - - - mac = dvobj_to_halmac(d); - api = HALMAC_GET_API(mac); - - status = api->halmac_get_sdio_tx_addr(mac, desc, size, &addr); - if (HALMAC_RET_SUCCESS != status) - return 0; - - return addr; -} - -int rtw_halmac_sdio_tx_allowed(struct dvobj_priv *d, u8 *buf, u32 size) -{ - PHALMAC_ADAPTER mac; - PHALMAC_API api; - HALMAC_RET_STATUS status; - - - mac = dvobj_to_halmac(d); - api = HALMAC_GET_API(mac); - - status = api->halmac_tx_allowed_sdio(mac, buf, size); - if (HALMAC_RET_SUCCESS != status) - return -1; - - return 0; -} - -u32 rtw_halmac_sdio_get_rx_addr(struct dvobj_priv *d, u8 *seq) -{ - u8 id; - -#define RTW_SDIO_ADDR_RX_RX0FF_PRFIX 0x0E000 -#define RTW_SDIO_ADDR_RX_RX0FF_GEN(a) (RTW_SDIO_ADDR_RX_RX0FF_PRFIX|(a&0x3)) - - id = *seq; - (*seq)++; - return RTW_SDIO_ADDR_RX_RX0FF_GEN(id); -} -#endif /* CONFIG_SDIO_HCI */ - -#ifdef CONFIG_USB_HCI -u8 rtw_halmac_usb_get_bulkout_id(struct dvobj_priv *d, u8 *buf, u32 size) -{ - PHALMAC_ADAPTER mac; - PHALMAC_API api; - HALMAC_RET_STATUS status; - u8 bulkout_id; - - - mac = dvobj_to_halmac(d); - api = HALMAC_GET_API(mac); - - status = api->halmac_get_usb_bulkout_id(mac, buf, size, &bulkout_id); - if (HALMAC_RET_SUCCESS != status) - return 0; - - return bulkout_id; -} - -static inline HALMAC_USB_MODE _usb_mode_drv2halmac(enum RTW_USB_SPEED usb_mode) -{ - HALMAC_USB_MODE halmac_usb_mode = HALMAC_USB_MODE_U2; - - switch (usb_mode) { - case RTW_USB_SPEED_2: - halmac_usb_mode = HALMAC_USB_MODE_U2; - break; - case RTW_USB_SPEED_3: - halmac_usb_mode = HALMAC_USB_MODE_U3; - break; - default: - halmac_usb_mode = HALMAC_USB_MODE_U2; - break; - } - - return halmac_usb_mode; -} - -u8 rtw_halmac_switch_usb_mode(struct dvobj_priv *d, enum RTW_USB_SPEED usb_mode) -{ - PHALMAC_ADAPTER mac; - PHALMAC_API api; - HALMAC_RET_STATUS status; - PADAPTER adapter; - HALMAC_USB_MODE halmac_usb_mode; - - adapter = dvobj_get_primary_adapter(d); - mac = dvobj_to_halmac(d); - api = HALMAC_GET_API(mac); - halmac_usb_mode = _usb_mode_drv2halmac(usb_mode); - status = api->halmac_set_hw_value(mac, HALMAC_HW_USB_MODE, (void *)&halmac_usb_mode); - - if (HALMAC_RET_SUCCESS != status) - return _FAIL; - - return _SUCCESS; -} -#endif /* CONFIG_USB_HCI */ diff --git a/hal/hal_halmac.h b/hal/hal_halmac.h deleted file mode 100644 index 980e8a4..0000000 --- a/hal/hal_halmac.h +++ /dev/null @@ -1,121 +0,0 @@ -/****************************************************************************** - * - * Copyright(c) 2015 - 2016 Realtek Corporation. All rights reserved. - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of version 2 of the GNU General Public License as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA - * - * - ******************************************************************************/ -#ifndef _HAL_HALMAC_H_ -#define _HAL_HALMAC_H_ - -#include /* adapter_to_dvobj(), struct intf_hdl and etc. */ -#include /* struct hal_spec_t */ -#include "halmac/halmac_api.h" /* PHALMAC_ADAPTER and etc. */ - -/* HALMAC Definition for Driver */ -#define RTW_HALMAC_H2C_MAX_SIZE HALMAC_H2C_CMD_ORIGINAL_SIZE_88XX -#define RTW_HALMAC_BA_SSN_RPT_SIZE 4 - -#define dvobj_set_halmac(d, mac) ((d)->halmac = (mac)) -#define dvobj_to_halmac(d) ((PHALMAC_ADAPTER)((d)->halmac)) -#define adapter_to_halmac(p) dvobj_to_halmac(adapter_to_dvobj(p)) - -/* for H2C cmd */ -#define MAX_H2C_BOX_NUMS 4 -#define MESSAGE_BOX_SIZE 4 -#define EX_MESSAGE_BOX_SIZE 4 - -typedef enum _RTW_HALMAC_MODE { - RTW_HALMAC_MODE_NORMAL, - RTW_HALMAC_MODE_WIFI_TEST, -} RTW_HALMAC_MODE; - -extern HALMAC_PLATFORM_API rtw_halmac_platform_api; - -/* HALMAC API for Driver(HAL) */ -u8 rtw_halmac_read8(struct intf_hdl *, u32 addr); -u16 rtw_halmac_read16(struct intf_hdl *, u32 addr); -u32 rtw_halmac_read32(struct intf_hdl *, u32 addr); -void rtw_halmac_read_mem(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *pmem); -#ifdef CONFIG_SDIO_INDIRECT_ACCESS -u8 rtw_halmac_iread8(struct intf_hdl *pintfhdl, u32 addr); -u16 rtw_halmac_iread16(struct intf_hdl *pintfhdl, u32 addr); -u32 rtw_halmac_iread32(struct intf_hdl *pintfhdl, u32 addr); -#endif -int rtw_halmac_write8(struct intf_hdl *, u32 addr, u8 value); -int rtw_halmac_write16(struct intf_hdl *, u32 addr, u16 value); -int rtw_halmac_write32(struct intf_hdl *, u32 addr, u32 value); - -void rtw_dump_halmac_info(void *sel); -int rtw_halmac_init_adapter(struct dvobj_priv *, PHALMAC_PLATFORM_API); -int rtw_halmac_deinit_adapter(struct dvobj_priv *); -int rtw_halmac_poweron(struct dvobj_priv *); -int rtw_halmac_poweroff(struct dvobj_priv *); -int rtw_halmac_init_hal(struct dvobj_priv *); -int rtw_halmac_init_hal_fw(struct dvobj_priv *, u8 *fw, u32 fwsize); -int rtw_halmac_init_hal_fw_file(struct dvobj_priv *, u8 *fwpath); -int rtw_halmac_deinit_hal(struct dvobj_priv *); -int rtw_halmac_self_verify(struct dvobj_priv *); -int rtw_halmac_dlfw(struct dvobj_priv *, u8 *fw, u32 fwsize); -int rtw_halmac_dlfw_from_file(struct dvobj_priv *, u8 *fwpath); -int rtw_halmac_phy_power_switch(struct dvobj_priv *, u8 enable); -int rtw_halmac_send_h2c(struct dvobj_priv *, u8 *h2c); -int rtw_halmac_c2h_handle(struct dvobj_priv *, u8 *c2h, u32 size); -int rtw_halmac_get_available_efuse_size(struct dvobj_priv *d, u32 *size); - -int rtw_halmac_get_physical_efuse_size(struct dvobj_priv *, u32 *size); -int rtw_halmac_read_physical_efuse_map(struct dvobj_priv *, u8 *map, u32 size); -int rtw_halmac_read_physical_efuse(struct dvobj_priv *, u32 offset, u32 cnt, u8 *data); -int rtw_halmac_write_physical_efuse(struct dvobj_priv *, u32 offset, u32 cnt, u8 *data); -int rtw_halmac_get_logical_efuse_size(struct dvobj_priv *, u32 *size); -int rtw_halmac_read_logical_efuse_map(struct dvobj_priv *, u8 *map, u32 size); -int rtw_halmac_write_logical_efuse_map(struct dvobj_priv *, u8 *map, u32 size, u8 *maskmap, u32 masksize); -int rtw_halmac_read_logical_efuse(struct dvobj_priv *, u32 offset, u32 cnt, u8 *data); -int rtw_halmac_write_logical_efuse(struct dvobj_priv *, u32 offset, u32 cnt, u8 *data); - -int rtw_halmac_write_bt_physical_efuse(struct dvobj_priv *, u32 offset, u32 cnt, u8 *data); -int rtw_halmac_read_bt_physical_efuse_map(struct dvobj_priv *, u8 *map, u32 size); - -int rtw_halmac_config_rx_info(struct dvobj_priv *, HALMAC_DRV_INFO); -int rtw_halmac_set_mac_address(struct dvobj_priv *, enum _hw_port, u8 *addr); -int rtw_halmac_set_bssid(struct dvobj_priv *, enum _hw_port hwport, u8 *addr); - -int rtw_halmac_set_bandwidth(struct dvobj_priv *, u8 channel, u8 pri_ch_idx, u8 bw); -int rtw_halmac_dump_fifo(struct dvobj_priv *d, u8 fifo_sel, u32 addr, u32 size, u8 *buffer); -int rtw_halmac_rx_agg_switch(struct dvobj_priv *, u8 enable); -int rtw_halmac_get_hw_value(struct dvobj_priv *, HALMAC_HW_ID hw_id, VOID *pvalue); -int rtw_halmac_get_wow_reason(struct dvobj_priv *, u8 *reason); -int rtw_halmac_get_drv_info_sz(struct dvobj_priv *, u8 *sz); -int rtw_halmac_get_rsvd_drv_pg_bndy(struct dvobj_priv *dvobj, u16 *drv_pg); -int rtw_halmac_download_rsvd_page(struct dvobj_priv *dvobj, u8 pg_offset, u8 *pbuf, u32 size); -int rtw_halmac_fill_hal_spec(struct dvobj_priv *, struct hal_spec_t *); - -#ifdef CONFIG_SDIO_HCI -int rtw_halmac_query_tx_page_num(struct dvobj_priv *); -int rtw_halmac_get_tx_queue_page_num(struct dvobj_priv *, u8 queue, u32 *page); -u32 rtw_halmac_sdio_get_tx_addr(struct dvobj_priv *, u8 *desc, u32 size); -int rtw_halmac_sdio_tx_allowed(struct dvobj_priv *, u8 *buf, u32 size); -u32 rtw_halmac_sdio_get_rx_addr(struct dvobj_priv *, u8 *seq); -#endif /* CONFIG_SDIO_HCI */ - -#ifdef CONFIG_USB_HCI -u8 rtw_halmac_usb_get_bulkout_id(struct dvobj_priv *, u8 *buf, u32 size); -u8 rtw_halmac_switch_usb_mode(struct dvobj_priv *d, enum RTW_USB_SPEED usb_mode); -#endif /* CONFIG_USB_HCI */ - -#ifdef CONFIG_SUPPORT_TRX_SHARED -void dump_trx_share_mode(void *sel, _adapter *adapter); -#endif -#endif /* _HAL_HALMAC_H_ */ diff --git a/hal/phydm/phydm_beamforming.h b/hal/phydm/phydm_beamforming.h index f13fa0b..ad76dcc 100644 --- a/hal/phydm/phydm_beamforming.h +++ b/hal/phydm/phydm_beamforming.h @@ -8,9 +8,6 @@ /*Beamforming Related*/ #include "txbf/halcomtxbf.h" #include "txbf/haltxbfjaguar.h" -#include "txbf/haltxbf8192e.h" -#include "txbf/haltxbf8814a.h" -#include "txbf/haltxbf8822b.h" #include "txbf/haltxbfinterface.h" #if (BEAMFORMING_SUPPORT == 1) diff --git a/hal/phydm/txbf/haltxbf8192e.c b/hal/phydm/txbf/haltxbf8192e.c deleted file mode 100644 index 7be33f0..0000000 --- a/hal/phydm/txbf/haltxbf8192e.c +++ /dev/null @@ -1,391 +0,0 @@ -/* ************************************************************ - * Description: - * - * This file is for 8192E TXBF mechanism - * - * ************************************************************ */ -#include "mp_precomp.h" -#include "../phydm_precomp.h" - -#if (BEAMFORMING_SUPPORT == 1) -#if (RTL8192E_SUPPORT == 1) - -void -hal_txbf_8192e_set_ndpa_rate( - void *p_dm_void, - u8 BW, - u8 rate -) -{ - struct PHY_DM_STRUCT *p_dm_odm = (struct PHY_DM_STRUCT *)p_dm_void; - - odm_write_1byte(p_dm_odm, REG_NDPA_OPT_CTRL_8192E, (rate << 2 | BW)); - -} - -void -hal_txbf_8192e_rf_mode( - void *p_dm_void, - struct _RT_BEAMFORMING_INFO *p_beam_info -) -{ - struct PHY_DM_STRUCT *p_dm_odm = (struct PHY_DM_STRUCT *)p_dm_void; - bool is_self_beamformer = false; - bool is_self_beamformee = false; - enum beamforming_cap beamform_cap = BEAMFORMING_CAP_NONE; - - ODM_RT_TRACE(p_dm_odm, PHYDM_COMP_TXBF, ODM_DBG_LOUD, ("[%s] Start!\n", __func__)); - - if (p_dm_odm->rf_type == ODM_1T1R) - return; - - odm_set_rf_reg(p_dm_odm, ODM_RF_PATH_A, RF_WE_LUT, 0x80000, 0x1); /*RF mode table write enable*/ - odm_set_rf_reg(p_dm_odm, ODM_RF_PATH_B, RF_WE_LUT, 0x80000, 0x1); /*RF mode table write enable*/ - - if (p_beam_info->beamformee_su_cnt > 0) { - /*Path_A*/ - odm_set_rf_reg(p_dm_odm, ODM_RF_PATH_A, 0x30, 0xfffff, 0x18000); /*Select RX mode 0x30=0x18000*/ - odm_set_rf_reg(p_dm_odm, ODM_RF_PATH_A, 0x31, 0xfffff, 0x0000f); /*Set Table data*/ - odm_set_rf_reg(p_dm_odm, ODM_RF_PATH_A, 0x32, 0xfffff, 0x77fc2); /*Enable TXIQGEN in RX mode*/ - /*Path_B*/ - odm_set_rf_reg(p_dm_odm, ODM_RF_PATH_B, 0x30, 0xfffff, 0x18000); /*Select RX mode*/ - odm_set_rf_reg(p_dm_odm, ODM_RF_PATH_B, 0x31, 0xfffff, 0x0000f); /*Set Table data*/ - odm_set_rf_reg(p_dm_odm, ODM_RF_PATH_B, 0x32, 0xfffff, 0x77fc2); /*Enable TXIQGEN in RX mode*/ - } else { - /*Path_A*/ - odm_set_rf_reg(p_dm_odm, ODM_RF_PATH_A, 0x30, 0xfffff, 0x18000); /*Select RX mode*/ - odm_set_rf_reg(p_dm_odm, ODM_RF_PATH_A, 0x31, 0xfffff, 0x0000f); /*Set Table data*/ - odm_set_rf_reg(p_dm_odm, ODM_RF_PATH_A, 0x32, 0xfffff, 0x77f82); /*Disable TXIQGEN in RX mode*/ - /*Path_B*/ - odm_set_rf_reg(p_dm_odm, ODM_RF_PATH_B, 0x30, 0xfffff, 0x18000); /*Select RX mode*/ - odm_set_rf_reg(p_dm_odm, ODM_RF_PATH_B, 0x31, 0xfffff, 0x0000f); /*Set Table data*/ - odm_set_rf_reg(p_dm_odm, ODM_RF_PATH_B, 0x32, 0xfffff, 0x77f82); /*Disable TXIQGEN in RX mode*/ - } - - odm_set_rf_reg(p_dm_odm, ODM_RF_PATH_A, RF_WE_LUT, 0x80000, 0x0); /*RF mode table write disable*/ - odm_set_rf_reg(p_dm_odm, ODM_RF_PATH_B, RF_WE_LUT, 0x80000, 0x0); /*RF mode table write disable*/ - - if (p_beam_info->beamformee_su_cnt > 0) { - odm_set_bb_reg(p_dm_odm, 0x90c, MASKDWORD, 0x83321333); - odm_set_bb_reg(p_dm_odm, 0xa04, MASKBYTE3, 0xc1); - } else - odm_set_bb_reg(p_dm_odm, 0x90c, MASKDWORD, 0x81121313); -} - - - -void -hal_txbf_8192e_fw_txbf_cmd( - void *p_dm_void -) -{ - struct PHY_DM_STRUCT *p_dm_odm = (struct PHY_DM_STRUCT *)p_dm_void; - u8 idx, period0 = 0, period1 = 0; - u8 PageNum0 = 0xFF, PageNum1 = 0xFF; - u8 u1_tx_bf_parm[3] = {0}; - struct _RT_BEAMFORMING_INFO *p_beam_info = &p_dm_odm->beamforming_info; - - for (idx = 0; idx < BEAMFORMEE_ENTRY_NUM; idx++) { - if (p_beam_info->beamformee_entry[idx].beamform_entry_state == BEAMFORMING_ENTRY_STATE_PROGRESSED) { - if (idx == 0) { - if (p_beam_info->beamformee_entry[idx].is_sound) - PageNum0 = 0xFE; - else - PageNum0 = 0xFF; /* stop sounding */ - period0 = (u8)(p_beam_info->beamformee_entry[idx].sound_period); - } else if (idx == 1) { - if (p_beam_info->beamformee_entry[idx].is_sound) - PageNum1 = 0xFE; - else - PageNum1 = 0xFF; /* stop sounding */ - period1 = (u8)(p_beam_info->beamformee_entry[idx].sound_period); - } - } - } - - u1_tx_bf_parm[0] = PageNum0; - u1_tx_bf_parm[1] = PageNum1; - u1_tx_bf_parm[2] = (period1 << 4) | period0; - odm_fill_h2c_cmd(p_dm_odm, PHYDM_H2C_TXBF, 3, u1_tx_bf_parm); - - ODM_RT_TRACE(p_dm_odm, PHYDM_COMP_TXBF, ODM_DBG_LOUD, - ("[%s] PageNum0 = %d period0 = %d, PageNum1 = %d period1 %d\n", __func__, PageNum0, period0, PageNum1, period1)); -} - - -void -hal_txbf_8192e_download_ndpa( - void *p_dm_void, - u8 idx -) -{ - struct PHY_DM_STRUCT *p_dm_odm = (struct PHY_DM_STRUCT *)p_dm_void; - u8 u1b_tmp = 0, tmp_reg422 = 0, head_page; - u8 bcn_valid_reg = 0, count = 0, dl_bcn_count = 0; - bool is_send_beacon = false; - struct _ADAPTER *adapter = p_dm_odm->adapter; - u8 tx_page_bndy = LAST_ENTRY_OF_TX_PKT_BUFFER_8812; - /*default reseved 1 page for the IC type which is undefined.*/ - struct _RT_BEAMFORMING_INFO *p_beam_info = &p_dm_odm->beamforming_info; - struct _RT_BEAMFORMEE_ENTRY *p_beam_entry = p_beam_info->beamformee_entry + idx; - - ODM_RT_TRACE(p_dm_odm, PHYDM_COMP_TXBF, ODM_DBG_LOUD, ("[%s] Start!\n", __func__)); -#if (DM_ODM_SUPPORT_TYPE == ODM_WIN) - *p_dm_odm->p_is_fw_dw_rsvd_page_in_progress = true; -#endif - if (idx == 0) - head_page = 0xFE; - else - head_page = 0xFE; - - phydm_get_hal_def_var_handler_interface(p_dm_odm, HAL_DEF_TX_PAGE_BOUNDARY, (u8 *)&tx_page_bndy); - - /*Set REG_CR bit 8. DMA beacon by SW.*/ - u1b_tmp = odm_read_1byte(p_dm_odm, REG_CR_8192E+1); - odm_write_1byte(p_dm_odm, REG_CR_8192E+1, (u1b_tmp | BIT(0))); - - /*Set FWHW_TXQ_CTRL 0x422[6]=0 to tell Hw the packet is not a real beacon frame.*/ - tmp_reg422 = odm_read_1byte(p_dm_odm, REG_FWHW_TXQ_CTRL_8192E+2); - odm_write_1byte(p_dm_odm, REG_FWHW_TXQ_CTRL_8192E+2, tmp_reg422 & (~BIT(6))); - - if (tmp_reg422 & BIT(6)) { - ODM_RT_TRACE(p_dm_odm, PHYDM_COMP_TXBF, ODM_DBG_WARNING, ("%s There is an adapter is sending beacon.\n", __func__)); - is_send_beacon = true; - } - - /*TDECTRL[15:8] 0x209[7:0] = 0xFE/0xFD NDPA Head for TXDMA*/ - odm_write_1byte(p_dm_odm, REG_DWBCN0_CTRL_8192E+1, head_page); - - do { - /*Clear beacon valid check bit.*/ - bcn_valid_reg = odm_read_1byte(p_dm_odm, REG_DWBCN0_CTRL_8192E+2); - odm_write_1byte(p_dm_odm, REG_DWBCN0_CTRL_8192E+2, (bcn_valid_reg | BIT(0))); - - /* download NDPA rsvd page. */ - beamforming_send_ht_ndpa_packet(p_dm_odm, p_beam_entry->mac_addr, p_beam_entry->sound_bw, BEACON_QUEUE); - -#if (DEV_BUS_TYPE == RT_PCI_INTERFACE) - u1b_tmp = odm_read_1byte(p_dm_odm, REG_MGQ_TXBD_NUM_8192E+3); - count = 0; - while ((count < 20) && (u1b_tmp & BIT(4))) { - count++; - ODM_delay_us(10); - u1b_tmp = odm_read_1byte(p_dm_odm, REG_MGQ_TXBD_NUM_8192E+3); - } - odm_write_1byte(p_dm_odm, REG_MGQ_TXBD_NUM_8192E+3, u1b_tmp | BIT(4)); -#endif - - /*check rsvd page download OK.*/ - bcn_valid_reg = odm_read_1byte(p_dm_odm, REG_DWBCN0_CTRL_8192E+2); - count = 0; - while (!(bcn_valid_reg & BIT(0)) && count < 20) { - count++; - ODM_delay_us(10); - bcn_valid_reg = odm_read_1byte(p_dm_odm, REG_DWBCN0_CTRL_8192E+2); - } - dl_bcn_count++; - } while (!(bcn_valid_reg & BIT(0)) && dl_bcn_count < 5); - - if (!(bcn_valid_reg & BIT(0))) - ODM_RT_TRACE(p_dm_odm, PHYDM_COMP_TXBF, ODM_DBG_WARNING, ("%s Download RSVD page failed!\n", __func__)); - - /*TDECTRL[15:8] 0x209[7:0] = 0xF9 Beacon Head for TXDMA*/ - odm_write_1byte(p_dm_odm, REG_DWBCN0_CTRL_8192E+1, tx_page_bndy); - - /*To make sure that if there exists an adapter which would like to send beacon.*/ - /*If exists, the origianl value of 0x422[6] will be 1, we should check this to*/ - /*prevent from setting 0x422[6] to 0 after download reserved page, or it will cause*/ - /*the beacon cannot be sent by HW.*/ - /*2010.06.23. Added by tynli.*/ - if (is_send_beacon) - odm_write_1byte(p_dm_odm, REG_FWHW_TXQ_CTRL_8192E+2, tmp_reg422); - - /*Do not enable HW DMA BCN or it will cause Pcie interface hang by timing issue. 2011.11.24. by tynli.*/ - /*Clear CR[8] or beacon packet will not be send to TxBuf anymore.*/ - u1b_tmp = odm_read_1byte(p_dm_odm, REG_CR_8192E+1); - odm_write_1byte(p_dm_odm, REG_CR_8192E+1, (u1b_tmp & (~BIT(0)))); - - p_beam_entry->beamform_entry_state = BEAMFORMING_ENTRY_STATE_PROGRESSED; -#if (DM_ODM_SUPPORT_TYPE == ODM_WIN) - *p_dm_odm->p_is_fw_dw_rsvd_page_in_progress = false; -#endif -} - - -void -hal_txbf_8192e_enter( - void *p_dm_void, - u8 bfer_bfee_idx -) -{ - struct PHY_DM_STRUCT *p_dm_odm = (struct PHY_DM_STRUCT *)p_dm_void; - u8 i = 0; - u8 bfer_idx = (bfer_bfee_idx & 0xF0) >> 4; - u8 bfee_idx = (bfer_bfee_idx & 0xF); - u32 csi_param; - struct _RT_BEAMFORMING_INFO *p_beamforming_info = &p_dm_odm->beamforming_info; - struct _RT_BEAMFORMEE_ENTRY beamformee_entry; - struct _RT_BEAMFORMER_ENTRY beamformer_entry; - u16 sta_id = 0; - - ODM_RT_TRACE(p_dm_odm, PHYDM_COMP_TXBF, ODM_DBG_LOUD, ("[%s] Start!\n", __func__)); - - hal_txbf_8192e_rf_mode(p_dm_odm, p_beamforming_info); - - if (p_dm_odm->rf_type == ODM_2T2R) - odm_write_4byte(p_dm_odm, 0xd80, 0x00000000); /*nc =2*/ - - if ((p_beamforming_info->beamformer_su_cnt > 0) && (bfer_idx < BEAMFORMER_ENTRY_NUM)) { - beamformer_entry = p_beamforming_info->beamformer_entry[bfer_idx]; - - /*Sounding protocol control*/ - odm_write_1byte(p_dm_odm, REG_SND_PTCL_CTRL_8192E, 0xCB); - - /*MAC address/Partial AID of Beamformer*/ - if (bfer_idx == 0) { - for (i = 0; i < 6 ; i++) - odm_write_1byte(p_dm_odm, (REG_ASSOCIATED_BFMER0_INFO_8192E+i), beamformer_entry.mac_addr[i]); - } else { - for (i = 0; i < 6 ; i++) - odm_write_1byte(p_dm_odm, (REG_ASSOCIATED_BFMER1_INFO_8192E+i), beamformer_entry.mac_addr[i]); - } - - /*CSI report parameters of Beamformer Default use nc = 2*/ - csi_param = 0x03090309; - - odm_write_4byte(p_dm_odm, REG_CSI_RPT_PARAM_BW20_8192E, csi_param); - odm_write_4byte(p_dm_odm, REG_CSI_RPT_PARAM_BW40_8192E, csi_param); - odm_write_4byte(p_dm_odm, REG_CSI_RPT_PARAM_BW80_8192E, csi_param); - - /*Timeout value for MAC to leave NDP_RX_standby_state (60 us, Test chip) (80 us, MP chip)*/ - odm_write_1byte(p_dm_odm, REG_SND_PTCL_CTRL_8192E+3, 0x50); - - } - - if ((p_beamforming_info->beamformee_su_cnt > 0) && (bfee_idx < BEAMFORMEE_ENTRY_NUM)) { - beamformee_entry = p_beamforming_info->beamformee_entry[bfee_idx]; - - if (phydm_acting_determine(p_dm_odm, phydm_acting_as_ibss)) - sta_id = beamformee_entry.mac_id; - else - sta_id = beamformee_entry.p_aid; - - ODM_RT_TRACE(p_dm_odm, PHYDM_COMP_TXBF, ODM_DBG_LOUD, ("[%s], sta_id=0x%X\n", __func__, sta_id)); - - /*P_AID of Beamformee & enable NDPA transmission & enable NDPA interrupt*/ - if (bfee_idx == 0) { - odm_write_2byte(p_dm_odm, REG_TXBF_CTRL_8192E, sta_id); - odm_write_1byte(p_dm_odm, REG_TXBF_CTRL_8192E+3, odm_read_1byte(p_dm_odm, REG_TXBF_CTRL_8192E+3) | BIT(4) | BIT(6) | BIT(7)); - } else - odm_write_2byte(p_dm_odm, REG_TXBF_CTRL_8192E+2, sta_id | BIT(12) | BIT(14) | BIT(15)); - - /*CSI report parameters of Beamformee*/ - if (bfee_idx == 0) { - /*Get BIT24 & BIT25*/ - u8 tmp = odm_read_1byte(p_dm_odm, REG_ASSOCIATED_BFMEE_SEL_8192E+3) & 0x3; - - odm_write_1byte(p_dm_odm, REG_ASSOCIATED_BFMEE_SEL_8192E+3, tmp | 0x60); - odm_write_2byte(p_dm_odm, REG_ASSOCIATED_BFMEE_SEL_8192E, sta_id | BIT(9)); - } else { - /*Set BIT25*/ - odm_write_2byte(p_dm_odm, REG_ASSOCIATED_BFMEE_SEL_8192E+2, sta_id | 0xE200); - } - phydm_beamforming_notify(p_dm_odm); - - } -} - - -void -hal_txbf_8192e_leave( - void *p_dm_void, - u8 idx -) -{ - struct PHY_DM_STRUCT *p_dm_odm = (struct PHY_DM_STRUCT *)p_dm_void; - struct _RT_BEAMFORMING_INFO *p_beam_info = &p_dm_odm->beamforming_info; - - hal_txbf_8192e_rf_mode(p_dm_odm, p_beam_info); - - /* Clear P_AID of Beamformee - * Clear MAC addresss of Beamformer - * Clear Associated Bfmee Sel - */ - if (p_beam_info->beamform_cap == BEAMFORMING_CAP_NONE) - odm_write_1byte(p_dm_odm, REG_SND_PTCL_CTRL_8192E, 0xC8); - - if (idx == 0) { - odm_write_2byte(p_dm_odm, REG_TXBF_CTRL_8192E, 0); - odm_write_4byte(p_dm_odm, REG_ASSOCIATED_BFMER0_INFO_8192E, 0); - odm_write_2byte(p_dm_odm, REG_ASSOCIATED_BFMER0_INFO_8192E+4, 0); - odm_write_2byte(p_dm_odm, REG_ASSOCIATED_BFMEE_SEL_8192E, 0); - } else { - odm_write_2byte(p_dm_odm, REG_TXBF_CTRL_8192E+2, odm_read_1byte(p_dm_odm, REG_TXBF_CTRL_8192E+2) & 0xF000); - odm_write_4byte(p_dm_odm, REG_ASSOCIATED_BFMER1_INFO_8192E, 0); - odm_write_2byte(p_dm_odm, REG_ASSOCIATED_BFMER1_INFO_8192E+4, 0); - odm_write_2byte(p_dm_odm, REG_ASSOCIATED_BFMEE_SEL_8192E+2, odm_read_2byte(p_dm_odm, REG_ASSOCIATED_BFMEE_SEL_8192E+2) & 0x60); - } - - ODM_RT_TRACE(p_dm_odm, PHYDM_COMP_TXBF, ODM_DBG_LOUD, ("[%s] idx %d\n", __func__, idx)); -} - - -void -hal_txbf_8192e_status( - void *p_dm_void, - u8 idx -) -{ - struct PHY_DM_STRUCT *p_dm_odm = (struct PHY_DM_STRUCT *)p_dm_void; - u16 beam_ctrl_val; - u32 beam_ctrl_reg; - struct _RT_BEAMFORMING_INFO *p_beam_info = &p_dm_odm->beamforming_info; - struct _RT_BEAMFORMEE_ENTRY beamform_entry = p_beam_info->beamformee_entry[idx]; - - if (phydm_acting_determine(p_dm_odm, phydm_acting_as_ibss)) - beam_ctrl_val = beamform_entry.mac_id; - else - beam_ctrl_val = beamform_entry.p_aid; - - if (idx == 0) - beam_ctrl_reg = REG_TXBF_CTRL_8192E; - else { - beam_ctrl_reg = REG_TXBF_CTRL_8192E+2; - beam_ctrl_val |= BIT(12) | BIT(14) | BIT(15); - } - - if ((beamform_entry.beamform_entry_state == BEAMFORMING_ENTRY_STATE_PROGRESSED) && (p_beam_info->apply_v_matrix == true)) { - if (beamform_entry.sound_bw == CHANNEL_WIDTH_20) - beam_ctrl_val |= BIT(9); - else if (beamform_entry.sound_bw == CHANNEL_WIDTH_40) - beam_ctrl_val |= BIT(10); - } else - beam_ctrl_val &= ~(BIT(9) | BIT(10) | BIT(11)); - - odm_write_2byte(p_dm_odm, beam_ctrl_reg, beam_ctrl_val); - - ODM_RT_TRACE(p_dm_odm, PHYDM_COMP_TXBF, ODM_DBG_LOUD, ("[%s] idx %d beam_ctrl_reg %x beam_ctrl_val %x\n", __func__, idx, beam_ctrl_reg, beam_ctrl_val)); -} - - -void -hal_txbf_8192e_fw_tx_bf( - void *p_dm_void, - u8 idx -) -{ - struct PHY_DM_STRUCT *p_dm_odm = (struct PHY_DM_STRUCT *)p_dm_void; - struct _RT_BEAMFORMING_INFO *p_beam_info = &p_dm_odm->beamforming_info; - struct _RT_BEAMFORMEE_ENTRY *p_beam_entry = p_beam_info->beamformee_entry + idx; - - ODM_RT_TRACE(p_dm_odm, PHYDM_COMP_TXBF, ODM_DBG_LOUD, ("[%s] Start!\n", __func__)); - - if (p_beam_entry->beamform_entry_state == BEAMFORMING_ENTRY_STATE_PROGRESSING) - hal_txbf_8192e_download_ndpa(p_dm_odm, idx); - - hal_txbf_8192e_fw_txbf_cmd(p_dm_odm); -} - -#endif /* #if (RTL8192E_SUPPORT == 1)*/ - -#endif diff --git a/hal/phydm/txbf/haltxbf8192e.h b/hal/phydm/txbf/haltxbf8192e.h deleted file mode 100644 index 618ca80..0000000 --- a/hal/phydm/txbf/haltxbf8192e.h +++ /dev/null @@ -1,60 +0,0 @@ -#ifndef __HAL_TXBF_8192E_H__ -#define __HAL_TXBF_8192E_H__ - -#if (RTL8192E_SUPPORT == 1) -#if (BEAMFORMING_SUPPORT == 1) - -void -hal_txbf_8192e_set_ndpa_rate( - void *p_dm_void, - u8 BW, - u8 rate -); - -void -hal_txbf_8192e_enter( - void *p_dm_void, - u8 idx -); - - -void -hal_txbf_8192e_leave( - void *p_dm_void, - u8 idx -); - - -void -hal_txbf_8192e_status( - void *p_dm_void, - u8 idx -); - - -void -hal_txbf_8192e_fw_tx_bf( - void *p_dm_void, - u8 idx -); -#else - -#define hal_txbf_8192e_set_ndpa_rate(p_dm_void, BW, rate) -#define hal_txbf_8192e_enter(p_dm_void, idx) -#define hal_txbf_8192e_leave(p_dm_void, idx) -#define hal_txbf_8192e_status(p_dm_void, idx) -#define hal_txbf_8192e_fw_tx_bf(p_dm_void, idx) - -#endif - -#else - -#define hal_txbf_8192e_set_ndpa_rate(p_dm_void, BW, rate) -#define hal_txbf_8192e_enter(p_dm_void, idx) -#define hal_txbf_8192e_leave(p_dm_void, idx) -#define hal_txbf_8192e_status(p_dm_void, idx) -#define hal_txbf_8192e_fw_tx_bf(p_dm_void, idx) - -#endif - -#endif diff --git a/hal/phydm/txbf/haltxbf8814a.c b/hal/phydm/txbf/haltxbf8814a.c deleted file mode 100644 index ffa7c3b..0000000 --- a/hal/phydm/txbf/haltxbf8814a.c +++ /dev/null @@ -1,700 +0,0 @@ -/* ************************************************************ - * Description: - * - * This file is for 8814A TXBF mechanism - * - * ************************************************************ */ - -#include "mp_precomp.h" -#include "../phydm_precomp.h" - -#if (BEAMFORMING_SUPPORT == 1) -#if (RTL8814A_SUPPORT == 1) - -bool -phydm_beamforming_set_iqgen_8814A( - void *p_dm_void -) -{ - struct PHY_DM_STRUCT *p_dm_odm = (struct PHY_DM_STRUCT *)p_dm_void; - u8 i = 0; - u16 counter = 0; - u32 rf_mode[4]; - - for (i = ODM_RF_PATH_A ; i < MAX_RF_PATH ; i++) - odm_set_rf_reg(p_dm_odm, i, RF_WE_LUT, 0x80000, 0x1); /*RF mode table write enable*/ - - while (1) { - counter++; - for (i = ODM_RF_PATH_A; i < MAX_RF_PATH; i++) - odm_set_rf_reg(p_dm_odm, i, RF_RCK_OS, 0xfffff, 0x18000); /*Select Rx mode*/ - - ODM_delay_us(2); - - for (i = ODM_RF_PATH_A; i < MAX_RF_PATH; i++) - rf_mode[i] = odm_get_rf_reg(p_dm_odm, i, RF_RCK_OS, 0xfffff); - - if ((rf_mode[0] == 0x18000) && (rf_mode[1] == 0x18000) && (rf_mode[2] == 0x18000) && (rf_mode[3] == 0x18000)) - break; - else if (counter == 100) { - ODM_RT_TRACE(p_dm_odm, PHYDM_COMP_TXBF, ODM_DBG_TRACE, ("iqgen setting fail:8814A\n")); - return false; - } - } - - for (i = ODM_RF_PATH_A ; i < MAX_RF_PATH ; i++) { - odm_set_rf_reg(p_dm_odm, i, RF_TXPA_G1, 0xfffff, 0xBE77F); /*Set Table data*/ - odm_set_rf_reg(p_dm_odm, i, RF_TXPA_G2, 0xfffff, 0x226BF); /*Enable TXIQGEN in Rx mode*/ - } - odm_set_rf_reg(p_dm_odm, ODM_RF_PATH_A, RF_TXPA_G2, 0xfffff, 0xE26BF); /*Enable TXIQGEN in Rx mode*/ - - for (i = ODM_RF_PATH_A; i < MAX_RF_PATH; i++) - odm_set_rf_reg(p_dm_odm, i, RF_WE_LUT, 0x80000, 0x0); /*RF mode table write disable*/ - - return true; - -} - - - -void -hal_txbf_8814a_set_ndpa_rate( - void *p_dm_void, - u8 BW, - u8 rate -) -{ - struct PHY_DM_STRUCT *p_dm_odm = (struct PHY_DM_STRUCT *)p_dm_void; - - odm_write_1byte(p_dm_odm, REG_NDPA_OPT_CTRL_8814A, BW); - odm_write_1byte(p_dm_odm, REG_NDPA_RATE_8814A, (u8) rate); - -} - -#define PHYDM_MEMORY_MAP_BUF_READ 0x8000 -#define PHYDM_CTRL_INFO_PAGE 0x660 - -void -phydm_data_rate_8814a( - struct PHY_DM_STRUCT *p_dm_odm, - u8 mac_id, - u32 *data, - u8 data_len -) -{ - u8 i = 0; - u16 x_read_data_addr = 0; - - odm_write_2byte(p_dm_odm, REG_PKTBUF_DBG_CTRL_8814A, PHYDM_CTRL_INFO_PAGE); - x_read_data_addr = PHYDM_MEMORY_MAP_BUF_READ + mac_id * 32; /*Ctrl Info: 32Bytes for each macid(n)*/ - - if ((x_read_data_addr < PHYDM_MEMORY_MAP_BUF_READ) || (x_read_data_addr > 0x8FFF)) { - ODM_RT_TRACE(p_dm_odm, PHYDM_COMP_TXBF, ODM_DBG_LOUD, ("x_read_data_addr(0x%x) is not correct!\n", x_read_data_addr)); - return; - } - - /* Read data */ - for (i = 0; i < data_len; i++) - *(data + i) = odm_read_2byte(p_dm_odm, x_read_data_addr + i); - -} - -void -hal_txbf_8814a_get_tx_rate( - void *p_dm_void -) -{ - struct PHY_DM_STRUCT *p_dm_odm = (struct PHY_DM_STRUCT *)p_dm_void; - struct _RT_BEAMFORMING_INFO *p_beam_info = &p_dm_odm->beamforming_info; - struct _RT_BEAMFORMEE_ENTRY *p_entry; - u32 tx_rpt_data = 0; - u8 data_rate = 0xFF; - - p_entry = &(p_beam_info->beamformee_entry[p_beam_info->beamformee_cur_idx]); - - phydm_data_rate_8814a(p_dm_odm, (u8)p_entry->mac_id, &tx_rpt_data, 1); - data_rate = (u8)tx_rpt_data; - data_rate &= 0x7f; /*Bit7 indicates SGI*/ - - p_dm_odm->tx_bf_data_rate = data_rate; - - ODM_RT_TRACE(p_dm_odm, PHYDM_COMP_TXBF, ODM_DBG_LOUD, ("[%s] p_dm_odm->tx_bf_data_rate = 0x%x\n", __func__, p_dm_odm->tx_bf_data_rate)); -} - -void -hal_txbf_8814a_reset_tx_path( - void *p_dm_void, - u8 idx -) -{ - struct PHY_DM_STRUCT *p_dm_odm = (struct PHY_DM_STRUCT *)p_dm_void; -#if DEV_BUS_TYPE == RT_USB_INTERFACE - struct _RT_BEAMFORMING_INFO *p_beamforming_info = &p_dm_odm->beamforming_info; - struct _RT_BEAMFORMEE_ENTRY beamformee_entry; - u8 nr_index = 0, tx_ss = 0; - - if (idx < BEAMFORMEE_ENTRY_NUM) - beamformee_entry = p_beamforming_info->beamformee_entry[idx]; - else - return; - - if ((p_dm_odm->last_usb_hub) != (*p_dm_odm->hub_usb_mode)) { - nr_index = tx_bf_nr(hal_txbf_8814a_get_ntx(p_dm_odm), beamformee_entry.comp_steering_num_of_bfer); - - if (*p_dm_odm->hub_usb_mode == 2) { - if (p_dm_odm->rf_type == ODM_4T4R) - tx_ss = 0xf; - else if (p_dm_odm->rf_type == ODM_3T3R) - tx_ss = 0xe; - else - tx_ss = 0x6; - } else if (*p_dm_odm->hub_usb_mode == 1) /*USB 2.0 always 2Tx*/ - tx_ss = 0x6; - else - tx_ss = 0x6; - - if (tx_ss == 0xf) { - odm_set_bb_reg(p_dm_odm, REG_BB_TX_PATH_SEL_1_8814A, MASKBYTE3 | MASKBYTE2HIGHNIBBLE, 0x93f); - odm_set_bb_reg(p_dm_odm, REG_BB_TX_PATH_SEL_1_8814A, MASKDWORD, 0x93f93f0); - } else if (tx_ss == 0xe) { - odm_set_bb_reg(p_dm_odm, REG_BB_TX_PATH_SEL_1_8814A, MASKBYTE3 | MASKBYTE2HIGHNIBBLE, 0x93e); - odm_set_bb_reg(p_dm_odm, REG_BB_TX_PATH_SEL_2_8814A, MASKDWORD, 0x93e93e0); - } else if (tx_ss == 0x6) { - odm_set_bb_reg(p_dm_odm, REG_BB_TX_PATH_SEL_1_8814A, MASKBYTE3 | MASKBYTE2HIGHNIBBLE, 0x936); - odm_set_bb_reg(p_dm_odm, REG_BB_TX_PATH_SEL_2_8814A, MASKLWORD, 0x9360); - } - - if (idx == 0) { - switch (nr_index) { - case 0: - break; - - case 1: /*Nsts = 2 BC*/ - odm_set_bb_reg(p_dm_odm, REG_BB_TXBF_ANT_SET_BF0_8814A, MASKBYTE3LOWNIBBLE | MASKL3BYTES, 0x9366); /*tx2path, BC*/ - break; - - case 2: /*Nsts = 3 BCD*/ - odm_set_bb_reg(p_dm_odm, REG_BB_TXBF_ANT_SET_BF0_8814A, MASKBYTE3LOWNIBBLE | MASKL3BYTES, 0x93e93ee); /*tx3path, BCD*/ - break; - - default: /*nr>3, same as Case 3*/ - odm_set_bb_reg(p_dm_odm, REG_BB_TXBF_ANT_SET_BF0_8814A, MASKBYTE3LOWNIBBLE | MASKL3BYTES, 0x93f93ff); /*tx4path, ABCD*/ - break; - } - } else { - switch (nr_index) { - case 0: - break; - - case 1: /*Nsts = 2 BC*/ - odm_set_bb_reg(p_dm_odm, REG_BB_TXBF_ANT_SET_BF1_8814A, MASKBYTE3LOWNIBBLE | MASKL3BYTES, 0x9366); /*tx2path, BC*/ - break; - - case 2: /*Nsts = 3 BCD*/ - odm_set_bb_reg(p_dm_odm, REG_BB_TXBF_ANT_SET_BF1_8814A, MASKBYTE3LOWNIBBLE | MASKL3BYTES, 0x93e93ee); /*tx3path, BCD*/ - break; - - default: /*nr>3, same as Case 3*/ - odm_set_bb_reg(p_dm_odm, REG_BB_TXBF_ANT_SET_BF1_8814A, MASKBYTE3LOWNIBBLE | MASKL3BYTES, 0x93f93ff); /*tx4path, ABCD*/ - break; - } - } - - p_dm_odm->last_usb_hub = *p_dm_odm->hub_usb_mode; - } else - return; -#endif -} - - -u8 -hal_txbf_8814a_get_ntx( - void *p_dm_void -) -{ - struct PHY_DM_STRUCT *p_dm_odm = (struct PHY_DM_STRUCT *)p_dm_void; - u8 ntx = 0, tx_ss = 3; - -#if DEV_BUS_TYPE == RT_USB_INTERFACE - tx_ss = *p_dm_odm->hub_usb_mode; -#endif - if (tx_ss == 3 || tx_ss == 2) { - if (p_dm_odm->rf_type == ODM_4T4R) - ntx = 3; - else if (p_dm_odm->rf_type == ODM_3T3R) - ntx = 2; - else - ntx = 1; - } else if (tx_ss == 1) /*USB 2.0 always 2Tx*/ - ntx = 1; - else - ntx = 1; - - ODM_RT_TRACE(p_dm_odm, PHYDM_COMP_TXBF, ODM_DBG_LOUD, ("[%s] ntx = %d\n", __func__, ntx)); - return ntx; -} - -u8 -hal_txbf_8814a_get_nrx( - void *p_dm_void -) -{ - struct PHY_DM_STRUCT *p_dm_odm = (struct PHY_DM_STRUCT *)p_dm_void; - u8 nrx = 0; - - if (p_dm_odm->rf_type == ODM_4T4R) - nrx = 3; - else if (p_dm_odm->rf_type == ODM_3T3R) - nrx = 2; - else if (p_dm_odm->rf_type == ODM_2T2R) - nrx = 1; - else if (p_dm_odm->rf_type == ODM_2T3R) - nrx = 2; - else if (p_dm_odm->rf_type == ODM_2T4R) - nrx = 3; - else if (p_dm_odm->rf_type == ODM_1T1R) - nrx = 0; - else if (p_dm_odm->rf_type == ODM_1T2R) - nrx = 1; - else - nrx = 0; - - ODM_RT_TRACE(p_dm_odm, PHYDM_COMP_TXBF, ODM_DBG_LOUD, ("[%s] nrx = %d\n", __func__, nrx)); - return nrx; -} - -void -hal_txbf_8814a_rf_mode( - void *p_dm_void, - struct _RT_BEAMFORMING_INFO *p_beamforming_info, - u8 idx -) -{ - struct PHY_DM_STRUCT *p_dm_odm = (struct PHY_DM_STRUCT *)p_dm_void; - u8 i, nr_index = 0; - u8 tx_ss = 3; /*default use 3 Tx*/ - struct _RT_BEAMFORMEE_ENTRY beamformee_entry; - - if (idx < BEAMFORMEE_ENTRY_NUM) - beamformee_entry = p_beamforming_info->beamformee_entry[idx]; - else - return; - - nr_index = tx_bf_nr(hal_txbf_8814a_get_ntx(p_dm_odm), beamformee_entry.comp_steering_num_of_bfer); - - if (p_dm_odm->rf_type == ODM_1T1R) - return; - - if (p_beamforming_info->beamformee_su_cnt > 0) { -#if DEV_BUS_TYPE == RT_USB_INTERFACE - p_dm_odm->last_usb_hub = *p_dm_odm->hub_usb_mode; - tx_ss = *p_dm_odm->hub_usb_mode; -#endif - if (tx_ss == 3 || tx_ss == 2) { - if (p_dm_odm->rf_type == ODM_4T4R) - tx_ss = 0xf; - else if (p_dm_odm->rf_type == ODM_3T3R) - tx_ss = 0xe; - else - tx_ss = 0x6; - } else if (tx_ss == 1) /*USB 2.0 always 2Tx*/ - tx_ss = 0x6; - else - tx_ss = 0x6; - - if (tx_ss == 0xf) { - odm_set_bb_reg(p_dm_odm, REG_BB_TX_PATH_SEL_1_8814A, MASKBYTE3 | MASKBYTE2HIGHNIBBLE, 0x93f); - odm_set_bb_reg(p_dm_odm, REG_BB_TX_PATH_SEL_1_8814A, MASKDWORD, 0x93f93f0); - } else if (tx_ss == 0xe) { - odm_set_bb_reg(p_dm_odm, REG_BB_TX_PATH_SEL_1_8814A, MASKBYTE3 | MASKBYTE2HIGHNIBBLE, 0x93e); - odm_set_bb_reg(p_dm_odm, REG_BB_TX_PATH_SEL_2_8814A, MASKDWORD, 0x93e93e0); - } else if (tx_ss == 0x6) { - odm_set_bb_reg(p_dm_odm, REG_BB_TX_PATH_SEL_1_8814A, MASKBYTE3 | MASKBYTE2HIGHNIBBLE, 0x936); - odm_set_bb_reg(p_dm_odm, REG_BB_TX_PATH_SEL_2_8814A, MASKLWORD, 0x9360); - } - - /*for 8814 19ac(idx 1), 19b4(idx 0), different Tx ant setting*/ - odm_set_bb_reg(p_dm_odm, REG_BB_TXBF_ANT_SET_BF1_8814A, BIT(28) | BIT29, 0x2); /*enable BB TxBF ant mapping register*/ - odm_set_bb_reg(p_dm_odm, REG_BB_TXBF_ANT_SET_BF1_8814A, BIT30, 0x1); /*if Nsts > Nc don't apply V matrix*/ - - if (idx == 0) { - switch (nr_index) { - case 0: - break; - - case 1: /*Nsts = 2 BC*/ - odm_set_bb_reg(p_dm_odm, REG_BB_TXBF_ANT_SET_BF0_8814A, MASKBYTE3LOWNIBBLE | MASKL3BYTES, 0x9366); /*tx2path, BC*/ - break; - - case 2: /*Nsts = 3 BCD*/ - odm_set_bb_reg(p_dm_odm, REG_BB_TXBF_ANT_SET_BF0_8814A, MASKBYTE3LOWNIBBLE | MASKL3BYTES, 0x93e93ee); /*tx3path, BCD*/ - break; - - default: /*nr>3, same as Case 3*/ - odm_set_bb_reg(p_dm_odm, REG_BB_TXBF_ANT_SET_BF0_8814A, MASKBYTE3LOWNIBBLE | MASKL3BYTES, 0x93f93ff); /*tx4path, ABCD*/ - - break; - } - } else { - switch (nr_index) { - case 0: - break; - - case 1: /*Nsts = 2 BC*/ - odm_set_bb_reg(p_dm_odm, REG_BB_TXBF_ANT_SET_BF1_8814A, MASKBYTE3LOWNIBBLE | MASKL3BYTES, 0x9366); /*tx2path, BC*/ - break; - - case 2: /*Nsts = 3 BCD*/ - odm_set_bb_reg(p_dm_odm, REG_BB_TXBF_ANT_SET_BF1_8814A, MASKBYTE3LOWNIBBLE | MASKL3BYTES, 0x93e93ee); /*tx3path, BCD*/ - break; - - default: /*nr>3, same as Case 3*/ - odm_set_bb_reg(p_dm_odm, REG_BB_TXBF_ANT_SET_BF1_8814A, MASKBYTE3LOWNIBBLE | MASKL3BYTES, 0x93f93ff); /*tx4path, ABCD*/ - break; - } - } - } - - if ((p_beamforming_info->beamformee_su_cnt == 0) && (p_beamforming_info->beamformer_su_cnt == 0)) { - odm_set_bb_reg(p_dm_odm, REG_BB_TX_PATH_SEL_1_8814A, MASKBYTE3 | MASKBYTE2HIGHNIBBLE, 0x932); /*set tx_path selection for 8814a BFer bug refine*/ - odm_set_bb_reg(p_dm_odm, REG_BB_TX_PATH_SEL_2_8814A, MASKDWORD, 0x93e9360); - } -} -#if 0 -void -hal_txbf_8814a_download_ndpa( - void *p_dm_void, - u8 idx -) -{ - struct PHY_DM_STRUCT *p_dm_odm = (struct PHY_DM_STRUCT *)p_dm_void; - u8 u1b_tmp = 0, tmp_reg422 = 0; - u8 bcn_valid_reg = 0, count = 0, dl_bcn_count = 0; - u16 head_page = 0x7FE; - bool is_send_beacon = false; - u16 tx_page_bndy = LAST_ENTRY_OF_TX_PKT_BUFFER_8814A; /*default reseved 1 page for the IC type which is undefined.*/ - struct _RT_BEAMFORMING_INFO *p_beam_info = &p_dm_odm->beamforming_info; - struct _RT_BEAMFORMEE_ENTRY *p_beam_entry = p_beam_info->beamformee_entry + idx; - struct _ADAPTER *adapter = p_dm_odm->adapter; - -#if (DM_ODM_SUPPORT_TYPE == ODM_WIN) - *p_dm_odm->p_is_fw_dw_rsvd_page_in_progress = true; -#endif - ODM_RT_TRACE(p_dm_odm, PHYDM_COMP_TXBF, ODM_DBG_LOUD, ("[%s] Start!\n", __func__)); - - phydm_get_hal_def_var_handler_interface(p_dm_odm, HAL_DEF_TX_PAGE_BOUNDARY, (u16 *)&tx_page_bndy); - - /*Set REG_CR bit 8. DMA beacon by SW.*/ - u1b_tmp = odm_read_1byte(p_dm_odm, REG_CR_8814A + 1); - odm_write_1byte(p_dm_odm, REG_CR_8814A + 1, (u1b_tmp | BIT(0))); - - - /*Set FWHW_TXQ_CTRL 0x422[6]=0 to tell Hw the packet is not a real beacon frame.*/ - tmp_reg422 = odm_read_1byte(p_dm_odm, REG_FWHW_TXQ_CTRL_8814A + 2); - odm_write_1byte(p_dm_odm, REG_FWHW_TXQ_CTRL_8814A + 2, tmp_reg422 & (~BIT(6))); - - if (tmp_reg422 & BIT(6)) { - ODM_RT_TRACE(p_dm_odm, PHYDM_COMP_TXBF, ODM_DBG_LOUD, ("%s: There is an adapter is sending beacon.\n", __func__)); - is_send_beacon = true; - } - - /*0x204[11:0] Beacon Head for TXDMA*/ - odm_write_2byte(p_dm_odm, REG_FIFOPAGE_CTRL_2_8814A, head_page); - - do { - /*Clear beacon valid check bit.*/ - bcn_valid_reg = odm_read_1byte(p_dm_odm, REG_FIFOPAGE_CTRL_2_8814A + 1); - odm_write_1byte(p_dm_odm, REG_FIFOPAGE_CTRL_2_8814A + 1, (bcn_valid_reg | BIT(7))); - - /*download NDPA rsvd page.*/ - if (p_beam_entry->beamform_entry_cap & BEAMFORMER_CAP_VHT_SU) - beamforming_send_vht_ndpa_packet(p_dm_odm, p_beam_entry->mac_addr, p_beam_entry->AID, p_beam_entry->sound_bw, BEACON_QUEUE); - else - beamforming_send_ht_ndpa_packet(p_dm_odm, p_beam_entry->mac_addr, p_beam_entry->sound_bw, BEACON_QUEUE); - - /*check rsvd page download OK.*/ - bcn_valid_reg = odm_read_1byte(p_dm_odm, REG_FIFOPAGE_CTRL_2_8814A + 1); - count = 0; - while (!(bcn_valid_reg & BIT(7)) && count < 20) { - count++; - ODM_delay_ms(10); - bcn_valid_reg = odm_read_1byte(p_dm_odm, REG_FIFOPAGE_CTRL_2_8814A + 2); - } - dl_bcn_count++; - } while (!(bcn_valid_reg & BIT(7)) && dl_bcn_count < 5); - - if (!(bcn_valid_reg & BIT(7))) - ODM_RT_TRACE(p_dm_odm, PHYDM_COMP_TXBF, ODM_DBG_LOUD, ("%s Download RSVD page failed!\n", __func__)); - - /*0x204[11:0] Beacon Head for TXDMA*/ - odm_write_2byte(p_dm_odm, REG_FIFOPAGE_CTRL_2_8814A, tx_page_bndy); - - /*To make sure that if there exists an adapter which would like to send beacon.*/ - /*If exists, the origianl value of 0x422[6] will be 1, we should check this to*/ - /*prevent from setting 0x422[6] to 0 after download reserved page, or it will cause */ - /*the beacon cannot be sent by HW.*/ - /*2010.06.23. Added by tynli.*/ - if (is_send_beacon) - odm_write_1byte(p_dm_odm, REG_FWHW_TXQ_CTRL_8814A + 2, tmp_reg422); - - /*Do not enable HW DMA BCN or it will cause Pcie interface hang by timing issue. 2011.11.24. by tynli.*/ - /*Clear CR[8] or beacon packet will not be send to TxBuf anymore.*/ - u1b_tmp = odm_read_1byte(p_dm_odm, REG_CR_8814A + 1); - odm_write_1byte(p_dm_odm, REG_CR_8814A + 1, (u1b_tmp & (~BIT(0)))); - - p_beam_entry->beamform_entry_state = BEAMFORMING_ENTRY_STATE_PROGRESSED; - -#if (DM_ODM_SUPPORT_TYPE == ODM_WIN) - *p_dm_odm->p_is_fw_dw_rsvd_page_in_progress = false; -#endif -} - -void -hal_txbf_8814a_fw_txbf_cmd( - void *p_dm_void -) -{ - struct PHY_DM_STRUCT *p_dm_odm = (struct PHY_DM_STRUCT *)p_dm_void; - u8 idx, period = 0; - u8 PageNum0 = 0xFF, PageNum1 = 0xFF; - u8 u1_tx_bf_parm[3] = {0}; - struct _RT_BEAMFORMING_INFO *p_beam_info = &p_dm_odm->beamforming_info; - - for (idx = 0; idx < BEAMFORMEE_ENTRY_NUM; idx++) { - if (p_beam_info->beamformee_entry[idx].is_used && p_beam_info->beamformee_entry[idx].beamform_entry_state == BEAMFORMING_ENTRY_STATE_PROGRESSED) { - if (p_beam_info->beamformee_entry[idx].is_sound) { - PageNum0 = 0xFE; - PageNum1 = 0x07; - period = (u8)(p_beam_info->beamformee_entry[idx].sound_period); - } else if (PageNum0 == 0xFF) { - PageNum0 = 0xFF; /*stop sounding*/ - PageNum1 = 0x0F; - } - } - } - - u1_tx_bf_parm[0] = PageNum0; - u1_tx_bf_parm[1] = PageNum1; - u1_tx_bf_parm[2] = period; - odm_fill_h2c_cmd(p_dm_odm, PHYDM_H2C_TXBF, 3, u1_tx_bf_parm); - - ODM_RT_TRACE(p_dm_odm, PHYDM_COMP_TXBF, ODM_DBG_LOUD, - ("[%s] PageNum0 = %d, PageNum1 = %d period = %d\n", __func__, PageNum0, PageNum1, period)); -} -#endif -void -hal_txbf_8814a_enter( - void *p_dm_void, - u8 bfer_bfee_idx -) -{ - struct PHY_DM_STRUCT *p_dm_odm = (struct PHY_DM_STRUCT *)p_dm_void; - u8 i = 0; - u8 bfer_idx = (bfer_bfee_idx & 0xF0) >> 4; - u8 bfee_idx = (bfer_bfee_idx & 0xF); - struct _RT_BEAMFORMING_INFO *p_beamforming_info = &p_dm_odm->beamforming_info; - struct _RT_BEAMFORMEE_ENTRY beamformee_entry; - struct _RT_BEAMFORMER_ENTRY beamformer_entry; - u16 sta_id = 0, csi_param = 0; - u8 nc_index = 0, nr_index = 0, grouping = 0, codebookinfo = 0, coefficientsize = 0; - - ODM_RT_TRACE(p_dm_odm, PHYDM_COMP_TXBF, ODM_DBG_LOUD, ("[%s] bfer_idx=%d, bfee_idx=%d\n", __func__, bfer_idx, bfee_idx)); - odm_set_mac_reg(p_dm_odm, REG_SND_PTCL_CTRL_8814A, MASKBYTE1 | MASKBYTE2, 0x0202); - - if ((p_beamforming_info->beamformer_su_cnt > 0) && (bfer_idx < BEAMFORMER_ENTRY_NUM)) { - beamformer_entry = p_beamforming_info->beamformer_entry[bfer_idx]; - /*Sounding protocol control*/ - odm_write_1byte(p_dm_odm, REG_SND_PTCL_CTRL_8814A, 0xDB); - - /*MAC address/Partial AID of Beamformer*/ - if (bfer_idx == 0) { - for (i = 0; i < 6 ; i++) - odm_write_1byte(p_dm_odm, (REG_ASSOCIATED_BFMER0_INFO_8814A + i), beamformer_entry.mac_addr[i]); - } else { - for (i = 0; i < 6 ; i++) - odm_write_1byte(p_dm_odm, (REG_ASSOCIATED_BFMER1_INFO_8814A + i), beamformer_entry.mac_addr[i]); - } - - /*CSI report parameters of Beamformer*/ - nc_index = hal_txbf_8814a_get_nrx(p_dm_odm); /*for 8814A nrx = 3(4 ant), min=0(1 ant)*/ - nr_index = beamformer_entry.num_of_sounding_dim; /*0x718[7] = 1 use Nsts, 0x718[7] = 0 use reg setting. as Bfee, we use Nsts, so nr_index don't care*/ - - grouping = 0; - - /*for ac = 1, for n = 3*/ - if (beamformer_entry.beamform_entry_cap & BEAMFORMEE_CAP_VHT_SU) - codebookinfo = 1; - else if (beamformer_entry.beamform_entry_cap & BEAMFORMEE_CAP_HT_EXPLICIT) - codebookinfo = 3; - - coefficientsize = 3; - - csi_param = (u16)((coefficientsize << 10) | (codebookinfo << 8) | (grouping << 6) | (nr_index << 3) | (nc_index)); - - if (bfer_idx == 0) - odm_write_2byte(p_dm_odm, REG_CSI_RPT_PARAM_BW20_8814A, csi_param); - else - odm_write_2byte(p_dm_odm, REG_CSI_RPT_PARAM_BW20_8814A + 2, csi_param); - /*ndp_rx_standby_timer, 8814 need > 0x56, suggest from Dvaid*/ - odm_write_1byte(p_dm_odm, REG_SND_PTCL_CTRL_8814A + 3, 0x40); - - } - - if ((p_beamforming_info->beamformee_su_cnt > 0) && (bfee_idx < BEAMFORMEE_ENTRY_NUM)) { - beamformee_entry = p_beamforming_info->beamformee_entry[bfee_idx]; - - hal_txbf_8814a_rf_mode(p_dm_odm, p_beamforming_info, bfee_idx); - - if (phydm_acting_determine(p_dm_odm, phydm_acting_as_ibss)) - sta_id = beamformee_entry.mac_id; - else - sta_id = beamformee_entry.p_aid; - - /*P_AID of Beamformee & enable NDPA transmission & enable NDPA interrupt*/ - if (bfee_idx == 0) { - odm_write_2byte(p_dm_odm, REG_TXBF_CTRL_8814A, sta_id); - odm_write_1byte(p_dm_odm, REG_TXBF_CTRL_8814A + 3, odm_read_1byte(p_dm_odm, REG_TXBF_CTRL_8814A + 3) | BIT(4) | BIT(6) | BIT(7)); - } else - odm_write_2byte(p_dm_odm, REG_TXBF_CTRL_8814A + 2, sta_id | BIT(14) | BIT(15) | BIT(12)); - - /*CSI report parameters of Beamformee*/ - if (bfee_idx == 0) { - /*Get BIT24 & BIT25*/ - u8 tmp = odm_read_1byte(p_dm_odm, REG_ASSOCIATED_BFMEE_SEL_8814A + 3) & 0x3; - - odm_write_1byte(p_dm_odm, REG_ASSOCIATED_BFMEE_SEL_8814A + 3, tmp | 0x60); - odm_write_2byte(p_dm_odm, REG_ASSOCIATED_BFMEE_SEL_8814A, sta_id | BIT(9)); - } else - odm_write_2byte(p_dm_odm, REG_ASSOCIATED_BFMEE_SEL_8814A + 2, sta_id | 0xE200); /*Set BIT25*/ - - phydm_beamforming_notify(p_dm_odm); - } - -} - - -void -hal_txbf_8814a_leave( - void *p_dm_void, - u8 idx -) -{ - struct PHY_DM_STRUCT *p_dm_odm = (struct PHY_DM_STRUCT *)p_dm_void; - struct _RT_BEAMFORMING_INFO *p_beamforming_info = &p_dm_odm->beamforming_info; - struct _RT_BEAMFORMER_ENTRY beamformer_entry; - struct _RT_BEAMFORMEE_ENTRY beamformee_entry; - - if (idx < BEAMFORMER_ENTRY_NUM) { - beamformer_entry = p_beamforming_info->beamformer_entry[idx]; - beamformee_entry = p_beamforming_info->beamformee_entry[idx]; - } else - return; - - /*Clear P_AID of Beamformee*/ - /*Clear MAC address of Beamformer*/ - /*Clear Associated Bfmee Sel*/ - - if (beamformer_entry.beamform_entry_cap == BEAMFORMING_CAP_NONE) { - odm_write_1byte(p_dm_odm, REG_SND_PTCL_CTRL_8814A, 0xD8); - if (idx == 0) { - odm_write_4byte(p_dm_odm, REG_ASSOCIATED_BFMER0_INFO_8814A, 0); - odm_write_2byte(p_dm_odm, REG_ASSOCIATED_BFMER0_INFO_8814A + 4, 0); - odm_write_2byte(p_dm_odm, REG_CSI_RPT_PARAM_BW20_8814A, 0); - } else { - odm_write_4byte(p_dm_odm, REG_ASSOCIATED_BFMER1_INFO_8814A, 0); - odm_write_2byte(p_dm_odm, REG_ASSOCIATED_BFMER1_INFO_8814A + 4, 0); - odm_write_2byte(p_dm_odm, REG_CSI_RPT_PARAM_BW20_8814A + 2, 0); - } - } - - if (beamformee_entry.beamform_entry_cap == BEAMFORMING_CAP_NONE) { - hal_txbf_8814a_rf_mode(p_dm_odm, p_beamforming_info, idx); - if (idx == 0) { - odm_write_2byte(p_dm_odm, REG_TXBF_CTRL_8814A, 0x0); - odm_write_1byte(p_dm_odm, REG_TXBF_CTRL_8814A + 3, odm_read_1byte(p_dm_odm, REG_TXBF_CTRL_8814A + 3) | BIT(4) | BIT(6) | BIT(7)); - odm_write_2byte(p_dm_odm, REG_ASSOCIATED_BFMEE_SEL_8814A, 0); - } else { - odm_write_2byte(p_dm_odm, REG_TXBF_CTRL_8814A + 2, 0x0 | BIT(14) | BIT(15) | BIT(12)); - - odm_write_2byte(p_dm_odm, REG_ASSOCIATED_BFMEE_SEL_8814A + 2, odm_read_2byte(p_dm_odm, REG_ASSOCIATED_BFMEE_SEL_8814A + 2) & 0x60); - } - } -} - -void -hal_txbf_8814a_status( - void *p_dm_void, - u8 idx -) -{ - struct PHY_DM_STRUCT *p_dm_odm = (struct PHY_DM_STRUCT *)p_dm_void; - u16 beam_ctrl_val, tmp_val; - u32 beam_ctrl_reg; - struct _RT_BEAMFORMING_INFO *p_beamforming_info = &p_dm_odm->beamforming_info; - struct _RT_BEAMFORMEE_ENTRY beamform_entry; - - if (idx < BEAMFORMEE_ENTRY_NUM) - beamform_entry = p_beamforming_info->beamformee_entry[idx]; - else - return; - - if (phydm_acting_determine(p_dm_odm, phydm_acting_as_ibss)) - beam_ctrl_val = beamform_entry.mac_id; - else - beam_ctrl_val = beamform_entry.p_aid; - - ODM_RT_TRACE(p_dm_odm, PHYDM_COMP_TXBF, ODM_DBG_LOUD, ("@%s, beamform_entry.beamform_entry_state = %d", __func__, beamform_entry.beamform_entry_state)); - - if (idx == 0) - beam_ctrl_reg = REG_TXBF_CTRL_8814A; - else { - beam_ctrl_reg = REG_TXBF_CTRL_8814A + 2; - beam_ctrl_val |= BIT(12) | BIT(14) | BIT(15); - } - - if ((beamform_entry.beamform_entry_state == BEAMFORMING_ENTRY_STATE_PROGRESSED) && (p_beamforming_info->apply_v_matrix == true)) { - if (beamform_entry.sound_bw == CHANNEL_WIDTH_20) - beam_ctrl_val |= BIT(9); - else if (beamform_entry.sound_bw == CHANNEL_WIDTH_40) - beam_ctrl_val |= (BIT(9) | BIT(10)); - else if (beamform_entry.sound_bw == CHANNEL_WIDTH_80) - beam_ctrl_val |= (BIT(9) | BIT(10) | BIT(11)); - } else { - ODM_RT_TRACE(p_dm_odm, PHYDM_COMP_TXBF, ODM_DBG_LOUD, ("@%s, Don't apply Vmatrix", __func__)); - beam_ctrl_val &= ~(BIT(9) | BIT(10) | BIT(11)); - } - - odm_write_2byte(p_dm_odm, beam_ctrl_reg, beam_ctrl_val); - /*disable NDP packet use beamforming */ - tmp_val = odm_read_2byte(p_dm_odm, REG_TXBF_CTRL_8814A); - odm_write_2byte(p_dm_odm, REG_TXBF_CTRL_8814A, tmp_val | BIT(15)); - -} - - - - - -void -hal_txbf_8814a_fw_txbf( - void *p_dm_void, - u8 idx -) -{ -#if 0 - struct PHY_DM_STRUCT *p_dm_odm = (struct PHY_DM_STRUCT *)p_dm_void; - struct _RT_BEAMFORMING_INFO *p_beam_info = &p_dm_odm->beamforming_info; - struct _RT_BEAMFORMEE_ENTRY *p_beam_entry = p_beam_info->beamformee_entry + idx; - - ODM_RT_TRACE(p_dm_odm, PHYDM_COMP_TXBF, ODM_DBG_LOUD, ("[%s] Start!\n", __func__)); - - if (p_beam_entry->beamform_entry_state == BEAMFORMING_ENTRY_STATE_PROGRESSING) - hal_txbf_8814a_download_ndpa(p_dm_odm, idx); - - hal_txbf_8814a_fw_txbf_cmd(p_dm_odm); -#endif -} - -#endif /* (RTL8814A_SUPPORT == 1)*/ - -#endif diff --git a/hal/phydm/txbf/haltxbf8814a.h b/hal/phydm/txbf/haltxbf8814a.h deleted file mode 100644 index d66374c..0000000 --- a/hal/phydm/txbf/haltxbf8814a.h +++ /dev/null @@ -1,89 +0,0 @@ -#ifndef __HAL_TXBF_8814A_H__ -#define __HAL_TXBF_8814A_H__ - -#if (RTL8814A_SUPPORT == 1) -#if (BEAMFORMING_SUPPORT == 1) - -bool -phydm_beamforming_set_iqgen_8814A( - void *p_dm_void -); - -void -hal_txbf_8814a_set_ndpa_rate( - void *p_dm_void, - u8 BW, - u8 rate -); - -u8 -hal_txbf_8814a_get_ntx( - void *p_dm_void -); - -void -hal_txbf_8814a_enter( - void *p_dm_void, - u8 idx -); - - -void -hal_txbf_8814a_leave( - void *p_dm_void, - u8 idx -); - - -void -hal_txbf_8814a_status( - void *p_dm_void, - u8 idx -); - -void -hal_txbf_8814a_reset_tx_path( - void *p_dm_void, - u8 idx -); - - -void -hal_txbf_8814a_get_tx_rate( - void *p_dm_void -); - -void -hal_txbf_8814a_fw_txbf( - void *p_dm_void, - u8 idx -); - -#else - -#define hal_txbf_8814a_set_ndpa_rate(p_dm_void, BW, rate) -#define hal_txbf_8814a_get_ntx(p_dm_void) 0 -#define hal_txbf_8814a_enter(p_dm_void, idx) -#define hal_txbf_8814a_leave(p_dm_void, idx) -#define hal_txbf_8814a_status(p_dm_void, idx) -#define hal_txbf_8814a_reset_tx_path(p_dm_void, idx) -#define hal_txbf_8814a_get_tx_rate(p_dm_void) -#define hal_txbf_8814a_fw_txbf(p_dm_void, idx) -#define phydm_beamforming_set_iqgen_8814A(p_dm_void) 0 - -#endif - -#else - -#define hal_txbf_8814a_set_ndpa_rate(p_dm_void, BW, rate) -#define hal_txbf_8814a_get_ntx(p_dm_void) 0 -#define hal_txbf_8814a_enter(p_dm_void, idx) -#define hal_txbf_8814a_leave(p_dm_void, idx) -#define hal_txbf_8814a_status(p_dm_void, idx) -#define hal_txbf_8814a_reset_tx_path(p_dm_void, idx) -#define hal_txbf_8814a_get_tx_rate(p_dm_void) -#define hal_txbf_8814a_fw_txbf(p_dm_void, idx) -#define phydm_beamforming_set_iqgen_8814A(p_dm_void) 0 -#endif - -#endif diff --git a/hal/phydm/txbf/haltxbf8822b.c b/hal/phydm/txbf/haltxbf8822b.c deleted file mode 100644 index 2503d58..0000000 --- a/hal/phydm/txbf/haltxbf8822b.c +++ /dev/null @@ -1,1099 +0,0 @@ -/*============================================================*/ -/* Description: */ -/* */ -/* This file is for 8814A TXBF mechanism */ -/* */ -/*============================================================*/ - -#include "mp_precomp.h" -#include "phydm_precomp.h" - -#if (RTL8822B_SUPPORT == 1) -#if (BEAMFORMING_SUPPORT == 1) - -u8 -hal_txbf_8822b_get_ntx( - void *p_dm_void -) -{ - struct PHY_DM_STRUCT *p_dm_odm = (struct PHY_DM_STRUCT *)p_dm_void; - u8 ntx = 0; - -#if DEV_BUS_TYPE == RT_USB_INTERFACE - if (p_dm_odm->support_interface == ODM_ITRF_USB) { - if (*p_dm_odm->hub_usb_mode == 2) {/*USB3.0*/ - if (p_dm_odm->rf_type == ODM_4T4R) - ntx = 3; - else if (p_dm_odm->rf_type == ODM_3T3R) - ntx = 2; - else - ntx = 1; - } else if (*p_dm_odm->hub_usb_mode == 1) /*USB 2.0 always 2Tx*/ - ntx = 1; - else - ntx = 1; - } else -#endif - { - if (p_dm_odm->rf_type == ODM_4T4R) - ntx = 3; - else if (p_dm_odm->rf_type == ODM_3T3R) - ntx = 2; - else - ntx = 1; - } - - return ntx; - -} - -u8 -hal_txbf_8822b_get_nrx( - void *p_dm_void -) -{ - struct PHY_DM_STRUCT *p_dm_odm = (struct PHY_DM_STRUCT *)p_dm_void; - u8 nrx = 0; - - if (p_dm_odm->rf_type == ODM_4T4R) - nrx = 3; - else if (p_dm_odm->rf_type == ODM_3T3R) - nrx = 2; - else if (p_dm_odm->rf_type == ODM_2T2R) - nrx = 1; - else if (p_dm_odm->rf_type == ODM_2T3R) - nrx = 2; - else if (p_dm_odm->rf_type == ODM_2T4R) - nrx = 3; - else if (p_dm_odm->rf_type == ODM_1T1R) - nrx = 0; - else if (p_dm_odm->rf_type == ODM_1T2R) - nrx = 1; - else - nrx = 0; - - return nrx; - -} - -/***************SU & MU BFee Entry********************/ -void -hal_txbf_8822b_rf_mode( - void *p_dm_void, - struct _RT_BEAMFORMING_INFO *p_beamforming_info, - u8 idx -) -{ -#if 0 - struct PHY_DM_STRUCT *p_dm_odm = (struct PHY_DM_STRUCT *)p_dm_void; - u8 i, nr_index = 0; - bool is_self_beamformer = false; - bool is_self_beamformee = false; - struct _RT_BEAMFORMEE_ENTRY beamformee_entry; - - if (idx < BEAMFORMEE_ENTRY_NUM) - beamformee_entry = p_beamforming_info->beamformee_entry[idx]; - else - return; - - if (p_dm_odm->rf_type == ODM_1T1R) - return; - - for (i = ODM_RF_PATH_A; i < ODM_RF_PATH_B; i++) { - odm_set_rf_reg(p_dm_odm, (enum odm_rf_radio_path_e)i, rf_welut_jaguar, 0x80000, 0x1); - /*RF mode table write enable*/ - } - - if ((p_beamforming_info->beamformee_su_cnt > 0) || (p_beamforming_info->beamformee_mu_cnt > 0)) { - for (i = ODM_RF_PATH_A; i < ODM_RF_PATH_B; i++) { - odm_set_rf_reg(p_dm_odm, (enum odm_rf_radio_path_e)i, rf_mode_table_addr, 0xfffff, 0x18000); - /*Select RX mode*/ - odm_set_rf_reg(p_dm_odm, (enum odm_rf_radio_path_e)i, rf_mode_table_data0, 0xfffff, 0xBE77F); - /*Set Table data*/ - odm_set_rf_reg(p_dm_odm, (enum odm_rf_radio_path_e)i, rf_mode_table_data1, 0xfffff, 0x226BF); - /*Enable TXIQGEN in RX mode*/ - } - odm_set_rf_reg(p_dm_odm, ODM_RF_PATH_A, rf_mode_table_data1, 0xfffff, 0xE26BF); - /*Enable TXIQGEN in RX mode*/ - } - - for (i = ODM_RF_PATH_A; i < ODM_RF_PATH_B; i++) { - odm_set_rf_reg(p_dm_odm, (enum odm_rf_radio_path_e)i, rf_welut_jaguar, 0x80000, 0x0); - /*RF mode table write disable*/ - } - - if (p_beamforming_info->beamformee_su_cnt > 0) { - - /*for 8814 19ac(idx 1), 19b4(idx 0), different Tx ant setting*/ - odm_set_bb_reg(p_dm_odm, REG_BB_TXBF_ANT_SET_BF1_8822B, BIT(28) | BIT29, 0x2); /*enable BB TxBF ant mapping register*/ - - if (idx == 0) { - /*Nsts = 2 AB*/ - odm_set_bb_reg(p_dm_odm, REG_BB_TXBF_ANT_SET_BF0_8822B, 0xffff, 0x0433); - odm_set_bb_reg(p_dm_odm, REG_BB_TX_PATH_SEL_1_8822B, 0xfff00000, 0x043); - /*odm_set_bb_reg(p_dm_odm, REG_BB_TX_PATH_SEL_2, MASKLWORD, 0x430);*/ - - } else {/*IDX =1*/ - odm_set_bb_reg(p_dm_odm, REG_BB_TXBF_ANT_SET_BF1_8822B, 0xffff, 0x0433); - odm_set_bb_reg(p_dm_odm, REG_BB_TX_PATH_SEL_1_8822B, 0xfff00000, 0x043); - /*odm_set_bb_reg(p_dm_odm, REG_BB_TX_PATH_SEL_2, MASKLWORD, 0x430;*/ - } - } else { - odm_set_bb_reg(p_dm_odm, REG_BB_TX_PATH_SEL_1_8822B, 0xfff00000, 0x1); /*1SS by path-A*/ - odm_set_bb_reg(p_dm_odm, REG_BB_TX_PATH_SEL_2_8822B, MASKLWORD, 0x430); /*2SS by path-A,B*/ - } - - if (p_beamforming_info->beamformee_mu_cnt > 0) { - /*MU STAs share the common setting*/ - odm_set_bb_reg(p_dm_odm, REG_BB_TXBF_ANT_SET_BF1_8822B, BIT(31), 1); - odm_set_bb_reg(p_dm_odm, REG_BB_TXBF_ANT_SET_BF1_8822B, 0xffff, 0x0433); - odm_set_bb_reg(p_dm_odm, REG_BB_TX_PATH_SEL_1_8822B, 0xfff00000, 0x043); - } -#endif -} -#if 0 -void -hal_txbf_8822b_download_ndpa( - struct _ADAPTER *adapter, - u8 idx -) -{ - u8 u1b_tmp = 0, tmp_reg422 = 0; - u8 bcn_valid_reg = 0, count = 0, dl_bcn_count = 0; - u16 head_page = 0x7FE; - bool is_send_beacon = false; - HAL_DATA_TYPE *p_hal_data = GET_HAL_DATA(adapter); - u16 tx_page_bndy = LAST_ENTRY_OF_TX_PKT_BUFFER_8814A; /*default reseved 1 page for the IC type which is undefined.*/ - struct _RT_BEAMFORMING_INFO *p_beam_info = GET_BEAMFORM_INFO(adapter); - struct _RT_BEAMFORMEE_ENTRY *p_beam_entry = p_beam_info->beamformee_entry + idx; - - p_hal_data->is_fw_dw_rsvd_page_in_progress = true; - phydm_get_hal_def_var_handler_interface(p_dm_odm, HAL_DEF_TX_PAGE_BOUNDARY, (u16 *)&tx_page_bndy); - - /*Set REG_CR bit 8. DMA beacon by SW.*/ - u1b_tmp = platform_efio_read_1byte(adapter, REG_CR_8814A + 1); - platform_efio_write_1byte(adapter, REG_CR_8814A + 1, (u1b_tmp | BIT(0))); - - - /*Set FWHW_TXQ_CTRL 0x422[6]=0 to tell Hw the packet is not a real beacon frame.*/ - tmp_reg422 = platform_efio_read_1byte(adapter, REG_FWHW_TXQ_CTRL_8814A + 2); - platform_efio_write_1byte(adapter, REG_FWHW_TXQ_CTRL_8814A + 2, tmp_reg422 & (~BIT(6))); - - if (tmp_reg422 & BIT(6)) { - RT_TRACE(COMP_INIT, DBG_LOUD, ("SetBeamformDownloadNDPA_8814A(): There is an adapter is sending beacon.\n")); - is_send_beacon = true; - } - - /*0x204[11:0] Beacon Head for TXDMA*/ - platform_efio_write_2byte(adapter, REG_FIFOPAGE_CTRL_2_8814A, head_page); - - do { - /*Clear beacon valid check bit.*/ - bcn_valid_reg = platform_efio_read_1byte(adapter, REG_FIFOPAGE_CTRL_2_8814A + 1); - platform_efio_write_1byte(adapter, REG_FIFOPAGE_CTRL_2_8814A + 1, (bcn_valid_reg | BIT(7))); - - /*download NDPA rsvd page.*/ - if (p_beam_entry->beamform_entry_cap & BEAMFORMER_CAP_VHT_SU) - beamforming_send_vht_ndpa_packet(p_dm_odm, p_beam_entry->mac_addr, p_beam_entry->AID, p_beam_entry->sound_bw, BEACON_QUEUE); - else - beamforming_send_ht_ndpa_packet(p_dm_odm, p_beam_entry->mac_addr, p_beam_entry->sound_bw, BEACON_QUEUE); - - /*check rsvd page download OK.*/ - bcn_valid_reg = platform_efio_read_1byte(adapter, REG_FIFOPAGE_CTRL_2_8814A + 1); - count = 0; - while (!(bcn_valid_reg & BIT(7)) && count < 20) { - count++; - delay_us(10); - bcn_valid_reg = platform_efio_read_1byte(adapter, REG_FIFOPAGE_CTRL_2_8814A + 2); - } - dl_bcn_count++; - } while (!(bcn_valid_reg & BIT(7)) && dl_bcn_count < 5); - - if (!(bcn_valid_reg & BIT(0))) - RT_DISP(FBEAM, FBEAM_ERROR, ("%s Download RSVD page failed!\n", __func__)); - - /*0x204[11:0] Beacon Head for TXDMA*/ - platform_efio_write_2byte(adapter, REG_FIFOPAGE_CTRL_2_8814A, tx_page_bndy); - - /*To make sure that if there exists an adapter which would like to send beacon.*/ - /*If exists, the origianl value of 0x422[6] will be 1, we should check this to*/ - /*prevent from setting 0x422[6] to 0 after download reserved page, or it will cause */ - /*the beacon cannot be sent by HW.*/ - /*2010.06.23. Added by tynli.*/ - if (is_send_beacon) - platform_efio_write_1byte(adapter, REG_FWHW_TXQ_CTRL_8814A + 2, tmp_reg422); - - /*Do not enable HW DMA BCN or it will cause Pcie interface hang by timing issue. 2011.11.24. by tynli.*/ - /*Clear CR[8] or beacon packet will not be send to TxBuf anymore.*/ - u1b_tmp = platform_efio_read_1byte(adapter, REG_CR_8814A + 1); - platform_efio_write_1byte(adapter, REG_CR_8814A + 1, (u1b_tmp & (~BIT(0)))); - - p_beam_entry->beamform_entry_state = BEAMFORMING_ENTRY_STATE_PROGRESSED; - - p_hal_data->is_fw_dw_rsvd_page_in_progress = false; -} - -void -hal_txbf_8822b_fw_txbf_cmd( - struct _ADAPTER *adapter -) -{ - u8 idx, period = 0; - u8 PageNum0 = 0xFF, PageNum1 = 0xFF; - u8 u1_tx_bf_parm[3] = {0}; - - PMGNT_INFO p_mgnt_info = &(adapter->MgntInfo); - struct _RT_BEAMFORMING_INFO *p_beam_info = GET_BEAMFORM_INFO(adapter); - - for (idx = 0; idx < BEAMFORMEE_ENTRY_NUM; idx++) { - if (p_beam_info->beamformee_entry[idx].is_used && p_beam_info->beamformee_entry[idx].beamform_entry_state == BEAMFORMING_ENTRY_STATE_PROGRESSED) { - if (p_beam_info->beamformee_entry[idx].is_sound) { - PageNum0 = 0xFE; - PageNum1 = 0x07; - period = (u8)(p_beam_info->beamformee_entry[idx].sound_period); - } else if (PageNum0 == 0xFF) { - PageNum0 = 0xFF; /*stop sounding*/ - PageNum1 = 0x0F; - } - } - } - - u1_tx_bf_parm[0] = PageNum0; - u1_tx_bf_parm[1] = PageNum1; - u1_tx_bf_parm[2] = period; - fill_h2c_cmd(adapter, PHYDM_H2C_TXBF, 3, u1_tx_bf_parm); - - RT_DISP(FBEAM, FBEAM_FUN, ("@%s End, PageNum0 = 0x%x, PageNum1 = 0x%x period = %d", __func__, PageNum0, PageNum1, period)); -} -#endif - -#if 0 -void -hal_txbf_8822b_init( - void *p_dm_void -) -{ - struct PHY_DM_STRUCT *p_dm_odm = (struct PHY_DM_STRUCT *)p_dm_void; - u8 u1b_tmp; - struct _RT_BEAMFORMING_INFO *p_beamforming_info = &p_dm_odm->beamforming_info; - struct _ADAPTER *adapter = p_dm_odm->adapter; - - odm_set_bb_reg(p_dm_odm, 0x14c0, BIT(16), 1); /*Enable P1 aggr new packet according to P0 transfer time*/ - odm_set_bb_reg(p_dm_odm, 0x14c0, BIT(15) | BIT14 | BIT13 | BIT12, 10); /*MU Retry Limit*/ - odm_set_bb_reg(p_dm_odm, 0x14c0, BIT(7), 0); /*Disable Tx MU-MIMO until sounding done*/ - odm_set_bb_reg(p_dm_odm, 0x14c0, 0x3F, 0); /* Clear validity of MU STAs */ - odm_write_1byte(p_dm_odm, 0x167c, 0x70); /*MU-MIMO Option as default value*/ - odm_write_2byte(p_dm_odm, 0x1680, 0); /*MU-MIMO Control as default value*/ - - /* Set MU NDPA rate & BW source */ - /* 0x42C[30] = 1 (0: from Tx desc, 1: from 0x45F) */ - u1b_tmp = odm_read_1byte(p_dm_odm, 0x42C); - odm_write_1byte(p_dm_odm, REG_TXBF_CTRL_8822B, (u1b_tmp | BIT(6))); - /* 0x45F[7:0] = 0x10 (rate=OFDM_6M, BW20) */ - odm_write_1byte(p_dm_odm, REG_NDPA_OPT_CTRL_8822B, 0x10); - - /*Temp Settings*/ - odm_set_bb_reg(p_dm_odm, 0x6DC, 0x3F000000, 4); /*STA2's CSI rate is fixed at 6M*/ - odm_set_bb_reg(p_dm_odm, 0x1C94, MASKDWORD, 0xAFFFAFFF); /*Grouping bitmap parameters*/ - - /* Init HW variable */ - p_beamforming_info->reg_mu_tx_ctrl = odm_read_4byte(p_dm_odm, 0x14c0); - - if (p_dm_odm->rf_type == ODM_2T2R) { /*2T2R*/ - ODM_RT_TRACE(p_dm_odm, PHYDM_COMP_TXBF, ODM_DBG_LOUD, ("%s: rf_type is 2T2R\n", __func__)); - config_phydm_trx_mode_8822b(p_dm_odm, (enum odm_rf_path_e)3, (enum odm_rf_path_e)3, true);/*Tx2path*/ - } - -#if (OMNIPEEK_SNIFFER_ENABLED == 1) - /* Config HW to receive packet on the user position from registry for sniffer mode. */ - /* odm_set_bb_reg(p_dm_odm, 0xB00, BIT(9), 1);*/ /* For A-cut only. RegB00[9] = 1 (enable PMAC Rx) */ - odm_set_bb_reg(p_dm_odm, 0xB54, BIT(30), 1); /* RegB54[30] = 1 (force user position) */ - odm_set_bb_reg(p_dm_odm, 0xB54, (BIT(29) | BIT28), adapter->MgntInfo.sniff_user_position); /* RegB54[29:28] = user position (0~3) */ - ODM_RT_TRACE(p_dm_odm, PHYDM_COMP_TXBF, ODM_DBG_LOUD, ("Set adapter->MgntInfo.sniff_user_position=%#X\n", adapter->MgntInfo.sniff_user_position)); -#endif -} -#endif - -void -hal_txbf_8822b_enter( - void *p_dm_void, - u8 bfer_bfee_idx -) -{ - struct PHY_DM_STRUCT *p_dm_odm = (struct PHY_DM_STRUCT *)p_dm_void; - u8 i = 0; - u8 bfer_idx = (bfer_bfee_idx & 0xF0) >> 4; - u8 bfee_idx = (bfer_bfee_idx & 0xF); - u16 csi_param = 0; - struct _RT_BEAMFORMING_INFO *p_beamforming_info = &p_dm_odm->beamforming_info; - struct _RT_BEAMFORMEE_ENTRY *p_beamformee_entry; - struct _RT_BEAMFORMER_ENTRY *p_beamformer_entry; - u16 value16, sta_id = 0; - u8 nc_index = 0, nr_index = 0, grouping = 0, codebookinfo = 0, coefficientsize = 0; - u32 gid_valid, user_position_l, user_position_h; - u32 mu_reg[6] = {0x1684, 0x1686, 0x1688, 0x168a, 0x168c, 0x168e}; - u8 u1b_tmp; - u32 u4b_tmp; - - RT_DISP(FBEAM, FBEAM_FUN, ("%s: bfer_bfee_idx=%d, bfer_idx=%d, bfee_idx=%d\n", __func__, bfer_bfee_idx, bfer_idx, bfee_idx)); - - /*************SU BFer Entry Init*************/ - if ((p_beamforming_info->beamformer_su_cnt > 0) && (bfer_idx < BEAMFORMER_ENTRY_NUM)) { - p_beamformer_entry = &p_beamforming_info->beamformer_entry[bfer_idx]; - p_beamformer_entry->is_mu_ap = false; - /*Sounding protocol control*/ - odm_write_1byte(p_dm_odm, REG_SND_PTCL_CTRL_8822B, 0xDB); - - - for (i = 0; i < MAX_BEAMFORMER_SU; i++) { - if ((p_beamforming_info->beamformer_su_reg_maping & BIT(i)) == 0) { - p_beamforming_info->beamformer_su_reg_maping |= BIT(i); - p_beamformer_entry->su_reg_index = i; - break; - } - } - - /*MAC address/Partial AID of Beamformer*/ - if (p_beamformer_entry->su_reg_index == 0) { - for (i = 0; i < 6 ; i++) - odm_write_1byte(p_dm_odm, (REG_ASSOCIATED_BFMER0_INFO_8822B + i), p_beamformer_entry->mac_addr[i]); - } else { - for (i = 0; i < 6 ; i++) - odm_write_1byte(p_dm_odm, (REG_ASSOCIATED_BFMER1_INFO_8822B + i), p_beamformer_entry->mac_addr[i]); - } - - /*CSI report parameters of Beamformer*/ - nc_index = hal_txbf_8822b_get_nrx(p_dm_odm); /*for 8814A nrx = 3(4 ant), min=0(1 ant)*/ - nr_index = p_beamformer_entry->num_of_sounding_dim; /*0x718[7] = 1 use Nsts, 0x718[7] = 0 use reg setting. as Bfee, we use Nsts, so nr_index don't care*/ - - grouping = 0; - - /*for ac = 1, for n = 3*/ - if (p_beamformer_entry->beamform_entry_cap & BEAMFORMEE_CAP_VHT_SU) - codebookinfo = 1; - else if (p_beamformer_entry->beamform_entry_cap & BEAMFORMEE_CAP_HT_EXPLICIT) - codebookinfo = 3; - - coefficientsize = 3; - - csi_param = (u16)((coefficientsize << 10) | (codebookinfo << 8) | (grouping << 6) | (nr_index << 3) | (nc_index)); - - if (bfer_idx == 0) - odm_write_2byte(p_dm_odm, REG_TX_CSI_RPT_PARAM_BW20_8822B, csi_param); - else - odm_write_2byte(p_dm_odm, REG_TX_CSI_RPT_PARAM_BW20_8822B + 2, csi_param); - /*ndp_rx_standby_timer, 8814 need > 0x56, suggest from Dvaid*/ - odm_write_1byte(p_dm_odm, REG_SND_PTCL_CTRL_8822B + 3, 0x70); - - } - - /*************SU BFee Entry Init*************/ - if ((p_beamforming_info->beamformee_su_cnt > 0) && (bfee_idx < BEAMFORMEE_ENTRY_NUM)) { - p_beamformee_entry = &p_beamforming_info->beamformee_entry[bfee_idx]; - p_beamformee_entry->is_mu_sta = false; - hal_txbf_8822b_rf_mode(p_dm_odm, p_beamforming_info, bfee_idx); - - if (phydm_acting_determine(p_dm_odm, phydm_acting_as_ibss)) - sta_id = p_beamformee_entry->mac_id; - else - sta_id = p_beamformee_entry->p_aid; - - for (i = 0; i < MAX_BEAMFORMEE_SU; i++) { - if ((p_beamforming_info->beamformee_su_reg_maping & BIT(i)) == 0) { - p_beamforming_info->beamformee_su_reg_maping |= BIT(i); - p_beamformee_entry->su_reg_index = i; - break; - } - } - - /*P_AID of Beamformee & enable NDPA transmission & enable NDPA interrupt*/ - if (p_beamformee_entry->su_reg_index == 0) { - odm_write_2byte(p_dm_odm, REG_TXBF_CTRL_8822B, sta_id); - odm_write_1byte(p_dm_odm, REG_TXBF_CTRL_8822B + 3, odm_read_1byte(p_dm_odm, REG_TXBF_CTRL_8822B + 3) | BIT(4) | BIT(6) | BIT(7)); - } else - odm_write_2byte(p_dm_odm, REG_TXBF_CTRL_8822B + 2, sta_id | BIT(14) | BIT(15) | BIT(12)); - - /*CSI report parameters of Beamformee*/ - if (p_beamformee_entry->su_reg_index == 0) { - /*Get BIT24 & BIT25*/ - u8 tmp = odm_read_1byte(p_dm_odm, REG_ASSOCIATED_BFMEE_SEL_8822B + 3) & 0x3; - - odm_write_1byte(p_dm_odm, REG_ASSOCIATED_BFMEE_SEL_8822B + 3, tmp | 0x60); - odm_write_2byte(p_dm_odm, REG_ASSOCIATED_BFMEE_SEL_8822B, sta_id | BIT(9)); - } else - odm_write_2byte(p_dm_odm, REG_ASSOCIATED_BFMEE_SEL_8822B + 2, sta_id | 0xE200); /*Set BIT25*/ - - phydm_beamforming_notify(p_dm_odm); - } - - /*************MU BFer Entry Init*************/ - if ((p_beamforming_info->beamformer_mu_cnt > 0) && (bfer_idx < BEAMFORMER_ENTRY_NUM)) { - p_beamformer_entry = &p_beamforming_info->beamformer_entry[bfer_idx]; - p_beamforming_info->mu_ap_index = bfer_idx; - p_beamformer_entry->is_mu_ap = true; - for (i = 0; i < 8; i++) - p_beamformer_entry->gid_valid[i] = 0; - for (i = 0; i < 16; i++) - p_beamformer_entry->user_position[i] = 0; - - /*Sounding protocol control*/ - odm_write_1byte(p_dm_odm, REG_SND_PTCL_CTRL_8822B, 0xDB); - - /* MAC address */ - for (i = 0; i < 6 ; i++) - odm_write_1byte(p_dm_odm, (REG_ASSOCIATED_BFMER0_INFO_8822B + i), p_beamformer_entry->mac_addr[i]); - - /* Set partial AID */ - odm_write_2byte(p_dm_odm, (REG_ASSOCIATED_BFMER0_INFO_8822B + 6), p_beamformer_entry->p_aid); - - /* Fill our AID to 0x1680[11:0] and [13:12] = 2b'00, BF report segment select to 3895 bytes*/ - u1b_tmp = odm_read_1byte(p_dm_odm, 0x1680); - u1b_tmp = (p_beamformer_entry->p_aid) & 0xFFF; - odm_write_1byte(p_dm_odm, 0x1680, u1b_tmp); - - /* Set 80us for leaving ndp_rx_standby_state */ - odm_write_1byte(p_dm_odm, 0x71B, 0x50); - - /* Set 0x6A0[14] = 1 to accept action_no_ack */ - u1b_tmp = odm_read_1byte(p_dm_odm, REG_RXFLTMAP0_8822B + 1); - u1b_tmp |= 0x40; - odm_write_1byte(p_dm_odm, REG_RXFLTMAP0_8822B + 1, u1b_tmp); - /* Set 0x6A2[5:4] = 1 to NDPA and BF report poll */ - u1b_tmp = odm_read_1byte(p_dm_odm, REG_RXFLTMAP1_8822B); - u1b_tmp |= 0x30; - odm_write_1byte(p_dm_odm, REG_RXFLTMAP1_8822B, u1b_tmp); - - /*CSI report parameters of Beamformer*/ - nc_index = hal_txbf_8822b_get_nrx(p_dm_odm); /* Depend on RF type */ - nr_index = 1; /*0x718[7] = 1 use Nsts, 0x718[7] = 0 use reg setting. as Bfee, we use Nsts, so nr_index don't care*/ - grouping = 0; /*no grouping*/ - codebookinfo = 1; /*7 bit for psi, 9 bit for phi*/ - coefficientsize = 0; /*This is nothing really matter*/ - csi_param = (u16)((coefficientsize << 10) | (codebookinfo << 8) | (grouping << 6) | (nr_index << 3) | (nc_index)); - odm_write_2byte(p_dm_odm, 0x6F4, csi_param); - - /*for B-cut*/ - odm_set_bb_reg(p_dm_odm, 0x6A0, BIT(20), 0); - odm_set_bb_reg(p_dm_odm, 0x688, BIT(20), 0); - - } - - /*************MU BFee Entry Init*************/ - if ((p_beamforming_info->beamformee_mu_cnt > 0) && (bfee_idx < BEAMFORMEE_ENTRY_NUM)) { - p_beamformee_entry = &p_beamforming_info->beamformee_entry[bfee_idx]; - p_beamformee_entry->is_mu_sta = true; - for (i = 0; i < MAX_BEAMFORMEE_MU; i++) { - if ((p_beamforming_info->beamformee_mu_reg_maping & BIT(i)) == 0) { - p_beamforming_info->beamformee_mu_reg_maping |= BIT(i); - p_beamformee_entry->mu_reg_index = i; - break; - } - } - - if (p_beamformee_entry->mu_reg_index == 0xFF) { - /* There is no valid bit in beamformee_mu_reg_maping */ - RT_DISP(FBEAM, FBEAM_FUN, ("%s: ERROR! There is no valid bit in beamformee_mu_reg_maping!\n", __func__)); - return; - } - - /*User position table*/ - switch (p_beamformee_entry->mu_reg_index) { - case 0: - gid_valid = 0x7fe; - user_position_l = 0x111110; - user_position_h = 0x0; - break; - case 1: - gid_valid = 0x7f806; - user_position_l = 0x11000004; - user_position_h = 0x11; - break; - case 2: - gid_valid = 0x1f81818; - user_position_l = 0x400040; - user_position_h = 0x11100; - break; - case 3: - gid_valid = 0x1e186060; - user_position_l = 0x4000400; - user_position_h = 0x1100040; - break; - case 4: - gid_valid = 0x66618180; - user_position_l = 0x40004000; - user_position_h = 0x10040400; - break; - case 5: - gid_valid = 0x79860600; - user_position_l = 0x40000; - user_position_h = 0x4404004; - break; - } - - for (i = 0; i < 8; i++) { - if (i < 4) { - p_beamformee_entry->gid_valid[i] = (u8)(gid_valid & 0xFF); - gid_valid = (gid_valid >> 8); - } else - p_beamformee_entry->gid_valid[i] = 0; - } - for (i = 0; i < 16; i++) { - if (i < 4) - p_beamformee_entry->user_position[i] = (u8)((user_position_l >> (i * 8)) & 0xFF); - else if (i < 8) - p_beamformee_entry->user_position[i] = (u8)((user_position_h >> ((i - 4) * 8)) & 0xFF); - else - p_beamformee_entry->user_position[i] = 0; - } - - /*Sounding protocol control*/ - odm_write_1byte(p_dm_odm, REG_SND_PTCL_CTRL_8822B, 0xDB); - - /*select MU STA table*/ - p_beamforming_info->reg_mu_tx_ctrl &= ~(BIT(8) | BIT(9) | BIT(10)); - p_beamforming_info->reg_mu_tx_ctrl |= (p_beamformee_entry->mu_reg_index << 8) & (BIT(8) | BIT(9) | BIT(10)); - odm_write_4byte(p_dm_odm, 0x14c0, p_beamforming_info->reg_mu_tx_ctrl); - - odm_set_bb_reg(p_dm_odm, 0x14c4, MASKDWORD, 0); /*Reset gid_valid table*/ - odm_set_bb_reg(p_dm_odm, 0x14c8, MASKDWORD, user_position_l); - odm_set_bb_reg(p_dm_odm, 0x14cc, MASKDWORD, user_position_h); - - /*set validity of MU STAs*/ - p_beamforming_info->reg_mu_tx_ctrl &= 0xFFFFFFC0; - p_beamforming_info->reg_mu_tx_ctrl |= p_beamforming_info->beamformee_mu_reg_maping & 0x3F; - odm_write_4byte(p_dm_odm, 0x14c0, p_beamforming_info->reg_mu_tx_ctrl); - - ODM_RT_TRACE(p_dm_odm, PHYDM_COMP_TXBF, ODM_DBG_LOUD, ("@%s, reg_mu_tx_ctrl = 0x%x, user_position_l = 0x%x, user_position_h = 0x%x\n", - __func__, p_beamforming_info->reg_mu_tx_ctrl, user_position_l, user_position_h)); - - value16 = odm_read_2byte(p_dm_odm, mu_reg[p_beamformee_entry->mu_reg_index]); - value16 &= 0xFE00; /*Clear PAID*/ - value16 |= BIT(9); /*Enable MU BFee*/ - value16 |= p_beamformee_entry->p_aid; - odm_write_2byte(p_dm_odm, mu_reg[p_beamformee_entry->mu_reg_index], value16); - - /* 0x42C[30] = 1 (0: from Tx desc, 1: from 0x45F) */ - u1b_tmp = odm_read_1byte(p_dm_odm, REG_TXBF_CTRL_8822B + 3); - u1b_tmp |= 0xD0; /* Set bit 28, 30, 31 to 3b'111*/ - odm_write_1byte(p_dm_odm, REG_TXBF_CTRL_8822B + 3, u1b_tmp); - /* Set NDPA to 6M*/ - odm_write_1byte(p_dm_odm, REG_NDPA_RATE_8822B, 0x4); - - u1b_tmp = odm_read_1byte(p_dm_odm, REG_NDPA_OPT_CTRL_8822B); - u1b_tmp &= 0xFC; /* Clear bit 0, 1*/ - odm_write_1byte(p_dm_odm, REG_NDPA_OPT_CTRL_8822B, u1b_tmp); - - u4b_tmp = odm_read_4byte(p_dm_odm, REG_SND_PTCL_CTRL_8822B); - u4b_tmp = ((u4b_tmp & 0xFF0000FF) | 0x020200); /* Set [23:8] to 0x0202*/ - odm_write_4byte(p_dm_odm, REG_SND_PTCL_CTRL_8822B, u4b_tmp); - - /* Set 0x6A0[14] = 1 to accept action_no_ack */ - u1b_tmp = odm_read_1byte(p_dm_odm, REG_RXFLTMAP0_8822B + 1); - u1b_tmp |= 0x40; - odm_write_1byte(p_dm_odm, REG_RXFLTMAP0_8822B + 1, u1b_tmp); - /* End of MAC registers setting */ - - hal_txbf_8822b_rf_mode(p_dm_odm, p_beamforming_info, bfee_idx); -#if (SUPPORT_MU_BF == 1) - /*Special for plugfest*/ - delay_ms(50); /* wait for 4-way handshake ending*/ - send_sw_vht_gid_mgnt_frame(p_dm_odm, p_beamformee_entry->mac_addr, bfee_idx); -#endif - - phydm_beamforming_notify(p_dm_odm); -#if 1 - { - u32 ctrl_info_offset, index; - /*Set Ctrl Info*/ - odm_write_2byte(p_dm_odm, 0x140, 0x660); - ctrl_info_offset = 0x8000 + 32 * p_beamformee_entry->mac_id; - /*Reset Ctrl Info*/ - for (index = 0; index < 8; index++) - odm_write_4byte(p_dm_odm, ctrl_info_offset + index * 4, 0); - - odm_write_4byte(p_dm_odm, ctrl_info_offset, (p_beamformee_entry->mu_reg_index + 1) << 16); - odm_write_1byte(p_dm_odm, 0x81, 0x80); /*RPTBUF ready*/ - - ODM_RT_TRACE(p_dm_odm, PHYDM_COMP_TXBF, ODM_DBG_LOUD, ("@%s, mac_id = %d, ctrl_info_offset = 0x%x, mu_reg_index = %x\n", - __func__, p_beamformee_entry->mac_id, ctrl_info_offset, p_beamformee_entry->mu_reg_index)); - } -#endif - } - -} - - -void -hal_txbf_8822b_leave( - void *p_dm_void, - u8 idx -) -{ - struct PHY_DM_STRUCT *p_dm_odm = (struct PHY_DM_STRUCT *)p_dm_void; - struct _RT_BEAMFORMING_INFO *p_beamforming_info = &p_dm_odm->beamforming_info; - struct _RT_BEAMFORMER_ENTRY *p_beamformer_entry; - struct _RT_BEAMFORMEE_ENTRY *p_beamformee_entry; - u32 mu_reg[6] = {0x1684, 0x1686, 0x1688, 0x168a, 0x168c, 0x168e}; - - if (idx < BEAMFORMER_ENTRY_NUM) { - p_beamformer_entry = &p_beamforming_info->beamformer_entry[idx]; - p_beamformee_entry = &p_beamforming_info->beamformee_entry[idx]; - } else - return; - - /*Clear P_AID of Beamformee*/ - /*Clear MAC address of Beamformer*/ - /*Clear Associated Bfmee Sel*/ - - if (p_beamformer_entry->beamform_entry_cap == BEAMFORMING_CAP_NONE) { - odm_write_1byte(p_dm_odm, REG_SND_PTCL_CTRL_8822B, 0xD8); - if (p_beamformer_entry->is_mu_ap == 0) { /*SU BFer */ - if (p_beamformer_entry->su_reg_index == 0) { - odm_write_4byte(p_dm_odm, REG_ASSOCIATED_BFMER0_INFO_8822B, 0); - odm_write_2byte(p_dm_odm, REG_ASSOCIATED_BFMER0_INFO_8822B + 4, 0); - odm_write_2byte(p_dm_odm, REG_TX_CSI_RPT_PARAM_BW20_8822B, 0); - } else { - odm_write_4byte(p_dm_odm, REG_ASSOCIATED_BFMER1_INFO_8822B, 0); - odm_write_2byte(p_dm_odm, REG_ASSOCIATED_BFMER1_INFO_8822B + 4, 0); - odm_write_2byte(p_dm_odm, REG_TX_CSI_RPT_PARAM_BW20_8822B + 2, 0); - } - p_beamforming_info->beamformer_su_reg_maping &= ~(BIT(p_beamformer_entry->su_reg_index)); - p_beamformer_entry->su_reg_index = 0xFF; - } else { /*MU BFer */ - /*set validity of MU STA0 and MU STA1*/ - p_beamforming_info->reg_mu_tx_ctrl &= 0xFFFFFFC0; - odm_write_4byte(p_dm_odm, 0x14c0, p_beamforming_info->reg_mu_tx_ctrl); - - odm_memory_set(p_dm_odm, p_beamformer_entry->gid_valid, 0, 8); - odm_memory_set(p_dm_odm, p_beamformer_entry->user_position, 0, 16); - p_beamformer_entry->is_mu_ap = false; - } - } - - if (p_beamformee_entry->beamform_entry_cap == BEAMFORMING_CAP_NONE) { - hal_txbf_8822b_rf_mode(p_dm_odm, p_beamforming_info, idx); - if (p_beamformee_entry->is_mu_sta == 0) { /*SU BFee*/ - if (p_beamformee_entry->su_reg_index == 0) { - odm_write_2byte(p_dm_odm, REG_TXBF_CTRL_8822B, 0x0); - odm_write_1byte(p_dm_odm, REG_TXBF_CTRL_8822B + 3, odm_read_1byte(p_dm_odm, REG_TXBF_CTRL_8822B + 3) | BIT(4) | BIT(6) | BIT(7)); - odm_write_2byte(p_dm_odm, REG_ASSOCIATED_BFMEE_SEL_8822B, 0); - } else { - odm_write_2byte(p_dm_odm, REG_TXBF_CTRL_8822B + 2, 0x0 | BIT(14) | BIT(15) | BIT(12)); - - odm_write_2byte(p_dm_odm, REG_ASSOCIATED_BFMEE_SEL_8822B + 2, - odm_read_2byte(p_dm_odm, REG_ASSOCIATED_BFMEE_SEL_8822B + 2) & 0x60); - } - p_beamforming_info->beamformee_su_reg_maping &= ~(BIT(p_beamformee_entry->su_reg_index)); - p_beamformee_entry->su_reg_index = 0xFF; - } else { /*MU BFee */ - /*Disable sending NDPA & BF-rpt-poll to this BFee*/ - odm_write_2byte(p_dm_odm, mu_reg[p_beamformee_entry->mu_reg_index], 0); - /*set validity of MU STA*/ - p_beamforming_info->reg_mu_tx_ctrl &= ~(BIT(p_beamformee_entry->mu_reg_index)); - odm_write_4byte(p_dm_odm, 0x14c0, p_beamforming_info->reg_mu_tx_ctrl); - - - p_beamformee_entry->is_mu_sta = false; - p_beamforming_info->beamformee_mu_reg_maping &= ~(BIT(p_beamformee_entry->mu_reg_index)); - p_beamformee_entry->mu_reg_index = 0xFF; - } - } -} - - -/***********SU & MU BFee Entry Only when souding done****************/ -void -hal_txbf_8822b_status( - void *p_dm_void, - u8 beamform_idx -) -{ - struct PHY_DM_STRUCT *p_dm_odm = (struct PHY_DM_STRUCT *)p_dm_void; - u16 beam_ctrl_val, tmp_val; - u32 beam_ctrl_reg; - struct _RT_BEAMFORMING_INFO *p_beamforming_info = &p_dm_odm->beamforming_info; - struct _RT_BEAMFORMEE_ENTRY *p_beamform_entry; - bool is_mu_sounding = p_beamforming_info->is_mu_sounding, is_bitmap_ready = false; - u16 bitmap; - u8 idx, gid, i; - u8 id1, id0; - u32 gid_valid[6] = {0}; - u32 user_position_lsb[6] = {0}; - u32 user_position_msb[6] = {0}; - u32 value32; - bool is_sounding_success[6] = {false}; - - if (beamform_idx < BEAMFORMEE_ENTRY_NUM) - p_beamform_entry = &p_beamforming_info->beamformee_entry[beamform_idx]; - else - return; - - /*SU sounding done */ - if (is_mu_sounding == false) { - - if (phydm_acting_determine(p_dm_odm, phydm_acting_as_ibss)) - beam_ctrl_val = p_beamform_entry->mac_id; - else - beam_ctrl_val = p_beamform_entry->p_aid; - - ODM_RT_TRACE(p_dm_odm, PHYDM_COMP_TXBF, ODM_DBG_LOUD, ("@%s, beamform_entry.beamform_entry_state = %d", __func__, p_beamform_entry->beamform_entry_state)); - - if (p_beamform_entry->su_reg_index == 0) - beam_ctrl_reg = REG_TXBF_CTRL_8822B; - else { - beam_ctrl_reg = REG_TXBF_CTRL_8822B + 2; - beam_ctrl_val |= BIT(12) | BIT(14) | BIT(15); - } - - if (p_beamform_entry->beamform_entry_state == BEAMFORMING_ENTRY_STATE_PROGRESSED) { - if (p_beamform_entry->sound_bw == CHANNEL_WIDTH_20) - beam_ctrl_val |= BIT(9); - else if (p_beamform_entry->sound_bw == CHANNEL_WIDTH_40) - beam_ctrl_val |= (BIT(9) | BIT(10)); - else if (p_beamform_entry->sound_bw == CHANNEL_WIDTH_80) - beam_ctrl_val |= (BIT(9) | BIT(10) | BIT(11)); - } else { - ODM_RT_TRACE(p_dm_odm, PHYDM_COMP_TXBF, ODM_DBG_LOUD, ("@%s, Don't apply Vmatrix", __func__)); - beam_ctrl_val &= ~(BIT(9) | BIT(10) | BIT(11)); - } - - odm_write_2byte(p_dm_odm, beam_ctrl_reg, beam_ctrl_val); - /*disable NDP packet use beamforming */ - tmp_val = odm_read_2byte(p_dm_odm, REG_TXBF_CTRL_8822B); - odm_write_2byte(p_dm_odm, REG_TXBF_CTRL_8822B, tmp_val | BIT(15)); - } else { - ODM_RT_TRACE(p_dm_odm, PHYDM_COMP_TXBF, ODM_DBG_LOUD, ("@%s, MU Sounding Done\n", __func__)); - /*MU sounding done */ - if (1) { /* (p_beamform_entry->beamform_entry_state == BEAMFORMING_ENTRY_STATE_PROGRESSED) { */ - ODM_RT_TRACE(p_dm_odm, PHYDM_COMP_TXBF, ODM_DBG_LOUD, ("@%s, BEAMFORMING_ENTRY_STATE_PROGRESSED\n", __func__)); - - value32 = odm_get_bb_reg(p_dm_odm, 0x1684, MASKDWORD); - is_sounding_success[0] = (value32 & BIT(10)) ? 1 : 0; - is_sounding_success[1] = (value32 & BIT(26)) ? 1 : 0; - value32 = odm_get_bb_reg(p_dm_odm, 0x1688, MASKDWORD); - is_sounding_success[2] = (value32 & BIT(10)) ? 1 : 0; - is_sounding_success[3] = (value32 & BIT(26)) ? 1 : 0; - value32 = odm_get_bb_reg(p_dm_odm, 0x168C, MASKDWORD); - is_sounding_success[4] = (value32 & BIT(10)) ? 1 : 0; - is_sounding_success[5] = (value32 & BIT(26)) ? 1 : 0; - - ODM_RT_TRACE(p_dm_odm, PHYDM_COMP_TXBF, ODM_DBG_LOUD, ("@%s, is_sounding_success STA1:%d, STA2:%d, STA3:%d, STA4:%d, STA5:%d, STA6:%d\n", - __func__, is_sounding_success[0], is_sounding_success[1], is_sounding_success[2], is_sounding_success[3], is_sounding_success[4], is_sounding_success[5])); - - value32 = odm_get_bb_reg(p_dm_odm, 0xF4C, 0xFFFF0000); - /* odm_set_bb_reg(p_dm_odm, 0x19E0, MASKHWORD, 0xFFFF);Let MAC ignore bitmap */ - - is_bitmap_ready = (bool)((value32 & BIT(15)) >> 15); - bitmap = (u16)(value32 & 0x3FFF); - - for (idx = 0; idx < 15; idx++) { - if (idx < 5) {/*bit0~4*/ - id0 = 0; - id1 = (u8)(idx + 1); - } else if (idx < 9) { /*bit5~8*/ - id0 = 1; - id1 = (u8)(idx - 3); - } else if (idx < 12) { /*bit9~11*/ - id0 = 2; - id1 = (u8)(idx - 6); - } else if (idx < 14) { /*bit12~13*/ - id0 = 3; - id1 = (u8)(idx - 8); - } else { /*bit14*/ - id0 = 4; - id1 = (u8)(idx - 9); - } - if (bitmap & BIT(idx)) { - /*Pair 1*/ - gid = (idx << 1) + 1; - gid_valid[id0] |= (BIT(gid)); - gid_valid[id1] |= (BIT(gid)); - /*Pair 2*/ - gid += 1; - gid_valid[id0] |= (BIT(gid)); - gid_valid[id1] |= (BIT(gid)); - } else { - /*Pair 1*/ - gid = (idx << 1) + 1; - gid_valid[id0] &= ~(BIT(gid)); - gid_valid[id1] &= ~(BIT(gid)); - /*Pair 2*/ - gid += 1; - gid_valid[id0] &= ~(BIT(gid)); - gid_valid[id1] &= ~(BIT(gid)); - } - } - - for (i = 0; i < BEAMFORMEE_ENTRY_NUM; i++) { - p_beamform_entry = &p_beamforming_info->beamformee_entry[i]; - if ((p_beamform_entry->is_mu_sta) && (p_beamform_entry->mu_reg_index < 6)) { - value32 = gid_valid[p_beamform_entry->mu_reg_index]; - for (idx = 0; idx < 4; idx++) { - p_beamform_entry->gid_valid[idx] = (u8)(value32 & 0xFF); - value32 = (value32 >> 8); - } - } - } - - for (idx = 0; idx < 6; idx++) { - p_beamforming_info->reg_mu_tx_ctrl &= ~(BIT(8) | BIT(9) | BIT(10)); - p_beamforming_info->reg_mu_tx_ctrl |= ((idx << 8) & (BIT(8) | BIT(9) | BIT(10))); - odm_write_4byte(p_dm_odm, 0x14c0, p_beamforming_info->reg_mu_tx_ctrl); - odm_set_mac_reg(p_dm_odm, 0x14C4, MASKDWORD, gid_valid[idx]); /*set MU STA gid valid table*/ - } - - /*Enable TxMU PPDU*/ - if (p_beamforming_info->dbg_disable_mu_tx == false) - p_beamforming_info->reg_mu_tx_ctrl |= BIT(7); - else - p_beamforming_info->reg_mu_tx_ctrl &= ~BIT(7); - odm_write_4byte(p_dm_odm, 0x14c0, p_beamforming_info->reg_mu_tx_ctrl); - } - } -} - -/*Only used for MU BFer Entry when get GID management frame (self is as MU STA)*/ -void -hal_txbf_8822b_config_gtab( - void *p_dm_void -) -{ - struct PHY_DM_STRUCT *p_dm_odm = (struct PHY_DM_STRUCT *)p_dm_void; - struct _RT_BEAMFORMING_INFO *p_beamforming_info = &p_dm_odm->beamforming_info; - struct _RT_BEAMFORMER_ENTRY *p_beamformer_entry = NULL; - u32 gid_valid = 0, user_position_l = 0, user_position_h = 0, i; - - if (p_beamforming_info->mu_ap_index < BEAMFORMER_ENTRY_NUM) - p_beamformer_entry = &p_beamforming_info->beamformer_entry[p_beamforming_info->mu_ap_index]; - else - return; - - ODM_RT_TRACE(p_dm_odm, PHYDM_COMP_TXBF, ODM_DBG_LOUD, ("%s==>\n", __func__)); - - /*For GID 0~31*/ - for (i = 0; i < 4; i++) - gid_valid |= (p_beamformer_entry->gid_valid[i] << (i << 3)); - for (i = 0; i < 8; i++) { - if (i < 4) - user_position_l |= (p_beamformer_entry->user_position[i] << (i << 3)); - else - user_position_h |= (p_beamformer_entry->user_position[i] << ((i - 4) << 3)); - } - /*select MU STA0 table*/ - p_beamforming_info->reg_mu_tx_ctrl &= ~(BIT(8) | BIT(9) | BIT(10)); - odm_write_4byte(p_dm_odm, 0x14c0, p_beamforming_info->reg_mu_tx_ctrl); - odm_set_bb_reg(p_dm_odm, 0x14c4, MASKDWORD, gid_valid); - odm_set_bb_reg(p_dm_odm, 0x14c8, MASKDWORD, user_position_l); - odm_set_bb_reg(p_dm_odm, 0x14cc, MASKDWORD, user_position_h); - - ODM_RT_TRACE(p_dm_odm, PHYDM_COMP_TXBF, ODM_DBG_LOUD, ("%s: STA0: gid_valid = 0x%x, user_position_l = 0x%x, user_position_h = 0x%x\n", - __func__, gid_valid, user_position_l, user_position_h)); - - gid_valid = 0; - user_position_l = 0; - user_position_h = 0; - - /*For GID 32~64*/ - for (i = 4; i < 8; i++) - gid_valid |= (p_beamformer_entry->gid_valid[i] << ((i - 4) << 3)); - for (i = 8; i < 16; i++) { - if (i < 4) - user_position_l |= (p_beamformer_entry->user_position[i] << ((i - 8) << 3)); - else - user_position_h |= (p_beamformer_entry->user_position[i] << ((i - 12) << 3)); - } - /*select MU STA1 table*/ - p_beamforming_info->reg_mu_tx_ctrl &= ~(BIT(8) | BIT(9) | BIT(10)); - p_beamforming_info->reg_mu_tx_ctrl |= BIT(8); - odm_write_4byte(p_dm_odm, 0x14c0, p_beamforming_info->reg_mu_tx_ctrl); - odm_set_bb_reg(p_dm_odm, 0x14c4, MASKDWORD, gid_valid); - odm_set_bb_reg(p_dm_odm, 0x14c8, MASKDWORD, user_position_l); - odm_set_bb_reg(p_dm_odm, 0x14cc, MASKDWORD, user_position_h); - - ODM_RT_TRACE(p_dm_odm, PHYDM_COMP_TXBF, ODM_DBG_LOUD, ("%s: STA1: gid_valid = 0x%x, user_position_l = 0x%x, user_position_h = 0x%x\n", - __func__, gid_valid, user_position_l, user_position_h)); - - /* Set validity of MU STA0 and MU STA1*/ - p_beamforming_info->reg_mu_tx_ctrl &= 0xFFFFFFC0; - p_beamforming_info->reg_mu_tx_ctrl |= 0x3; /* STA0, STA1*/ - odm_write_4byte(p_dm_odm, 0x14c0, p_beamforming_info->reg_mu_tx_ctrl); - -} - - - -#if 0 -/*This function translate the bitmap to GTAB*/ -void -haltxbf8822b_gtab_translation( - struct PHY_DM_STRUCT *p_dm_odm -) -{ - u8 idx, gid; - u8 id1, id0; - u32 gid_valid[6] = {0}; - u32 user_position_lsb[6] = {0}; - u32 user_position_msb[6] = {0}; - - for (idx = 0; idx < 15; idx++) { - if (idx < 5) {/*bit0~4*/ - id0 = 0; - id1 = (u8)(idx + 1); - } else if (idx < 9) { /*bit5~8*/ - id0 = 1; - id1 = (u8)(idx - 3); - } else if (idx < 12) { /*bit9~11*/ - id0 = 2; - id1 = (u8)(idx - 6); - } else if (idx < 14) { /*bit12~13*/ - id0 = 3; - id1 = (u8)(idx - 8); - } else { /*bit14*/ - id0 = 4; - id1 = (u8)(idx - 9); - } - - /*Pair 1*/ - gid = (idx << 1) + 1; - gid_valid[id0] |= (1 << gid); - gid_valid[id1] |= (1 << gid); - if (gid < 16) { - /*user_position_lsb[id0] |= (0 << (gid << 1));*/ - user_position_lsb[id1] |= (1 << (gid << 1)); - } else { - /*user_position_msb[id0] |= (0 << ((gid - 16) << 1));*/ - user_position_msb[id1] |= (1 << ((gid - 16) << 1)); - } - - /*Pair 2*/ - gid += 1; - gid_valid[id0] |= (1 << gid); - gid_valid[id1] |= (1 << gid); - if (gid < 16) { - user_position_lsb[id0] |= (1 << (gid << 1)); - /*user_position_lsb[id1] |= (0 << (gid << 1));*/ - } else { - user_position_msb[id0] |= (1 << ((gid - 16) << 1)); - /*user_position_msb[id1] |= (0 << ((gid - 16) << 1));*/ - } - - } - - - for (idx = 0; idx < 6; idx++) { - /*dbg_print("gid_valid[%d] = 0x%x\n", idx, gid_valid[idx]); - dbg_print("user_position[%d] = 0x%x %x\n", idx, user_position_msb[idx], user_position_lsb[idx]);*/ - } -} -#endif - -void -hal_txbf_8822b_fw_txbf( - void *p_dm_void, - u8 idx -) -{ -#if 0 - struct _RT_BEAMFORMING_INFO *p_beam_info = GET_BEAMFORM_INFO(adapter); - struct _RT_BEAMFORMEE_ENTRY *p_beam_entry = p_beam_info->beamformee_entry + idx; - - if (p_beam_entry->beamform_entry_state == BEAMFORMING_ENTRY_STATE_PROGRESSING) - hal_txbf_8822b_download_ndpa(adapter, idx); - - hal_txbf_8822b_fw_txbf_cmd(adapter); -#endif -} - -#endif - -#if (defined(CONFIG_BB_TXBF_API)) -/*this function is only used for BFer*/ -void -phydm_8822btxbf_rfmode( - void *p_dm_void, - u8 su_bfee_cnt, - u8 mu_bfee_cnt -) -{ - struct PHY_DM_STRUCT *p_dm_odm = (struct PHY_DM_STRUCT *)p_dm_void; - u8 i, nr_index = 0; - - if (p_dm_odm->rf_type == ODM_1T1R) - return; - - if ((su_bfee_cnt > 0) || (mu_bfee_cnt > 0)) { - for (i = ODM_RF_PATH_A; i <= ODM_RF_PATH_B; i++) { - odm_set_rf_reg(p_dm_odm, (enum odm_rf_radio_path_e)i, 0xEF, BIT(19), 0x1); /*RF mode table write enable*/ - odm_set_rf_reg(p_dm_odm, (enum odm_rf_radio_path_e)i, 0x33, 0xF, 3); /*Select RX mode*/ - odm_set_rf_reg(p_dm_odm, (enum odm_rf_radio_path_e)i, 0x3E, 0xfffff, 0x00036); /*Set Table data*/ - odm_set_rf_reg(p_dm_odm, (enum odm_rf_radio_path_e)i, 0x3F, 0xfffff, 0x5AFCE); /*Set Table data*/ - odm_set_rf_reg(p_dm_odm, (enum odm_rf_radio_path_e)i, 0xEF, BIT(19), 0x0); /*RF mode table write disable*/ - } - } - - odm_set_bb_reg(p_dm_odm, REG_BB_TXBF_ANT_SET_BF1_8822B, BIT(30), 1); /*if Nsts > Nc, don't apply V matrix*/ - - if (su_bfee_cnt > 0 || mu_bfee_cnt > 0) { - /*for 8814 19ac(idx 1), 19b4(idx 0), different Tx ant setting*/ - odm_set_bb_reg(p_dm_odm, REG_BB_TXBF_ANT_SET_BF1_8822B, BIT(28) | BIT29, 0x2); /*enable BB TxBF ant mapping register*/ - odm_set_bb_reg(p_dm_odm, REG_BB_TXBF_ANT_SET_BF1_8822B, BIT(31), 1); /*ignore user since 8822B only 2Tx*/ - - /*Nsts = 2 AB*/ - odm_set_bb_reg(p_dm_odm, REG_BB_TXBF_ANT_SET_BF1_8822B, 0xffff, 0x0433); - odm_set_bb_reg(p_dm_odm, REG_BB_TX_PATH_SEL_1_8822B, 0xfff00000, 0x043); - - } else { - odm_set_bb_reg(p_dm_odm, REG_BB_TXBF_ANT_SET_BF1_8822B, BIT(28) | BIT29, 0x0); /*enable BB TxBF ant mapping register*/ - odm_set_bb_reg(p_dm_odm, REG_BB_TXBF_ANT_SET_BF1_8822B, BIT(31), 0); /*ignore user since 8822B only 2Tx*/ - - odm_set_bb_reg(p_dm_odm, REG_BB_TX_PATH_SEL_1_8822B, 0xfff00000, 0x1); /*1SS by path-A*/ - odm_set_bb_reg(p_dm_odm, REG_BB_TX_PATH_SEL_2_8822B, MASKLWORD, 0x430); /*2SS by path-A,B*/ - } - -} - - -/*this function is for BFer bug workaround*/ -void -phydm_8822b_sutxbfer_workaroud( - void *p_dm_void, - bool enable_su_bfer, - u8 nc, - u8 nr, - u8 ng, - u8 CB, - u8 BW, - bool is_vht -) -{ - struct PHY_DM_STRUCT *p_dm_odm = (struct PHY_DM_STRUCT *)p_dm_void; - - if (enable_su_bfer) { - odm_set_bb_reg(p_dm_odm, 0x19f8, BIT(22) | BIT(21) | BIT(20), 0x1); - odm_set_bb_reg(p_dm_odm, 0x19f8, BIT(25) | BIT(24) | BIT(23), 0x0); - odm_set_bb_reg(p_dm_odm, 0x19f8, BIT(16), 0x1); - - if (is_vht) - odm_set_bb_reg(p_dm_odm, 0x19f0, BIT(5) | BIT(4) | BIT(3) | BIT(2) | BIT(1) | BIT(0), 0x1f); - else - odm_set_bb_reg(p_dm_odm, 0x19f0, BIT(5) | BIT(4) | BIT(3) | BIT(2) | BIT(1) | BIT(0), 0x22); - - odm_set_bb_reg(p_dm_odm, 0x19f0, BIT(7) | BIT(6), nc); - odm_set_bb_reg(p_dm_odm, 0x19f0, BIT(9) | BIT(8), nr); - odm_set_bb_reg(p_dm_odm, 0x19f0, BIT(11) | BIT(10), ng); - odm_set_bb_reg(p_dm_odm, 0x19f0, BIT(13) | BIT(12), CB); - - odm_set_bb_reg(p_dm_odm, 0xb58, BIT(3) | BIT(2), BW); - odm_set_bb_reg(p_dm_odm, 0xb58, BIT(7) | BIT(6) | BIT(5) | BIT(4), 0x0); - odm_set_bb_reg(p_dm_odm, 0xb58, BIT(9) | BIT(8), BW); - odm_set_bb_reg(p_dm_odm, 0xb58, BIT(13) | BIT(12) | BIT(11) | BIT(10), 0x0); - } else - odm_set_bb_reg(p_dm_odm, 0x19f8, BIT(16), 0x0); - - ODM_RT_TRACE(p_dm_odm, PHYDM_COMP_TXBF, ODM_DBG_TRACE, ("[%s] enable_su_bfer = %d, is_vht = %d\n", __func__, enable_su_bfer, is_vht)); - ODM_RT_TRACE(p_dm_odm, PHYDM_COMP_TXBF, ODM_DBG_TRACE, ("[%s] nc = %d, nr = %d, ng = %d, CB = %d, BW = %d\n", __func__, nc, nr, ng, CB, BW)); - - -} -#endif -#endif /* (RTL8822B_SUPPORT == 1)*/ diff --git a/hal/phydm/txbf/haltxbf8822b.h b/hal/phydm/txbf/haltxbf8822b.h deleted file mode 100644 index 9f86f7c..0000000 --- a/hal/phydm/txbf/haltxbf8822b.h +++ /dev/null @@ -1,79 +0,0 @@ -#ifndef __HAL_TXBF_8822B_H__ -#define __HAL_TXBF_8822B_H__ - -#if (RTL8822B_SUPPORT == 1) -#if (BEAMFORMING_SUPPORT == 1) - -void -hal_txbf_8822b_enter( - void *p_dm_void, - u8 idx -); - - -void -hal_txbf_8822b_leave( - void *p_dm_void, - u8 idx -); - - -void -hal_txbf_8822b_status( - void *p_dm_void, - u8 beamform_idx -); - -void -hal_txbf_8822b_config_gtab( - void *p_dm_void -); - -void -hal_txbf_8822b_fw_txbf( - void *p_dm_void, - u8 idx -); -#else -#define hal_txbf_8822b_enter(p_dm_void, idx) -#define hal_txbf_8822b_leave(p_dm_void, idx) -#define hal_txbf_8822b_status(p_dm_void, idx) -#define hal_txbf_8822b_fw_txbf(p_dm_void, idx) -#define hal_txbf_8822b_config_gtab(p_dm_void) - -#endif - -#if (defined(CONFIG_BB_TXBF_API)) -void -phydm_8822btxbf_rfmode( - void *p_dm_void, - u8 su_bfee_cnt, - u8 mu_bfee_cnt -); - -void -phydm_8822b_sutxbfer_workaroud( - void *p_dm_void, - bool enable_su_bfer, - u8 nc, - u8 nr, - u8 ng, - u8 CB, - u8 BW, - bool is_vht -); - -#else -#define phydm_8822btxbf_rfmode(p_dm_void, su_bfee_cnt, mu_bfee_cnt) -#define phydm_8822b_sutxbfer_workaroud(p_dm_void, enable_su_bfer, nc, nr, ng, CB, BW, is_vht) -#endif - -#else -#define hal_txbf_8822b_enter(p_dm_void, idx) -#define hal_txbf_8822b_leave(p_dm_void, idx) -#define hal_txbf_8822b_status(p_dm_void, idx) -#define hal_txbf_8822b_fw_txbf(p_dm_void, idx) -#define hal_txbf_8822b_config_gtab(p_dm_void) - -#endif -#endif diff --git a/hal/phydm/txbf/haltxbfjaguar.c b/hal/phydm/txbf/haltxbfjaguar.c deleted file mode 100644 index 600d703..0000000 --- a/hal/phydm/txbf/haltxbfjaguar.c +++ /dev/null @@ -1,526 +0,0 @@ -/* ************************************************************ - * Description: - * - * This file is for 8812/8821/8811 TXBF mechanism - * - * ************************************************************ */ -#include "mp_precomp.h" -#include "../phydm_precomp.h" - -#if (BEAMFORMING_SUPPORT == 1) -#if ((RTL8812A_SUPPORT == 1) || (RTL8821A_SUPPORT == 1)) -void -hal_txbf_8812a_set_ndpa_rate( - void *p_dm_void, - u8 BW, - u8 rate -) -{ - struct PHY_DM_STRUCT *p_dm_odm = (struct PHY_DM_STRUCT *)p_dm_void; - - odm_write_1byte(p_dm_odm, REG_NDPA_OPT_CTRL_8812A, (rate << 2 | BW)); - -} - -void -hal_txbf_jaguar_rf_mode( - void *p_dm_void, - struct _RT_BEAMFORMING_INFO *p_beam_info -) -{ - struct PHY_DM_STRUCT *p_dm_odm = (struct PHY_DM_STRUCT *)p_dm_void; - - if (p_dm_odm->rf_type == ODM_1T1R) - return; - - ODM_RT_TRACE(p_dm_odm, PHYDM_COMP_TXBF, ODM_DBG_LOUD, ("[%s] set TxIQGen\n", __func__)); - - odm_set_rf_reg(p_dm_odm, ODM_RF_PATH_A, 0xef, 0x80000, 0x1); /*RF mode table write enable*/ - odm_set_rf_reg(p_dm_odm, ODM_RF_PATH_B, 0xef, 0x80000, 0x1); /*RF mode table write enable*/ - - if (p_beam_info->beamformee_su_cnt > 0) { - /* Paath_A */ - odm_set_rf_reg(p_dm_odm, ODM_RF_PATH_A, 0x30, 0x78000, 0x3); /*Select RX mode*/ - odm_set_rf_reg(p_dm_odm, ODM_RF_PATH_A, 0x31, 0xfffff, 0x3F7FF); /*Set Table data*/ - odm_set_rf_reg(p_dm_odm, ODM_RF_PATH_A, 0x32, 0xfffff, 0xE26BF); /*Enable TXIQGEN in RX mode*/ - /* Path_B */ - odm_set_rf_reg(p_dm_odm, ODM_RF_PATH_B, 0x30, 0x78000, 0x3); /*Select RX mode*/ - odm_set_rf_reg(p_dm_odm, ODM_RF_PATH_B, 0x31, 0xfffff, 0x3F7FF); /*Set Table data*/ - odm_set_rf_reg(p_dm_odm, ODM_RF_PATH_B, 0x32, 0xfffff, 0xE26BF); /*Enable TXIQGEN in RX mode*/ - } else { - /* Paath_A */ - odm_set_rf_reg(p_dm_odm, ODM_RF_PATH_A, 0x30, 0x78000, 0x3); /*Select RX mode*/ - odm_set_rf_reg(p_dm_odm, ODM_RF_PATH_A, 0x31, 0xfffff, 0x3F7FF); /*Set Table data*/ - odm_set_rf_reg(p_dm_odm, ODM_RF_PATH_A, 0x32, 0xfffff, 0xC26BF); /*Disable TXIQGEN in RX mode*/ - /* Path_B */ - odm_set_rf_reg(p_dm_odm, ODM_RF_PATH_B, 0x30, 0x78000, 0x3); /*Select RX mode*/ - odm_set_rf_reg(p_dm_odm, ODM_RF_PATH_B, 0x31, 0xfffff, 0x3F7FF); /*Set Table data*/ - odm_set_rf_reg(p_dm_odm, ODM_RF_PATH_B, 0x32, 0xfffff, 0xC26BF); /*Disable TXIQGEN in RX mode*/ - } - - odm_set_rf_reg(p_dm_odm, ODM_RF_PATH_A, 0xef, 0x80000, 0x0); /*RF mode table write disable*/ - odm_set_rf_reg(p_dm_odm, ODM_RF_PATH_B, 0xef, 0x80000, 0x0); /*RF mode table write disable*/ - - if (p_beam_info->beamformee_su_cnt > 0) - odm_set_bb_reg(p_dm_odm, 0x80c, MASKBYTE1, 0x33); - else - odm_set_bb_reg(p_dm_odm, 0x80c, MASKBYTE1, 0x11); -} - - -void -hal_txbf_jaguar_download_ndpa( - void *p_dm_void, - u8 idx -) -{ - struct PHY_DM_STRUCT *p_dm_odm = (struct PHY_DM_STRUCT *)p_dm_void; - u8 u1b_tmp = 0, tmp_reg422 = 0, head_page; - u8 bcn_valid_reg = 0, count = 0, dl_bcn_count = 0; - bool is_send_beacon = false; - u8 tx_page_bndy = LAST_ENTRY_OF_TX_PKT_BUFFER_8812; /*default reseved 1 page for the IC type which is undefined.*/ - struct _RT_BEAMFORMING_INFO *p_beam_info = &p_dm_odm->beamforming_info; - struct _RT_BEAMFORMEE_ENTRY *p_beam_entry = p_beam_info->beamformee_entry + idx; - struct _ADAPTER *adapter = p_dm_odm->adapter; -#if (DM_ODM_SUPPORT_TYPE == ODM_WIN) - *p_dm_odm->p_is_fw_dw_rsvd_page_in_progress = true; -#endif - ODM_RT_TRACE(p_dm_odm, PHYDM_COMP_TXBF, ODM_DBG_LOUD, ("[%s] Start!\n", __func__)); - - if (idx == 0) - head_page = 0xFE; - else - head_page = 0xFE; - - phydm_get_hal_def_var_handler_interface(p_dm_odm, HAL_DEF_TX_PAGE_BOUNDARY, (u8 *)&tx_page_bndy); - - /*Set REG_CR bit 8. DMA beacon by SW.*/ - u1b_tmp = odm_read_1byte(p_dm_odm, REG_CR_8812A + 1); - odm_write_1byte(p_dm_odm, REG_CR_8812A + 1, (u1b_tmp | BIT(0))); - - - /*Set FWHW_TXQ_CTRL 0x422[6]=0 to tell Hw the packet is not a real beacon frame.*/ - tmp_reg422 = odm_read_1byte(p_dm_odm, REG_FWHW_TXQ_CTRL_8812A + 2); - odm_write_1byte(p_dm_odm, REG_FWHW_TXQ_CTRL_8812A + 2, tmp_reg422 & (~BIT(6))); - - if (tmp_reg422 & BIT(6)) { - ODM_RT_TRACE(p_dm_odm, PHYDM_COMP_TXBF, ODM_DBG_LOUD, ("SetBeamformDownloadNDPA_8812(): There is an adapter is sending beacon.\n")); - is_send_beacon = true; - } - - /*TDECTRL[15:8] 0x209[7:0] = 0xF6 Beacon Head for TXDMA*/ - odm_write_1byte(p_dm_odm, REG_TDECTRL_8812A + 1, head_page); - - do { - /*Clear beacon valid check bit.*/ - bcn_valid_reg = odm_read_1byte(p_dm_odm, REG_TDECTRL_8812A + 2); - odm_write_1byte(p_dm_odm, REG_TDECTRL_8812A + 2, (bcn_valid_reg | BIT(0))); - - /*download NDPA rsvd page.*/ - if (p_beam_entry->beamform_entry_cap & BEAMFORMER_CAP_VHT_SU) - beamforming_send_vht_ndpa_packet(p_dm_odm, p_beam_entry->mac_addr, p_beam_entry->aid, p_beam_entry->sound_bw, BEACON_QUEUE); - else - beamforming_send_ht_ndpa_packet(p_dm_odm, p_beam_entry->mac_addr, p_beam_entry->sound_bw, BEACON_QUEUE); - - /*check rsvd page download OK.*/ - bcn_valid_reg = odm_read_1byte(p_dm_odm, REG_TDECTRL_8812A + 2); - count = 0; - while (!(bcn_valid_reg & BIT(0)) && count < 20) { - count++; - ODM_delay_ms(10); - bcn_valid_reg = odm_read_1byte(p_dm_odm, REG_TDECTRL_8812A + 2); - } - dl_bcn_count++; - } while (!(bcn_valid_reg & BIT(0)) && dl_bcn_count < 5); - - if (!(bcn_valid_reg & BIT(0))) - ODM_RT_TRACE(p_dm_odm, PHYDM_COMP_TXBF, ODM_DBG_LOUD, ("%s Download RSVD page failed!\n", __func__)); - - /*TDECTRL[15:8] 0x209[7:0] = 0xF6 Beacon Head for TXDMA*/ - odm_write_1byte(p_dm_odm, REG_TDECTRL_8812A + 1, tx_page_bndy); - - /*To make sure that if there exists an adapter which would like to send beacon.*/ - /*If exists, the origianl value of 0x422[6] will be 1, we should check this to*/ - /*prevent from setting 0x422[6] to 0 after download reserved page, or it will cause*/ - /*the beacon cannot be sent by HW.*/ - /*2010.06.23. Added by tynli.*/ - if (is_send_beacon) - odm_write_1byte(p_dm_odm, REG_FWHW_TXQ_CTRL_8812A + 2, tmp_reg422); - - /*Do not enable HW DMA BCN or it will cause Pcie interface hang by timing issue. 2011.11.24. by tynli.*/ - /*Clear CR[8] or beacon packet will not be send to TxBuf anymore.*/ - u1b_tmp = odm_read_1byte(p_dm_odm, REG_CR_8812A + 1); - odm_write_1byte(p_dm_odm, REG_CR_8812A + 1, (u1b_tmp & (~BIT(0)))); - - p_beam_entry->beamform_entry_state = BEAMFORMING_ENTRY_STATE_PROGRESSED; -#if (DM_ODM_SUPPORT_TYPE == ODM_WIN) - *p_dm_odm->p_is_fw_dw_rsvd_page_in_progress = false; -#endif -} - - -void -hal_txbf_jaguar_fw_txbf_cmd( - void *p_dm_void -) -{ - struct PHY_DM_STRUCT *p_dm_odm = (struct PHY_DM_STRUCT *)p_dm_void; - u8 idx, period0 = 0, period1 = 0; - u8 PageNum0 = 0xFF, PageNum1 = 0xFF; - u8 u1_tx_bf_parm[3] = {0}; - struct _RT_BEAMFORMING_INFO *p_beam_info = &p_dm_odm->beamforming_info; - - for (idx = 0; idx < BEAMFORMEE_ENTRY_NUM; idx++) { - /*Modified by David*/ - if (p_beam_info->beamformee_entry[idx].is_used && p_beam_info->beamformee_entry[idx].beamform_entry_state == BEAMFORMING_ENTRY_STATE_PROGRESSED) { - if (idx == 0) { - if (p_beam_info->beamformee_entry[idx].is_sound) - PageNum0 = 0xFE; - else - PageNum0 = 0xFF; /*stop sounding*/ - period0 = (u8)(p_beam_info->beamformee_entry[idx].sound_period); - } else if (idx == 1) { - if (p_beam_info->beamformee_entry[idx].is_sound) - PageNum1 = 0xFE; - else - PageNum1 = 0xFF; /*stop sounding*/ - period1 = (u8)(p_beam_info->beamformee_entry[idx].sound_period); - } - } - } - - u1_tx_bf_parm[0] = PageNum0; - u1_tx_bf_parm[1] = PageNum1; - u1_tx_bf_parm[2] = (period1 << 4) | period0; - odm_fill_h2c_cmd(p_dm_odm, PHYDM_H2C_TXBF, 3, u1_tx_bf_parm); - - ODM_RT_TRACE(p_dm_odm, PHYDM_COMP_TXBF, ODM_DBG_LOUD, - ("[%s] PageNum0 = %d period0 = %d, PageNum1 = %d period1 %d\n", __func__, PageNum0, period0, PageNum1, period1)); -} - - -void -hal_txbf_jaguar_enter( - void *p_dm_void, - u8 bfer_bfee_idx -) -{ - struct PHY_DM_STRUCT *p_dm_odm = (struct PHY_DM_STRUCT *)p_dm_void; - u8 i = 0; - u8 bfer_idx = (bfer_bfee_idx & 0xF0) >> 4; - u8 bfee_idx = (bfer_bfee_idx & 0xF); - u32 csi_param; - struct _RT_BEAMFORMING_INFO *p_beamforming_info = &p_dm_odm->beamforming_info; - struct _RT_BEAMFORMEE_ENTRY beamformee_entry; - struct _RT_BEAMFORMER_ENTRY beamformer_entry; - u16 sta_id = 0; - - ODM_RT_TRACE(p_dm_odm, PHYDM_COMP_TXBF, ODM_DBG_LOUD, ("[%s]Start!\n", __func__)); - - hal_txbf_jaguar_rf_mode(p_dm_odm, p_beamforming_info); - - if (p_dm_odm->rf_type == ODM_2T2R) - odm_set_bb_reg(p_dm_odm, ODM_REG_CSI_CONTENT_VALUE, MASKDWORD, 0x00000000); /*nc =2*/ - else - odm_set_bb_reg(p_dm_odm, ODM_REG_CSI_CONTENT_VALUE, MASKDWORD, 0x01081008); /*nc =1*/ - - if ((p_beamforming_info->beamformer_su_cnt > 0) && (bfer_idx < BEAMFORMER_ENTRY_NUM)) { - beamformer_entry = p_beamforming_info->beamformer_entry[bfer_idx]; - - /*Sounding protocol control*/ - odm_write_1byte(p_dm_odm, REG_SND_PTCL_CTRL_8812A, 0xCB); - - /*MAC address/Partial AID of Beamformer*/ - if (bfer_idx == 0) { - for (i = 0; i < 6 ; i++) - odm_write_1byte(p_dm_odm, (REG_BFMER0_INFO_8812A + i), beamformer_entry.mac_addr[i]); - /*CSI report use legacy ofdm so don't need to fill P_AID. */ - /*platform_efio_write_2byte(adapter, REG_BFMER0_INFO_8812A+6, beamform_entry.P_AID); */ - } else { - for (i = 0; i < 6 ; i++) - odm_write_1byte(p_dm_odm, (REG_BFMER1_INFO_8812A + i), beamformer_entry.mac_addr[i]); - /*CSI report use legacy ofdm so don't need to fill P_AID.*/ - /*platform_efio_write_2byte(adapter, REG_BFMER1_INFO_8812A+6, beamform_entry.P_AID);*/ - } - - /*CSI report parameters of Beamformee*/ - if (beamformer_entry.beamform_entry_cap & BEAMFORMEE_CAP_VHT_SU) { - if (p_dm_odm->rf_type == ODM_2T2R) - csi_param = 0x01090109; - else - csi_param = 0x01080108; - } else { - if (p_dm_odm->rf_type == ODM_2T2R) - csi_param = 0x03090309; - else - csi_param = 0x03080308; - } - - odm_write_4byte(p_dm_odm, REG_CSI_RPT_PARAM_BW20_8812A, csi_param); - odm_write_4byte(p_dm_odm, REG_CSI_RPT_PARAM_BW40_8812A, csi_param); - odm_write_4byte(p_dm_odm, REG_CSI_RPT_PARAM_BW80_8812A, csi_param); - - /*Timeout value for MAC to leave NDP_RX_standby_state (60 us, Test chip) (80 us, MP chip)*/ - odm_write_1byte(p_dm_odm, REG_SND_PTCL_CTRL_8812A + 3, 0x50); - } - - - if ((p_beamforming_info->beamformee_su_cnt > 0) && (bfee_idx < BEAMFORMEE_ENTRY_NUM)) { - beamformee_entry = p_beamforming_info->beamformee_entry[bfee_idx]; - - if (phydm_acting_determine(p_dm_odm, phydm_acting_as_ibss)) - sta_id = beamformee_entry.mac_id; - else - sta_id = beamformee_entry.p_aid; - - /*P_AID of Beamformee & enable NDPA transmission & enable NDPA interrupt*/ - if (bfee_idx == 0) { - odm_write_2byte(p_dm_odm, REG_TXBF_CTRL_8812A, sta_id); - odm_write_1byte(p_dm_odm, REG_TXBF_CTRL_8812A + 3, odm_read_1byte(p_dm_odm, REG_TXBF_CTRL_8812A + 3) | BIT(4) | BIT(6) | BIT(7)); - } else - odm_write_2byte(p_dm_odm, REG_TXBF_CTRL_8812A + 2, sta_id | BIT(12) | BIT(14) | BIT(15)); - - /*CSI report parameters of Beamformee*/ - if (bfee_idx == 0) { - /*Get BIT24 & BIT25*/ - u8 tmp = odm_read_1byte(p_dm_odm, REG_BFMEE_SEL_8812A + 3) & 0x3; - - odm_write_1byte(p_dm_odm, REG_BFMEE_SEL_8812A + 3, tmp | 0x60); - odm_write_2byte(p_dm_odm, REG_BFMEE_SEL_8812A, sta_id | BIT(9)); - } else { - /*Set BIT25*/ - odm_write_2byte(p_dm_odm, REG_BFMEE_SEL_8812A + 2, sta_id | 0xE200); - } - phydm_beamforming_notify(p_dm_odm); - } -} - - -void -hal_txbf_jaguar_leave( - void *p_dm_void, - u8 idx -) -{ - struct PHY_DM_STRUCT *p_dm_odm = (struct PHY_DM_STRUCT *)p_dm_void; - struct _RT_BEAMFORMING_INFO *p_beamforming_info = &p_dm_odm->beamforming_info; - struct _RT_BEAMFORMER_ENTRY beamformer_entry; - struct _RT_BEAMFORMEE_ENTRY beamformee_entry; - - if (idx < BEAMFORMER_ENTRY_NUM) { - beamformer_entry = p_beamforming_info->beamformer_entry[idx]; - beamformee_entry = p_beamforming_info->beamformee_entry[idx]; - } else - return; - - ODM_RT_TRACE(p_dm_odm, PHYDM_COMP_TXBF, ODM_DBG_LOUD, ("[%s]Start!, IDx = %d\n", __func__, idx)); - - /*Clear P_AID of Beamformee*/ - /*Clear MAC address of Beamformer*/ - /*Clear Associated Bfmee Sel*/ - - if (beamformer_entry.beamform_entry_cap == BEAMFORMING_CAP_NONE) { - odm_write_1byte(p_dm_odm, REG_SND_PTCL_CTRL_8812A, 0xC8); - if (idx == 0) { - odm_write_4byte(p_dm_odm, REG_BFMER0_INFO_8812A, 0); - odm_write_2byte(p_dm_odm, REG_BFMER0_INFO_8812A + 4, 0); - odm_write_2byte(p_dm_odm, REG_CSI_RPT_PARAM_BW20_8812A, 0); - odm_write_2byte(p_dm_odm, REG_CSI_RPT_PARAM_BW40_8812A, 0); - odm_write_2byte(p_dm_odm, REG_CSI_RPT_PARAM_BW80_8812A, 0); - } else { - odm_write_4byte(p_dm_odm, REG_BFMER1_INFO_8812A, 0); - odm_write_2byte(p_dm_odm, REG_BFMER1_INFO_8812A + 4, 0); - odm_write_2byte(p_dm_odm, REG_CSI_RPT_PARAM_BW20_8812A, 0); - odm_write_2byte(p_dm_odm, REG_CSI_RPT_PARAM_BW40_8812A, 0); - odm_write_2byte(p_dm_odm, REG_CSI_RPT_PARAM_BW80_8812A, 0); - } - } - - if (beamformee_entry.beamform_entry_cap == BEAMFORMING_CAP_NONE) { - hal_txbf_jaguar_rf_mode(p_dm_odm, p_beamforming_info); - if (idx == 0) { - odm_write_2byte(p_dm_odm, REG_TXBF_CTRL_8812A, 0x0); - odm_write_2byte(p_dm_odm, REG_BFMEE_SEL_8812A, 0); - } else { - odm_write_2byte(p_dm_odm, REG_TXBF_CTRL_8812A + 2, odm_read_2byte(p_dm_odm, REG_TXBF_CTRL_8812A + 2) & 0xF000); - odm_write_2byte(p_dm_odm, REG_BFMEE_SEL_8812A + 2, odm_read_2byte(p_dm_odm, REG_BFMEE_SEL_8812A + 2) & 0x60); - } - } - -} - - -void -hal_txbf_jaguar_status( - void *p_dm_void, - u8 idx -) -{ - struct PHY_DM_STRUCT *p_dm_odm = (struct PHY_DM_STRUCT *)p_dm_void; - u16 beam_ctrl_val; - u32 beam_ctrl_reg; - struct _RT_BEAMFORMING_INFO *p_beam_info = &p_dm_odm->beamforming_info; - struct _RT_BEAMFORMEE_ENTRY beamform_entry = p_beam_info->beamformee_entry[idx]; - - if (phydm_acting_determine(p_dm_odm, phydm_acting_as_ibss)) - beam_ctrl_val = beamform_entry.mac_id; - else - beam_ctrl_val = beamform_entry.p_aid; - - if (idx == 0) - beam_ctrl_reg = REG_TXBF_CTRL_8812A; - else { - beam_ctrl_reg = REG_TXBF_CTRL_8812A + 2; - beam_ctrl_val |= BIT(12) | BIT(14) | BIT(15); - } - - if ((beamform_entry.beamform_entry_state == BEAMFORMING_ENTRY_STATE_PROGRESSED) && (p_beam_info->apply_v_matrix == true)) { - if (beamform_entry.sound_bw == CHANNEL_WIDTH_20) - beam_ctrl_val |= BIT(9); - else if (beamform_entry.sound_bw == CHANNEL_WIDTH_40) - beam_ctrl_val |= (BIT(9) | BIT(10)); - else if (beamform_entry.sound_bw == CHANNEL_WIDTH_80) - beam_ctrl_val |= (BIT(9) | BIT(10) | BIT(11)); - } else - beam_ctrl_val &= ~(BIT(9) | BIT(10) | BIT(11)); - - ODM_RT_TRACE(p_dm_odm, PHYDM_COMP_TXBF, ODM_DBG_LOUD, ("[%s] beam_ctrl_val = 0x%x!\n", __func__, beam_ctrl_val)); - - odm_write_2byte(p_dm_odm, beam_ctrl_reg, beam_ctrl_val); -} - - - -void -hal_txbf_jaguar_fw_txbf( - void *p_dm_void, - u8 idx -) -{ - struct PHY_DM_STRUCT *p_dm_odm = (struct PHY_DM_STRUCT *)p_dm_void; - struct _RT_BEAMFORMING_INFO *p_beam_info = &p_dm_odm->beamforming_info; - struct _RT_BEAMFORMEE_ENTRY *p_beam_entry = p_beam_info->beamformee_entry + idx; - - ODM_RT_TRACE(p_dm_odm, PHYDM_COMP_TXBF, ODM_DBG_LOUD, ("[%s] Start!\n", __func__)); - - if (p_beam_entry->beamform_entry_state == BEAMFORMING_ENTRY_STATE_PROGRESSING) - hal_txbf_jaguar_download_ndpa(p_dm_odm, idx); - - hal_txbf_jaguar_fw_txbf_cmd(p_dm_odm); -} - - -void -hal_txbf_jaguar_patch( - void *p_dm_void, - u8 operation -) -{ - struct PHY_DM_STRUCT *p_dm_odm = (struct PHY_DM_STRUCT *)p_dm_void; - struct _RT_BEAMFORMING_INFO *p_beam_info = &p_dm_odm->beamforming_info; - - ODM_RT_TRACE(p_dm_odm, PHYDM_COMP_TXBF, ODM_DBG_LOUD, ("[%s] Start!\n", __func__)); - - if (p_beam_info->beamform_cap == BEAMFORMING_CAP_NONE) - return; -#if (DM_ODM_SUPPORT_TYPE == ODM_WIN) - if (operation == SCAN_OPT_BACKUP_BAND0) - odm_write_1byte(p_dm_odm, REG_SND_PTCL_CTRL_8812A, 0xC8); - else if (operation == SCAN_OPT_RESTORE) - odm_write_1byte(p_dm_odm, REG_SND_PTCL_CTRL_8812A, 0xCB); -#endif -} - -void -hal_txbf_jaguar_clk_8812a( - void *p_dm_void -) -{ - struct PHY_DM_STRUCT *p_dm_odm = (struct PHY_DM_STRUCT *)p_dm_void; - u16 u2btmp; - u8 count = 0, u1btmp; - struct _ADAPTER *adapter = p_dm_odm->adapter; - - ODM_RT_TRACE(p_dm_odm, PHYDM_COMP_TXBF, ODM_DBG_LOUD, ("[%s] Start!\n", __func__)); - - if (*(p_dm_odm->p_is_scan_in_process)) { - ODM_RT_TRACE(p_dm_odm, PHYDM_COMP_TXBF, ODM_DBG_LOUD, ("[%s] return by Scan\n", __func__)); - return; - } -#if DEV_BUS_TYPE == RT_PCI_INTERFACE - /*Stop PCIe TxDMA*/ - odm_write_1byte(p_dm_odm, REG_PCIE_CTRL_REG_8812A + 1, 0xFE); -#endif - - /*Stop Usb TxDMA*/ -#if (DM_ODM_SUPPORT_TYPE == ODM_WIN) - RT_DISABLE_FUNC(adapter, DF_TX_BIT); - PlatformReturnAllPendingTxPackets(adapter); -#else - rtw_write_port_cancel(adapter); -#endif - - /*Wait TXFF empty*/ - for (count = 0; count < 100; count++) { - u2btmp = odm_read_2byte(p_dm_odm, REG_TXPKT_EMPTY_8812A); - u2btmp = u2btmp & 0xfff; - if (u2btmp != 0xfff) { - ODM_delay_ms(10); - continue; - } else - break; - } - - /*TX pause*/ - odm_write_1byte(p_dm_odm, REG_TXPAUSE_8812A, 0xFF); - - /*Wait TX state Machine OK*/ - for (count = 0; count < 100; count++) { - if (odm_read_4byte(p_dm_odm, REG_SCH_TXCMD_8812A) != 0) - continue; - else - break; - } - - - /*Stop RX DMA path*/ - u1btmp = odm_read_1byte(p_dm_odm, REG_RXDMA_CONTROL_8812A); - odm_write_1byte(p_dm_odm, REG_RXDMA_CONTROL_8812A, u1btmp | BIT(2)); - - for (count = 0; count < 100; count++) { - u1btmp = odm_read_1byte(p_dm_odm, REG_RXDMA_CONTROL_8812A); - if (u1btmp & BIT(1)) - break; - else - ODM_delay_ms(10); - } - - /*Disable clock*/ - odm_write_1byte(p_dm_odm, REG_SYS_CLKR_8812A + 1, 0xf0); - /*Disable 320M*/ - odm_write_1byte(p_dm_odm, REG_AFE_PLL_CTRL_8812A + 3, 0x8); - /*Enable 320M*/ - odm_write_1byte(p_dm_odm, REG_AFE_PLL_CTRL_8812A + 3, 0xa); - /*Enable clock*/ - odm_write_1byte(p_dm_odm, REG_SYS_CLKR_8812A + 1, 0xfc); - - - /*Release Tx pause*/ - odm_write_1byte(p_dm_odm, REG_TXPAUSE_8812A, 0); - - /*Enable RX DMA path*/ - u1btmp = odm_read_1byte(p_dm_odm, REG_RXDMA_CONTROL_8812A); - odm_write_1byte(p_dm_odm, REG_RXDMA_CONTROL_8812A, u1btmp & (~BIT(2))); -#if DEV_BUS_TYPE == RT_PCI_INTERFACE - /*Enable PCIe TxDMA*/ - odm_write_1byte(p_dm_odm, REG_PCIE_CTRL_REG_8812A + 1, 0); -#endif - /*Start Usb TxDMA*/ - RT_ENABLE_FUNC(adapter, DF_TX_BIT); -} - -#endif - - - -#endif diff --git a/os_dep/custom_gpio_linux.c b/os_dep/custom_gpio_linux.c deleted file mode 100644 index 623685e..0000000 --- a/os_dep/custom_gpio_linux.c +++ /dev/null @@ -1,281 +0,0 @@ -/****************************************************************************** - * Customer code to add GPIO control during WLAN start/stop - * - * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of version 2 of the GNU General Public License as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA - * - * - ******************************************************************************/ -#include "drv_types.h" - -#ifdef CONFIG_PLATFORM_SPRD - -/* gspi func & GPIO define */ -#include /* 0915 */ -#include - -#if !(defined ANDROID_2X) - -#include -#include - -#ifndef GPIO_WIFI_POWER -#define GPIO_WIFI_POWER -1 -#endif /* !GPIO_WIFI_POWER */ - -#ifndef GPIO_WIFI_RESET -#define GPIO_WIFI_RESET -1 -#endif /* !GPIO_WIFI_RESET */ - -#ifndef GPIO_WIFI_PWDN -#define GPIO_WIFI_PWDN -1 -#endif /* !GPIO_WIFI_RESET */ -#ifdef CONFIG_GSPI_HCI -extern unsigned int oob_irq; -#endif /* CONFIG_GSPI_HCI */ - -#ifdef CONFIG_SDIO_HCI -extern int rtw_mp_mode; -#else /* !CONFIG_SDIO_HCI */ -#endif /* !CONFIG_SDIO_HCI */ - -int rtw_wifi_gpio_init(void) -{ -#ifdef CONFIG_GSPI_HCI - if (GPIO_WIFI_IRQ > 0) { - gpio_request(GPIO_WIFI_IRQ, "oob_irq"); - gpio_direction_input(GPIO_WIFI_IRQ); - - oob_irq = gpio_to_irq(GPIO_WIFI_IRQ); - - RTW_INFO("%s oob_irq:%d\n", __func__, oob_irq); - } -#endif - if (GPIO_WIFI_RESET > 0) - gpio_request(GPIO_WIFI_RESET , "wifi_rst"); - if (GPIO_WIFI_POWER > 0) - gpio_request(GPIO_WIFI_POWER, "wifi_power"); - - return 0; -} - -int rtw_wifi_gpio_deinit(void) -{ -#ifdef CONFIG_GSPI_HCI - if (GPIO_WIFI_IRQ > 0) - gpio_free(GPIO_WIFI_IRQ); -#endif - if (GPIO_WIFI_RESET > 0) - gpio_free(GPIO_WIFI_RESET); - if (GPIO_WIFI_POWER > 0) - gpio_free(GPIO_WIFI_POWER); - - return 0; -} - -/* Customer function to control hw specific wlan gpios */ -void rtw_wifi_gpio_wlan_ctrl(int onoff) -{ - switch (onoff) { - case WLAN_PWDN_OFF: - RTW_INFO("%s: call customer specific GPIO(%d) to set wifi power down pin to 0\n", - __func__, GPIO_WIFI_RESET); - -#ifndef CONFIG_DONT_BUS_SCAN - if (GPIO_WIFI_RESET > 0) - gpio_direction_output(GPIO_WIFI_RESET , 0); -#endif - break; - - case WLAN_PWDN_ON: - RTW_INFO("%s: callc customer specific GPIO(%d) to set wifi power down pin to 1\n", - __func__, GPIO_WIFI_RESET); - - if (GPIO_WIFI_RESET > 0) - gpio_direction_output(GPIO_WIFI_RESET , 1); - break; - - case WLAN_POWER_OFF: - break; - - case WLAN_POWER_ON: - break; - } -} - -#else /* ANDROID_2X */ - -#include - -extern int sprd_3rdparty_gpio_wifi_power; -extern int sprd_3rdparty_gpio_wifi_pwd; - -int rtw_wifi_gpio_init(void) -{ - return 0; -} - -int rtw_wifi_gpio_deinit(void) -{ - return 0; -} - -/* Customer function to control hw specific wlan gpios */ -void rtw_wifi_gpio_wlan_ctrl(int onoff) -{ - switch (onoff) { - case WLAN_PWDN_OFF: - RTW_INFO("%s: call customer specific GPIO to set wifi power down pin to 0\n", - __func__); - if (sprd_3rdparty_gpio_wifi_pwd > 0) - gpio_set_value(sprd_3rdparty_gpio_wifi_pwd, 0); - - if (sprd_3rdparty_gpio_wifi_pwd == 60) { - RTW_INFO("%s: turn off VSIM2 2.8V\n", __func__); - LDO_TurnOffLDO(LDO_LDO_SIM2); - } - break; - - case WLAN_PWDN_ON: - RTW_INFO("%s: callc customer specific GPIO to set wifi power down pin to 1\n", - __func__); - if (sprd_3rdparty_gpio_wifi_pwd == 60) { - RTW_INFO("%s: turn on VSIM2 2.8V\n", __func__); - LDO_SetVoltLevel(LDO_LDO_SIM2, LDO_VOLT_LEVEL0); - LDO_TurnOnLDO(LDO_LDO_SIM2); - } - if (sprd_3rdparty_gpio_wifi_pwd > 0) - gpio_set_value(sprd_3rdparty_gpio_wifi_pwd, 1); - break; - - case WLAN_POWER_OFF: -#ifdef CONFIG_WIF1_LDO - RTW_INFO("%s: turn off VDD-WIFI0 1.2V\n", __func__); - LDO_TurnOffLDO(LDO_LDO_WIF1); -#endif /* CONFIG_WIF1_LDO */ - - RTW_INFO("%s: turn off VDD-WIFI0 3.3V\n", __func__); - LDO_TurnOffLDO(LDO_LDO_WIF0); - - RTW_INFO("%s: call customer specific GPIO(%d) to turn off wifi power\n", - __func__, sprd_3rdparty_gpio_wifi_power); - if (sprd_3rdparty_gpio_wifi_power != 65535) - gpio_set_value(sprd_3rdparty_gpio_wifi_power, 0); - break; - - case WLAN_POWER_ON: - RTW_INFO("%s: call customer specific GPIO(%d) to turn on wifi power\n", - __func__, sprd_3rdparty_gpio_wifi_power); - if (sprd_3rdparty_gpio_wifi_power != 65535) - gpio_set_value(sprd_3rdparty_gpio_wifi_power, 1); - - RTW_INFO("%s: turn on VDD-WIFI0 3.3V\n", __func__); - LDO_TurnOnLDO(LDO_LDO_WIF0); - LDO_SetVoltLevel(LDO_LDO_WIF0, LDO_VOLT_LEVEL1); - -#ifdef CONFIG_WIF1_LDO - RTW_INFO("%s: turn on VDD-WIFI1 1.2V\n", __func__); - LDO_TurnOnLDO(LDO_LDO_WIF1); - LDO_SetVoltLevel(LDO_LDO_WIF1, LDO_VOLT_LEVEL3); -#endif /* CONFIG_WIF1_LDO */ - break; - - case WLAN_BT_PWDN_OFF: - RTW_INFO("%s: call customer specific GPIO to set bt power down pin to 0\n", - __func__); - break; - case WLAN_BT_PWDN_ON: - RTW_INFO("%s: callc customer specific GPIO to set bt power down pin to 1\n", - __func__); - break; - } -} -#endif /* ANDROID_2X */ - -#elif defined(CONFIG_PLATFORM_ARM_RK3066) -#include - -#define GPIO_WIFI_IRQ RK30_PIN2_PC2 -extern unsigned int oob_irq; -int rtw_wifi_gpio_init(void) -{ -#ifdef CONFIG_GSPI_HCI - if (GPIO_WIFI_IRQ > 0) { - rk30_mux_api_set(GPIO2C2_LCDC1DATA18_SMCBLSN1_HSADCDATA5_NAME, GPIO2C_GPIO2C2);/* jacky_test */ - gpio_request(GPIO_WIFI_IRQ, "oob_irq"); - gpio_direction_input(GPIO_WIFI_IRQ); - - oob_irq = gpio_to_irq(GPIO_WIFI_IRQ); - - RTW_INFO("%s oob_irq:%d\n", __func__, oob_irq); - } -#endif - return 0; -} - - -int rtw_wifi_gpio_deinit(void) -{ -#ifdef CONFIG_GSPI_HCI - if (GPIO_WIFI_IRQ > 0) - gpio_free(GPIO_WIFI_IRQ); -#endif - return 0; -} - -void rtw_wifi_gpio_wlan_ctrl(int onoff) -{ -} - -#ifdef CONFIG_GPIO_API -/* this is a demo for extending GPIO pin[7] as interrupt mode */ -struct net_device *rtl_net; -extern int rtw_register_gpio_interrupt(struct net_device *netdev, int gpio_num, void(*callback)(u8 level)); -extern int rtw_disable_gpio_interrupt(struct net_device *netdev, int gpio_num); -void gpio_int(u8 is_high) -{ - RTW_INFO("%s level=%d\n", __func__, is_high); -} -int register_net_gpio_init(void) -{ - rtl_net = dev_get_by_name(&init_net, "wlan0"); - if (!rtl_net) { - RTW_INFO("rtl_net init fail!\n"); - return -1; - } - return rtw_register_gpio_interrupt(rtl_net, 7, gpio_int); -} -int unregister_net_gpio_init(void) -{ - rtl_net = dev_get_by_name(&init_net, "wlan0"); - if (!rtl_net) { - RTW_INFO("rtl_net init fail!\n"); - return -1; - } - return rtw_disable_gpio_interrupt(rtl_net, 7); -} -#endif - -#else - -int rtw_wifi_gpio_init(void) -{ - return 0; -} - -void rtw_wifi_gpio_wlan_ctrl(int onoff) -{ -} -#endif /* CONFIG_PLATFORM_SPRD */