Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    2)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    3)  *  Realtek Bluetooth USB driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6)  *  This program is free software; you can redistribute it and/or modify
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7)  *  it under the terms of the GNU General Public License as published by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8)  *  the Free Software Foundation; either version 2 of the License, or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9)  *  (at your option) any later version.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11)  *  This program is distributed in the hope that it will be useful,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12)  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13)  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14)  *  GNU General Public License for more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16)  *  You should have received a copy of the GNU General Public License
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17)  *  along with this program; if not, write to the Free Software
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18)  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29) #include <linux/skbuff.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30) #include <linux/usb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32) #include <linux/ioctl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34) #include <linux/firmware.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35) #include <linux/vmalloc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38) #include <linux/reboot.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40) #include "rtk_btusb.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42) #define RTKBT_RELEASE_NAME "20180702_BT_ANDROID_8.1"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43) #define VERSION "4.1.5"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) #define SUSPNED_DW_FW 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46) #define SET_WAKEUP_DEVICE 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) static spinlock_t queue_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) static spinlock_t dlfw_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) static volatile uint16_t    dlfw_dis_state = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53) #if SUSPNED_DW_FW
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) static firmware_info *fw_info_4_suspend = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) static uint32_t usb_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59) static patch_info fw_patch_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60) /* { vid, pid, lmp_sub_default, lmp_sub, everion, mp_fw_name, fw_name, config_name, fw_cache, fw_len, mac_offset } */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) { 0x0BDA, 0x1724, 0x1200, 0, 0, "mp_rtl8723a_fw", "rtl8723a_fw", "rtl8723a_config", NULL, 0 ,CONFIG_MAC_OFFSET_GEN_1_2, MAX_PATCH_SIZE_24K}, /* RTL8723A */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62) { 0x0BDA, 0x8723, 0x1200, 0, 0, "mp_rtl8723a_fw", "rtl8723a_fw", "rtl8723a_config", NULL, 0 ,CONFIG_MAC_OFFSET_GEN_1_2, MAX_PATCH_SIZE_24K}, /* 8723AE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) { 0x0BDA, 0xA723, 0x1200, 0, 0, "mp_rtl8723a_fw", "rtl8723a_fw", "rtl8723a_config", NULL, 0 ,CONFIG_MAC_OFFSET_GEN_1_2, MAX_PATCH_SIZE_24K}, /* 8723AE for LI */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64) { 0x0BDA, 0x0723, 0x1200, 0, 0, "mp_rtl8723a_fw", "rtl8723a_fw", "rtl8723a_config", NULL, 0 ,CONFIG_MAC_OFFSET_GEN_1_2, MAX_PATCH_SIZE_24K}, /* 8723AE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) { 0x13D3, 0x3394, 0x1200, 0, 0, "mp_rtl8723a_fw", "rtl8723a_fw", "rtl8723a_config", NULL, 0 ,CONFIG_MAC_OFFSET_GEN_1_2, MAX_PATCH_SIZE_24K}, /* 8723AE for Azurewave*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67) { 0x0BDA, 0x0724, 0x1200, 0, 0, "mp_rtl8723a_fw", "rtl8723a_fw", "rtl8723a_config", NULL, 0 ,CONFIG_MAC_OFFSET_GEN_1_2, MAX_PATCH_SIZE_24K}, /* 8723AU */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68) { 0x0BDA, 0x8725, 0x1200, 0, 0, "mp_rtl8723a_fw", "rtl8723a_fw", "rtl8723a_config", NULL, 0 ,CONFIG_MAC_OFFSET_GEN_1_2, MAX_PATCH_SIZE_24K}, /* 8723AU */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69) { 0x0BDA, 0x872A, 0x1200, 0, 0, "mp_rtl8723a_fw", "rtl8723a_fw", "rtl8723a_config", NULL, 0 ,CONFIG_MAC_OFFSET_GEN_1_2, MAX_PATCH_SIZE_24K}, /* 8723AU */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70) { 0x0BDA, 0x872B, 0x1200, 0, 0, "mp_rtl8723a_fw", "rtl8723a_fw", "rtl8723a_config", NULL, 0 ,CONFIG_MAC_OFFSET_GEN_1_2, MAX_PATCH_SIZE_24K}, /* 8723AU */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) { 0x0BDA, 0xb720, 0x8723, 0, 0, "mp_rtl8723b_fw", "rtl8723b_fw", "rtl8723bu_config", NULL, 0 ,CONFIG_MAC_OFFSET_GEN_1_2, MAX_PATCH_SIZE_24K}, /* RTL8723BU */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) { 0x0BDA, 0xb72A, 0x8723, 0, 0, "mp_rtl8723b_fw", "rtl8723b_fw", "rtl8723bu_config", NULL, 0 ,CONFIG_MAC_OFFSET_GEN_1_2, MAX_PATCH_SIZE_24K}, /* RTL8723BU */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) { 0x0BDA, 0xb728, 0x8723, 0, 0, "mp_rtl8723b_fw", "rtl8723b_fw", "rtl8723b_config", NULL, 0 ,CONFIG_MAC_OFFSET_GEN_1_2, MAX_PATCH_SIZE_24K}, /* RTL8723BE for LC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75) { 0x0BDA, 0xb723, 0x8723, 0, 0, "mp_rtl8723b_fw", "rtl8723b_fw", "rtl8723b_config", NULL, 0 ,CONFIG_MAC_OFFSET_GEN_1_2, MAX_PATCH_SIZE_24K}, /* RTL8723BE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76) { 0x0BDA, 0xb72B, 0x8723, 0, 0, "mp_rtl8723b_fw", "rtl8723b_fw", "rtl8723b_config", NULL, 0 ,CONFIG_MAC_OFFSET_GEN_1_2, MAX_PATCH_SIZE_24K}, /* RTL8723BE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77) { 0x0BDA, 0xb001, 0x8723, 0, 0, "mp_rtl8723b_fw", "rtl8723b_fw", "rtl8723b_config", NULL, 0 ,CONFIG_MAC_OFFSET_GEN_1_2, MAX_PATCH_SIZE_24K}, /* RTL8723BE for HP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) { 0x0BDA, 0xb002, 0x8723, 0, 0, "mp_rtl8723b_fw", "rtl8723b_fw", "rtl8723b_config", NULL, 0 ,CONFIG_MAC_OFFSET_GEN_1_2, MAX_PATCH_SIZE_24K}, /* RTL8723BE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) { 0x0BDA, 0xb003, 0x8723, 0, 0, "mp_rtl8723b_fw", "rtl8723b_fw", "rtl8723b_config", NULL, 0 ,CONFIG_MAC_OFFSET_GEN_1_2, MAX_PATCH_SIZE_24K}, /* RTL8723BE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80) { 0x0BDA, 0xb004, 0x8723, 0, 0, "mp_rtl8723b_fw", "rtl8723b_fw", "rtl8723b_config", NULL, 0 ,CONFIG_MAC_OFFSET_GEN_1_2, MAX_PATCH_SIZE_24K}, /* RTL8723BE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81) { 0x0BDA, 0xb005, 0x8723, 0, 0, "mp_rtl8723b_fw", "rtl8723b_fw", "rtl8723b_config", NULL, 0 ,CONFIG_MAC_OFFSET_GEN_1_2, MAX_PATCH_SIZE_24K}, /* RTL8723BE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83) { 0x13D3, 0x3410, 0x8723, 0, 0, "mp_rtl8723b_fw", "rtl8723b_fw", "rtl8723b_config", NULL, 0 ,CONFIG_MAC_OFFSET_GEN_1_2, MAX_PATCH_SIZE_24K}, /* RTL8723BE for Azurewave */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84) { 0x13D3, 0x3416, 0x8723, 0, 0, "mp_rtl8723b_fw", "rtl8723b_fw", "rtl8723b_config", NULL, 0 ,CONFIG_MAC_OFFSET_GEN_1_2, MAX_PATCH_SIZE_24K}, /* RTL8723BE for Azurewave */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85) { 0x13D3, 0x3459, 0x8723, 0, 0, "mp_rtl8723b_fw", "rtl8723b_fw", "rtl8723b_config", NULL, 0 ,CONFIG_MAC_OFFSET_GEN_1_2, MAX_PATCH_SIZE_24K}, /* RTL8723BE for Azurewave */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) { 0x0489, 0xE085, 0x8723, 0, 0, "mp_rtl8723b_fw", "rtl8723b_fw", "rtl8723b_config", NULL, 0 ,CONFIG_MAC_OFFSET_GEN_1_2, MAX_PATCH_SIZE_24K}, /* RTL8723BE for Foxconn */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) { 0x0489, 0xE08B, 0x8723, 0, 0, "mp_rtl8723b_fw", "rtl8723b_fw", "rtl8723b_config", NULL, 0 ,CONFIG_MAC_OFFSET_GEN_1_2, MAX_PATCH_SIZE_24K}, /* RTL8723BE for Foxconn */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) { 0x0BDA, 0x2850, 0x8761, 0, 0, "mp_rtl8761a_fw", "rtl8761au_fw", "rtl8761a_config", NULL, 0 ,CONFIG_MAC_OFFSET_GEN_1_2, MAX_PATCH_SIZE_24K}, /* RTL8761AU */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90) { 0x0BDA, 0xA761, 0x8761, 0, 0, "mp_rtl8761a_fw", "rtl8761au_fw", "rtl8761a_config", NULL, 0 ,CONFIG_MAC_OFFSET_GEN_1_2, MAX_PATCH_SIZE_24K}, /* RTL8761AU only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91) { 0x0BDA, 0x818B, 0x8761, 0, 0, "mp_rtl8761a_fw", "rtl8761aw8192eu_fw", "rtl8761aw8192eu_config", NULL, 0 ,CONFIG_MAC_OFFSET_GEN_1_2, MAX_PATCH_SIZE_24K}, /* RTL8761AW + 8192EU */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92) { 0x0BDA, 0x818C, 0x8761, 0, 0, "mp_rtl8761a_fw", "rtl8761aw8192eu_fw", "rtl8761aw8192eu_config", NULL, 0 ,CONFIG_MAC_OFFSET_GEN_1_2, MAX_PATCH_SIZE_24K}, /* RTL8761AW + 8192EU */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93) { 0x0BDA, 0x8760, 0x8761, 0, 0, "mp_rtl8761a_fw", "rtl8761au8192ee_fw", "rtl8761a_config", NULL, 0 ,CONFIG_MAC_OFFSET_GEN_1_2, MAX_PATCH_SIZE_24K}, /* RTL8761AU + 8192EE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94) { 0x0BDA, 0xB761, 0x8761, 0, 0, "mp_rtl8761a_fw", "rtl8761au_fw", "rtl8761a_config", NULL, 0 ,CONFIG_MAC_OFFSET_GEN_1_2, MAX_PATCH_SIZE_24K}, /* RTL8761AUV only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95) { 0x0BDA, 0x8761, 0x8761, 0, 0, "mp_rtl8761a_fw", "rtl8761au8192ee_fw", "rtl8761a_config", NULL, 0 ,CONFIG_MAC_OFFSET_GEN_1_2, MAX_PATCH_SIZE_24K}, /* RTL8761AU + 8192EE for LI */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96) { 0x0BDA, 0x8A60, 0x8761, 0, 0, "mp_rtl8761a_fw", "rtl8761au8812ae_fw", "rtl8761a_config", NULL, 0 ,CONFIG_MAC_OFFSET_GEN_1_2, MAX_PATCH_SIZE_24K}, /* RTL8761AU + 8812AE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98) { 0x0BDA, 0x8821, 0x8821, 0, 0, "mp_rtl8821a_fw", "rtl8821a_fw", "rtl8821a_config", NULL, 0 ,CONFIG_MAC_OFFSET_GEN_1_2, MAX_PATCH_SIZE_24K}, /* RTL8821AE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99) { 0x0BDA, 0x0821, 0x8821, 0, 0, "mp_rtl8821a_fw", "rtl8821a_fw", "rtl8821a_config", NULL, 0 ,CONFIG_MAC_OFFSET_GEN_1_2, MAX_PATCH_SIZE_24K}, /* RTL8821AE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) { 0x0BDA, 0x0823, 0x8821, 0, 0, "mp_rtl8821a_fw", "rtl8821a_fw", "rtl8821a_config", NULL, 0 ,CONFIG_MAC_OFFSET_GEN_1_2, MAX_PATCH_SIZE_24K}, /* RTL8821AU */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) { 0x13D3, 0x3414, 0x8821, 0, 0, "mp_rtl8821a_fw", "rtl8821a_fw", "rtl8821a_config", NULL, 0 ,CONFIG_MAC_OFFSET_GEN_1_2, MAX_PATCH_SIZE_24K}, /* RTL8821AE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) { 0x13D3, 0x3458, 0x8821, 0, 0, "mp_rtl8821a_fw", "rtl8821a_fw", "rtl8821a_config", NULL, 0 ,CONFIG_MAC_OFFSET_GEN_1_2, MAX_PATCH_SIZE_24K}, /* RTL8821AE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103) { 0x13D3, 0x3461, 0x8821, 0, 0, "mp_rtl8821a_fw", "rtl8821a_fw", "rtl8821a_config", NULL, 0 ,CONFIG_MAC_OFFSET_GEN_1_2, MAX_PATCH_SIZE_24K}, /* RTL8821AE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104) { 0x13D3, 0x3462, 0x8821, 0, 0, "mp_rtl8821a_fw", "rtl8821a_fw", "rtl8821a_config", NULL, 0 ,CONFIG_MAC_OFFSET_GEN_1_2, MAX_PATCH_SIZE_24K}, /* RTL8821AE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106) { 0x0BDA, 0xB822, 0x8822, 0, 0, "mp_rtl8822b_fw", "rtl8822b_fw", "rtl8822b_config", NULL, 0 ,CONFIG_MAC_OFFSET_GEN_3PLUS, MAX_PATCH_SIZE_24K}, /* RTL8822BE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107) { 0x0BDA, 0xB82C, 0x8822, 0, 0, "mp_rtl8822b_fw", "rtl8822b_fw", "rtl8822b_config", NULL, 0 ,CONFIG_MAC_OFFSET_GEN_3PLUS, MAX_PATCH_SIZE_24K}, /* RTL8822BU */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108) { 0x0BDA, 0xB023, 0x8822, 0, 0, "mp_rtl8822b_fw", "rtl8822b_fw", "rtl8822b_config", NULL, 0 ,CONFIG_MAC_OFFSET_GEN_3PLUS, MAX_PATCH_SIZE_24K}, /* RTL8822BE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109) { 0x0BDA, 0xB703, 0x8703, 0, 0, "mp_rtl8723c_fw", "rtl8723c_fw", "rtl8723c_config", NULL, 0 ,CONFIG_MAC_OFFSET_GEN_3PLUS, MAX_PATCH_SIZE_24K}, /* RTL8723CU */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110) /* todo: RTL8703BU */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112) { 0x0BDA, 0xD723, 0x8723, 0, 0, "mp_rtl8723d_fw", "rtl8723d_fw", "rtl8723d_config", NULL, 0 ,CONFIG_MAC_OFFSET_GEN_3PLUS, MAX_PATCH_SIZE_40K}, /* RTL8723DU */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113) { 0x0BDA, 0xD720, 0x8723, 0, 0, "mp_rtl8723d_fw", "rtl8723d_fw", "rtl8723d_config", NULL, 0 ,CONFIG_MAC_OFFSET_GEN_3PLUS, MAX_PATCH_SIZE_40K}, /* RTL8723DE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114) { 0x0BDA, 0xB820, 0x8821, 0, 0, "mp_rtl8821c_fw", "rtl8821c_fw", "rtl8821c_config", NULL, 0 ,CONFIG_MAC_OFFSET_GEN_3PLUS, MAX_PATCH_SIZE_40K}, /* RTL8821CU */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115) { 0x0BDA, 0xC820, 0x8821, 0, 0, "mp_rtl8821c_fw", "rtl8821c_fw", "rtl8821c_config", NULL, 0 ,CONFIG_MAC_OFFSET_GEN_3PLUS, MAX_PATCH_SIZE_40K}, /* RTL8821CU */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) { 0x0BDA, 0xC821, 0x8821, 0, 0, "mp_rtl8821c_fw", "rtl8821c_fw", "rtl8821c_config", NULL, 0 ,CONFIG_MAC_OFFSET_GEN_3PLUS, MAX_PATCH_SIZE_40K}, /* RTL8821CE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) /* todo: RTL8703CU */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) /* NOTE: must append patch entries above the null entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) { 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, 0, 0 }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) struct btusb_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124)     struct hci_dev       *hdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125)     struct usb_device    *udev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126)     struct usb_interface *intf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127)     struct usb_interface *isoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129)     spinlock_t lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131)     unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133)     struct work_struct work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134)     struct work_struct waker;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136)     struct usb_anchor tx_anchor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137)     struct usb_anchor intr_anchor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138)     struct usb_anchor bulk_anchor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139)     struct usb_anchor isoc_anchor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140)     struct usb_anchor deferred;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141)     int tx_in_flight;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142)     spinlock_t txlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144)     struct usb_endpoint_descriptor *intr_ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145)     struct usb_endpoint_descriptor *bulk_tx_ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146)     struct usb_endpoint_descriptor *bulk_rx_ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147)     struct usb_endpoint_descriptor *isoc_tx_ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148)     struct usb_endpoint_descriptor *isoc_rx_ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150)     __u8 cmdreq_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152)     unsigned int sco_num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153)     int isoc_altsetting;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154)     int suspend_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155)     uint16_t sco_handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) //#ifdef CONFIG_HAS_EARLYSUSPEND
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) #if 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158)     struct early_suspend early_suspend;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160)     struct notifier_block pm_notifier;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161)     struct notifier_block reboot_notifier;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163)     firmware_info *fw_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) #ifdef CONFIG_SCO_OVER_HCI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166)     RTK_sco_card_t  *pSCOSnd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 7, 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170) static bool reset_on_close = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) int download_patch(firmware_info *fw_info, int cached);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) int reset_controller(firmware_info* fw_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) static inline int check_set_dlfw_state_value(uint16_t change_value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178)     int state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179)     spin_lock(&dlfw_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180)     if(!dlfw_dis_state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181)         dlfw_dis_state = change_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183)     state = dlfw_dis_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184)     spin_unlock(&dlfw_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185)     return state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) static inline void set_dlfw_state_value(uint16_t change_value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190)     spin_lock(&dlfw_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191)     dlfw_dis_state = change_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192)     spin_unlock(&dlfw_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) #if SUSPNED_DW_FW
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) static int download_suspend_patch(firmware_info *fw_info, int cached);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) #if SET_WAKEUP_DEVICE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) static void set_wakeup_device_from_conf(firmware_info *fw_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) int set_wakeup_device(firmware_info* fw_info, uint8_t* wakeup_bdaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) static void rtk_free( struct btusb_data *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206)     kfree(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208)     return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) static struct btusb_data *rtk_alloc(struct usb_interface *intf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213)     struct btusb_data *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215)     data = kzalloc(sizeof(*data), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217)     data = devm_kzalloc(&intf->dev, sizeof(*data), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219)     return data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222) static void print_acl(struct sk_buff *skb, int direction)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) #if PRINT_ACL_DATA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225)     uint wlength = skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226)     u16 *handle = (u16 *)(skb->data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227)     u16 len = *(handle+1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228)     u8 *acl_data = (u8 *)(skb->data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230)     RTK_INFO("%s: direction %d, handle %04x, len %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231)             __func__, direction, *handle, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) static void print_sco(struct sk_buff *skb, int direction)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) #if PRINT_SCO_DATA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238)     uint wlength = skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239)     u16 *handle = (u16 *)(skb->data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240)     u8 len = *(u8 *)(handle+1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241)     u8 *sco_data =(u8 *)(skb->data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243)     RTKBT_INFO("%s: direction %d, handle %04x, len %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244)             __func__, direction, *handle, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) static void print_error_command(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250)     uint wlength = skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251)     uint icount = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252)     u16 *opcode = (u16*)(skb->data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253)     u8 *cmd_data = (u8*)(skb->data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254)     u8 len = *(cmd_data+2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256)     switch (*opcode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257)     case HCI_OP_INQUIRY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258)         printk("HCI_OP_INQUIRY");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259)         break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260)     case HCI_OP_INQUIRY_CANCEL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261)         printk("HCI_OP_INQUIRY_CANCEL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262)         break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263)     case HCI_OP_EXIT_PERIODIC_INQ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264)         printk("HCI_OP_EXIT_PERIODIC_INQ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265)         break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266)     case HCI_OP_CREATE_CONN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267)         printk("HCI_OP_CREATE_CONN");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268)         break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269)     case HCI_OP_DISCONNECT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270)         printk("HCI_OP_DISCONNECT");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271)         break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272)     case HCI_OP_CREATE_CONN_CANCEL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273)         printk("HCI_OP_CREATE_CONN_CANCEL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274)         break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275)     case HCI_OP_ACCEPT_CONN_REQ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276)         printk("HCI_OP_ACCEPT_CONN_REQ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277)         break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278)     case HCI_OP_REJECT_CONN_REQ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279)         printk("HCI_OP_REJECT_CONN_REQ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280)         break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281)     case HCI_OP_AUTH_REQUESTED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282)         printk("HCI_OP_AUTH_REQUESTED");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283)         break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284)     case HCI_OP_SET_CONN_ENCRYPT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285)         printk("HCI_OP_SET_CONN_ENCRYPT");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286)         break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287)     case HCI_OP_REMOTE_NAME_REQ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288)         printk("HCI_OP_REMOTE_NAME_REQ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289)         break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290)     case HCI_OP_READ_REMOTE_FEATURES:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291)         printk("HCI_OP_READ_REMOTE_FEATURES");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292)         break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293)     case HCI_OP_SNIFF_MODE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294)         printk("HCI_OP_SNIFF_MODE");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295)         break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296)     case HCI_OP_EXIT_SNIFF_MODE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297)         printk("HCI_OP_EXIT_SNIFF_MODE");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298)         break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299)     case HCI_OP_SWITCH_ROLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300)         printk("HCI_OP_SWITCH_ROLE");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301)         break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302)     case HCI_OP_SNIFF_SUBRATE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303)         printk("HCI_OP_SNIFF_SUBRATE");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304)         break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305)     case HCI_OP_RESET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306)         printk("HCI_OP_RESET");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307)         break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308)     case HCI_OP_Write_Extended_Inquiry_Response:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309)         printk("HCI_Write_Extended_Inquiry_Response");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310)         break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312)     default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313)         printk("CMD");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314)         break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316)     printk(":%04x,len:%d,", *opcode,len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317)     for (icount = 3; (icount < wlength) && (icount < 24); icount++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318)         printk("%02x ", *(cmd_data+icount));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319)     printk("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) static void print_command(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) #if PRINT_CMD_EVENT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325)     print_error_command(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) #if CONFIG_BLUEDROID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) /* Global parameters for bt usb char driver */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) #define BT_CHAR_DEVICE_NAME "rtkbt_dev"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) struct mutex btchr_mutex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) static struct sk_buff_head btchr_readq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) static wait_queue_head_t btchr_read_wait;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) static wait_queue_head_t bt_dlfw_wait;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) static bool bt_char_dev_registered;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) static dev_t bt_devid; /* bt char device number */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) static struct cdev bt_char_dev; /* bt character device structure */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) static struct class *bt_char_class; /* device class for usb char driver */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) static int bt_reset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) /* HCI device & lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) DEFINE_RWLOCK(hci_dev_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) struct hci_dev *ghdev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) static void print_event(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) #if PRINT_CMD_EVENT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348)     uint wlength = skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349)     uint icount = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350)     u8 *opcode = (u8*)(skb->data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351)     u8 len = *(opcode+1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353)     switch (*opcode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354)     case HCI_EV_INQUIRY_COMPLETE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355)         printk("HCI_EV_INQUIRY_COMPLETE");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356)         break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357)     case HCI_EV_INQUIRY_RESULT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358)         printk("HCI_EV_INQUIRY_RESULT");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359)         break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360)     case HCI_EV_CONN_COMPLETE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361)         printk("HCI_EV_CONN_COMPLETE");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362)         break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363)     case HCI_EV_CONN_REQUEST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364)         printk("HCI_EV_CONN_REQUEST");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365)         break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366)     case HCI_EV_DISCONN_COMPLETE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367)         printk("HCI_EV_DISCONN_COMPLETE");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368)         break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369)     case HCI_EV_AUTH_COMPLETE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370)         printk("HCI_EV_AUTH_COMPLETE");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371)         break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372)     case HCI_EV_REMOTE_NAME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373)         printk("HCI_EV_REMOTE_NAME");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374)         break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375)     case HCI_EV_ENCRYPT_CHANGE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376)         printk("HCI_EV_ENCRYPT_CHANGE");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377)         break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378)     case HCI_EV_CHANGE_LINK_KEY_COMPLETE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379)         printk("HCI_EV_CHANGE_LINK_KEY_COMPLETE");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380)         break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381)     case HCI_EV_REMOTE_FEATURES:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382)         printk("HCI_EV_REMOTE_FEATURES");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383)         break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384)     case HCI_EV_REMOTE_VERSION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385)         printk("HCI_EV_REMOTE_VERSION");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386)         break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387)     case HCI_EV_QOS_SETUP_COMPLETE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388)         printk("HCI_EV_QOS_SETUP_COMPLETE");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389)         break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390)     case HCI_EV_CMD_COMPLETE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391)         printk("HCI_EV_CMD_COMPLETE");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392)         break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393)     case HCI_EV_CMD_STATUS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394)         printk("HCI_EV_CMD_STATUS");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395)         break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396)     case HCI_EV_ROLE_CHANGE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397)         printk("HCI_EV_ROLE_CHANGE");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398)         break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399)     case HCI_EV_NUM_COMP_PKTS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400)         printk("HCI_EV_NUM_COMP_PKTS");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401)         break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402)     case HCI_EV_MODE_CHANGE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403)         printk("HCI_EV_MODE_CHANGE");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404)         break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405)     case HCI_EV_PIN_CODE_REQ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406)         printk("HCI_EV_PIN_CODE_REQ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407)         break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408)     case HCI_EV_LINK_KEY_REQ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409)         printk("HCI_EV_LINK_KEY_REQ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410)         break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411)     case HCI_EV_LINK_KEY_NOTIFY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412)         printk("HCI_EV_LINK_KEY_NOTIFY");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413)         break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414)     case HCI_EV_CLOCK_OFFSET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415)         printk("HCI_EV_CLOCK_OFFSET");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416)         break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417)     case HCI_EV_PKT_TYPE_CHANGE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418)         printk("HCI_EV_PKT_TYPE_CHANGE");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419)         break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420)     case HCI_EV_PSCAN_REP_MODE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421)         printk("HCI_EV_PSCAN_REP_MODE");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422)         break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423)     case HCI_EV_INQUIRY_RESULT_WITH_RSSI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424)         printk("HCI_EV_INQUIRY_RESULT_WITH_RSSI");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425)         break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426)     case HCI_EV_REMOTE_EXT_FEATURES:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427)         printk("HCI_EV_REMOTE_EXT_FEATURES");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428)         break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429)     case HCI_EV_SYNC_CONN_COMPLETE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430)         printk("HCI_EV_SYNC_CONN_COMPLETE");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431)         break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432)     case HCI_EV_SYNC_CONN_CHANGED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433)         printk("HCI_EV_SYNC_CONN_CHANGED");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434)         break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435)     case HCI_EV_SNIFF_SUBRATE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436)         printk("HCI_EV_SNIFF_SUBRATE");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437)         break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438)     case HCI_EV_EXTENDED_INQUIRY_RESULT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439)         printk("HCI_EV_EXTENDED_INQUIRY_RESULT");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440)         break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441)     case HCI_EV_IO_CAPA_REQUEST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442)         printk("HCI_EV_IO_CAPA_REQUEST");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443)         break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444)     case HCI_EV_SIMPLE_PAIR_COMPLETE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445)         printk("HCI_EV_SIMPLE_PAIR_COMPLETE");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446)         break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447)     case HCI_EV_REMOTE_HOST_FEATURES:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448)         printk("HCI_EV_REMOTE_HOST_FEATURES");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449)         break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450)     default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451)         printk("event");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452)         break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454)     printk(":%02x,len:%d,", *opcode,len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455)     for (icount = 2; (icount < wlength) && (icount < 24); icount++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456)         printk("%02x ", *(opcode+icount));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457)     printk("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) static inline ssize_t usb_put_user(struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462)         char __user *buf, int count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464)     char __user *ptr = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465)     int len = min_t(unsigned int, skb->len, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467)     if (copy_to_user(ptr, skb->data, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468)         return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470)     return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) static struct sk_buff *rtk_skb_queue[QUEUE_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) static int rtk_skb_queue_front = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) static int rtk_skb_queue_rear = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) static void rtk_enqueue(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479)     spin_lock(&queue_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480)     if (rtk_skb_queue_front == (rtk_skb_queue_rear + 1) % QUEUE_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481)         /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482)          * If queue is full, current solution is to drop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483)          * the following entries.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484)          */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485)         RTKBT_WARN("%s: Queue is full, entry will be dropped", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486)     } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487)         rtk_skb_queue[rtk_skb_queue_rear] = skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489)         rtk_skb_queue_rear++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490)         rtk_skb_queue_rear %= QUEUE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493)     spin_unlock(&queue_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) static struct sk_buff *rtk_dequeue_try(unsigned int deq_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498)     struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499)     struct sk_buff *skb_copy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501)     if (rtk_skb_queue_front == rtk_skb_queue_rear) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502)         RTKBT_WARN("%s: Queue is empty", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503)         return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506)     skb = rtk_skb_queue[rtk_skb_queue_front];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507)     if (deq_len >= skb->len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508)         rtk_skb_queue[rtk_skb_queue_front] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509)         rtk_skb_queue_front++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510)         rtk_skb_queue_front %= QUEUE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512)         /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513)          * Return skb addr to be dequeued, and the caller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514)          * should free the skb eventually.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515)          */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516)         return skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517)     } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518)         skb_copy = pskb_copy(skb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519)         skb_pull(skb, deq_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520)         /* Return its copy to be freed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521)         return skb_copy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) static inline int is_queue_empty(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527)     return (rtk_skb_queue_front == rtk_skb_queue_rear) ? 1 : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) static void rtk_clear_queue(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532)     struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533)     spin_lock(&queue_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534)     while(!is_queue_empty()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535)         skb = rtk_skb_queue[rtk_skb_queue_front];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536)         rtk_skb_queue[rtk_skb_queue_front] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537)         rtk_skb_queue_front++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538)         rtk_skb_queue_front %= QUEUE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539)         if (skb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540)             kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543)     spin_unlock(&queue_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547)  * Realtek - Integrate from hci_core.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) /* Get HCI device by index.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551)  * Device is held on return. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) static struct hci_dev *hci_dev_get(int index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554)     if (index != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555)         return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557)     return ghdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) /* ---- HCI ioctl helpers ---- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) static int hci_dev_open(__u16 dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563)     struct hci_dev *hdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564)     int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566)     RTKBT_DBG("%s: dev %d", __func__, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568)     hdev = hci_dev_get(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569)     if (!hdev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570)         RTKBT_ERR("%s: Failed to get hci dev[Null]", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571)         return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574)     if (test_bit(HCI_UNREGISTER, &hdev->dev_flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575)         ret = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576)         goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579)     if (test_bit(HCI_UP, &hdev->flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580)         ret = -EALREADY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581)         goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584)     ret = hdev->open(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585)     if(ret < 0){
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586)         RTKBT_ERR("%s:Failed in hdev->open(hdev):%d",__func__,ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587)         goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589)     set_bit(HCI_UP, &hdev->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593)     return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) static int hci_dev_do_close(struct hci_dev *hdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598)     if (hdev->flush)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599)         hdev->flush(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600)     /* After this point our queues are empty
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601)      * and no tasks are scheduled. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602)     hdev->close(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603)     /* Clear flags */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604)     hdev->flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605)     return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) static int hci_dev_close(__u16 dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610)     struct hci_dev *hdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611)     int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612)     hdev = hci_dev_get(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613)     if (!hdev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614)         RTKBT_ERR("%s: failed to get hci dev[Null]", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615)         return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618)     err = hci_dev_do_close(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620)     return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) static struct hci_dev *hci_alloc_dev(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625)     struct hci_dev *hdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627)     hdev = kzalloc(sizeof(struct hci_dev), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628)     if (!hdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629)         return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631)     return hdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) /* Free HCI device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) static void hci_free_dev(struct hci_dev *hdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637)     kfree(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) /* Register HCI device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) static int hci_register_dev(struct hci_dev *hdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643)     int i, id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645)     RTKBT_DBG("%s: %p name %s bus %d", __func__, hdev, hdev->name, hdev->bus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646)     /* Do not allow HCI_AMP devices to register at index 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647)      * so the index can be used as the AMP controller ID.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648)      */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649)     id = (hdev->dev_type == HCI_BREDR) ? 0 : 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651)     write_lock(&hci_dev_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653)     sprintf(hdev->name, "hci%d", id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654)     hdev->id = id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655)     hdev->flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656)     hdev->dev_flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657)     mutex_init(&hdev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659)     RTKBT_DBG("%s: id %d, name %s", __func__, hdev->id, hdev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662)     for (i = 0; i < NUM_REASSEMBLY; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663)         hdev->reassembly[i] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665)     memset(&hdev->stat, 0, sizeof(struct hci_dev_stats));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666)     atomic_set(&hdev->promisc, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668)     if (ghdev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669)         write_unlock(&hci_dev_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670)         RTKBT_ERR("%s: Hci device has been registered already", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671)         return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672)     } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673)         ghdev = hdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675)     write_unlock(&hci_dev_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677)     return id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) /* Unregister HCI device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) static void hci_unregister_dev(struct hci_dev *hdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683)     int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685)     RTKBT_DBG("%s: hdev %p name %s bus %d", __func__, hdev, hdev->name, hdev->bus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686)     set_bit(HCI_UNREGISTER, &hdev->dev_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688)     write_lock(&hci_dev_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689)     ghdev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690)     write_unlock(&hci_dev_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692)     hci_dev_do_close(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693)     for (i = 0; i < NUM_REASSEMBLY; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694)         kfree_skb(hdev->reassembly[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) #ifdef CONFIG_SCO_OVER_HCI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) /* copy data from the URB buffer into the ALSA ring buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) static bool rtk_copy_capture_data_to_alsa(struct btusb_data *data, uint8_t* p_data, unsigned int frames)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702)   	struct snd_pcm_runtime *runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703)   	unsigned int frame_bytes, frames1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704)   	u8 *dest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705)     RTK_sco_card_t  *pSCOSnd = data->pSCOSnd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707)   	runtime = pSCOSnd->capture.substream->runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708)   	frame_bytes = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710)   	dest = runtime->dma_area + pSCOSnd->capture.buffer_pos * frame_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711)   	if (pSCOSnd->capture.buffer_pos + frames <= runtime->buffer_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712)   		memcpy(dest, p_data, frames * frame_bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713)   	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714)   		/* wrap around at end of ring buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715)   		frames1 = runtime->buffer_size - pSCOSnd->capture.buffer_pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716)   		memcpy(dest, p_data, frames1 * frame_bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717)   		memcpy(runtime->dma_area,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718)   		       p_data + frames1 * frame_bytes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719)   		       (frames - frames1) * frame_bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720)   	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722)   	pSCOSnd->capture.buffer_pos += frames;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723)   	if (pSCOSnd->capture.buffer_pos >= runtime->buffer_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724)   		pSCOSnd->capture.buffer_pos -= runtime->buffer_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725)   	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727)     if((pSCOSnd->capture.buffer_pos%runtime->period_size) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728)         snd_pcm_period_elapsed(pSCOSnd->capture.substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731)   	return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) static void hci_send_to_alsa_ringbuffer(struct hci_dev *hdev, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737)     struct btusb_data *data = GET_DRV_DATA(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738)     RTK_sco_card_t  *pSCOSnd = data->pSCOSnd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739)     uint8_t* p_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740)     int sco_length = skb->len - HCI_SCO_HDR_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742)     RTKBT_DBG("%s", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744)     if (!hdev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745)         RTKBT_ERR("%s: Frame for unknown HCI device", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746)         return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749)     if (!test_bit(ALSA_CAPTURE_RUNNING, &pSCOSnd->states)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750)         //RTKBT_WARN("%s: ALSA is not running", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751)         return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754)     p_data = (uint8_t *)skb->data + HCI_SCO_HDR_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755)     rtk_copy_capture_data_to_alsa(data, p_data, sco_length/2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) static void hci_send_to_stack(struct hci_dev *hdev, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762)     struct sk_buff *rtk_skb_copy = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764)     RTKBT_DBG("%s", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766)     if (!hdev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767)         RTKBT_ERR("%s: Frame for unknown HCI device", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768)         return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771)     if (!test_bit(HCI_RUNNING, &hdev->flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772)         RTKBT_ERR("%s: HCI not running", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773)         return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776)     rtk_skb_copy = pskb_copy(skb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777)     if (!rtk_skb_copy) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778)         RTKBT_ERR("%s: Copy skb error", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779)         return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782)     memcpy(skb_push(rtk_skb_copy, 1), &bt_cb(skb)->pkt_type, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783)     rtk_enqueue(rtk_skb_copy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785)     /* Make sure bt char device existing before wakeup read queue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786)     hdev = hci_dev_get(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787)     if (hdev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788)         RTKBT_DBG("%s: Try to wakeup read queue", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789)         wake_up_interruptible(&btchr_read_wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792)     return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) /* Receive frame from HCI drivers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) static int hci_recv_frame(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798)     struct hci_dev *hdev = (struct hci_dev *) skb->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800)     if (!hdev ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801)         (!test_bit(HCI_UP, &hdev->flags) && !test_bit(HCI_INIT, &hdev->flags))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802)         kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803)         return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806)     /* Incomming skb */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807)     bt_cb(skb)->incoming = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809)     /* Time stamp */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810)     __net_timestamp(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812)     if (atomic_read(&hdev->promisc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) #ifdef CONFIG_SCO_OVER_HCI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814)         if(bt_cb(skb)->pkt_type == HCI_SCODATA_PKT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815)             hci_send_to_alsa_ringbuffer(hdev, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817)         /* Send copy to the sockets */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818)         hci_send_to_stack(hdev, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821)     kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822)     return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) static int hci_reassembly(struct hci_dev *hdev, int type, void *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826)                           int count, __u8 index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828)     int len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829)     int hlen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830)     int remain = count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831)     struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832)     struct bt_skb_cb *scb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834)     RTKBT_DBG("%s", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836)     if ((type < HCI_ACLDATA_PKT || type > HCI_EVENT_PKT) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837)             index >= NUM_REASSEMBLY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838)         return -EILSEQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840)     skb = hdev->reassembly[index];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842)     if (!skb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843)         switch (type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844)         case HCI_ACLDATA_PKT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845)             len = HCI_MAX_FRAME_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846)             hlen = HCI_ACL_HDR_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847)             break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848)         case HCI_EVENT_PKT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849)             len = HCI_MAX_EVENT_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850)             hlen = HCI_EVENT_HDR_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851)             break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852)         case HCI_SCODATA_PKT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853)             len = HCI_MAX_SCO_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854)             hlen = HCI_SCO_HDR_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855)             break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858)         skb = bt_skb_alloc(len, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859)         if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860)             return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862)         scb = (void *) skb->cb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863)         scb->expect = hlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864)         scb->pkt_type = type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866)         skb->dev = (void *) hdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867)         hdev->reassembly[index] = skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870)     while (count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871)         scb = (void *) skb->cb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872)         len = min_t(uint, scb->expect, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874)         memcpy(skb_put(skb, len), data, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876)         count -= len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877)         data += len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878)         scb->expect -= len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879)         remain = count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881)         switch (type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882)         case HCI_EVENT_PKT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883)             if (skb->len == HCI_EVENT_HDR_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884)                 struct hci_event_hdr *h = hci_event_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885)                 scb->expect = h->plen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887)                 if (skb_tailroom(skb) < scb->expect) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888)                     kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889)                     hdev->reassembly[index] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890)                     return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891)                 }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892)             }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893)             break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895)         case HCI_ACLDATA_PKT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896)             if (skb->len  == HCI_ACL_HDR_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897)                 struct hci_acl_hdr *h = hci_acl_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898)                 scb->expect = __le16_to_cpu(h->dlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900)                 if (skb_tailroom(skb) < scb->expect) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901)                     kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902)                     hdev->reassembly[index] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903)                     return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904)                 }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905)             }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906)             break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908)         case HCI_SCODATA_PKT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909)             if (skb->len == HCI_SCO_HDR_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910)                 struct hci_sco_hdr *h = hci_sco_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911)                 scb->expect = h->dlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913)                 if (skb_tailroom(skb) < scb->expect) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914)                     kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915)                     hdev->reassembly[index] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916)                     return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917)                 }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918)             }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919)             break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922)         if (scb->expect == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923)             /* Complete frame */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924)             if(HCI_ACLDATA_PKT == type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925)                 print_acl(skb,0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926)             if(HCI_SCODATA_PKT == type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927)                 print_sco(skb,0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928)             if(HCI_EVENT_PKT == type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929)                 print_event(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931)             bt_cb(skb)->pkt_type = type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932)             hci_recv_frame(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934)             hdev->reassembly[index] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935)             return remain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939)     return remain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) static int hci_recv_fragment(struct hci_dev *hdev, int type, void *data, int count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944)     int rem = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946)     if (type < HCI_ACLDATA_PKT || type > HCI_EVENT_PKT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947)         return -EILSEQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949)     while (count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950)         rem = hci_reassembly(hdev, type, data, count, type - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951)         if (rem < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952)             return rem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954)         data += (count - rem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955)         count = rem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958)     return rem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) void hci_hardware_error(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963)     struct sk_buff *rtk_skb_copy = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964)     int len = 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965)     uint8_t hardware_err_pkt[4] = {HCI_EVENT_PKT, 0x10, 0x01, HCI_VENDOR_USB_DISC_HARDWARE_ERROR};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967)     rtk_skb_copy = alloc_skb(len, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968)     if (!rtk_skb_copy) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969)         RTKBT_ERR("%s: Failed to allocate mem", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970)         return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973)     memcpy(skb_put(rtk_skb_copy, len), hardware_err_pkt, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974)     rtk_enqueue(rtk_skb_copy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976)     wake_up_interruptible(&btchr_read_wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) static int btchr_open(struct inode *inode_p, struct file  *file_p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981)     struct btusb_data *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982)     struct hci_dev *hdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984)     RTKBT_INFO("%s: BT usb char device is opening", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985)     /* Not open unless wanna tracing log */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986)     /* trace_printk("%s: open....\n", __func__); */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988)     hdev = hci_dev_get(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989)     if (!hdev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990)         RTKBT_ERR("%s: Failed to get hci dev[NULL]", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991)         return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993)     data = GET_DRV_DATA(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995)     atomic_inc(&hdev->promisc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996)     /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997)      * As bt device is not re-opened when hotplugged out, we cannot
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998)      * trust on file's private data(may be null) when other file ops
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999)      * are invoked.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000)      */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001)     file_p->private_data = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003)     mutex_lock(&btchr_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004)     hci_dev_open(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005)     mutex_unlock(&btchr_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007)     rtk_clear_queue();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008)     return nonseekable_open(inode_p, file_p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) static int btchr_close(struct inode  *inode_p, struct file   *file_p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013)     struct btusb_data *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014)     struct hci_dev *hdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016)     RTKBT_INFO("%s: BT usb char device is closing", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017)     /* Not open unless wanna tracing log */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018)     /* trace_printk("%s: close....\n", __func__); */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020)     data = file_p->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021)     file_p->private_data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) #if CONFIG_BLUEDROID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024)     /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025)      * If the upper layer closes bt char interfaces, no reset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026)      * action required even bt device hotplugged out.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027)      */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028)     bt_reset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031)     hdev = hci_dev_get(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032)     if (hdev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033)         atomic_set(&hdev->promisc, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034)         mutex_lock(&btchr_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035)         hci_dev_close(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036)         mutex_unlock(&btchr_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039)     return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) static ssize_t btchr_read(struct file *file_p,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043)         char __user *buf_p,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044)         size_t count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045)         loff_t *pos_p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047)     struct hci_dev *hdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048)     struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049)     ssize_t ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051)     RTKBT_DBG("%s: BT usb char device is reading", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053)     while (count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054)         hdev = hci_dev_get(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055)         if (!hdev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056)             /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057)              * Note: Only when BT device hotplugged out, we wil get
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058)              * into such situation. In order to keep the upper layer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059)              * stack alive (blocking the read), we should never return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060)              * EFAULT or break the loop.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061)              */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062)             RTKBT_ERR("%s: Failed to get hci dev[Null]", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065)         ret = wait_event_interruptible(btchr_read_wait, !is_queue_empty());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066)         if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067)             RTKBT_ERR("%s: wait event is signaled %d", __func__, (int)ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068)             break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071)         skb = rtk_dequeue_try(count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072)         if (skb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073)             ret = usb_put_user(skb, buf_p, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074)             if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075)                 RTKBT_ERR("%s: Failed to put data to user space", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076)             kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077)             break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081)     return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) static ssize_t btchr_write(struct file *file_p,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085)         const char __user *buf_p,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086)         size_t count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087)         loff_t *pos_p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089)     struct btusb_data *data = file_p->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090)     struct hci_dev *hdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091)     struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093)     RTKBT_DBG("%s: BT usb char device is writing", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095)     hdev = hci_dev_get(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096)     if (!hdev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097)         RTKBT_WARN("%s: Failed to get hci dev[Null]", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098)         /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099)          * Note: we bypass the data from the upper layer if bt device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100)          * is hotplugged out. Fortunatelly, H4 or H5 HCI stack does
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101)          * NOT check btchr_write's return value. However, returning
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102)          * count instead of EFAULT is preferable.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103)          */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104)         /* return -EFAULT; */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105)         return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108)     /* Never trust on btusb_data, as bt device may be hotplugged out */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109)     data = GET_DRV_DATA(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110)     if (!data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111)         RTKBT_WARN("%s: Failed to get bt usb driver data[Null]", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112)         return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115)     if (count > HCI_MAX_FRAME_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116)         return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118)     skb = bt_skb_alloc(count, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119)     if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120)         return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121)     skb_reserve(skb, -1); // Add this line
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123)     if (copy_from_user(skb_put(skb, count), buf_p, count)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124)         RTKBT_ERR("%s: Failed to get data from user space", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125)         kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126)         return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129)     skb->dev = (void *)hdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130)     bt_cb(skb)->pkt_type = *((__u8 *)skb->data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131)     skb_pull(skb, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132)     data->hdev->send(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134)     return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) static unsigned int btchr_poll(struct file *file_p, poll_table *wait)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139)     struct btusb_data *data = file_p->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140)     struct hci_dev *hdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142)     RTKBT_DBG("%s: BT usb char device is polling", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144)     if(!bt_char_dev_registered) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145)         RTKBT_ERR("%s: char device has not registered!", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146)         return POLLERR | POLLHUP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149)     poll_wait(file_p, &btchr_read_wait, wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151)     hdev = hci_dev_get(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152)     if (!hdev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153)         RTKBT_ERR("%s: Failed to get hci dev[Null]", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154)         mdelay(URB_CANCELING_DELAY_MS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155)         return POLLOUT | POLLWRNORM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158)     /* Never trust on btusb_data, as bt device may be hotplugged out */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159)     data = GET_DRV_DATA(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160)     if (!data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161)         /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162)          * When bt device is hotplugged out, btusb_data will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163)          * be freed in disconnect.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164)          */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165)         RTKBT_ERR("%s: Failed to get bt usb driver data[Null]", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166)         mdelay(URB_CANCELING_DELAY_MS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167)         return POLLOUT | POLLWRNORM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170)     if (!is_queue_empty())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171)         return POLLIN | POLLRDNORM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173)     return POLLOUT | POLLWRNORM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) static long btchr_ioctl(struct file *file_p, unsigned int cmd, unsigned long arg){
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176)     int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177)     struct hci_dev *hdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178)     struct btusb_data *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179)     firmware_info *fw_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181)     if(!bt_char_dev_registered) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182)         return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185)     if(check_set_dlfw_state_value(1) != 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186)         RTKBT_ERR("%s bt controller is disconnecting!", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187)         return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190)     hdev = hci_dev_get(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191)     if(!hdev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192)         RTKBT_ERR("%s device is NULL!", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193)         set_dlfw_state_value(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194)         return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196)     data = GET_DRV_DATA(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197)     fw_info = data->fw_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199)     RTKBT_INFO(" btchr_ioctl DOWN_FW_CFG with Cmd:%d",cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200)     switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201)         case DOWN_FW_CFG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202)             ret = usb_autopm_get_interface(data->intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203)             if (ret < 0){
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204)                 goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205)             }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207)             ret = download_patch(fw_info,1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208)             usb_autopm_put_interface(data->intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209)             if(ret < 0){
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210)                 RTKBT_ERR("%s:Failed in download_patch with ret:%d",__func__,ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211)                 goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212)             }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214)             ret = hdev->open(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215)             if(ret < 0){
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216)                 RTKBT_ERR("%s:Failed in hdev->open(hdev):%d",__func__,ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217)                 goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218)             }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219)             set_bit(HCI_UP, &hdev->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220)             set_dlfw_state_value(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221)             wake_up_interruptible(&bt_dlfw_wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222)             return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223)         case GET_USB_INFO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224)             ret = hdev->open(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225)             if(ret < 0){
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226)                 RTKBT_ERR("%s:Failed in hdev->open(hdev):%d",__func__,ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227)                 //goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228)             }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229)             set_bit(HCI_UP, &hdev->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230)             return usb_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231)         case RESET_CONTROLLER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232)             reset_controller(fw_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233)             return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) #ifdef CONFIG_SCO_OVER_HCI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236)         case SET_ISO_CFG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237)             hdev->voice_setting = *(__u16 *)arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238)             RTKBT_INFO(" voice settings = 0x%04x", hdev->voice_setting);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239)             return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241)         default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242)             RTKBT_ERR("%s:Failed with wrong Cmd:%d",__func__,cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243)             goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245)     failed:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246)         set_dlfw_state_value(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247)         wake_up_interruptible(&bt_dlfw_wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248)         return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) static struct file_operations bt_chrdev_ops  = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255)     open    :    btchr_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256)     release    :    btchr_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257)     read    :    btchr_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258)     write    :    btchr_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259)     poll    :    btchr_poll,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260)     unlocked_ioctl   :   btchr_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) static int btchr_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265)     int res = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266)     struct device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268)     RTKBT_INFO("Register usb char device interface for BT driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269)     /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270)      * btchr mutex is used to sync between
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271)      * 1) downloading patch and opening bt char driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272)      * 2) the file operations of bt char driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273)      */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274)     mutex_init(&btchr_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276)     skb_queue_head_init(&btchr_readq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277)     init_waitqueue_head(&btchr_read_wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278)     init_waitqueue_head(&bt_dlfw_wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280)     bt_char_class = class_create(THIS_MODULE, BT_CHAR_DEVICE_NAME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281)     if (IS_ERR(bt_char_class)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282)         RTKBT_ERR("Failed to create bt char class");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283)         return PTR_ERR(bt_char_class);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286)     res = alloc_chrdev_region(&bt_devid, 0, 1, BT_CHAR_DEVICE_NAME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287)     if (res < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288)         RTKBT_ERR("Failed to allocate bt char device");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289)         goto err_alloc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292)     dev = device_create(bt_char_class, NULL, bt_devid, NULL, BT_CHAR_DEVICE_NAME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293)     if (IS_ERR(dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294)         RTKBT_ERR("Failed to create bt char device");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295)         res = PTR_ERR(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296)         goto err_create;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299)     cdev_init(&bt_char_dev, &bt_chrdev_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300)     res = cdev_add(&bt_char_dev, bt_devid, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301)     if (res < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302)         RTKBT_ERR("Failed to add bt char device");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303)         goto err_add;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306)     return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) err_add:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309)     device_destroy(bt_char_class, bt_devid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) err_create:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311)     unregister_chrdev_region(bt_devid, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) err_alloc:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313)     class_destroy(bt_char_class);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314)     return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) static void btchr_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319)     RTKBT_INFO("Unregister usb char device interface for BT driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321)     device_destroy(bt_char_class, bt_devid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322)     cdev_del(&bt_char_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323)     unregister_chrdev_region(bt_devid, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324)     class_destroy(bt_char_class);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326)     return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) int send_hci_cmd(firmware_info *fw_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332)    int i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333)    int ret_val = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334)    while((ret_val<0)&&(i++<10))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335)    {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336)        ret_val = usb_control_msg(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337)           fw_info->udev, fw_info->pipe_out,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338)           0, USB_TYPE_CLASS, 0, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339)           (void *)(fw_info->send_pkt),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340)           fw_info->pkt_len, MSG_TO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341)    }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342)    return ret_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) int rcv_hci_evt(firmware_info *fw_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347)     int ret_len = 0, ret_val = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348)     int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350)     while (1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351)         for(i = 0; i < 5; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352)         ret_val = usb_interrupt_msg(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353)             fw_info->udev, fw_info->pipe_in,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354)             (void *)(fw_info->rcv_pkt), PKT_LEN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355)             &ret_len, MSG_TO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356)             if (ret_val >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357)                 break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360)         if (ret_val < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361)             return ret_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363)         if (CMD_CMP_EVT == fw_info->evt_hdr->evt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364)             if (fw_info->cmd_hdr->opcode == fw_info->cmd_cmp->opcode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365)                 return ret_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) int set_bt_onoff(firmware_info *fw_info, uint8_t onoff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372)     patch_info *patch_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373)     int ret_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375)     RTKBT_INFO("%s: %s", __func__, onoff != 0 ? "on" : "off");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377)     patch_entry = fw_info->patch_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378)     if (!patch_entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379)         return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381)     fw_info->cmd_hdr->opcode = cpu_to_le16(BTOFF_OPCODE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382)     fw_info->cmd_hdr->plen = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383)     fw_info->pkt_len = CMD_HDR_LEN + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384)     fw_info->send_pkt[CMD_HDR_LEN] = onoff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386)     ret_val = send_hci_cmd(fw_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387)     if (ret_val < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388)         RTKBT_ERR("%s: Failed to send bt %s cmd, errno %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389)                 __func__, onoff != 0 ? "on" : "off", ret_val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390)         return ret_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393)     ret_val = rcv_hci_evt(fw_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394)     if (ret_val < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395)         RTKBT_ERR("%s: Failed to receive bt %s event, errno %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396)                 __func__, onoff != 0 ? "on" : "off", ret_val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397)         return ret_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400)     return ret_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) static patch_info *get_fw_table_entry(struct usb_device* udev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405)     patch_info *patch_entry = fw_patch_table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406)     uint16_t vid = le16_to_cpu(udev->descriptor.idVendor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407)     uint16_t pid = le16_to_cpu(udev->descriptor.idProduct);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408)     uint32_t entry_size = sizeof(fw_patch_table) / sizeof(fw_patch_table[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409)     uint32_t i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411)     RTKBT_INFO("%s: Product id = 0x%04x, fw table entry size %d", __func__, pid, entry_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412)     usb_info = (uint32_t)(vid<<16) | pid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414)     for (i = 0; i < entry_size; i++, patch_entry++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415)         if ((vid == patch_entry->vid)&&(pid == patch_entry->pid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416)             break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419)     if (i == entry_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420)         RTKBT_ERR("%s: No fw table entry found", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421)         return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424)     return patch_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) #if SUSPNED_DW_FW
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) static patch_info *get_suspend_fw_table_entry(struct usb_device* udev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430)     patch_info *patch_entry = fw_patch_table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431)     uint16_t vid = le16_to_cpu(udev->descriptor.idVendor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432)     uint16_t pid = le16_to_cpu(udev->descriptor.idProduct);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433)     uint32_t entry_size = sizeof(fw_patch_table) / sizeof(fw_patch_table[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434)     uint32_t i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436)     RTKBT_INFO("%s: Product id = 0x%04x, fw table entry size %d", __func__, pid, entry_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438)     for (i = 0; i < entry_size; i++, patch_entry++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439)         if ((vid == patch_entry->vid)&&(pid == patch_entry->pid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440)             break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443)     if (i == entry_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444)         RTKBT_ERR("%s: No fw table entry found", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445)         return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448)     return patch_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) static struct rtk_epatch_entry *get_fw_patch_entry(struct rtk_epatch *epatch_info, uint16_t eco_ver)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454)     int patch_num = epatch_info->number_of_total_patch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455)     uint8_t *epatch_buf = (uint8_t *)epatch_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456)     struct rtk_epatch_entry *p_entry = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457)     int coex_date;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458)     int coex_ver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459)     int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461)     for (i = 0; i < patch_num; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462)         if (*(uint16_t *)(epatch_buf + 14 + 2*i) == eco_ver + 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463)             p_entry = kzalloc(sizeof(*p_entry), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464)             if (!p_entry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465)                 RTKBT_ERR("%s: Failed to allocate mem for patch entry", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466)                 return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467)             }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468)             p_entry->chip_id = eco_ver + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469)             p_entry->patch_length = *(uint16_t*)(epatch_buf + 14 + 2*patch_num + 2*i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470)             p_entry->start_offset = *(uint32_t*)(epatch_buf + 14 + 4*patch_num + 4*i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471)             p_entry->coex_version = *(uint32_t*)(epatch_buf + p_entry->start_offset + p_entry->patch_length - 12);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472)             p_entry->svn_version = *(uint32_t*)(epatch_buf + p_entry->start_offset + p_entry->patch_length - 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473)             p_entry->fw_version = *(uint32_t*)(epatch_buf + p_entry->start_offset + p_entry->patch_length - 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475)             coex_date = ((p_entry->coex_version >> 16) & 0x7ff) + ((p_entry->coex_version >> 27) * 10000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476)             coex_ver = p_entry->coex_version & 0xffff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478)             RTKBT_INFO("BTCOEX:20%06d-0x%04x svn version:0x%08x fw version:0x%08x rtk_btusb version:%s Cut:%d, patch length:0x%04x, patch offset:0x%08x\n", \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479)                     coex_date, coex_ver, p_entry->svn_version, p_entry->fw_version, VERSION, p_entry->chip_id, p_entry->patch_length, p_entry->start_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480)             break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484)     return p_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) /*reset_controller is aimed to reset_bt_fw before updata Fw patch*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) int reset_controller(firmware_info* fw_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490)     int ret_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491)     RTKBT_ERR("reset_controller");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493)     if (!fw_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494)         return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496)     fw_info->cmd_hdr->opcode = cpu_to_le16(HCI_VENDOR_FORCE_RESET_AND_PATCHABLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497)     fw_info->cmd_hdr->plen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498)     fw_info->pkt_len = CMD_HDR_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499)     ret_val = send_hci_cmd(fw_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501)     if (ret_val < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502)         RTKBT_ERR("%s: Failed to send hci cmd 0x%04x, errno %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503)                 __func__, fw_info->cmd_hdr->opcode, ret_val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504)         return ret_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507)     //sleep 1s for firmware reset.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508)     msleep(1000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509)     RTKBT_INFO("%s: Wait fw reset for 1000ms",__func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511)     return ret_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) /*reset_controller is aimed to reset_bt_fw before updata Fw patch*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516)  * check the return value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517)  * 1: need to download fw patch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518)  * 0: no need to download fw patch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519)  * <0: failed to check lmp version
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) int check_fw_version(firmware_info* fw_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523)     struct hci_rp_read_local_version *read_ver_rsp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524)     patch_info *patch_entry = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525)     int ret_val = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527)     fw_info->cmd_hdr->opcode = cpu_to_le16(HCI_OP_READ_LOCAL_VERSION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528)     fw_info->cmd_hdr->plen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529)     fw_info->pkt_len = CMD_HDR_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531)     ret_val = send_hci_cmd(fw_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532)     if (ret_val < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533)         RTKBT_ERR("%s: Failed to send hci cmd 0x%04x, errno %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534)                 __func__, fw_info->cmd_hdr->opcode, ret_val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535)         return ret_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538)     ret_val = rcv_hci_evt(fw_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539)     if (ret_val < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540)         RTKBT_ERR("%s: Failed to receive hci event, errno %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541)                 __func__, ret_val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542)         return ret_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545)     patch_entry = fw_info->patch_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546)     read_ver_rsp = (struct hci_rp_read_local_version *)(fw_info->rsp_para);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548)     RTKBT_INFO("%s: Controller lmp = 0x%04x, patch lmp = 0x%04x, default patch lmp = 0x%04x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549)             __func__, read_ver_rsp->lmp_subver, patch_entry->lmp_sub, patch_entry->lmp_sub_default);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551)     if (read_ver_rsp->lmp_subver == patch_entry->lmp_sub_default) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552)         RTKBT_INFO("%s: Cold BT controller startup", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554)         return 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556)     } else if (read_ver_rsp->lmp_subver != patch_entry->lmp_sub) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557)         RTKBT_INFO("%s: Warm BT controller startup with updated lmp", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558)         return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559)     } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560)         RTKBT_INFO("%s: Warm BT controller startup with same lmp", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561)         return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) #if SET_WAKEUP_DEVICE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) int set_wakeup_device(firmware_info* fw_info, uint8_t* wakeup_bdaddr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568)     struct rtk_eversion_evt *ever_evt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569)     int ret_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571)     if (!fw_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572)         return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574)     fw_info->cmd_hdr->opcode = cpu_to_le16(HCI_VENDOR_ADD_WAKE_UP_DEVICE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575)     fw_info->cmd_hdr->plen = 7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576)     memcpy(fw_info->req_para, wakeup_bdaddr, 7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577)     fw_info->pkt_len = CMD_HDR_LEN + 7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579)     ret_val = send_hci_cmd(fw_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580)     if (ret_val < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581)         RTKBT_ERR("%s: Failed to send hci cmd 0x%04x, errno %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582)             __func__, fw_info->cmd_hdr->opcode, ret_val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583)         return ret_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586)     ret_val = rcv_hci_evt(fw_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587)     if (ret_val < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588)         RTKBT_ERR("%s: Failed to receive hci event, errno %d\n",__func__, ret_val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589)         return ret_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592)     ever_evt = (struct rtk_eversion_evt *)(fw_info->rsp_para);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594)     RTKBT_DBG("%s: status %d, eversion %d", __func__, ever_evt->status, ever_evt->version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595)     return ret_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) /*reset_channel to recover the communication between wifi 8192eu with 8761 bt controller in case of geteversion error*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) int reset_channel(firmware_info* fw_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603)     struct rtk_reset_evt *ever_evt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604)     int ret_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606)     if (!fw_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607)         return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609)     fw_info->cmd_hdr->opcode = cpu_to_le16(HCI_VENDOR_RESET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610)     fw_info->cmd_hdr->plen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611)     fw_info->pkt_len = CMD_HDR_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613)     ret_val = send_hci_cmd(fw_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614)     if (ret_val < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615)         RTKBT_ERR("%s: Failed to send  hci cmd 0x%04x, errno %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616)                 __func__, fw_info->cmd_hdr->opcode, ret_val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617)         return ret_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620)     ret_val = rcv_hci_evt(fw_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621)     if (ret_val < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622)         RTKBT_ERR("%s: Failed to receive  hci event, errno %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623)                 __func__, ret_val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624)         return ret_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627)     ever_evt = (struct rtk_reset_evt *)(fw_info->rsp_para);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629)     RTKBT_INFO("%s: status %d ", __func__, ever_evt->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631)     //sleep 300ms for channel reset.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632)     msleep(300);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633)     RTKBT_INFO("%s: Wait channel reset for 300ms",__func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635)     return ret_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) int read_localversion(firmware_info* fw_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640)     struct rtk_localversion_evt *ever_evt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641)     int ret_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643)     if (!fw_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644)         return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646)     fw_info->cmd_hdr->opcode = cpu_to_le16(HCI_VENDOR_READ_LMP_VERISION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647)     fw_info->cmd_hdr->plen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648)     fw_info->pkt_len = CMD_HDR_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650)     ret_val = send_hci_cmd(fw_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651)     if (ret_val < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652)         RTKBT_ERR("%s: Failed to send  hci cmd 0x%04x, errno %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653)                 __func__, fw_info->cmd_hdr->opcode, ret_val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654)         return ret_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657)     ret_val = rcv_hci_evt(fw_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658)     if (ret_val < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659)         RTKBT_ERR("%s: Failed to receive  hci event, errno %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660)                 __func__, ret_val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661)         return ret_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664)     ever_evt = (struct rtk_localversion_evt *)(fw_info->rsp_para);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666)     RTKBT_INFO("%s: status %d ", __func__, ever_evt->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667)     RTKBT_INFO("%s: hci_version %d ", __func__, ever_evt->hci_version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668)     RTKBT_INFO("%s: hci_revision %d ", __func__, ever_evt->hci_revision);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669)     RTKBT_INFO("%s: lmp_version %d ", __func__, ever_evt->lmp_version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670)     RTKBT_INFO("%s: lmp_subversion %d ", __func__, ever_evt->lmp_subversion);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671)     RTKBT_INFO("%s: lmp_manufacture %d ", __func__, ever_evt->lmp_manufacture);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672)     //sleep 300ms for channel reset.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673)     msleep(300);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674)     RTKBT_INFO("%s: Wait channel reset for 300ms",__func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676)     return ret_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) int get_eversion(firmware_info* fw_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681)     struct rtk_eversion_evt *ever_evt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682)     int ret_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684)     if (!fw_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685)         return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687)     fw_info->cmd_hdr->opcode = cpu_to_le16(HCI_VENDOR_READ_RTK_ROM_VERISION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688)     fw_info->cmd_hdr->plen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689)     fw_info->pkt_len = CMD_HDR_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691)     ret_val = send_hci_cmd(fw_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692)     if (ret_val < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693)         RTKBT_ERR("%s: Failed to send hci cmd 0x%04x, errno %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694)                 __func__, fw_info->cmd_hdr->opcode, ret_val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695)         return ret_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698)     ret_val = rcv_hci_evt(fw_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699)     if (ret_val < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700)         RTKBT_ERR("%s: Failed to receive hci event, errno %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701)                 __func__, ret_val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702)         return ret_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705)     ever_evt = (struct rtk_eversion_evt *)(fw_info->rsp_para);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707)     RTKBT_INFO("%s: status %d, eversion %d", __func__, ever_evt->status, ever_evt->version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709)     if (ever_evt->status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710)         fw_info->patch_entry->eversion = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711)     else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712)         fw_info->patch_entry->eversion = ever_evt->version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714)     return ret_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717) void rtk_update_altsettings(patch_info *patch_entry, const unsigned char* org_config_buf, int org_config_len, unsigned char ** new_config_buf_ptr, int *new_config_len_ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719)     static unsigned char config_buf[1024];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720)     unsigned short offset[256];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721)     unsigned char val[256];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723)     struct rtk_bt_vendor_config* config = (struct rtk_bt_vendor_config*) config_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724)     struct rtk_bt_vendor_config_entry* entry = config->entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726)     int count = 0,temp = 0, i = 0, j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728)     memset(config_buf, 0, sizeof(config_buf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729)     memset(offset, 0, sizeof(offset));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730)     memset(val, 0, sizeof(val));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732)     memcpy(config_buf, org_config_buf, org_config_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733)     *new_config_buf_ptr = config_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734)     *new_config_len_ptr = org_config_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736)     count = getAltSettings(patch_entry, offset, sizeof(offset)/sizeof(unsigned short));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737)     if(count <= 0){
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738)         RTKBT_INFO("rtk_update_altsettings: No AltSettings");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739)         return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740)     }else{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741)         RTKBT_INFO("rtk_update_altsettings: %d AltSettings", count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744)     RTKBT_INFO("ORG Config len=%08x:\n", org_config_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745)     for(i=0;i<=org_config_len;i+=0x10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747)         RTKBT_INFO("%08x: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n", i, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748)             config_buf[i], config_buf[i+1], config_buf[i+2], config_buf[i+3], config_buf[i+4], config_buf[i+5], config_buf[i+6], config_buf[i+7], \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749)             config_buf[i+8], config_buf[i+9], config_buf[i+10], config_buf[i+11], config_buf[i+12], config_buf[i+13], config_buf[i+14], config_buf[i+15]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752)     if (config->data_len != org_config_len - sizeof(struct rtk_bt_vendor_config))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754)         RTKBT_ERR("rtk_update_altsettings: config len(%x) is not right(%x)", config->data_len, org_config_len-(int)sizeof(struct rtk_bt_vendor_config));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755)         return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758)     for (i=0; i<config->data_len;)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760)         for(j = 0; j < count;j++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761)         {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762)             if(entry->offset == offset[j])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763)                 offset[j] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765)         if(getAltSettingVal(patch_entry, entry->offset, val) == entry->entry_len){
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766)             RTKBT_INFO("rtk_update_altsettings: replace %04x[%02x]", entry->offset, entry->entry_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767)             memcpy(entry->entry_data, val, entry->entry_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769)         temp = entry->entry_len + sizeof(struct rtk_bt_vendor_config_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770)         i += temp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771)         entry = (struct rtk_bt_vendor_config_entry*)((uint8_t*)entry + temp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773)     for(j = 0; j < count;j++){
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774)         if(offset[j] == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775)             continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776)         entry->entry_len = getAltSettingVal(patch_entry, offset[j], val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777)         if(entry->entry_len <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778)             continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779)         entry->offset = offset[j];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780)         memcpy(entry->entry_data, val, entry->entry_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781)         RTKBT_INFO("rtk_update_altsettings: add %04x[%02x]", entry->offset, entry->entry_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782)         temp = entry->entry_len + sizeof(struct rtk_bt_vendor_config_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783)         i += temp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784)         entry = (struct rtk_bt_vendor_config_entry*)((uint8_t*)entry + temp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786)     config->data_len = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787)     *new_config_buf_ptr = config_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788)     *new_config_len_ptr = config->data_len+sizeof(struct rtk_bt_vendor_config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790)     return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1791) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1792) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1793) int load_firmware(firmware_info *fw_info, uint8_t **buff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1794) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1795)     const struct firmware *fw, *cfg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1796)     struct usb_device *udev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1797)     patch_info *patch_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1798)     char *config_name, *fw_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1799)     int fw_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1800)     int ret_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1801) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1802)     int config_len = 0, buf_len = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1803)     uint8_t *buf = *buff, *config_file_buf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1804)     uint8_t *epatch_buf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1805) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1806)     struct rtk_epatch *epatch_info = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1807)     uint8_t need_download_fw = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1808)     struct rtk_extension_entry patch_lmp = {0};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1809)     struct rtk_epatch_entry *p_epatch_entry = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1810)     uint16_t lmp_version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1811)     //uint8_t use_mp_fw = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1812)     RTKBT_DBG("%s: start", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1813) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1814)     udev = fw_info->udev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1815)     patch_entry = fw_info->patch_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1816)     lmp_version = patch_entry->lmp_sub_default;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1817)     config_name = patch_entry->config_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1818) /* 1 Mptool Fw; 0 Normal Fw */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1819)     if(DRV_MP_MODE == mp_drv_mode){
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1820)         fw_name = patch_entry->mp_patch_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1821)     }else{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1822)         fw_name = patch_entry->patch_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1823)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1824) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1825)     RTKBT_INFO("%s: Default lmp version = 0x%04x, config file name[%s], "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1826)             "fw file name[%s]", __func__, lmp_version,config_name, fw_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1827) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1828)     ret_val = request_firmware(&cfg, config_name, &udev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1829)     if (ret_val < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1830)         config_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1831)     else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1832)         int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1833)         rtk_update_altsettings(patch_entry, cfg->data, cfg->size, &config_file_buf, &config_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1834) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1835)         RTKBT_INFO("Final Config len=%08x:\n", config_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1836)         for(i=0;i<=config_len;i+=0x10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1837)         {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1838)             RTKBT_INFO("%08x: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n", i, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1839)                 config_file_buf[i], config_file_buf[i+1], config_file_buf[i+2], config_file_buf[i+3], config_file_buf[i+4], config_file_buf[i+5], config_file_buf[i+6], config_file_buf[i+7], \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1840)                 config_file_buf[i+8], config_file_buf[i+9], config_file_buf[i+10], config_file_buf[i+11], config_file_buf[i+12], config_file_buf[i+13], config_file_buf[i+14], config_file_buf[i+15]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1841)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1842) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1843)         release_firmware(cfg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1844)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1845) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1846)     ret_val = request_firmware(&fw, fw_name, &udev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1847)     if (ret_val < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1848)         goto fw_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1849)     else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1850)         epatch_buf = vmalloc(fw->size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1851)         RTKBT_INFO("%s: epatch_buf = vmalloc(fw->size, GFP_KERNEL)", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1852)         if (!epatch_buf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1853)             release_firmware(fw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1854)             goto fw_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1855)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1856)         memcpy(epatch_buf, fw->data, fw->size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1857)         fw_len = fw->size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1858)         buf_len = fw_len + config_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1859)         release_firmware(fw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1860)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1861) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1862)     if (lmp_version == ROM_LMP_8723a) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1863)         RTKBT_DBG("%s: 8723a -> use old style patch", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1864)         if (!memcmp(epatch_buf, RTK_EPATCH_SIGNATURE, 8)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1865)             RTKBT_ERR("%s: 8723a check signature error", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1866)             need_download_fw = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1867)         } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1868)             if (!(buf = kzalloc(buf_len, GFP_KERNEL))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1869)                 RTKBT_ERR("%s: Failed to allocate mem for fw&config", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1870)                 buf_len = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1871)             } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1872)                 RTKBT_DBG("%s: 8723a -> fw copy directly", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1873)                 memcpy(buf, epatch_buf, buf_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1874)                 patch_entry->lmp_sub = *(uint16_t *)(buf + buf_len - config_len - 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1875)                 RTKBT_DBG("%s: Config lmp version = 0x%04x", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1876)                         patch_entry->lmp_sub);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1877)                 vfree(epatch_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1878)                 RTKBT_INFO("%s:ROM_LMP_8723a vfree(epatch_buf)", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1879)                 epatch_buf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1880)                 if (config_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1881)                     memcpy(buf + buf_len - config_len, config_file_buf, config_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1882)             }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1883)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1884)     } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1885)         RTKBT_DBG("%s: Not 8723a -> use new style patch", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1886) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1887)         RTKBT_DBG("%s: reset_channel before get_eversion from bt controller", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1888)         ret_val = reset_channel(fw_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1889)         if (ret_val < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1890)             RTKBT_ERR("%s: Failed to reset_channel, errno %d", __func__, ret_val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1891)             goto fw_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1892)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1893) //        read_localversion(fw_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1894)         RTKBT_DBG("%s: get_eversion from bt controller", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1895) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1896)         ret_val = get_eversion(fw_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1897)         if (ret_val < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1898)             RTKBT_ERR("%s: Failed to get eversion, errno %d", __func__, ret_val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1899)             goto fw_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1900)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1901)         RTKBT_DBG("%s: Get eversion =%d", __func__, patch_entry->eversion);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1902)         if (memcmp(epatch_buf + buf_len - config_len - 4 , EXTENSION_SECTION_SIGNATURE, 4)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1903)             RTKBT_ERR("%s: Failed to check extension section signature", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1904)             need_download_fw = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1905)         } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1906)             uint8_t *temp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1907)             temp = epatch_buf+buf_len-config_len - 5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1908)             do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1909)                 if (*temp == 0x00) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1910)                     patch_lmp.opcode = *temp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1911)                     patch_lmp.length = *(temp-1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1912)                     if ((patch_lmp.data = kzalloc(patch_lmp.length, GFP_KERNEL))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1913)                         int k;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1914)                         for (k = 0; k < patch_lmp.length; k++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1915)                             *(patch_lmp.data+k) = *(temp-2-k);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1916)                             RTKBT_DBG("data = 0x%x", *(patch_lmp.data+k));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1917)                         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1918)                     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1919)                     RTKBT_DBG("%s: opcode = 0x%x, length = 0x%x, data = 0x%x", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1920)                             patch_lmp.opcode, patch_lmp.length, *(patch_lmp.data));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1921)                     break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1922)                 }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1923)                 temp -= *(temp-1) + 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1924)             } while (*temp != 0xFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1925) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1926)             if (lmp_version != project_id[*(patch_lmp.data)]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1927)                 RTKBT_ERR("%s: Default lmp_version 0x%04x, project_id[%d] 0x%04x "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1928)                         "-> not match", __func__, lmp_version, *(patch_lmp.data),project_id[*(patch_lmp.data)]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1929)                 if (patch_lmp.data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1930)                     kfree(patch_lmp.data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1931)                 need_download_fw = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1932)             } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1933)                 RTKBT_INFO("%s: Default lmp_version 0x%04x, project_id[%d] 0x%04x "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1934)                         "-> match", __func__, lmp_version, *(patch_lmp.data), project_id[*(patch_lmp.data)]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1935)                 if (patch_lmp.data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1936)                     kfree(patch_lmp.data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1937)                 if (memcmp(epatch_buf, RTK_EPATCH_SIGNATURE, 8)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1938)                     RTKBT_ERR("%s: Check signature error", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1939)                     need_download_fw = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1940)                 } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1941)                     epatch_info = (struct rtk_epatch*)epatch_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1942)                     patch_entry->lmp_sub = (uint16_t)epatch_info->fw_version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1943) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1944)                     RTKBT_DBG("%s: lmp version 0x%04x, fw_version 0x%x, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1945)                             "number_of_total_patch %d", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1946)                             patch_entry->lmp_sub, epatch_info->fw_version,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1947)                             epatch_info->number_of_total_patch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1948) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1949)                     /* Get right epatch entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1950)                     p_epatch_entry = get_fw_patch_entry(epatch_info, patch_entry->eversion);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1951)                     if (p_epatch_entry == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1952)                         RTKBT_WARN("%s: Failed to get fw patch entry", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1953)                         ret_val = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1954)                         goto fw_fail ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1955)                     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1956) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1957)                     buf_len = p_epatch_entry->patch_length + config_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1958)                     RTKBT_DBG("buf_len = 0x%x", buf_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1959) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1960)                     if (!(buf = kzalloc(buf_len, GFP_KERNEL))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1961)                         RTKBT_ERR("%s: Can't alloc memory for  fw&config", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1962)                         buf_len = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1963)                     } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1964)                         memcpy(buf, &epatch_buf[p_epatch_entry->start_offset], p_epatch_entry->patch_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1965)                         memcpy(&buf[p_epatch_entry->patch_length-4], &epatch_info->fw_version, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1966)                         kfree(p_epatch_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1967)                     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1968)                     vfree(epatch_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1969)                     RTKBT_INFO("%s: vfree(epatch_buf)", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1970)                     epatch_buf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1971) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1972)                     if (config_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1973)                         memcpy(&buf[buf_len - config_len], config_file_buf, config_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1974)                 }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1975)             }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1976)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1977)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1978) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1979)     RTKBT_INFO("%s: fw%s exists, config file%s exists", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1980)             (buf_len > 0) ? "" : " not", (config_len > 0) ? "":" not");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1981) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1982)     if (buf && buf_len > 0 && need_download_fw)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1983)         *buff = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1984) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1985)     RTKBT_DBG("%s: done", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1986) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1987)     return buf_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1988) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1989) fw_fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1990)     return ret_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1991) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1992) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1993) #if SUSPNED_DW_FW
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1994) static int load_suspend_firmware(firmware_info *fw_info, uint8_t **buff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1995) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1996)     const struct firmware *fw, *cfg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1997)     struct usb_device *udev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1998)     patch_info *patch_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1999)     char config_name[100] = {0};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2000)     char fw_name[100] = {0};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2001)     int fw_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2002)     int ret_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2003) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2004)     int config_len = 0, buf_len = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2005)     uint8_t *buf = *buff, *config_file_buf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2006)     uint8_t *epatch_buf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2007) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2008)     struct rtk_epatch *epatch_info = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2009)     uint8_t need_download_fw = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2010)     struct rtk_extension_entry patch_lmp = {0};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2011)     struct rtk_epatch_entry *p_epatch_entry = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2012)     uint16_t lmp_version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2013)     RTKBT_DBG("%s: start", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2014) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2015)     udev = fw_info->udev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2016)     patch_entry = fw_info->patch_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2017)     lmp_version = patch_entry->lmp_sub_default;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2018)     sprintf(config_name, "%s_suspend", patch_entry->config_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2019)     sprintf(fw_name, "%s_suspend", patch_entry->patch_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2020) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2021)     RTKBT_INFO("%s: Default lmp version = 0x%04x, config file name[%s], "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2022)             "fw file name[%s]", __func__, lmp_version,config_name, fw_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2023) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2024)     ret_val = request_firmware(&cfg, config_name, &udev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2025)     if (ret_val < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2026)         config_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2027)     else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2028)         config_file_buf = vmalloc(cfg->size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2029)         RTKBT_INFO("%s: epatch_buf = vmalloc(cfg->size)", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2030)         if (!config_file_buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2031)             return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2032)         memcpy(config_file_buf, cfg->data, cfg->size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2033)         config_len = cfg->size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2034)         release_firmware(cfg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2035)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2036) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2037)     ret_val = request_firmware(&fw, fw_name, &udev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2038)     if (ret_val < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2039)         goto fw_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2040)     else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2041)         epatch_buf = vmalloc(fw->size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2042)         RTKBT_INFO("%s: epatch_buf = vmalloc(fw->size, GFP_KERNEL)", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2043)         if (!epatch_buf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2044)             release_firmware(fw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2045)             goto fw_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2046)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2047)         memcpy(epatch_buf, fw->data, fw->size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2048)         fw_len = fw->size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2049)         buf_len = fw_len + config_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2050)         release_firmware(fw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2051)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2052) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2053)     RTKBT_DBG("%s: Not 8723a -> use new style patch", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2054) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2055)     RTKBT_DBG("%s: get_eversion from bt controller", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2056) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2057)     ret_val = get_eversion(fw_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2058)     if (ret_val < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2059)         RTKBT_ERR("%s: Failed to get eversion, errno %d", __func__, ret_val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2060)         goto fw_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2061)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2062)     RTKBT_DBG("%s: Get eversion =%d", __func__, patch_entry->eversion);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2063)     if (memcmp(epatch_buf + buf_len - config_len - 4 , EXTENSION_SECTION_SIGNATURE, 4)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2064)         RTKBT_ERR("%s: Failed to check extension section signature", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2065)         need_download_fw = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2066)     } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2067)         uint8_t *temp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2068)         temp = epatch_buf+buf_len-config_len - 5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2069)         do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2070)             if (*temp == 0x00) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2071)                 patch_lmp.opcode = *temp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2072)                 patch_lmp.length = *(temp-1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2073)                 if ((patch_lmp.data = kzalloc(patch_lmp.length, GFP_KERNEL))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2074)                     int k;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2075)                     for (k = 0; k < patch_lmp.length; k++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2076)                         *(patch_lmp.data+k) = *(temp-2-k);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2077)                         RTKBT_DBG("data = 0x%x", *(patch_lmp.data+k));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2078)                     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2079)                 }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2080)                 RTKBT_DBG("%s: opcode = 0x%x, length = 0x%x, data = 0x%x", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2081)                     patch_lmp.opcode, patch_lmp.length, *(patch_lmp.data));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2082)                 break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2083)             }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2084)             temp -= *(temp-1) + 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2085)         } while (*temp != 0xFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2086) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2087)         if (lmp_version != project_id[*(patch_lmp.data)]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2088)             RTKBT_ERR("%s: Default lmp_version 0x%04x, project_id[%d] 0x%04x "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2089)                 "-> not match", __func__, lmp_version, *(patch_lmp.data),project_id[*(patch_lmp.data)]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2090)             if (patch_lmp.data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2091)                 kfree(patch_lmp.data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2092)             need_download_fw = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2093)         } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2094)             RTKBT_INFO("%s: Default lmp_version 0x%04x, project_id[%d] 0x%04x "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2095)                 "-> match", __func__, lmp_version, *(patch_lmp.data), project_id[*(patch_lmp.data)]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2096)             if (patch_lmp.data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2097)                 kfree(patch_lmp.data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2098)             if (memcmp(epatch_buf, RTK_EPATCH_SIGNATURE, 8)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2099)                 RTKBT_ERR("%s: Check signature error", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2100)                 need_download_fw = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2101)             } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2102)                 epatch_info = (struct rtk_epatch*)epatch_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2103)                 patch_entry->lmp_sub = (uint16_t)epatch_info->fw_version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2105)                 RTKBT_DBG("%s: lmp version 0x%04x, fw_version 0x%x, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2106)                     "number_of_total_patch %d", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2107)                     patch_entry->lmp_sub, epatch_info->fw_version,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2108)                     epatch_info->number_of_total_patch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2110)              /* Get right epatch entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2111)                 p_epatch_entry = get_fw_patch_entry(epatch_info, patch_entry->eversion);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2112)                 if (p_epatch_entry == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2113)                     RTKBT_WARN("%s: Failed to get fw patch entry", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2114)                     ret_val = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2115)                     goto fw_fail ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2116)                 }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2118)                 buf_len = p_epatch_entry->patch_length + config_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2119)                 RTKBT_DBG("buf_len = 0x%x", buf_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2121)                 if (!(buf = kzalloc(buf_len, GFP_KERNEL))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2122)                     RTKBT_ERR("%s: Can't alloc memory for  fw&config", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2123)                     buf_len = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2124)                 } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2125)                     memcpy(buf, &epatch_buf[p_epatch_entry->start_offset], p_epatch_entry->patch_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2126)                     memcpy(&buf[p_epatch_entry->patch_length-4], &epatch_info->fw_version, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2127)                     kfree(p_epatch_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2128)                 }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2129)                 vfree(epatch_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2130)                 RTKBT_INFO("%s: vfree(epatch_buf)", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2131)                 epatch_buf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2133)                 if (config_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2134)                     memcpy(&buf[buf_len - config_len], config_file_buf, config_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2135)             }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2136)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2137)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2139)     if (config_file_buf){
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2140)         vfree(config_file_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2141)         config_file_buf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2142)         RTKBT_INFO("%s: vfree(config_file_buf)", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2143)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2145)     RTKBT_INFO("%s: fw%s exists, config file%s exists", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2146)             (buf_len > 0) ? "" : " not", (config_len > 0) ? "":" not");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2148)     if (buf && buf_len > 0 && need_download_fw)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2149)         *buff = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2151)     RTKBT_DBG("%s: done", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2153)     return buf_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2155) fw_fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2156)     if (config_file_buf){
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2157)         vfree(config_file_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2158)         config_file_buf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2159)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2160)     RTKBT_INFO("%s: fw_fail vfree(config_file_buf)", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2161)     return ret_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2162) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2163) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2165) int get_firmware(firmware_info *fw_info, int cached)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2166) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2167)     patch_info *patch_entry = fw_info->patch_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2169)     RTKBT_INFO("%s: start, cached %d,patch_entry->fw_len= %d", __func__, cached,patch_entry->fw_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2171)     if (cached > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2172)         if (patch_entry->fw_len > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2173)             fw_info->fw_data = kzalloc(patch_entry->fw_len, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2174)             if (!fw_info->fw_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2175)                 return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2176)             memcpy(fw_info->fw_data, patch_entry->fw_cache, patch_entry->fw_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2177)             fw_info->fw_len = patch_entry->fw_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2178)         } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2179)             fw_info->fw_len = load_firmware(fw_info, &fw_info->fw_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2180)             if (fw_info->fw_len <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2181)                 return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2182)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2183)     } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2184)         fw_info->fw_len = load_firmware(fw_info, &fw_info->fw_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2185)         if (fw_info->fw_len <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2186)             return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2187)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2189)     return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2190) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2192) #if SUSPNED_DW_FW
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2193) static int get_suspend_firmware(firmware_info *fw_info, int cached)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2194) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2195)     patch_info *patch_entry = fw_info->patch_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2197)     RTKBT_INFO("%s: start, cached %d,patch_entry->fw_len= %d", __func__, cached,patch_entry->fw_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2199)     if (cached > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2200)         if (patch_entry->fw_len > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2201)             fw_info->fw_data = kzalloc(patch_entry->fw_len, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2202)             if (!fw_info->fw_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2203)                 return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2204)             memcpy(fw_info->fw_data, patch_entry->fw_cache, patch_entry->fw_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2205)             fw_info->fw_len = patch_entry->fw_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2206)         } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2207)             fw_info->fw_len = load_suspend_firmware(fw_info, &fw_info->fw_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2208)             if (fw_info->fw_len <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2209)                 return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2210)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2211)     } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2212)         fw_info->fw_len = load_suspend_firmware(fw_info, &fw_info->fw_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2213)         if (fw_info->fw_len <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2214)             return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2215)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2217)     return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2218) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2219) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2221) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2222)  * Open the log message only if in debugging,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2223)  * or it will decelerate download procedure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2224)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2225) int download_data(firmware_info *fw_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2226) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2227)     download_cp *cmd_para;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2228)     download_rp *evt_para;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2229)     uint8_t *pcur;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2230)     int pkt_len, frag_num, frag_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2231)     int i, ret_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2232)     int ncmd = 1, step = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2234)     RTKBT_DBG("%s: start", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2236)     cmd_para = (download_cp *)fw_info->req_para;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2237)     evt_para = (download_rp *)fw_info->rsp_para;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2238)     pcur = fw_info->fw_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2239)     pkt_len = CMD_HDR_LEN + sizeof(download_cp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2240)     frag_num = fw_info->fw_len / PATCH_SEG_MAX + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2241)     frag_len = PATCH_SEG_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2243)     for (i = 0; i < frag_num; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2244)         cmd_para->index = i?((i-1)%0x7f+1):0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2245)         if (i == (frag_num - 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2246)             cmd_para->index |= DATA_END;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2247)             frag_len = fw_info->fw_len % PATCH_SEG_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2248)             pkt_len -= (PATCH_SEG_MAX - frag_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2249)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2250)         fw_info->cmd_hdr->opcode = cpu_to_le16(DOWNLOAD_OPCODE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2251)         fw_info->cmd_hdr->plen = sizeof(uint8_t) + frag_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2252)         fw_info->pkt_len = pkt_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2253)         memcpy(cmd_para->data, pcur, frag_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2255)         if (step > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2256)             ret_val = send_hci_cmd(fw_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2257)             if (ret_val < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2258)                 RTKBT_DBG("%s: Failed to send frag num %d", __func__, cmd_para->index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2259)                 return ret_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2260)             } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2261)                 RTKBT_DBG("%s: Send frag num %d", __func__, cmd_para->index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2263)             if (--step > 0 && i < frag_num - 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2264)                 RTKBT_DBG("%s: Continue to send frag num %d", __func__, cmd_para->index + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2265)                 pcur += PATCH_SEG_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2266)                 continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2267)             }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2268)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2270)         while (ncmd > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2271)             ret_val = rcv_hci_evt(fw_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2272)             if (ret_val < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2273)                 RTKBT_ERR("%s: rcv_hci_evt err %d", __func__, ret_val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2274)                 return ret_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2275)             } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2276)                 RTKBT_DBG("%s: Receive acked frag num %d", __func__, evt_para->index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2277)                 ncmd--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2278)             }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2279) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2280)             if (0 != evt_para->status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2281)                 RTKBT_ERR("%s: Receive acked frag num %d, err status %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2282)                         __func__, ret_val, evt_para->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2283)                 return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2284)             }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2286)             if ((evt_para->index & DATA_END) || (evt_para->index == frag_num - 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2287)                 RTKBT_DBG("%s: Receive last acked index %d", __func__, evt_para->index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2288)                 goto end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2289)             }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2290)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2292)         ncmd = step = fw_info->cmd_cmp->ncmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2293)         pcur += PATCH_SEG_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2294)         RTKBT_DBG("%s: HCI command packet num %d", __func__, ncmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2295)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2297)     /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2298)      * It is tricky that Host cannot receive DATA_END index from BT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2299)      * controller, at least for 8723au. We are doomed if failed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2300)      */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2301) #if 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2302)     /* Continue to receive the responsed events until last index occurs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2303)     if (i == frag_num) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2304)         RTKBT_DBG("%s: total frag count %d", __func__, frag_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2305)         while (!(evt_para->index & DATA_END)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2306)             ret_val = rcv_hci_evt(fw_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2307)             if (ret_val < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2308)                 RTKBT_ERR("%s: rcv_hci_evt err %d", __func__, ret_val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2309)                 return ret_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2310)             }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2311)             if (0 != evt_para->status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2312)                 return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2313)             RTKBT_DBG("%s: continue to receive acked frag num %d", __func__, evt_para->index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2314)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2315)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2316) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2317) end:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2318)     RTKBT_INFO("%s: done, sent %d frag pkts, received %d frag events",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2319)             __func__, cmd_para->index, evt_para->index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2320)     return fw_info->fw_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2321) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2322) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2323) int download_patch(firmware_info *fw_info, int cached)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2324) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2325)     int ret_val = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2326) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2327)     RTKBT_DBG("%s: Download fw patch start, cached %d", __func__, cached);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2328) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2329)     if (!fw_info || !fw_info->patch_entry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2330)         RTKBT_ERR("%s: No patch entry exists(fw_info %p)", __func__, fw_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2331)         ret_val = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2332)         goto end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2333)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2335)     /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2336)      * step1: get local firmware if existed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2337)      * step2: check firmware version
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2338)      * step3: download firmware if updated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2339)      */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2340)     ret_val = get_firmware(fw_info, cached);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2341)     if (ret_val < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2342)         RTKBT_ERR("%s: Failed to get firmware", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2343)         goto end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2344)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2345) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2346) #if SUSPNED_DW_FW
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2347)     if(fw_info_4_suspend) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2348)         RTKBT_DBG("%s: get suspend fw first cached %d", __func__, cached);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2349)         ret_val = get_suspend_firmware(fw_info_4_suspend, cached);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2350)         if (ret_val < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2351)             RTKBT_ERR("%s: Failed to get suspend firmware", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2352)             goto end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2353)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2354)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2355) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2356) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2357)     /*check the length of fw to be download*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2358)     RTKBT_DBG("%s: Check fw_info->fw_len:%d max_patch_size %d", __func__, fw_info->fw_len, fw_info->patch_entry->max_patch_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2359)     if (fw_info->fw_len > fw_info->patch_entry->max_patch_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2360)         RTKBT_ERR("%s: Total length of fw&config(%08x) larger than max_patch_size 0x%08x", __func__, fw_info->fw_len, fw_info->patch_entry->max_patch_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2361)         ret_val = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2362)         goto free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2363)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2364) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2365)     ret_val = check_fw_version(fw_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2366) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2367)     if (2 == ret_val) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2368)         RTKBT_ERR("%s: Cold reset bt chip only download", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2369)         ret_val = download_data(fw_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2370)         if (ret_val > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2371)             RTKBT_ERR("%s: Download fw patch done, fw len %d", __func__, ret_val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2372)     } else if(1 == ret_val){
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2373)         //   reset bt chip to update Fw patch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2374)         ret_val = reset_controller(fw_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2375)         RTKBT_ERR("%s: reset bt chip to update Fw patch, fw len %d", __func__, ret_val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2376)         ret_val = download_data(fw_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2377)         if (ret_val > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2378)                 RTKBT_ERR("%s: Download fw patch done, fw len %d", __func__, ret_val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2379)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2380) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2381) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2382) free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2383)     /* Free fw data after download finished */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2384)     kfree(fw_info->fw_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2385)     fw_info->fw_data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2387) end:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2388)     return ret_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2389) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2390) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2391) #if SUSPNED_DW_FW
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2392) static int download_suspend_patch(firmware_info *fw_info, int cached)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2393) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2394)     int ret_val = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2395) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2396)     RTKBT_DBG("%s: Download fw patch start, cached %d", __func__, cached);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2397) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2398)     if (!fw_info || !fw_info->patch_entry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2399)         RTKBT_ERR("%s: No patch entry exists(fw_info %p)", __func__, fw_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2400)         ret_val = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2401)         goto end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2402)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2403) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2404)     /*check the length of fw to be download*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2405)     RTKBT_DBG("%s:Check RTK_PATCH_LENGTH fw_info->fw_len:%d", __func__,fw_info->fw_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2406)     if (fw_info->fw_len > RTK_PATCH_LENGTH_MAX || fw_info->fw_len == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2407)         RTKBT_ERR("%s: Total length of fw&config larger than allowed 24K or no fw len:%d", __func__, fw_info->fw_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2408)         ret_val = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2409)         goto free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2410)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2411) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2412)     ret_val = check_fw_version(fw_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2413) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2414)     if (2 == ret_val) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2415)         RTKBT_ERR("%s: Cold reset bt chip only download", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2416)         ret_val = download_data(fw_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2417)         if (ret_val > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2418)             RTKBT_ERR("%s: Download fw patch done, fw len %d", __func__, ret_val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2419)     } else if(1 == ret_val){
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2420)         //   reset bt chip to update Fw patch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2421)         ret_val = reset_controller(fw_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2422)         RTKBT_ERR("%s: reset bt chip to update Fw patch, fw len %d", __func__, ret_val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2423)         ret_val = download_data(fw_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2424)         if (ret_val > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2425)                 RTKBT_ERR("%s: Download fw patch done, fw len %d", __func__, ret_val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2426)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2427) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2428) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2429) free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2430)     /* Free fw data after download finished */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2431)     kfree(fw_info->fw_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2432)     fw_info->fw_data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2433) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2434) end:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2435)     return ret_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2436) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2437) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2438) static void suspend_firmware_info_init(firmware_info *fw_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2439) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2440)     RTKBT_DBG("%s: start", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2441)     if(!fw_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2442)         return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2443) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2444)     fw_info_4_suspend= kzalloc(sizeof(*fw_info), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2445)     if (!fw_info_4_suspend)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2446)         goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2447) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2448)     fw_info_4_suspend->send_pkt = kzalloc(PKT_LEN, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2449)     if (!fw_info_4_suspend->send_pkt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2450)         kfree(fw_info_4_suspend);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2451)         goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2452)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2453) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2454)     fw_info_4_suspend->rcv_pkt = kzalloc(PKT_LEN, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2455)     if (!fw_info_4_suspend->rcv_pkt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2456)         kfree(fw_info_4_suspend->send_pkt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2457)         kfree(fw_info_4_suspend);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2458)         goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2459)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2460) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2461)     fw_info_4_suspend->patch_entry = get_suspend_fw_table_entry(fw_info->udev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2462)     if (!fw_info_4_suspend->patch_entry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2463)         kfree(fw_info_4_suspend->rcv_pkt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2464)         kfree(fw_info_4_suspend->send_pkt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2465)         kfree(fw_info_4_suspend);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2466)         goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2467)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2468) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2469)     fw_info_4_suspend->intf = fw_info->intf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2470)     fw_info_4_suspend->udev = fw_info->udev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2471)     fw_info_4_suspend->cmd_hdr = (struct hci_command_hdr *)(fw_info_4_suspend->send_pkt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2472)     fw_info_4_suspend->evt_hdr = (struct hci_event_hdr *)(fw_info_4_suspend->rcv_pkt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2473)     fw_info_4_suspend->cmd_cmp = (struct hci_ev_cmd_complete *)(fw_info_4_suspend->rcv_pkt + EVT_HDR_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2474)     fw_info_4_suspend->req_para = fw_info_4_suspend->send_pkt + CMD_HDR_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2475)     fw_info_4_suspend->rsp_para = fw_info_4_suspend->rcv_pkt + EVT_HDR_LEN + CMD_CMP_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2476)     fw_info_4_suspend->pipe_in = fw_info->pipe_in;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2477)     fw_info_4_suspend->pipe_out = fw_info->pipe_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2478) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2479)     return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2480) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2481)     RTKBT_DBG("%s: fail !", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2482)     fw_info_4_suspend = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2483)     return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2484) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2485) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2486) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2487) #if SET_WAKEUP_DEVICE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2488) static void set_wakeup_device_from_conf(firmware_info *fw_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2489) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2490)     uint8_t paired_wakeup_bdaddr[7];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2491)     uint8_t num = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2492)     int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2493)     struct file *fp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2494)     mm_segment_t fs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2495)     loff_t pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2496) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2497)     memset(paired_wakeup_bdaddr, 0, 7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2498)     fp = filp_open(SET_WAKEUP_DEVICE_CONF, O_RDWR, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2499)     if (!IS_ERR(fp)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2500)         fs = get_fs();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2501)         set_fs(KERNEL_DS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2502)         pos = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2503)         //read number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2504)         vfs_read(fp, &num, 1, &pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2505)         RTKBT_DBG("read number = %d", num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2506)         if(num) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2507)             for(i = 0; i < num; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2508)             vfs_read(fp, paired_wakeup_bdaddr, 7, &pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2509)             RTKBT_DBG("paired_wakeup_bdaddr: 0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2510)                 paired_wakeup_bdaddr[1],paired_wakeup_bdaddr[2],paired_wakeup_bdaddr[3],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2511)                 paired_wakeup_bdaddr[4],paired_wakeup_bdaddr[5],paired_wakeup_bdaddr[6]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2512)             set_wakeup_device(fw_info, paired_wakeup_bdaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2513)             }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2514)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2515)         filp_close(fp, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2516)         set_fs(fs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2517)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2518)     else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2519)         RTKBT_ERR("open wakeup config file fail! errno = %ld", PTR_ERR(fp));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2520)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2521) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2522) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2523) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2524) firmware_info *firmware_info_init(struct usb_interface *intf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2525) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2526)     struct usb_device *udev = interface_to_usbdev(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2527)     firmware_info *fw_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2528) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2529)     RTKBT_DBG("%s: start", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2530) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2531)     fw_info = kzalloc(sizeof(*fw_info), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2532)     if (!fw_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2533)         return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2534) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2535)     fw_info->send_pkt = kzalloc(PKT_LEN, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2536)     if (!fw_info->send_pkt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2537)         kfree(fw_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2538)         return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2539)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2540) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2541)     fw_info->rcv_pkt = kzalloc(PKT_LEN, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2542)     if (!fw_info->rcv_pkt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2543)         kfree(fw_info->send_pkt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2544)         kfree(fw_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2545)         return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2546)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2547) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2548)     fw_info->patch_entry = get_fw_table_entry(udev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2549)     if (!fw_info->patch_entry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2550)         kfree(fw_info->rcv_pkt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2551)         kfree(fw_info->send_pkt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2552)         kfree(fw_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2553)         return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2554)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2555) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2556)     fw_info->intf = intf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2557)     fw_info->udev = udev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2558)     fw_info->pipe_in = usb_rcvintpipe(fw_info->udev, INTR_EP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2559)     fw_info->pipe_out = usb_sndctrlpipe(fw_info->udev, CTRL_EP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2560)     fw_info->cmd_hdr = (struct hci_command_hdr *)(fw_info->send_pkt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2561)     fw_info->evt_hdr = (struct hci_event_hdr *)(fw_info->rcv_pkt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2562)     fw_info->cmd_cmp = (struct hci_ev_cmd_complete *)(fw_info->rcv_pkt + EVT_HDR_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2563)     fw_info->req_para = fw_info->send_pkt + CMD_HDR_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2564)     fw_info->rsp_para = fw_info->rcv_pkt + EVT_HDR_LEN + CMD_CMP_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2565) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2566) #if SUSPNED_DW_FW
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2567)     suspend_firmware_info_init(fw_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2568) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2569) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2570) #if BTUSB_RPM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2571)     RTKBT_INFO("%s: Auto suspend is enabled", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2572)     usb_enable_autosuspend(udev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2573)     pm_runtime_set_autosuspend_delay(&(udev->dev), 2000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2574) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2575)     RTKBT_INFO("%s: Auto suspend is disabled", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2576)     usb_disable_autosuspend(udev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2577) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2578) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2579) #if BTUSB_WAKEUP_HOST
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2580)     device_wakeup_enable(&udev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2581) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2582) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2583)     return fw_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2584) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2585) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2586) void firmware_info_destroy(struct usb_interface *intf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2587) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2588)     firmware_info *fw_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2589)     struct usb_device *udev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2590)     struct btusb_data *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2591) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2592)     udev = interface_to_usbdev(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2593)     data = usb_get_intfdata(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2594) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2595)     fw_info = data->fw_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2596)     if (!fw_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2597)         return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2598) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2599) #if BTUSB_RPM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2600)     usb_disable_autosuspend(udev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2601) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2602) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2603)     /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2604)      * In order to reclaim fw data mem, we free fw_data immediately
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2605)      * after download patch finished instead of here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2606)      */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2607)     kfree(fw_info->rcv_pkt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2608)     kfree(fw_info->send_pkt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2609)     kfree(fw_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2610) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2611) #if SUSPNED_DW_FW
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2612)     if (!fw_info_4_suspend)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2613)         return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2614) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2615)     kfree(fw_info_4_suspend->rcv_pkt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2616)     kfree(fw_info_4_suspend->send_pkt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2617)     kfree(fw_info_4_suspend);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2618) 	fw_info_4_suspend = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2619) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2620) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2621) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2622) static struct usb_driver btusb_driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2623) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2624) static struct usb_device_id btusb_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2625)     { .match_flags = USB_DEVICE_ID_MATCH_VENDOR |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2626)                      USB_DEVICE_ID_MATCH_INT_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2627)       .idVendor = 0x0bda,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2628)       .bInterfaceClass = 0xe0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2629)       .bInterfaceSubClass = 0x01,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2630)       .bInterfaceProtocol = 0x01 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2631) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2632)     { .match_flags = USB_DEVICE_ID_MATCH_VENDOR |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2633)                      USB_DEVICE_ID_MATCH_INT_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2634)       .idVendor = 0x13d3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2635)       .bInterfaceClass = 0xe0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2636)       .bInterfaceSubClass = 0x01,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2637)       .bInterfaceProtocol = 0x01 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2638) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2639)     { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2640) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2641) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2642) MODULE_DEVICE_TABLE(usb, btusb_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2643) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2644) static int inc_tx(struct btusb_data *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2645) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2646)     unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2647)     int rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2648) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2649)     spin_lock_irqsave(&data->txlock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2650)     rv = test_bit(BTUSB_SUSPENDING, &data->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2651)     if (!rv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2652)         data->tx_in_flight++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2653)     spin_unlock_irqrestore(&data->txlock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2654) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2655)     return rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2656) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2657) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2658) void check_sco_event(struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2659) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2660)     u8* opcode = (u8*)(urb->transfer_buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2661)     u8 status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2662)     uint16_t handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2663)     struct hci_dev *hdev = urb->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2664)     struct btusb_data *data = GET_DRV_DATA(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2665) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2666)     switch (*opcode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2667)     case HCI_EV_SYNC_CONN_COMPLETE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2668)         RTKBT_INFO("%s: HCI_EV_SYNC_CONN_COMPLETE(0x%02x)", __func__, *opcode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2669)         status = *(opcode + 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2670)         data->sco_handle = *(opcode + 3) | *(opcode + 4) << 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2671)         //hdev->voice_setting = *(uint16_t*)&opcode[15];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2672)         if (status == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2673)             hdev->conn_hash.sco_num++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2674)             hdev->notify(hdev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2675)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2676)         break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2677)     case HCI_EV_DISCONN_COMPLETE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2678)         status = *(opcode + 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2679)         handle = *(opcode + 3) | *(opcode + 4) << 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2680)         if (status == 0 && data->sco_handle == handle) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2681)             RTKBT_INFO("%s: SCO HCI_EV_DISCONN_COMPLETE(0x%02x)", __func__, *opcode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2682)             hdev->conn_hash.sco_num--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2683)             hdev->notify(hdev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2684)             data->sco_handle = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2685)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2686)         break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2687)     default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2688)         RTKBT_DBG("%s: event 0x%02x", __func__, *opcode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2689)         break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2690)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2691) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2692) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2693) static void btusb_intr_complete(struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2694) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2695)     struct hci_dev *hdev = urb->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2696)     struct btusb_data *data = GET_DRV_DATA(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2697)     int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2698) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2699)     RTKBT_DBG("%s: urb %p status %d count %d ", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2700)             urb, urb->status, urb->actual_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2701) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2702) #ifdef CONFIG_SCO_OVER_HCI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2703)     check_sco_event(urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2704) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2705) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2706)     if (!test_bit(HCI_RUNNING, &hdev->flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2707)         return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2708) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2709) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2710)     if (urb->status == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2711)         hdev->stat.byte_rx += urb->actual_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2712) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2713)         if (hci_recv_fragment(hdev, HCI_EVENT_PKT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2714)                         urb->transfer_buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2715)                         urb->actual_length) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2716)             RTKBT_ERR("%s: Corrupted event packet", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2717)             hdev->stat.err_rx++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2718)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2719)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2720)     /* Avoid suspend failed when usb_kill_urb */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2721)     else if(urb->status == -ENOENT)    {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2722)         return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2723)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2724) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2725) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2726)     if (!test_bit(BTUSB_INTR_RUNNING, &data->flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2727)         return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2728) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2729)     usb_mark_last_busy(data->udev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2730)     usb_anchor_urb(urb, &data->intr_anchor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2731) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2732)     err = usb_submit_urb(urb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2733)     if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2734)         /* EPERM: urb is being killed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2735)          * ENODEV: device got disconnected */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2736)         if (err != -EPERM && err != -ENODEV)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2737)             RTKBT_ERR("%s: Failed to re-submit urb %p, err %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2738)                     __func__, urb, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2739)         usb_unanchor_urb(urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2740)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2741) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2742) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2743) static int btusb_submit_intr_urb(struct hci_dev *hdev, gfp_t mem_flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2744) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2745)     struct btusb_data *data = GET_DRV_DATA(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2746)     struct urb *urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2747)     unsigned char *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2748)     unsigned int pipe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2749)     int err, size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2750) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2751)     if (!data->intr_ep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2752)         return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2753) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2754)     urb = usb_alloc_urb(0, mem_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2755)     if (!urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2756)         return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2757) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2758)     size = le16_to_cpu(data->intr_ep->wMaxPacketSize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2759) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2760)     buf = kmalloc(size, mem_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2761)     if (!buf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2762)         usb_free_urb(urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2763)         return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2764)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2765) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2766)     RTKBT_DBG("%s: mMaxPacketSize %d, bEndpointAddress 0x%02x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2767)             __func__, size, data->intr_ep->bEndpointAddress);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2768) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2769)     pipe = usb_rcvintpipe(data->udev, data->intr_ep->bEndpointAddress);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2770) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2771)     usb_fill_int_urb(urb, data->udev, pipe, buf, size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2772)                         btusb_intr_complete, hdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2773)                         data->intr_ep->bInterval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2774) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2775)     urb->transfer_flags |= URB_FREE_BUFFER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2776) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2777)     usb_anchor_urb(urb, &data->intr_anchor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2778) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2779)     err = usb_submit_urb(urb, mem_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2780)     if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2781)         RTKBT_ERR("%s: Failed to submit urb %p, err %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2782)                 __func__, urb, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2783)         usb_unanchor_urb(urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2784)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2785) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2786)     usb_free_urb(urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2787) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2788)     return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2789) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2790) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2791) static void btusb_bulk_complete(struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2792) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2793)     struct hci_dev *hdev = urb->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2794)     struct btusb_data *data = GET_DRV_DATA(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2795)     int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2796) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2797)     RTKBT_DBG("%s: urb %p status %d count %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2798)             __func__, urb, urb->status, urb->actual_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2799) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2800)     if (!test_bit(HCI_RUNNING, &hdev->flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2801)         return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2802) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2803)     if (urb->status == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2804)         hdev->stat.byte_rx += urb->actual_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2805) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2806)         if (hci_recv_fragment(hdev, HCI_ACLDATA_PKT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2807)                         urb->transfer_buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2808)                         urb->actual_length) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2809)             RTKBT_ERR("%s: Corrupted ACL packet", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2810)             hdev->stat.err_rx++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2811)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2812)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2813)     /* Avoid suspend failed when usb_kill_urb */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2814)     else if(urb->status == -ENOENT)    {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2815)         return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2816)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2817) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2818) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2819)     if (!test_bit(BTUSB_BULK_RUNNING, &data->flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2820)         return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2821) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2822)     usb_anchor_urb(urb, &data->bulk_anchor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2823)     usb_mark_last_busy(data->udev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2824) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2825)     err = usb_submit_urb(urb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2826)     if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2827)         /* -EPERM: urb is being killed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2828)          * -ENODEV: device got disconnected */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2829)         if (err != -EPERM && err != -ENODEV)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2830)             RTKBT_ERR("btusb_bulk_complete %s urb %p failed to resubmit (%d)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2831)                         hdev->name, urb, -err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2832)         usb_unanchor_urb(urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2833)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2834) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2835) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2836) static int btusb_submit_bulk_urb(struct hci_dev *hdev, gfp_t mem_flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2837) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2838)     struct btusb_data *data = GET_DRV_DATA(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2839)     struct urb *urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2840)     unsigned char *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2841)     unsigned int pipe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2842)     int err, size = HCI_MAX_FRAME_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2843) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2844)     RTKBT_DBG("%s: hdev name %s", __func__, hdev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2845) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2846)     if (!data->bulk_rx_ep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2847)         return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2848) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2849)     urb = usb_alloc_urb(0, mem_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2850)     if (!urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2851)         return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2852) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2853)     buf = kmalloc(size, mem_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2854)     if (!buf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2855)         usb_free_urb(urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2856)         return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2857)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2858) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2859)     pipe = usb_rcvbulkpipe(data->udev, data->bulk_rx_ep->bEndpointAddress);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2860) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2861)     usb_fill_bulk_urb(urb, data->udev, pipe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2862)                     buf, size, btusb_bulk_complete, hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2863) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2864)     urb->transfer_flags |= URB_FREE_BUFFER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2865) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2866)     usb_mark_last_busy(data->udev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2867)     usb_anchor_urb(urb, &data->bulk_anchor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2868) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2869)     err = usb_submit_urb(urb, mem_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2870)     if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2871)         RTKBT_ERR("%s: Failed to submit urb %p, err %d", __func__, urb, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2872)         usb_unanchor_urb(urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2873)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2874) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2875)     usb_free_urb(urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2876) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2877)     return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2878) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2879) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2880) static void btusb_isoc_complete(struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2881) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2882)     struct hci_dev *hdev = urb->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2883)     struct btusb_data *data = GET_DRV_DATA(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2884)     int i, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2885) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2886) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2887)     RTKBT_DBG("%s: urb %p status %d count %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2888)             __func__, urb, urb->status, urb->actual_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2889) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2890)     if (!test_bit(HCI_RUNNING, &hdev->flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2891)         return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2892) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2893)     if (urb->status == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2894)         for (i = 0; i < urb->number_of_packets; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2895)             unsigned int offset = urb->iso_frame_desc[i].offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2896)             unsigned int length = urb->iso_frame_desc[i].actual_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2897) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2898)             if (urb->iso_frame_desc[i].status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2899)                 continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2900) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2901)             hdev->stat.byte_rx += length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2902) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2903)             if (hci_recv_fragment(hdev, HCI_SCODATA_PKT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2904)                         urb->transfer_buffer + offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2905)                                 length) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2906)                 RTKBT_ERR("%s: Corrupted SCO packet", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2907)                 hdev->stat.err_rx++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2908)             }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2909)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2910)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2911)     /* Avoid suspend failed when usb_kill_urb */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2912)     else if(urb->status == -ENOENT)    {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2913)         return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2914)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2915) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2916) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2917)     if (!test_bit(BTUSB_ISOC_RUNNING, &data->flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2918)         return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2919) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2920)     usb_anchor_urb(urb, &data->isoc_anchor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2921)     i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2922) retry:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2923)     err = usb_submit_urb(urb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2924)     if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2925)         /* -EPERM: urb is being killed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2926)          * -ENODEV: device got disconnected */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2927)         if (err != -EPERM && err != -ENODEV)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2928)             RTKBT_ERR("%s: Failed to re-sumbit urb %p, retry %d, err %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2929)                     __func__, urb, i, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2930)         if (i < 10) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2931)             i++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2932)             mdelay(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2933)             goto retry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2934)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2935) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2936)         usb_unanchor_urb(urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2937)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2938) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2939) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2940) static inline void fill_isoc_descriptor(struct urb *urb, int len, int mtu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2941) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2942)     int i, offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2943) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2944)     RTKBT_DBG("%s: len %d mtu %d", __func__, len, mtu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2945) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2946)     for (i = 0; i < BTUSB_MAX_ISOC_FRAMES && len >= mtu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2947)                     i++, offset += mtu, len -= mtu) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2948)         urb->iso_frame_desc[i].offset = offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2949)         urb->iso_frame_desc[i].length = mtu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2950)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2951) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2952)     if (len && i < BTUSB_MAX_ISOC_FRAMES) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2953)         urb->iso_frame_desc[i].offset = offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2954)         urb->iso_frame_desc[i].length = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2955)         i++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2956)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2957) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2958)     urb->number_of_packets = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2959) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2960) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2961) static int btusb_submit_isoc_urb(struct hci_dev *hdev, gfp_t mem_flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2962) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2963)     struct btusb_data *data = GET_DRV_DATA(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2964)     struct urb *urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2965)     unsigned char *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2966)     unsigned int pipe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2967)     int err, size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2968) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2969)     if (!data->isoc_rx_ep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2970)         return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2971) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2972)     urb = usb_alloc_urb(BTUSB_MAX_ISOC_FRAMES, mem_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2973)     if (!urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2974)         return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2975) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2976)     size = le16_to_cpu(data->isoc_rx_ep->wMaxPacketSize) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2977)                         BTUSB_MAX_ISOC_FRAMES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2978) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2979)     buf = kmalloc(size, mem_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2980)     if (!buf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2981)         usb_free_urb(urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2982)         return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2983)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2984) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2985)     pipe = usb_rcvisocpipe(data->udev, data->isoc_rx_ep->bEndpointAddress);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2986) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2987)     urb->dev      = data->udev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2988)     urb->pipe     = pipe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2989)     urb->context  = hdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2990)     urb->complete = btusb_isoc_complete;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2991)     urb->interval = data->isoc_rx_ep->bInterval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2992) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2993)     urb->transfer_flags  = URB_FREE_BUFFER | URB_ISO_ASAP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2994)     urb->transfer_buffer = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2995)     urb->transfer_buffer_length = size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2996) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2997)     fill_isoc_descriptor(urb, size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2998)             le16_to_cpu(data->isoc_rx_ep->wMaxPacketSize));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2999) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3000)     usb_anchor_urb(urb, &data->isoc_anchor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3001) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3002)     err = usb_submit_urb(urb, mem_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3003)     if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3004)         RTKBT_ERR("%s: Failed to submit urb %p, err %d", __func__, urb, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3005)         usb_unanchor_urb(urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3006)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3007) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3008)     usb_free_urb(urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3009) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3010)     return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3011) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3012) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3013) static void btusb_tx_complete(struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3014) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3015)     struct sk_buff *skb = urb->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3016)     struct hci_dev *hdev = (struct hci_dev *) skb->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3017)     struct btusb_data *data = GET_DRV_DATA(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3018) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3019)     if (!test_bit(HCI_RUNNING, &hdev->flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3020)         goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3021) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3022)     if (!urb->status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3023)         hdev->stat.byte_tx += urb->transfer_buffer_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3024)     else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3025)         hdev->stat.err_tx++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3026) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3027) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3028)     spin_lock(&data->txlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3029)     data->tx_in_flight--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3030)     spin_unlock(&data->txlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3031) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3032)     kfree(urb->setup_packet);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3033) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3034)     kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3035) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3036) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3037) static void btusb_isoc_tx_complete(struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3038) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3039)     struct sk_buff *skb = urb->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3040)     struct hci_dev *hdev = (struct hci_dev *) skb->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3041) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3042)     RTKBT_DBG("%s: urb %p status %d count %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3043)             __func__, urb, urb->status, urb->actual_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3044) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3045)     if (skb && hdev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3046)         if (!test_bit(HCI_RUNNING, &hdev->flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3047)             goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3048) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3049)         if (!urb->status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3050)             hdev->stat.byte_tx += urb->transfer_buffer_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3051)         else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3052)             hdev->stat.err_tx++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3053)     } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3054)         RTKBT_ERR("%s: skb 0x%p hdev 0x%p", __func__, skb, hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3055) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3056) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3057)     kfree(urb->setup_packet);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3058) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3059)     kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3060) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3061) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3062) static int btusb_open(struct hci_dev *hdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3063) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3064)     struct btusb_data *data = GET_DRV_DATA(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3065)     int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3066) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3067)     RTKBT_INFO("%s: Start, PM usage count %d", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3068)             atomic_read(&(data->intf->pm_usage_cnt)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3069) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3070)     err = usb_autopm_get_interface(data->intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3071)     if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3072)         return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3073) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3074)     data->intf->needs_remote_wakeup = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3075) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3076)     if (test_and_set_bit(HCI_RUNNING, &hdev->flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3077)         goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3078) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3079)     if (test_and_set_bit(BTUSB_INTR_RUNNING, &data->flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3080)         goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3081) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3082)     err = btusb_submit_intr_urb(hdev, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3083)     if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3084)         goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3085) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3086)     err = btusb_submit_bulk_urb(hdev, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3087)     if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3088)         mdelay(URB_CANCELING_DELAY_MS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3089)         usb_kill_anchored_urbs(&data->intr_anchor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3090)         goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3091)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3092) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3093)     set_bit(BTUSB_BULK_RUNNING, &data->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3094)     btusb_submit_bulk_urb(hdev, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3095) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3096) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3097)     usb_autopm_put_interface(data->intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3098)     RTKBT_INFO("%s: End, PM usage count %d", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3099)             atomic_read(&(data->intf->pm_usage_cnt)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3100)     return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3102) failed:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3103)     clear_bit(BTUSB_INTR_RUNNING, &data->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3104)     clear_bit(HCI_RUNNING, &hdev->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3105)     usb_autopm_put_interface(data->intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3106)     RTKBT_ERR("%s: Failed, PM usage count %d", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3107)             atomic_read(&(data->intf->pm_usage_cnt)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3108)     return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3111) static void btusb_stop_traffic(struct btusb_data *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3112) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3113)     mdelay(URB_CANCELING_DELAY_MS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3114)     usb_kill_anchored_urbs(&data->intr_anchor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3115)     usb_kill_anchored_urbs(&data->bulk_anchor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3116)     usb_kill_anchored_urbs(&data->isoc_anchor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3117) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3119) static int btusb_close(struct hci_dev *hdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3120) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3121)     struct btusb_data *data = GET_DRV_DATA(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3122)     int i, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3124)     RTKBT_INFO("%s: hci running %lu", __func__, hdev->flags & HCI_RUNNING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3126)     if (!test_and_clear_bit(HCI_RUNNING, &hdev->flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3127)         return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3129)     for (i = 0; i < NUM_REASSEMBLY; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3130)         if (hdev->reassembly[i]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3131)             RTKBT_DBG("%s: free ressembly[%d]", __func__, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3132)             kfree_skb(hdev->reassembly[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3133)             hdev->reassembly[i] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3134)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3135)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3137)     cancel_work_sync(&data->work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3138)     cancel_work_sync(&data->waker);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3140)     clear_bit(BTUSB_ISOC_RUNNING, &data->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3141)     clear_bit(BTUSB_BULK_RUNNING, &data->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3142)     clear_bit(BTUSB_INTR_RUNNING, &data->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3144)     btusb_stop_traffic(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3145)     err = usb_autopm_get_interface(data->intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3146)     if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3147)         goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3149)     data->intf->needs_remote_wakeup = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3150)     usb_autopm_put_interface(data->intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3152) failed:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3153)     mdelay(URB_CANCELING_DELAY_MS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3154)     usb_scuttle_anchored_urbs(&data->deferred);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3155)     return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3158) static int btusb_flush(struct hci_dev *hdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3159) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3160)     struct btusb_data *data = GET_DRV_DATA(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3162)     RTKBT_DBG("%s", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3164)     mdelay(URB_CANCELING_DELAY_MS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3165)     usb_kill_anchored_urbs(&data->tx_anchor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3167)     return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3168) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3170) #ifdef CONFIG_SCO_OVER_HCI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3171) static void btusb_isoc_snd_tx_complete(struct urb *urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3173) static int snd_send_sco_frame(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3174) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3175)     struct hci_dev *hdev = (struct hci_dev *) skb->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3177)     struct btusb_data *data = GET_DRV_DATA(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3178)     //struct usb_ctrlrequest *dr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3179)     struct urb *urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3180)     unsigned int pipe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3181)     int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3183)     RTKBT_DBG("%s:pkt type %d, packet_len : %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3184)             __func__,bt_cb(skb)->pkt_type, skb->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3186)     if (!hdev && !test_bit(HCI_RUNNING, &hdev->flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3187)         return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3189)     if (!data->isoc_tx_ep || hdev->conn_hash.sco_num < 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3190)         kfree(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3191)         return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3192)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3194)     urb = usb_alloc_urb(BTUSB_MAX_ISOC_FRAMES, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3195)     if (!urb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3196)         RTKBT_ERR("%s: Failed to allocate mem for sco pkts", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3197)         kfree(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3198)         return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3199)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3201)     pipe = usb_sndisocpipe(data->udev, data->isoc_tx_ep->bEndpointAddress);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3203)     usb_fill_int_urb(urb, data->udev, pipe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3204)             skb->data, skb->len, btusb_isoc_snd_tx_complete,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3205)             skb, data->isoc_tx_ep->bInterval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3207)     urb->transfer_flags  = URB_ISO_ASAP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3209)     fill_isoc_descriptor(urb, skb->len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3210)             le16_to_cpu(data->isoc_tx_ep->wMaxPacketSize));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3212)     hdev->stat.sco_tx++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3214)     usb_anchor_urb(urb, &data->tx_anchor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3216)     err = usb_submit_urb(urb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3217)     if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3218)         RTKBT_ERR("%s: Failed to submit urb %p, pkt type %d, err %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3219)                 __func__, urb, bt_cb(skb)->pkt_type, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3220)         kfree(urb->setup_packet);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3221)         usb_unanchor_urb(urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3222)     } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3223)         usb_mark_last_busy(data->udev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3224)     usb_free_urb(urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3226)     return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3228) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3230) static bool snd_copy_send_sco_data( RTK_sco_card_t *pSCOSnd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3231) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3232)     struct snd_pcm_runtime *runtime = pSCOSnd->playback.substream->runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3233)   	unsigned int frame_bytes = 2, frames1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3234)     const u8 *source;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3236)     snd_pcm_uframes_t period_size = runtime->period_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3237)     int i, count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3238)     u8 buffer[period_size * 3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3239)     int sco_packet_bytes = pSCOSnd->playback.sco_packet_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3240)     struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3242)     count = frames_to_bytes(runtime, period_size)/sco_packet_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3243)     skb = bt_skb_alloc(((sco_packet_bytes + HCI_SCO_HDR_SIZE) * count), GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3244)     skb->dev = (void *)hci_dev_get(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3245)     bt_cb(skb)->pkt_type = HCI_SCODATA_PKT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3246)     skb_put(skb, ((sco_packet_bytes + HCI_SCO_HDR_SIZE) * count));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3247)     if(!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3248)         return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3250)     RTKBT_DBG("%s, buffer_pos: %d", __FUNCTION__, pSCOSnd->playback.buffer_pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3252)     source = runtime->dma_area + pSCOSnd->playback.buffer_pos * frame_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3254)     if (pSCOSnd->playback.buffer_pos + period_size <= runtime->buffer_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3255)       memcpy(buffer, source, period_size * frame_bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3256)     } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3257)       /* wrap around at end of ring buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3258)       frames1 = runtime->buffer_size - pSCOSnd->playback.buffer_pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3259)       memcpy(buffer, source, frames1 * frame_bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3260)       memcpy(&buffer[frames1 * frame_bytes],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3261)              runtime->dma_area, (period_size - frames1) * frame_bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3262)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3264)     pSCOSnd->playback.buffer_pos += period_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3265)     if ( pSCOSnd->playback.buffer_pos >= runtime->buffer_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3266)        pSCOSnd->playback.buffer_pos -= runtime->buffer_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3268)     for(i = 0; i < count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3269)         *((__u16 *)(skb->data + i * (sco_packet_bytes + HCI_SCO_HDR_SIZE))) = pSCOSnd->usb_data->sco_handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3270)         *((__u8 *)(skb->data + i*(sco_packet_bytes + HCI_SCO_HDR_SIZE) + 2)) = sco_packet_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3271)         memcpy((skb->data + i * (sco_packet_bytes + HCI_SCO_HDR_SIZE) + HCI_SCO_HDR_SIZE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3272)           &buffer[sco_packet_bytes * i], sco_packet_bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3273)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3275)     if(test_bit(ALSA_PLAYBACK_RUNNING, &pSCOSnd->states)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3276)         snd_pcm_period_elapsed(pSCOSnd->playback.substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3277)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3278)     snd_send_sco_frame(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3279)     return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3280) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3282) static void btusb_isoc_snd_tx_complete(struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3283) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3284)     struct sk_buff *skb = urb->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3285)     struct hci_dev *hdev = (struct hci_dev *) skb->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3286)     struct btusb_data *data = GET_DRV_DATA(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3287)     RTK_sco_card_t  *pSCOSnd = data->pSCOSnd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3289)     RTKBT_DBG("%s: status %d count %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3290)             __func__,urb->status, urb->actual_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3292)     if (skb && hdev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3293)         if (!test_bit(HCI_RUNNING, &hdev->flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3294)             goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3296)         if (!urb->status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3297)             hdev->stat.byte_tx += urb->transfer_buffer_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3298)         else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3299)             hdev->stat.err_tx++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3300)     } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3301)         RTKBT_ERR("%s: skb 0x%p hdev 0x%p", __func__, skb, hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3303) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3304)     kfree(urb->setup_packet);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3305)     kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3306)     if(test_bit(ALSA_PLAYBACK_RUNNING, &pSCOSnd->states)){
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3307)         snd_copy_send_sco_data(pSCOSnd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3308)         //schedule_work(&pSCOSnd->send_sco_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3309)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3310) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3311) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3312) static void playback_work(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3313) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3314)     RTK_sco_card_t *pSCOSnd = container_of(work, RTK_sco_card_t, send_sco_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3315) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3316)     snd_copy_send_sco_data(pSCOSnd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3317) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3318) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3319) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3321) static int btusb_send_frame(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3322) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3323)     struct hci_dev *hdev = (struct hci_dev *) skb->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3325)     struct btusb_data *data = GET_DRV_DATA(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3326)     struct usb_ctrlrequest *dr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3327)     struct urb *urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3328)     unsigned int pipe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3329)     int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3330)     int retries = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3331) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3332)     RTKBT_DBG("%s: hdev %p, btusb data %p, pkt type %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3333)             __func__, hdev, data, bt_cb(skb)->pkt_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3335)     if (!test_bit(HCI_RUNNING, &hdev->flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3336)         return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3337) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3339) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3340)     switch (bt_cb(skb)->pkt_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3341)     case HCI_COMMAND_PKT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3342)         print_command(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3343)         urb = usb_alloc_urb(0, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3344)         if (!urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3345)             return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3346) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3347)         dr = kmalloc(sizeof(*dr), GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3348)         if (!dr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3349)             usb_free_urb(urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3350)             return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3351)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3353)         dr->bRequestType = data->cmdreq_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3354)         dr->bRequest     = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3355)         dr->wIndex       = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3356)         dr->wValue       = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3357)         dr->wLength      = __cpu_to_le16(skb->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3358) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3359)         pipe = usb_sndctrlpipe(data->udev, 0x00);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3360) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3361)         usb_fill_control_urb(urb, data->udev, pipe, (void *) dr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3362)                 skb->data, skb->len, btusb_tx_complete, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3363) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3364)         hdev->stat.cmd_tx++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3365)         break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3366) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3367)     case HCI_ACLDATA_PKT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3368)         print_acl(skb, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3369)         if (!data->bulk_tx_ep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3370)             return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3371) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3372)         urb = usb_alloc_urb(0, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3373)         if (!urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3374)             return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3375) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3376)         pipe = usb_sndbulkpipe(data->udev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3377)                     data->bulk_tx_ep->bEndpointAddress);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3378) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3379)         usb_fill_bulk_urb(urb, data->udev, pipe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3380)                 skb->data, skb->len, btusb_tx_complete, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3381) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3382)         hdev->stat.acl_tx++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3383)         break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3384) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3385)     case HCI_SCODATA_PKT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3386)         print_sco(skb, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3387)         if (!data->isoc_tx_ep || hdev->conn_hash.sco_num < 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3388)             kfree(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3389)             return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3390)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3391) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3392)         urb = usb_alloc_urb(BTUSB_MAX_ISOC_FRAMES, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3393)         if (!urb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3394)             RTKBT_ERR("%s: Failed to allocate mem for sco pkts", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3395)             kfree(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3396)             return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3397)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3398) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3399)         pipe = usb_sndisocpipe(data->udev, data->isoc_tx_ep->bEndpointAddress);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3400) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3401)         usb_fill_int_urb(urb, data->udev, pipe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3402)                 skb->data, skb->len, btusb_isoc_tx_complete,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3403)                 skb, data->isoc_tx_ep->bInterval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3404) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3405)         urb->transfer_flags  = URB_ISO_ASAP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3406) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3407)         fill_isoc_descriptor(urb, skb->len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3408)                 le16_to_cpu(data->isoc_tx_ep->wMaxPacketSize));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3409) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3410)         hdev->stat.sco_tx++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3411)         goto skip_waking;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3412) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3413)     default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3414)         return -EILSEQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3415)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3416) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3417)     err = inc_tx(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3418)     if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3419)         usb_anchor_urb(urb, &data->deferred);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3420)         schedule_work(&data->waker);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3421)         err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3422)         goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3423)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3424) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3425) skip_waking:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3426)     usb_anchor_urb(urb, &data->tx_anchor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3427) retry:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3428)     err = usb_submit_urb(urb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3429)     if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3430)         RTKBT_ERR("%s: Failed to submit urb %p, pkt type %d, err %d, retries %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3431)                 __func__, urb, bt_cb(skb)->pkt_type, err, retries);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3432)         if ((bt_cb(skb)->pkt_type != HCI_SCODATA_PKT) && (retries < 10)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3433)             mdelay(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3434) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3435)             if (bt_cb(skb)->pkt_type == HCI_COMMAND_PKT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3436)                 print_error_command(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3437)             retries++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3438)             goto retry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3439)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3440)         kfree(urb->setup_packet);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3441)         usb_unanchor_urb(urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3442)     } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3443)         usb_mark_last_busy(data->udev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3444)     usb_free_urb(urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3445) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3446) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3447)     return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3448) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3449) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3450) #if LINUX_VERSION_CODE <= KERNEL_VERSION(3, 4, 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3451) static void btusb_destruct(struct hci_dev *hdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3452) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3453)     struct btusb_data *data = GET_DRV_DATA(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3454) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3455)     RTKBT_DBG("%s: name %s", __func__, hdev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3456) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3457)     kfree(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3458) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3459) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3460) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3461) static void btusb_notify(struct hci_dev *hdev, unsigned int evt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3462) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3463)     struct btusb_data *data = GET_DRV_DATA(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3464) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3465)     RTKBT_DBG("%s: name %s, evt %d", __func__, hdev->name, evt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3466) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3467)     RTKBT_INFO("%s: hdev->conn_hash.sco_num= %d, data->sco_num = %d", __func__, hdev->conn_hash.sco_num,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3468)       data->sco_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3469)     if (hdev->conn_hash.sco_num != data->sco_num) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3470)         data->sco_num = hdev->conn_hash.sco_num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3471)         schedule_work(&data->work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3472)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3473) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3474) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3475) static inline int set_isoc_interface(struct hci_dev *hdev, int altsetting)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3476) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3477)     struct btusb_data *data = GET_DRV_DATA(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3478)     struct usb_interface *intf = data->isoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3479)     struct usb_endpoint_descriptor *ep_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3480)     int i, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3481) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3482)     if (!data->isoc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3483)         return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3484) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3485)     err = usb_set_interface(data->udev, 1, altsetting);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3486)     if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3487)         RTKBT_ERR("%s: Failed to set interface, altsetting %d, err %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3488)                 __func__, altsetting, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3489)         return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3490)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3491) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3492)     data->isoc_altsetting = altsetting;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3493) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3494)     data->isoc_tx_ep = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3495)     data->isoc_rx_ep = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3496) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3497)     for (i = 0; i < intf->cur_altsetting->desc.bNumEndpoints; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3498)         ep_desc = &intf->cur_altsetting->endpoint[i].desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3499) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3500)         if (!data->isoc_tx_ep && usb_endpoint_is_isoc_out(ep_desc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3501)             data->isoc_tx_ep = ep_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3502)             continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3503)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3504) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3505)         if (!data->isoc_rx_ep && usb_endpoint_is_isoc_in(ep_desc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3506)             data->isoc_rx_ep = ep_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3507)             continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3508)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3509)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3510) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3511)     if (!data->isoc_tx_ep || !data->isoc_rx_ep) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3512)         RTKBT_ERR("%s: Invalid SCO descriptors", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3513)         return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3514)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3515) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3516)     return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3517) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3518) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3519) static int check_controller_support_msbc( struct usb_device *udev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3520) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3521)     //fix this in the future,when new card support msbc decode and encode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3522)     RTKBT_INFO("%s:pid = 0x%02x, vid = 0x%02x",__func__,udev->descriptor.idProduct, udev->descriptor.idVendor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3523)     switch (udev->descriptor.idProduct) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3524) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3525)         default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3526)           return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3527)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3528)     return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3529) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3530) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3531) static void btusb_work(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3532) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3533)     struct btusb_data *data = container_of(work, struct btusb_data, work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3534)     struct hci_dev *hdev = data->hdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3535) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3536)     int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3537)     int new_alts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3538)     if (data->sco_num > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3539)         if (!test_bit(BTUSB_DID_ISO_RESUME, &data->flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3540)             err = usb_autopm_get_interface(data->isoc ? data->isoc : data->intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3541)             if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3542)                 clear_bit(BTUSB_ISOC_RUNNING, &data->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3543)                 mdelay(URB_CANCELING_DELAY_MS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3544)                 usb_kill_anchored_urbs(&data->isoc_anchor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3545)                 return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3546)             }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3547) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3548)             set_bit(BTUSB_DID_ISO_RESUME, &data->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3549)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3550) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3551)         RTKBT_INFO("%s voice settings = 0x%04x", __func__, hdev->voice_setting);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3552)         if (!(hdev->voice_setting & 0x0003)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3553)             if(data->sco_num == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3554)                 new_alts = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3555)             else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3556)               RTKBT_ERR("%s: we don't support mutiple sco link for cvsd", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3557)               return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3558)             }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3559)         } else{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3560)             if(check_controller_support_msbc(data->udev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3561)                 if(data->sco_num == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3562)                     new_alts = 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3563)                 else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3564)                     RTKBT_ERR("%s: we don't support mutiple sco link for msbc", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3565)                     return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3566)                 }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3567)             } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3568)                 new_alts = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3569)             }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3570)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3571)         if (data->isoc_altsetting != new_alts) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3572) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3573)             clear_bit(BTUSB_ISOC_RUNNING, &data->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3574)             mdelay(URB_CANCELING_DELAY_MS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3575)             usb_kill_anchored_urbs(&data->isoc_anchor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3576) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3577)             if (set_isoc_interface(hdev, new_alts) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3578)                 return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3579)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3580) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3581)         if (!test_and_set_bit(BTUSB_ISOC_RUNNING, &data->flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3582)             if (btusb_submit_isoc_urb(hdev, GFP_KERNEL) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3583)                 clear_bit(BTUSB_ISOC_RUNNING, &data->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3584)             else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3585)                 btusb_submit_isoc_urb(hdev, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3586)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3587) #ifdef CONFIG_SCO_OVER_HCI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3588)         if(test_bit(BTUSB_ISOC_RUNNING, &data->flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3589)             set_bit(USB_CAPTURE_RUNNING, &data->pSCOSnd->states);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3590)             set_bit(USB_PLAYBACK_RUNNING, &data->pSCOSnd->states);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3591)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3592) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3593)     } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3594)         clear_bit(BTUSB_ISOC_RUNNING, &data->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3595) #ifdef CONFIG_SCO_OVER_HCI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3596)         clear_bit(USB_CAPTURE_RUNNING, &data->pSCOSnd->states);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3597)         clear_bit(USB_PLAYBACK_RUNNING, &data->pSCOSnd->states);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3598) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3599)         mdelay(URB_CANCELING_DELAY_MS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3600)         usb_kill_anchored_urbs(&data->isoc_anchor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3601) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3602)         set_isoc_interface(hdev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3603)         if (test_and_clear_bit(BTUSB_DID_ISO_RESUME, &data->flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3604)             usb_autopm_put_interface(data->isoc ? data->isoc : data->intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3605)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3606) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3607) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3608) static void btusb_waker(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3609) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3610)     struct btusb_data *data = container_of(work, struct btusb_data, waker);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3611)     int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3612) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3613)     RTKBT_DBG("%s: PM usage count %d", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3614)             atomic_read(&data->intf->pm_usage_cnt));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3615) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3616)     err = usb_autopm_get_interface(data->intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3617)     if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3618)         return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3619) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3620)     usb_autopm_put_interface(data->intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3621) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3622) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3623) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3624) //#ifdef CONFIG_HAS_EARLYSUSPEND
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3625) #if 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3626) static void btusb_early_suspend(struct early_suspend *h)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3627) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3628)     struct btusb_data *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3629)     firmware_info *fw_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3630)     patch_info *patch_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3631) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3632)     RTKBT_INFO("%s", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3633) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3634)     data = container_of(h, struct btusb_data, early_suspend);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3635)     fw_info = data->fw_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3636)     patch_entry = fw_info->patch_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3637) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3638)     patch_entry->fw_len = load_firmware(fw_info, &patch_entry->fw_cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3639)     if (patch_entry->fw_len <= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3640)         /* We may encount failure in loading firmware, just give a warning */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3641)         RTKBT_WARN("%s: Failed to load firmware", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3642)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3643) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3644) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3645) static void btusb_late_resume(struct early_suspend *h)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3646) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3647)     struct btusb_data *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3648)     firmware_info *fw_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3649)     patch_info *patch_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3650) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3651)     RTKBT_INFO("%s", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3652) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3653)     data = container_of(h, struct btusb_data, early_suspend);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3654)     fw_info = data->fw_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3655)     patch_entry = fw_info->patch_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3656) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3657)     /* Reclaim fw buffer when bt usb resumed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3658)     if (patch_entry->fw_len > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3659)         kfree(patch_entry->fw_cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3660)         patch_entry->fw_cache = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3661)         patch_entry->fw_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3662)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3663) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3664) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3665) int bt_pm_notify(struct notifier_block *notifier, ulong pm_event, void *unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3666) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3667)     struct btusb_data *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3668)     firmware_info *fw_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3669)     patch_info *patch_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3670)     struct usb_device *udev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3671) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3672)     RTKBT_INFO("%s: pm event %ld", __func__, pm_event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3673) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3674)     data = container_of(notifier, struct btusb_data, pm_notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3675)     fw_info = data->fw_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3676)     patch_entry = fw_info->patch_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3677)     udev = fw_info->udev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3678) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3679)     switch (pm_event) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3680)     case PM_SUSPEND_PREPARE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3681)     case PM_HIBERNATION_PREPARE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3682) #if 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3683)         patch_entry->fw_len = load_firmware(fw_info, &patch_entry->fw_cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3684)         if (patch_entry->fw_len <= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3685)         /* We may encount failure in loading firmware, just give a warning */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3686)             RTKBT_WARN("%s: Failed to load firmware", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3687)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3688) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3689)         if (!device_may_wakeup(&udev->dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3690) #if (CONFIG_RESET_RESUME || CONFIG_BLUEDROID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3691)             RTKBT_INFO("%s:remote wakeup not supported, reset resume supported", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3692) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3693)             fw_info->intf->needs_binding = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3694)             RTKBT_INFO("%s:remote wakeup not supported, binding needed", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3695) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3696)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3697)         break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3698) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3699)     case PM_POST_SUSPEND:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3700)     case PM_POST_HIBERNATION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3701)     case PM_POST_RESTORE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3702) #if 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3703)         /* Reclaim fw buffer when bt usb resumed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3704)         if (patch_entry->fw_len > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3705)             kfree(patch_entry->fw_cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3706)             patch_entry->fw_cache = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3707)             patch_entry->fw_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3708)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3709) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3710) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3711) #if BTUSB_RPM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3712)         usb_disable_autosuspend(udev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3713)         usb_enable_autosuspend(udev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3714)         pm_runtime_set_autosuspend_delay(&(udev->dev), 2000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3715) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3716)         break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3717) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3718)     default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3719)         break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3720)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3721) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3722)     return NOTIFY_DONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3723) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3724) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3725) int bt_reboot_notify(struct notifier_block *notifier, ulong pm_event, void *unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3726) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3727)     struct btusb_data *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3728)     firmware_info *fw_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3729)     patch_info *patch_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3730)     struct usb_device *udev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3731) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3732)     RTKBT_INFO("%s: pm event %ld", __func__, pm_event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3733) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3734)     data = container_of(notifier, struct btusb_data, reboot_notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3735)     fw_info = data->fw_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3736)     patch_entry = fw_info->patch_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3737)     udev = fw_info->udev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3738) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3739)     switch (pm_event) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3740)     case SYS_DOWN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3741)         RTKBT_DBG("%s:system down or restart", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3742)     break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3743) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3744)     case SYS_HALT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3745)     case SYS_POWER_OFF:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3746) #if SUSPNED_DW_FW
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3747)         cancel_work_sync(&data->work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3748) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3749)         btusb_stop_traffic(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3750)         mdelay(URB_CANCELING_DELAY_MS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3751)         usb_kill_anchored_urbs(&data->tx_anchor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3752) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3753) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3754)         if(fw_info_4_suspend) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3755)             download_suspend_patch(fw_info_4_suspend,1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3756)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3757) 	    else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3758) 		    RTKBT_ERR("%s: Failed to download suspend fw", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3759) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3760) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3761) #if SET_WAKEUP_DEVICE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3762)         set_wakeup_device_from_conf(fw_info_4_suspend);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3763) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3764)         RTKBT_DBG("%s:system halt or power off", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3765)     break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3766) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3767)     default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3768)         break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3769)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3770) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3771)     return NOTIFY_DONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3772) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3773) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3774) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3775) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3776) #ifdef CONFIG_SCO_OVER_HCI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3777) static const struct snd_pcm_hardware snd_card_sco_capture_default =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3778) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3779)     .info               = (SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_NONINTERLEAVED |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3780)                             SNDRV_PCM_ACCESS_RW_INTERLEAVED | SNDRV_PCM_INFO_FIFO_IN_FRAMES),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3781)     .formats            = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3782)     .rates              = (SNDRV_PCM_RATE_8000),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3783)     .rate_min           = 8000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3784)     .rate_max           = 8000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3785)     .channels_min       = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3786)     .channels_max       = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3787)     .buffer_bytes_max   = 8 * 768,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3788)     .period_bytes_min   = 48,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3789)     .period_bytes_max   = 768,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3790)     .periods_min        = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3791)     .periods_max        = 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3792)     .fifo_size          = 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3793) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3794) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3795) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3796) static int snd_sco_capture_pcm_open(struct snd_pcm_substream * substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3797) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3798)     RTK_sco_card_t  *pSCOSnd = substream->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3799) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3800)     RTKBT_INFO("%s", __FUNCTION__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3801)     pSCOSnd->capture.substream = substream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3802) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3803)     memcpy(&substream->runtime->hw, &snd_card_sco_capture_default, sizeof(struct snd_pcm_hardware));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3804) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3805)     if(check_controller_support_msbc(pSCOSnd->dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3806)         substream->runtime->hw.rates |= SNDRV_PCM_RATE_16000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3807)         substream->runtime->hw.rate_max = 16000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3808)         substream->runtime->hw.period_bytes_min = 96;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3809)         substream->runtime->hw.period_bytes_max = 16 * 96;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3810)         substream->runtime->hw.buffer_bytes_max = 8 * 16 * 96;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3811)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3812)     set_bit(ALSA_CAPTURE_OPEN, &pSCOSnd->states);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3813)     return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3814) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3815) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3816) static int snd_sco_capture_pcm_close(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3817) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3818) 	RTK_sco_card_t *pSCOSnd = substream->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3819) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3820) 	clear_bit(ALSA_CAPTURE_OPEN, &pSCOSnd->states);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3821) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3822) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3823) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3824) static int snd_sco_capture_ioctl(struct snd_pcm_substream *substream,  unsigned int cmd, void *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3825) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3826)     RTKBT_DBG("%s, cmd = %d", __FUNCTION__, cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3827)     switch (cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3828)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3829)         default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3830)             return snd_pcm_lib_ioctl(substream, cmd, arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3831)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3832)     return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3833) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3834) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3835) static int snd_sco_capture_pcm_hw_params(struct snd_pcm_substream * substream, struct snd_pcm_hw_params * hw_params)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3836) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3837) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3838)     int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3839)     struct snd_pcm_runtime *runtime = substream->runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3840)     err = snd_pcm_lib_alloc_vmalloc_buffer(substream, params_buffer_bytes(hw_params));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3841)     RTKBT_INFO("%s,err : %d,  runtime state : %d", __FUNCTION__, err, runtime->status->state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3842)     return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3843) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3844) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3845) static int snd_sco_capture_pcm_hw_free(struct snd_pcm_substream * substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3846) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3847)     RTKBT_DBG("%s", __FUNCTION__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3848)     return snd_pcm_lib_free_vmalloc_buffer(substream);;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3849) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3850) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3851) static int snd_sco_capture_pcm_prepare(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3852) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3853)     RTK_sco_card_t *pSCOSnd = substream->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3854)     struct snd_pcm_runtime *runtime = substream->runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3855) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3856)     RTKBT_INFO("%s", __FUNCTION__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3857)     if (test_bit(DISCONNECTED, &pSCOSnd->states))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3858) 		    return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3859) 	  if (!test_bit(USB_CAPTURE_RUNNING, &pSCOSnd->states))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3860) 		    return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3861) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3862)     if(runtime->rate == 8000) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3863)         if(pSCOSnd->usb_data->isoc_altsetting != 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3864)             return -ENOEXEC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3865)         pSCOSnd->capture.sco_packet_bytes = 48;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3866)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3867)     else if(runtime->rate == 16000 && check_controller_support_msbc(pSCOSnd->dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3868)         if(pSCOSnd->usb_data->isoc_altsetting != 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3869)             return -ENOEXEC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3870)         pSCOSnd->capture.sco_packet_bytes = 96;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3871)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3872)     else if(pSCOSnd->usb_data->isoc_altsetting == 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3873)         pSCOSnd->capture.sco_packet_bytes = 48;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3874)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3875)     else if(pSCOSnd->usb_data->isoc_altsetting == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3876)         pSCOSnd->capture.sco_packet_bytes = 24;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3877)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3878)     return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3879) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3880) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3881) static int snd_sco_capture_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3882) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3883) 	  RTK_sco_card_t *pSCOSnd = substream->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3884)     RTKBT_INFO("%s, cmd : %d", __FUNCTION__, cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3885) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3886) 	  switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3887) 	    case SNDRV_PCM_TRIGGER_START:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3888) 		      if (!test_bit(USB_CAPTURE_RUNNING, &pSCOSnd->states))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3889) 			      return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3890) 		      set_bit(ALSA_CAPTURE_RUNNING, &pSCOSnd->states);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3891) 		      return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3892) 	    case SNDRV_PCM_TRIGGER_STOP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3893) 		      clear_bit(ALSA_CAPTURE_RUNNING, &pSCOSnd->states);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3894) 		      return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3895) 	    default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3896) 		      return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3897) 	  }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3898) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3899) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3900) static snd_pcm_uframes_t snd_sco_capture_pcm_pointer(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3901) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3902) 	  RTK_sco_card_t *pSCOSnd = substream->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3903) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3904) 	  return pSCOSnd->capture.buffer_pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3905) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3906) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3907) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3908) static struct snd_pcm_ops snd_sco_capture_pcm_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3909) 	.open =         snd_sco_capture_pcm_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3910) 	.close =        snd_sco_capture_pcm_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3911) 	.ioctl =        snd_sco_capture_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3912) 	.hw_params =    snd_sco_capture_pcm_hw_params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3913) 	.hw_free =      snd_sco_capture_pcm_hw_free,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3914) 	.prepare =      snd_sco_capture_pcm_prepare,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3915) 	.trigger =      snd_sco_capture_pcm_trigger,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3916) 	.pointer =      snd_sco_capture_pcm_pointer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3917) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3918) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3919) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3920) static const struct snd_pcm_hardware snd_card_sco_playback_default =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3921) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3922)     .info               = (SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_NONINTERLEAVED |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3923)                             SNDRV_PCM_ACCESS_RW_INTERLEAVED | SNDRV_PCM_INFO_FIFO_IN_FRAMES),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3924)     .formats            = SNDRV_PCM_FMTBIT_S16_LE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3925)     .rates              = (SNDRV_PCM_RATE_8000),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3926)     .rate_min           = 8000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3927)     .rate_max           = 8000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3928)     .channels_min       = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3929)     .channels_max       = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3930)     .buffer_bytes_max   = 8 * 768,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3931)     .period_bytes_min   = 48,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3932)     .period_bytes_max   = 768,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3933)     .periods_min        = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3934)     .periods_max        = 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3935)     .fifo_size          = 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3936) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3937) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3938) static int snd_sco_playback_pcm_open(struct snd_pcm_substream * substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3939) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3940)     RTK_sco_card_t *pSCOSnd = substream->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3941)     int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3942) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3943)     RTKBT_INFO("%s, rate : %d", __FUNCTION__, substream->runtime->rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3944)     memcpy(&substream->runtime->hw, &snd_card_sco_playback_default, sizeof(struct snd_pcm_hardware));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3945)     if(check_controller_support_msbc(pSCOSnd->dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3946)         substream->runtime->hw.rates |= SNDRV_PCM_RATE_16000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3947)         substream->runtime->hw.rate_max = 16000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3948)         substream->runtime->hw.period_bytes_min = 96;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3949)         substream->runtime->hw.period_bytes_max = 16 * 96;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3950)         substream->runtime->hw.buffer_bytes_max = 8 * 16 * 96;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3951)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3952)     pSCOSnd->playback.substream = substream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3953)     set_bit(ALSA_PLAYBACK_OPEN, &pSCOSnd->states);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3954) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3955)     return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3956) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3957) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3958) static int snd_sco_playback_pcm_close(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3959) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3960)     RTK_sco_card_t *pSCOSnd = substream->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3961) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3962) 	  clear_bit(ALSA_PLAYBACK_OPEN, &pSCOSnd->states);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3963)     cancel_work_sync(&pSCOSnd->send_sco_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3964) 	  return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3965) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3966) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3967) static int snd_sco_playback_ioctl(struct snd_pcm_substream *substream,  unsigned int cmd, void *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3968) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3969)     RTKBT_DBG("%s, cmd : %d", __FUNCTION__, cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3970)     switch (cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3971)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3972)         default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3973)             return snd_pcm_lib_ioctl(substream, cmd, arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3974)             break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3975)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3976)     return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3977) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3978) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3979) static int snd_sco_playback_pcm_hw_params(struct snd_pcm_substream * substream, struct snd_pcm_hw_params * hw_params)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3980) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3981)     int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3982)     err = snd_pcm_lib_alloc_vmalloc_buffer(substream, params_buffer_bytes(hw_params));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3983)     return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3984) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3985) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3986) static int snd_sco_palyback_pcm_hw_free(struct snd_pcm_substream * substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3987) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3988)     RTKBT_DBG("%s", __FUNCTION__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3989)     return snd_pcm_lib_free_vmalloc_buffer(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3990) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3991) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3992) static int snd_sco_playback_pcm_prepare(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3993) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3994) 	  RTK_sco_card_t *pSCOSnd = substream->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3995)     struct snd_pcm_runtime *runtime = substream->runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3996) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3997)     RTKBT_INFO("%s, bound_rate = %d", __FUNCTION__, runtime->rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3998) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3999) 	  if (test_bit(DISCONNECTED, &pSCOSnd->states))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4000) 		    return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4001) 	  if (!test_bit(USB_PLAYBACK_RUNNING, &pSCOSnd->states))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4002) 		    return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4003) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4004)     if(runtime->rate == 8000) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4005)         if(pSCOSnd->usb_data->isoc_altsetting != 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4006)             return -ENOEXEC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4007)         pSCOSnd->playback.sco_packet_bytes = 48;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4008)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4009)     else if(runtime->rate == 16000) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4010)         if(pSCOSnd->usb_data->isoc_altsetting != 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4011)             return -ENOEXEC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4012)         pSCOSnd->playback.sco_packet_bytes = 96;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4013)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4014) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4015)   	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4016) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4017) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4018) static int snd_sco_playback_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4019) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4020)   	RTK_sco_card_t *pSCOSnd = substream->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4021) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4022)     RTKBT_INFO("%s, cmd = %d", __FUNCTION__, cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4023)   	switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4024)       	case SNDRV_PCM_TRIGGER_START:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4025)       		if (!test_bit(USB_PLAYBACK_RUNNING, &pSCOSnd->states))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4026)       			return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4027)       		set_bit(ALSA_PLAYBACK_RUNNING, &pSCOSnd->states);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4028)           schedule_work(&pSCOSnd->send_sco_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4029)       		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4030)       	case SNDRV_PCM_TRIGGER_STOP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4031)       		clear_bit(ALSA_PLAYBACK_RUNNING, &pSCOSnd->states);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4032)       		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4033)       	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4034)       		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4035)   	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4036) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4037) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4038) static snd_pcm_uframes_t snd_sco_playback_pcm_pointer(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4039) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4040)   	RTK_sco_card_t *pSCOSnd = substream->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4041) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4042)   	return pSCOSnd->playback.buffer_pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4043) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4044) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4045) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4046) static struct snd_pcm_ops snd_sco_playback_pcm_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4047) 	.open =         snd_sco_playback_pcm_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4048) 	.close =        snd_sco_playback_pcm_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4049) 	.ioctl =        snd_sco_playback_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4050) 	.hw_params =    snd_sco_playback_pcm_hw_params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4051) 	.hw_free =      snd_sco_palyback_pcm_hw_free,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4052) 	.prepare =      snd_sco_playback_pcm_prepare,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4053) 	.trigger =      snd_sco_playback_pcm_trigger,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4054) 	.pointer =      snd_sco_playback_pcm_pointer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4055) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4056) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4057) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4058) static RTK_sco_card_t* btusb_snd_init(struct usb_interface *intf, const struct usb_device_id *id, struct btusb_data *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4059) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4060)     struct snd_card *card;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4061)     RTK_sco_card_t  *pSCOSnd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4062)     int err=0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4063)     RTKBT_INFO("%s", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4064)     err = snd_card_new(&intf->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4065)      -1, RTK_SCO_ID, THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4066)      sizeof(RTK_sco_card_t), &card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4067)     if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4068)         RTKBT_ERR("%s: sco snd card create fail", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4069)         return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4070)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4071)     // private data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4072)     pSCOSnd = (RTK_sco_card_t *)card->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4073)     pSCOSnd->card = card;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4074)     pSCOSnd->dev = interface_to_usbdev(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4075)     pSCOSnd->usb_data = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4076) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4077)     strcpy(card->driver, RTK_SCO_ID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4078)     strcpy(card->shortname, "Realtek sco snd");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4079)     sprintf(card->longname, "Realtek sco over hci: VID:0x%04x, PID:0x%04x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4080)         id->idVendor, pSCOSnd->dev->descriptor.idProduct);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4081) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4082)     err = snd_pcm_new(card, RTK_SCO_ID, 0, 1, 1, &pSCOSnd->pcm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4083)     if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4084)         RTKBT_ERR("%s: sco snd card new pcm fail", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4085)         return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4086)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4087)     pSCOSnd->pcm->private_data = pSCOSnd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4088)     sprintf(pSCOSnd->pcm->name, "sco_pcm:VID:0x%04x, PID:0x%04x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4089)       id->idVendor, pSCOSnd->dev->descriptor.idProduct);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4090) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4091)     snd_pcm_set_ops(pSCOSnd->pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_sco_playback_pcm_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4092)     snd_pcm_set_ops(pSCOSnd->pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_sco_capture_pcm_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4093) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4094)     err = snd_card_register(card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4095)     if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4096)         RTKBT_ERR("%s: sco snd card register card fail", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4097)         return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4098)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4099) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4100)     spin_lock_init(&pSCOSnd->capture_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4101)     spin_lock_init(&pSCOSnd->playback_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4102)     INIT_WORK(&pSCOSnd->send_sco_work, playback_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4103)     return pSCOSnd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4105) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4107) static int btusb_probe(struct usb_interface *intf, const struct usb_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4108) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4109)     struct usb_device *udev = interface_to_usbdev(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4110)     struct usb_endpoint_descriptor *ep_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4111)     struct btusb_data *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4112)     struct hci_dev *hdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4113)     firmware_info *fw_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4114)     int i, err=0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4116)     RTKBT_INFO("%s: usb_interface %p, bInterfaceNumber %d, idVendor 0x%04x, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4117)             "idProduct 0x%04x", __func__, intf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4118)             intf->cur_altsetting->desc.bInterfaceNumber,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4119)             id->idVendor, id->idProduct);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4121)     /* interface numbers are hardcoded in the spec */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4122)     if (intf->cur_altsetting->desc.bInterfaceNumber != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4123)         return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4125)     RTKBT_DBG("%s: can wakeup = %x, may wakeup = %x", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4126)             device_can_wakeup(&udev->dev), device_may_wakeup(&udev->dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4128)     data = rtk_alloc(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4129)     if (!data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4130)         return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4132)     for (i = 0; i < intf->cur_altsetting->desc.bNumEndpoints; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4133)         ep_desc = &intf->cur_altsetting->endpoint[i].desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4135)         if (!data->intr_ep && usb_endpoint_is_int_in(ep_desc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4136)             data->intr_ep = ep_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4137)             continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4138)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4140)         if (!data->bulk_tx_ep && usb_endpoint_is_bulk_out(ep_desc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4141)             data->bulk_tx_ep = ep_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4142)             continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4143)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4145)         if (!data->bulk_rx_ep && usb_endpoint_is_bulk_in(ep_desc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4146)             data->bulk_rx_ep = ep_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4147)             continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4148)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4149)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4151)     if (!data->intr_ep || !data->bulk_tx_ep || !data->bulk_rx_ep) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4152)         rtk_free(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4153)         return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4154)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4156)     data->cmdreq_type = USB_TYPE_CLASS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4158)     data->udev = udev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4159)     data->intf = intf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4161)     dlfw_dis_state = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4162)     spin_lock_init(&queue_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4163)     spin_lock_init(&dlfw_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4164)     spin_lock_init(&data->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4166)     INIT_WORK(&data->work, btusb_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4167)     INIT_WORK(&data->waker, btusb_waker);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4168)     spin_lock_init(&data->txlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4170)     init_usb_anchor(&data->tx_anchor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4171)     init_usb_anchor(&data->intr_anchor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4172)     init_usb_anchor(&data->bulk_anchor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4173)     init_usb_anchor(&data->isoc_anchor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4174)     init_usb_anchor(&data->deferred);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4176)     fw_info = firmware_info_init(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4177)     if (fw_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4178)         data->fw_info = fw_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4179)     else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4180)         RTKBT_WARN("%s: Failed to initialize fw info", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4181)         /* Skip download patch */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4182)         goto end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4183)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4185)     hdev = hci_alloc_dev();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4186)     if (!hdev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4187)         rtk_free(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4188)         data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4189)         return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4190)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4192)     HDEV_BUS = HCI_USB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4194)     data->hdev = hdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4196)     SET_HCIDEV_DEV(hdev, &intf->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4198)     hdev->open     = btusb_open;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4199)     hdev->close    = btusb_close;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4200)     hdev->flush    = btusb_flush;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4201)     hdev->send     = btusb_send_frame;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4202)     hdev->notify   = btusb_notify;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4204) #if LINUX_VERSION_CODE > KERNEL_VERSION(3, 4, 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4205)     hci_set_drvdata(hdev, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4206) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4207)     hdev->driver_data = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4208)     hdev->destruct = btusb_destruct;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4209)     hdev->owner = THIS_MODULE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4210) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4212) #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 7, 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4213)     if (!reset_on_close){
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4214)         /* set_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks); */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4215)         RTKBT_DBG("%s: Set HCI_QUIRK_RESET_ON_CLOSE", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4216)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4217) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4219)     /* Interface numbers are hardcoded in the specification */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4220)     data->isoc = usb_ifnum_to_if(data->udev, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4221)     if (data->isoc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4222)         err = usb_driver_claim_interface(&btusb_driver,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4223)                             data->isoc, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4224)         if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4225)             hci_free_dev(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4226)             hdev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4227)             rtk_free(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4228)             data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4229)             return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4230)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4231) #ifdef CONFIG_SCO_OVER_HCI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4232)         data->pSCOSnd = btusb_snd_init(intf, id, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4233) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4234)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4236)     err = hci_register_dev(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4237)     if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4238)         hci_free_dev(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4239)         hdev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4240)         rtk_free(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4241)         data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4242)         return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4243)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4245)     usb_set_intfdata(intf, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4247) //#ifdef CONFIG_HAS_EARLYSUSPEND
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4248) #if 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4249)     data->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4250)     data->early_suspend.suspend = btusb_early_suspend;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4251)     data->early_suspend.resume = btusb_late_resume;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4252)     register_early_suspend(&data->early_suspend);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4253) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4254)     data->pm_notifier.notifier_call = bt_pm_notify;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4255)     data->reboot_notifier.notifier_call = bt_reboot_notify;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4256)     register_pm_notifier(&data->pm_notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4257)     register_reboot_notifier(&data->reboot_notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4258) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4260) #if CONFIG_BLUEDROID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4261)     RTKBT_INFO("%s: Check bt reset flag %d", __func__, bt_reset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4262)     /* Report hci hardware error after everthing is ready,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4263)      * especially hci register is completed. Or, btchr_poll
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4264)      * will get null hci dev when hotplug in.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4265)      */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4266)     if (bt_reset == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4267)         hci_hardware_error();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4268)         bt_reset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4269)     } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4270)         bt_reset = 0; /* Clear and reset it anyway */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4271) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4273) end:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4274)     return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4275) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4276) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4277) static void btusb_disconnect(struct usb_interface *intf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4278) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4279)     struct btusb_data *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4280)     struct hci_dev *hdev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4282)     if (intf->cur_altsetting->desc.bInterfaceNumber != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4283)         return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4284) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4285)     wait_event_interruptible(bt_dlfw_wait, (check_set_dlfw_state_value(2) == 2));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4287)     RTKBT_INFO("%s: usb_interface %p, bInterfaceNumber %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4288)             __func__, intf, intf->cur_altsetting->desc.bInterfaceNumber);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4290)     data = usb_get_intfdata(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4292)     if (data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4293)         hdev = data->hdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4294)     else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4295)         RTKBT_WARN("%s: Failed to get bt usb data[Null]", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4296)         return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4297)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4298) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4299) #ifdef CONFIG_SCO_OVER_HCI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4300)     if (intf->cur_altsetting->desc.bInterfaceNumber == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4301)         RTK_sco_card_t *pSCOSnd = data->pSCOSnd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4302)         if(!pSCOSnd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4303)             RTKBT_ERR("%s: sco private data is null", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4304)             return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4305)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4306)         set_bit(DISCONNECTED, &pSCOSnd->states);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4307)         snd_card_disconnect(pSCOSnd->card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4308)         snd_card_free_when_closed(pSCOSnd->card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4309)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4310) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4311) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4312) //#ifdef CONFIG_HAS_EARLYSUSPEND
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4313) #if 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4314)     unregister_early_suspend(&data->early_suspend);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4315) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4316)     unregister_pm_notifier(&data->pm_notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4317)     unregister_reboot_notifier(&data->reboot_notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4318) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4320)     firmware_info_destroy(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4321) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4322) #if CONFIG_BLUEDROID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4323)     if (test_bit(HCI_RUNNING, &hdev->flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4324)         RTKBT_INFO("%s: Set BT reset flag", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4325)         bt_reset = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4326)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4327) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4328) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4329)     usb_set_intfdata(data->intf, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4331)     if (data->isoc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4332)         usb_set_intfdata(data->isoc, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4334)     hci_unregister_dev(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4335) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4336)     if (intf == data->isoc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4337)         usb_driver_release_interface(&btusb_driver, data->intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4338)     else if (data->isoc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4339)         usb_driver_release_interface(&btusb_driver, data->isoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4341) #if !CONFIG_BLUEDROID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4342) #if LINUX_VERSION_CODE <= KERNEL_VERSION(3, 4, 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4343)     __hci_dev_put(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4344) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4345) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4346) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4347)     hci_free_dev(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4348)     rtk_free(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4349)     data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4350)     set_dlfw_state_value(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4351) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4353) #ifdef CONFIG_PM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4354) static int btusb_suspend(struct usb_interface *intf, pm_message_t message)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4355) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4356)     struct btusb_data *data = usb_get_intfdata(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4357)     firmware_info *fw_info = data->fw_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4358) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4359)     RTKBT_INFO("%s: event 0x%x, suspend count %d", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4360)             message.event, data->suspend_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4361) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4362)     if (intf->cur_altsetting->desc.bInterfaceNumber != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4363)         return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4364) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4365)     if (!test_bit(HCI_RUNNING, &data->hdev->flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4366)         set_bt_onoff(fw_info, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4368)     if (data->suspend_count++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4369)         return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4370) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4371)     spin_lock_irq(&data->txlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4372)     if (!((message.event & PM_EVENT_AUTO) && data->tx_in_flight)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4373)         set_bit(BTUSB_SUSPENDING, &data->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4374)         spin_unlock_irq(&data->txlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4375)     } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4376)         spin_unlock_irq(&data->txlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4377)         data->suspend_count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4378)         RTKBT_ERR("%s: Failed to enter suspend", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4379)         return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4380)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4381) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4382)     cancel_work_sync(&data->work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4383) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4384)     btusb_stop_traffic(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4385)     mdelay(URB_CANCELING_DELAY_MS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4386)     usb_kill_anchored_urbs(&data->tx_anchor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4387) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4388) #if SUSPNED_DW_FW
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4389)     if(fw_info_4_suspend) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4390)         download_suspend_patch(fw_info_4_suspend,1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4391)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4392)     else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4393)         RTKBT_ERR("%s: Failed to download suspend fw", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4394) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4395) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4396) #if SET_WAKEUP_DEVICE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4397)     set_wakeup_device_from_conf(fw_info_4_suspend);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4398) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4399) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4400)     return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4401) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4402) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4403) static void play_deferred(struct btusb_data *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4404) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4405)     struct urb *urb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4406)     int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4407) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4408)     while ((urb = usb_get_from_anchor(&data->deferred))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4409)         usb_anchor_urb(urb, &data->tx_anchor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4410)         err = usb_submit_urb(urb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4411)         if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4412)             RTKBT_ERR("%s: Failed to submit urb %p, err %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4413)                     __func__, urb, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4414)             kfree(urb->setup_packet);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4415)             usb_unanchor_urb(urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4416)         } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4417)             usb_mark_last_busy(data->udev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4418)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4419)         usb_free_urb(urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4420) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4421)         data->tx_in_flight++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4422)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4423)     mdelay(URB_CANCELING_DELAY_MS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4424)     usb_scuttle_anchored_urbs(&data->deferred);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4425) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4426) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4427) static int btusb_resume(struct usb_interface *intf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4428) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4429)     struct btusb_data *data = usb_get_intfdata(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4430)     struct hci_dev *hdev = data->hdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4431)     firmware_info *fw_info = data->fw_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4432)     int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4433) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4434)     RTKBT_INFO("%s: Suspend count %d", __func__, data->suspend_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4435) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4436)     if (intf->cur_altsetting->desc.bInterfaceNumber != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4437)         return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4438) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4439)     if (--data->suspend_count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4440)         return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4441) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4442)     /*check_fw_version to check the status of the BT Controller after USB Resume*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4443)     err = check_fw_version(fw_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4444)     if (err !=0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4445)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4446)         RTKBT_INFO("%s: BT Controller Power OFF And Return hci_hardware_error:%d", __func__, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4447)         hci_hardware_error();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4448)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4449) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4450) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4451)     if (test_bit(BTUSB_INTR_RUNNING, &data->flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4452)         err = btusb_submit_intr_urb(hdev, GFP_NOIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4453)         if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4454)             clear_bit(BTUSB_INTR_RUNNING, &data->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4455)             goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4456)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4457)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4458) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4459)     if (test_bit(BTUSB_BULK_RUNNING, &data->flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4460)         err = btusb_submit_bulk_urb(hdev, GFP_NOIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4461)         if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4462)             clear_bit(BTUSB_BULK_RUNNING, &data->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4463)             goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4464)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4465) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4466)         btusb_submit_bulk_urb(hdev, GFP_NOIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4467)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4468) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4469)     if (test_bit(BTUSB_ISOC_RUNNING, &data->flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4470)         if (btusb_submit_isoc_urb(hdev, GFP_NOIO) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4471)             clear_bit(BTUSB_ISOC_RUNNING, &data->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4472)         else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4473)             btusb_submit_isoc_urb(hdev, GFP_NOIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4474)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4475) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4476)     spin_lock_irq(&data->txlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4477)     play_deferred(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4478)     clear_bit(BTUSB_SUSPENDING, &data->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4479)     spin_unlock_irq(&data->txlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4480)     schedule_work(&data->work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4481) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4482)     return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4483) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4484) failed:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4485)     mdelay(URB_CANCELING_DELAY_MS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4486)     usb_scuttle_anchored_urbs(&data->deferred);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4487)     spin_lock_irq(&data->txlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4488)     clear_bit(BTUSB_SUSPENDING, &data->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4489)     spin_unlock_irq(&data->txlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4490) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4491)     return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4492) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4493) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4494) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4495) static struct usb_driver btusb_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4496)     .name        = "rtk_btusb",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4497)     .probe        = btusb_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4498)     .disconnect    = btusb_disconnect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4499) #ifdef CONFIG_PM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4500)     .suspend    = btusb_suspend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4501)     .resume        = btusb_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4502) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4503) #if CONFIG_RESET_RESUME
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4504)     .reset_resume    = btusb_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4505) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4506)     .id_table    = btusb_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4507)     .supports_autosuspend = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4508) #if LINUX_VERSION_CODE > KERNEL_VERSION(3, 7, 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4509)     .disable_hub_initiated_lpm = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4510) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4511) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4512) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4513) static int __init btusb_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4514) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4515)     int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4516) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4517)     RTKBT_INFO("RTKBT_RELEASE_NAME: %s",RTKBT_RELEASE_NAME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4518)     RTKBT_INFO("Realtek Bluetooth USB driver module init, version %s", VERSION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4519) #if CONFIG_BLUEDROID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4520)     err = btchr_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4521)     if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4522)         /* usb register will go on, even bt char register failed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4523)         RTKBT_ERR("Failed to register usb char device interfaces");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4524)     } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4525)         bt_char_dev_registered = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4526) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4527)     err = usb_register(&btusb_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4528)     if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4529)         RTKBT_ERR("Failed to register RTK bluetooth USB driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4530)     return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4531) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4532) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4533) static void __exit btusb_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4534) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4535)     struct hci_dev *hdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4536)     RTKBT_INFO("Realtek Bluetooth USB driver module exit");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4537) #if CONFIG_BLUEDROID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4538)     hdev = hci_dev_get(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4539)     if (bt_char_dev_registered) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4540)         bt_char_dev_registered = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4541)         while(hdev && atomic_read(&hdev->promisc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4542)             RTKBT_ERR("%s: rtkbt driver is being removed, but application is still running!", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4543)             RTKBT_ERR("%s: wait bt application to stop, or the driver can't be removed", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4544)             mdelay(100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4545)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4546)         btchr_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4547)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4548) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4549)     usb_deregister(&btusb_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4550) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4551) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4552) module_init(btusb_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4553) module_exit(btusb_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4554) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4555) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4556) module_param(mp_drv_mode, int, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4557) MODULE_PARM_DESC(mp_drv_mode, "0: NORMAL; 1: MP MODE");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4558) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4559) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4560) MODULE_AUTHOR("Realtek Corporation");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4561) MODULE_DESCRIPTION("Realtek Bluetooth USB driver version");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4562) MODULE_VERSION(VERSION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4563) MODULE_LICENSE("GPL");