From d789a5d9252aadac1d0dc65560d90a4a0b142264 Mon Sep 17 00:00:00 2001 From: gwl Date: Tue, 18 Mar 2014 10:21:53 +0800 Subject: [PATCH] wifi:rfkill:bcmdhd: insmod wifi driver after android started. --- arch/arm/boot/dts/rk3188-tb.dts | 2 +- .../rockchip_wlan/rkwifi/bcmdhd/Makefile | 4 +- .../rockchip_wlan/rkwifi/bcmdhd/dhd_gpio.c | 4 +- .../rockchip_wlan/rkwifi/bcmdhd/dhd_linux.c | 11 +- .../rockchip_wlan/rkwifi/bcmdhd/rkversion.c | 2 +- .../rockchip_wlan/rkwifi/rk_wifi_config.c | 20 -- .../rockchip_wlan/wifi_sys/rkwifi_sys_iface.c | 290 +++--------------- include/linux/rfkill-wlan.h | 1 + net/rfkill/rfkill-wlan.c | 14 +- 9 files changed, 70 insertions(+), 278 deletions(-) diff --git a/arch/arm/boot/dts/rk3188-tb.dts b/arch/arm/boot/dts/rk3188-tb.dts index 02308cc8e93b..fa6f6bf590e4 100755 --- a/arch/arm/boot/dts/rk3188-tb.dts +++ b/arch/arm/boot/dts/rk3188-tb.dts @@ -183,7 +183,7 @@ supports-highspeed; supports-sdio; - status = "diabled"; + status = "okay"; }; diff --git a/drivers/net/wireless/rockchip_wlan/rkwifi/bcmdhd/Makefile b/drivers/net/wireless/rockchip_wlan/rkwifi/bcmdhd/Makefile index e4b4ed2c4f69..2205af16fe36 100644 --- a/drivers/net/wireless/rockchip_wlan/rkwifi/bcmdhd/Makefile +++ b/drivers/net/wireless/rockchip_wlan/rkwifi/bcmdhd/Makefile @@ -15,7 +15,7 @@ DHDCFLAGS = -Wall -Wstrict-prototypes -Dlinux -DBCMDRIVER \ -DMMC_SDIO_ABORT -DBCMSDIO -DBCMLXSDMMC -DBCMPLATFORM_BUS \ -DWIFI_ACT_FRAME -DARP_OFFLOAD_SUPPORT \ -DKEEP_ALIVE -DPKT_FILTER_SUPPORT -DGET_CUSTOM_MAC_ENABLE \ - -DEMBEDDED_PLATFORM -DENABLE_INSMOD_NO_FW_LOAD -DPNO_SUPPORT \ + -DEMBEDDED_PLATFORM -DPNO_SUPPORT \ -DDHD_USE_IDLECOUNT -DSET_RANDOM_MAC_SOFTAP -DVSDB \ -DWL_CFG80211_VSDB_PRIORITIZE_SCAN_REQUEST -DSDIO_CRC_ERROR_FIX \ -DESCAN_RESULT_PATCH -DHT40_GO -DPASS_ARP_PACKET -DSUPPORT_PM2_ONLY \ @@ -24,7 +24,7 @@ DHDCFLAGS = -Wall -Wstrict-prototypes -Dlinux -DBCMDRIVER \ -DWL_SUPPORT_BACKPORTED_KPATCHES \ -Idrivers/net/wireless/rockchip_wlan/rkwifi/bcmdhd \ -Idrivers/net/wireless/rockchip_wlan/rkwifi/bcmdhd/include - +#-DENABLE_INSMOD_NO_FW_LOAD DHDOFILES = aiutils.o bcmsdh_sdmmc_linux.o dhd_linux.o siutils.o bcmutils.o \ dhd_linux_sched.o bcmwifi_channels.o dhd_sdio.o bcmevent.o dhd_bta.o hndpmu.o \ bcmsdh.o dhd_cdc.o bcmsdh_linux.o dhd_common.o dhd_wlfc.o dhd_ip.o linux_osl.o \ diff --git a/drivers/net/wireless/rockchip_wlan/rkwifi/bcmdhd/dhd_gpio.c b/drivers/net/wireless/rockchip_wlan/rkwifi/bcmdhd/dhd_gpio.c index 7cd273097d34..79103d69761c 100644 --- a/drivers/net/wireless/rockchip_wlan/rkwifi/bcmdhd/dhd_gpio.c +++ b/drivers/net/wireless/rockchip_wlan/rkwifi/bcmdhd/dhd_gpio.c @@ -31,6 +31,7 @@ #include #include #include +#include #ifdef CUSTOMER_HW #ifdef CUSTOMER_OOB @@ -43,14 +44,13 @@ int bcm_wlan_get_oob_irq(void) } #endif -extern int rockchip_wifi_power(int on); - void bcm_wlan_power_on(int flag) { if (flag == 1) { printk("======== PULL WL_REG_ON HIGH! ========\n"); rockchip_wifi_power(1); msleep(100); + rockchip_wifi_set_carddetect(); } else { printk("======== PULL WL_REG_ON HIGH! (flag = %d) ========\n", flag); rockchip_wifi_power(1); diff --git a/drivers/net/wireless/rockchip_wlan/rkwifi/bcmdhd/dhd_linux.c b/drivers/net/wireless/rockchip_wlan/rkwifi/bcmdhd/dhd_linux.c index 7d48d53019f7..0e35b1763674 100644 --- a/drivers/net/wireless/rockchip_wlan/rkwifi/bcmdhd/dhd_linux.c +++ b/drivers/net/wireless/rockchip_wlan/rkwifi/bcmdhd/dhd_linux.c @@ -4879,6 +4879,7 @@ dhd_module_cleanup(void) extern bool g_wifi_poweron; #endif /* CONFIG_WIFI_CONTROL_FUNC */ + static int dhd_module_init(void) { @@ -5020,7 +5021,7 @@ fail_0: extern char WIFI_MODULE_NAME[]; extern char RKWIFI_DRV_VERSION[]; -static int __init rockchip_wifi_init_module(void) +int rockchip_wifi_init_module(void) { printk("=======================================================\n"); printk("==== Launching Wi-Fi driver! (Powered by Rockchip) ====\n"); @@ -5030,7 +5031,7 @@ static int __init rockchip_wifi_init_module(void) return dhd_module_init(); } -static void __exit rockchip_wifi_exit_module(void) +void rockchip_wifi_exit_module(void) { printk("=======================================================\n"); printk("== Dis-launching Wi-Fi driver! (Powered by Rockchip) ==\n"); @@ -5038,8 +5039,10 @@ static void __exit rockchip_wifi_exit_module(void) dhd_module_cleanup(); } -late_initcall(rockchip_wifi_init_module); -module_exit(rockchip_wifi_exit_module); +EXPORT_SYMBOL(rockchip_wifi_init_module); +EXPORT_SYMBOL(rockchip_wifi_exit_module); +//late_initcall(rockchip_wifi_init_module); +//module_exit(rockchip_wifi_exit_module); /* #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0) #ifdef USE_LATE_INITCALL_SYNC diff --git a/drivers/net/wireless/rockchip_wlan/rkwifi/bcmdhd/rkversion.c b/drivers/net/wireless/rockchip_wlan/rkwifi/bcmdhd/rkversion.c index 132928310cca..7654d8d1a673 100644 --- a/drivers/net/wireless/rockchip_wlan/rkwifi/bcmdhd/rkversion.c +++ b/drivers/net/wireless/rockchip_wlan/rkwifi/bcmdhd/rkversion.c @@ -10,7 +10,7 @@ */ -const char RKWIFI_DRV_VERSION[] = "4.75.WFD"; +const char RKWIFI_DRV_VERSION[] = "4.76.WFD"; const char WIFI_MODULE_NAME[] = ""; const char CONFIG_BCMDHD_FW_PATH[] = ""; diff --git a/drivers/net/wireless/rockchip_wlan/rkwifi/rk_wifi_config.c b/drivers/net/wireless/rockchip_wlan/rkwifi/rk_wifi_config.c index 0cedd82d2602..67ac0f887196 100644 --- a/drivers/net/wireless/rockchip_wlan/rkwifi/rk_wifi_config.c +++ b/drivers/net/wireless/rockchip_wlan/rkwifi/rk_wifi_config.c @@ -11,18 +11,6 @@ #include #include -/* Set INIT_COUNTRY_CODE - * "US" ---> 11 channels, this is default setting. - * "EU" ---> 13 channels - * "JP" ---> 14 channels - */ - -int rkwifi_set_country_code(char *code) -{ - sprintf(code, "%s", "EU"); - return 0; -} - /* * Set Firmware Path */ @@ -107,12 +95,4 @@ int rkwifi_set_firmware(char *fw, char *nvram) return 0; } -extern int wifi_pcba_test; -int rkwifi_pcba_status(void) -{ - return wifi_pcba_test; -} - -EXPORT_SYMBOL(rkwifi_set_country_code); EXPORT_SYMBOL(rkwifi_set_firmware); -EXPORT_SYMBOL(rkwifi_pcba_status); diff --git a/drivers/net/wireless/rockchip_wlan/wifi_sys/rkwifi_sys_iface.c b/drivers/net/wireless/rockchip_wlan/wifi_sys/rkwifi_sys_iface.c index 9c3a74b8906e..12485130c081 100755 --- a/drivers/net/wireless/rockchip_wlan/wifi_sys/rkwifi_sys_iface.c +++ b/drivers/net/wireless/rockchip_wlan/wifi_sys/rkwifi_sys_iface.c @@ -8,50 +8,12 @@ #include #include #include +#include -#ifdef CONFIG_MACH_RK_FAC -#include -extern int wifi_type; -#endif -#if 1//(LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) static ssize_t wifi_chip_read(struct class *cls, struct class_attribute *attr, char *_buf) -#else -static ssize_t wifi_chip_read(struct class *cls, char *_buf) -#endif { int count = 0; -#ifdef CONFIG_MACH_RK_FAC - if(wifi_type==WIFI_TYPE_RTL8188CU) { - count = sprintf(_buf, "%s", "RTL8188CU"); - printk("Current WiFi chip is RTL8188CU.\n"); - return count; - } else if(wifi_type==WIFI_TYPE_RTL8188EU) { - count = sprintf(_buf, "%s", "RTL8188EU"); - printk("Current WiFi chip is RTL8188EU.\n"); - return count; - } else if(wifi_type==WIFI_TYPE_MT7601) { - count = sprintf(_buf, "%s", "MT7601"); - printk("Current WiFi chip is MT7601.\n"); - return count; - } else if(wifi_type==WIFI_TYPE_RTL8188ETV) { - count = sprintf(_buf, "%s", "RTL8188ETV"); - printk("Current WiFi chip is RTL8188ETV.\n"); - return count; - } else if(wifi_type==WIFI_TYPE_MT5370) { - count = sprintf(_buf, "%s", "MT5370"); - printk("Current WiFi chip is MT5370.\n"); - return count; - } else { - //printk("NOT surpport type %d\n",wifi_type); - } -#endif - -#ifdef CONFIG_BCM4329 - count = sprintf(_buf, "%s", "BCM4329"); - printk("Current WiFi chip is BCM4329.\n"); -#endif - #ifdef CONFIG_RTL8192CU count = sprintf(_buf, "%s", "RTL8188CU"); printk("Current WiFi chip is RTL8188CU.\n"); @@ -77,11 +39,6 @@ static ssize_t wifi_chip_read(struct class *cls, char *_buf) printk("Current WiFi chip is RTL8723BS.\n"); #endif -#ifdef CONFIG_RTL8189ES - count = sprintf(_buf, "%s", "RTL8189ES"); - printk("Current WiFi chip is RTL8189ES.\n"); -#endif - #ifdef CONFIG_BCM4330 count = sprintf(_buf, "%s", "BCM4330"); printk("Current WiFi chip is BCM4330.\n"); @@ -147,11 +104,6 @@ static ssize_t wifi_chip_read(struct class *cls, char *_buf) printk("Current WiFi chip is MT6620.\n"); #endif -#ifdef CONFIG_RT5370 - count = sprintf(_buf, "%s", "RT5370"); - printk("Current WiFi chip is RT5370.\n"); -#endif - #ifdef CONFIG_MT5931 count = sprintf(_buf, "%s", "MT5931"); printk("Current WiFi chip is MT5931.\n"); @@ -172,12 +124,6 @@ static ssize_t wifi_chip_read(struct class *cls, char *_buf) printk("Current WiFi chip is MT7601.\n"); #endif - -#ifdef CONFIG_RTL8723AS - count = sprintf(_buf, "%s", "RTL8723AS"); - printk("Current WiFi chip is RTL8723AS.\n"); -#endif - #ifdef CONFIG_ESP8089 count = sprintf(_buf, "%s", "ESP8089"); printk("Current WiFi chip is ESP8089.\n"); @@ -186,200 +132,55 @@ static ssize_t wifi_chip_read(struct class *cls, char *_buf) return count; } -/* -static ssize_t wifi_channel_write(struct class *cls, const char *_buf, size_t _count) +static ssize_t wifi_power_write(struct class *cls, struct class_attribute *attr, const char *_buf, size_t _count) { - int ret, channel; - - if (wifi_enabled == 0) - { - printk("WiFi is disabled.\n"); - return _count; - } - - channel = simple_strtol(_buf, NULL, 10); - - ret = wifi_emi_set_channel(channel); - if (ret != 0) - { - //printk("Set channel=%d fail.\n", channel); - } - else - { - //printk("Set channel=%d successfully.\n", channel); - wifi_channel = channel; + int poweren = 0; + poweren = simple_strtol(_buf, NULL, 10); + printk("%s: poweren = %d\n", __func__, poweren); + if(poweren > 0) { + rockchip_wifi_power(1); + } else { + rockchip_wifi_power(0); } - - return _count; -} -*/ - -#if 1//(LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) -static ssize_t wifi_p2p_read(struct class *cls, struct class_attribute *attr, char *_buf) -#else -static ssize_t wifi_p2p_read(struct class *cls, char *_buf) -#endif -{ - int count = 0; - -#ifdef CONFIG_BK3515A_COMBO - count = sprintf(_buf, "%s", "BK3515A"); - printk("Current WiFi chip is ESP8089+BK3515A Combo.\n"); -#endif -#ifdef CONFIG_BCM4329 - count = sprintf(_buf, "%s", "false"); - printk("Current WiFi chip BCM4329 doesn't support direct.(%s)\n", _buf); -#endif - -#ifdef CONFIG_RTL8192CU - count = sprintf(_buf, "%s", "false"); - printk("Current WiFi chip RTL8188 support direct.(%s)\n", _buf); -#endif - -#ifdef CONFIG_RK903 - count = sprintf(_buf, "%s", "true"); - printk("Current WiFi chip RK903 support direct.(%s)\n", _buf); -#endif - -#ifdef CONFIG_BCM4330 - count = sprintf(_buf, "%s", "true"); - printk("Current WiFi chip BCM4330 support direct.(%s)\n", _buf); -#endif - - return count; +return _count; } -int wifi_pcba_test = 0; +extern int rockchip_wifi_init_module(void); +extern void rockchip_wifi_exit_module(void); +static struct semaphore driver_sem; +static int wifi_driver_insmod = 0; -#if 1//(LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) -static ssize_t wifi_pcba_read(struct class *cls, struct class_attribute *attr, char *_buf) -#else -static ssize_t wifi_pcba_read(struct class *cls, char *_buf) -#endif +static ssize_t wifi_driver_write(struct class *cls, struct class_attribute *attr, const char *_buf, size_t _count) { - int count = 0; - - count = sprintf(_buf, "%d", wifi_pcba_test); - return count; -} - -#if 1//(LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) -static ssize_t wifi_pcba_write(struct class *cls, struct class_attribute *attr, const char *_buf, size_t _count) -#else -static ssize_t wifi_pcba_write(struct class *cls, char *_buf, size_t _count) -#endif -{ - wifi_pcba_test = simple_strtol(_buf, NULL, 10); - if(wifi_pcba_test > 0) { - wifi_pcba_test = 1; - } + int enable = 0, ret = 0; + + down(&driver_sem); + enable = simple_strtol(_buf, NULL, 10); + //printk("%s: enable = %d\n", __func__, enable); + if (wifi_driver_insmod == enable) { + printk("%s: wifi driver already %s\n", __func__, enable? "insmod":"rmmod"); + up(&driver_sem); return _count; -} - -#ifdef CONFIG_AIDC -int check_wifi_type_from_id(int id, char * _buf) { - int count = 0; - - switch(id) { - case 0x8179: - count = sprintf(_buf, "%s", "RTL8188EU"); - printk("Current WiFi chip is RTL8188EU.\n"); - break; - case 0x0179: - count = sprintf(_buf, "%s", "RTL8188EU"); - printk("Current WiFi chip is RTL8188ETV.\n"); - break; - case 0x5370: - count = sprintf(_buf, "%s", "RT5370"); - printk("Current WiFi chip is RT5370.\n"); - break; - case 0x0724: - count = sprintf(_buf, "%s", "RTL8723AU"); - printk("Current WiFi chip is RTL8723AU.\n"); - break; - case 0x8176: - count = sprintf(_buf, "%s", "RTL8188CU"); - printk("Current WiFi chip is RTL8188CU.\n"); - break; - case 0x018A: - count = sprintf(_buf, "%s", "RTL8188CU"); - printk("Current WiFi chip is RTL8188CTV.\n"); - break; - default: - printk("Unsupported usb wifi.............\n"); - } - return count; -} + } + if(enable > 0) { + ret = rockchip_wifi_init_module(); + if (ret >= 0) + wifi_driver_insmod = enable; + } else { + rockchip_wifi_exit_module(); + wifi_driver_insmod = enable; + } -extern int rk29sdk_wifi_power(int on); -extern int wifi_activate_usb(void); -extern int wifi_deactivate_usb(void); -#define USB_IDP_SYS_PATCH_1 "/sys/bus/usb/devices/1-1/idProduct" -#define USB_IDP_SYS_PATCH_2 "/sys/bus/usb/devices/2-1/idProduct" -#define USB_IDV_SYS_PATCH_1 "/sys/bus/usb/devices/1-1/idVendor" -#define USB_IDV_SYS_PATCH_2 "/sys/bus/usb/devices/2-1/idVendor" -#define USB_PRODUCT_SYS_PATCH "/sys/bus/usb/devices/1-1/product" -//5370 802.11 n WLAN -//8723 802.11n WLAN Adapter -//8188eu 802.11n NIC -//8188cu 802.11n WLAN Adapter -char aidc_type[20] = {0}; - -#if 1//(LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) -static ssize_t wifi_aidc_read(struct class *cls, struct class_attribute *attr, char *_buf) -#else -static ssize_t wifi_aidc_read(struct class *cls, char *_buf) -#endif -{ - int count = 0, retry = 10, idP = 0;// idV = 0; - ssize_t nread; - loff_t pos = 0; - char usbid[20] = {0}; - struct file *file = NULL; - mm_segment_t old_fs; - - sprintf(_buf, "%s", "UNKNOW"); - wifi_activate_usb(); - msleep(2000); - old_fs = get_fs(); - set_fs(KERNEL_DS); - while(retry--) { - file = filp_open(USB_IDP_SYS_PATCH_2, O_RDONLY, 0); - if (IS_ERR(file)) { - printk("\nCannot open \"%s\", retry = %d\n", USB_IDP_SYS_PATCH_2, retry); - file = filp_open(USB_IDP_SYS_PATCH_1, O_RDONLY, 0); - if (IS_ERR(file)) { - printk("\nCannot open \"%s\", retry = %d\n", USB_IDP_SYS_PATCH_1, retry); - msleep(500); - continue; - } - } - break; - } - if(retry <= 0) { - set_fs(old_fs); - return count; - } - nread = vfs_read(file, (char __user *)usbid, sizeof(usbid), &pos); - set_fs(old_fs); - filp_close(file, NULL); - wifi_deactivate_usb(); - idP = simple_strtol(usbid, NULL, 16); - printk("Get usb wifi idProduct = 0X%04X\n", idP); - count = check_wifi_type_from_id(idP, _buf); - - return count; + up(&driver_sem); + //printk("%s: ret = %d\n", __func__, ret); + return _count; } -#endif //CONFIG_AIDC static struct class *rkwifi_class = NULL; static CLASS_ATTR(chip, 0664, wifi_chip_read, NULL); -static CLASS_ATTR(p2p, 0664, wifi_p2p_read, NULL); -static CLASS_ATTR(pcba, 0664, wifi_pcba_read, wifi_pcba_write); -#ifdef CONFIG_AIDC -static CLASS_ATTR(aidc, 0664, wifi_aidc_read, NULL); -#endif +static CLASS_ATTR(power, 0222, NULL, wifi_power_write); +static CLASS_ATTR(driver, 0222, NULL, wifi_driver_write); int rkwifi_sysif_init(void) { @@ -397,11 +198,9 @@ int rkwifi_sysif_init(void) } ret = class_create_file(rkwifi_class, &class_attr_chip); - ret = class_create_file(rkwifi_class, &class_attr_p2p); - ret = class_create_file(rkwifi_class, &class_attr_pcba); -#ifdef CONFIG_AIDC - ret = class_create_file(rkwifi_class, &class_attr_aidc); -#endif + ret = class_create_file(rkwifi_class, &class_attr_power); + ret = class_create_file(rkwifi_class, &class_attr_driver); + sema_init(&driver_sem, 1); return 0; } @@ -410,11 +209,8 @@ void rkwifi_sysif_exit(void) { // need to remove the sys files and class class_remove_file(rkwifi_class, &class_attr_chip); - class_remove_file(rkwifi_class, &class_attr_p2p); - class_remove_file(rkwifi_class, &class_attr_pcba); -#ifdef CONFIG_AIDC - class_remove_file(rkwifi_class, &class_attr_aidc); -#endif + class_remove_file(rkwifi_class, &class_attr_power); + class_remove_file(rkwifi_class, &class_attr_driver); class_destroy(rkwifi_class); rkwifi_class = NULL; @@ -423,7 +219,7 @@ void rkwifi_sysif_exit(void) module_init(rkwifi_sysif_init); module_exit(rkwifi_sysif_exit); -MODULE_AUTHOR("Yongle Lai"); +MODULE_AUTHOR("Yongle Lai & gwl"); MODULE_DESCRIPTION("WiFi SYS @ Rockchip"); MODULE_LICENSE("GPL"); diff --git a/include/linux/rfkill-wlan.h b/include/linux/rfkill-wlan.h index d7fcba686231..7d80cee25d37 100755 --- a/include/linux/rfkill-wlan.h +++ b/include/linux/rfkill-wlan.h @@ -40,6 +40,7 @@ struct rksdmmc_gpio_wifi_moudle { void *rockchip_mem_prealloc(int section, unsigned long size); int rockchip_wifi_power(int on); +int rockchip_wifi_set_carddetect(void); int rockchip_wifi_reset(int on); int rockchip_wifi_mac_addr(unsigned char *buf); void *rockchip_wifi_country_code(char *ccode); diff --git a/net/rfkill/rfkill-wlan.c b/net/rfkill/rfkill-wlan.c index 81356127038b..49789bca1fe5 100755 --- a/net/rfkill/rfkill-wlan.c +++ b/net/rfkill/rfkill-wlan.c @@ -263,6 +263,18 @@ int rockchip_wifi_power(int on) } EXPORT_SYMBOL(rockchip_wifi_power); +/************************************************************************** + * + * Wifi Sdio Detect Func + * + *************************************************************************/ +extern int mmc_host_rescan(struct mmc_host *host); +int rockchip_wifi_set_carddetect(void) +{ + return mmc_host_rescan(NULL);//NULL => SDIO host +} +EXPORT_SYMBOL(rockchip_wifi_set_carddetect); + /************************************************************************** * * Wifi Reset Func @@ -502,7 +514,7 @@ static int rfkill_wlan_probe(struct platform_device *pdev) // Turn off wifi power as default if (gpio_is_valid(pdata->power_n.io)) { - gpio_direction_output(pdata->power_n.io, pdata->power_n.enable); + gpio_direction_output(pdata->power_n.io, !pdata->power_n.enable); } #if BCM_STATIC_MEMORY_SUPPORT -- 2.34.1