[RK3288][Android6.0] WiFi的驱动初始化过程小结

Platform: Rockchip
OS: Android 6.0
Kernel: 3.10.92

用的是AP6335, SDIO接口。

电源相关部分:
rfkill_wlan_init -> rfkill-waln.c
  platform_driver_register -> //platform_driver是rfkill_wlan_driver, name是wlan-platdata,dts中配置
    rfkill_wlan_probe ->
      wlan_platdata_parse_dt //解析dts中关于wifi的配置,dts的说明参考前面一篇文章
      gpio_direction_output //默认关闭WiFi电源
      rockchip_wifi_voltage_select //设置IO power.

驱动加载:
另外,在dhd_linux.c中有:


#ifdef CONFIG_WIFI_LOAD_DRIVER_WHEN_KERNEL_BOOTUP
late_initcall(rockchip_wifi_init_module_rkwifi);
module_exit(rockchip_wifi_exit_module_rkwifi);
#else
EXPORT_SYMBOL(rockchip_wifi_init_module_rkwifi);
EXPORT_SYMBOL(rockchip_wifi_exit_module_rkwifi);
#endif


由于定义了CONFIG_WIFI_LOAD_DRIVER_WHEN_KERNEL_BOOTUP, 那么rockchip_wifi_init_module_rkwifi()也会被调用

rockchip_wifi_init_module_rkwifi -> dhd_linux.c
  get_wifi_chip_type -> 返回AP6335
  wifi_init_thread -> //单独一个线程去加载
    dhd_module_init ->
      dhd_wifi_platform_register_drv -> dhd_linux_platdev.c
        wifi_ctrlfunc_register_drv -> //CUSTOMER_HW的定义是在
        //kernel/drivers/net/wireless/rockchip_wlan/rkwifi/bcmdhd/Makefile中
          bcm_wlan_set_plat_data  dhd_gpio.c //设置wifi_platform_data里对应的函数,一会就要用到
          bcm_wlan_get_oob_irq //获取irq gpio,在前面的wlan_platdata_parse_dt()从dts获取到的
          dhd_wifi_platform_load ->
            wl_android_init ->
              bcm_strncpy_s //设置iface_name为"wlan"
              wl_netlink_init //初始化netlink socket,供和用户空间通信
            dhd_wifi_platform_load_sdio -> //加载sdio相关,如果是usb的,那么调dhd_wifi_platform_load_usb()
              dhd_bus_reg_sdio_notify -> dhd_sdio.c //传的dhd_chipup_sem后面用来判断sdio是否rescan成功
                bcmsdh_reg_sdio_notify -> bcmsdh_linux.c
                  bcmsdh_reg_sdio_notify ->
                    sdio_register_driver //注册sdio_driver: dummy_sdmmc_driver,
                                        //name: "dummy_sdmmc",这里device还没有
                                        //后面rescan会匹配上。
              wifi_platform_set_power -> //WiFi模块上电
                plat_data->set_power -> //在前面bcm_wlan_set_plat_data()赋值
                  bcm_wlan_set_power -> dhd_gpio.c
                   rockchip_wifi_power ->
                     gpio_set_value
              wifi_platform_bus_enumerate -> dhd_linux_platdev.c //枚举sdio
                plat_data->set_carddetect ->
                  bcm_wlan_set_carddetect ->
                    mmc_host_rescan -> host.c
                      host->ops->set_sdio_status ->
                        dw_mci_set_sdio_status -> Rk_sdmmc.c
                          mmc_detect_change -> //触发rescan,当发现总线上有设备时,会调用上面注册的"dummy_sdmmc"对应的probe
                            dummy_probe -> Bcmsdh_sdmmc_linux.c    //注意这里是异步的
                            up(notify_semaphore)    //释放了信号量
              down_timeout //另一方面,此线程还在等待信号量释放,正常返回表示探测到sdio设备,否则枚举失败
              wifi_platform_set_power //关闭WiFi电源
              dhd_bus_register ->
                bcmsdh_register -> //参数一会probe会用到,函数会打印vendor和device id.
                  bcmsdh_register_client_driver ->
                    sdio_register_driver -> //sdio_driver: bcmsdh_sdmmc_driver
                      driver_register ->
                        bcmsdh_sdmmc_probe -> sdio总线驱动检测到的id和bcmsdh_sdmmc_ids表里的匹配才会调用probe函数
                          sdioh_probe ->
                            bcmsdh_probe ->
                              drvinfo.probe -> driverinfo在bcmsdh_register()中赋值,对应dhd_sdio变量
                                dhdsdio_probe -> dhd_sdio.c
                                  dhd_attach ->
                                    dhd_update_fw_nv_path -> //关注下载固件部分
                                      //AP6335对应的是fw_bcm4339a0_ag.bin和nvram_AP6335.txt
                                      //在/system/etc/firmware/路径下存放
                                      rkwifi_set_firmware  rk_wifi_config.c
                                    dhd_allocate_if -> //分配网络设备
                                      alloc_etherdev
                                      wl_cfg80211_attach
                                   dhd_register_if -> 注册网络设备
                                     register_netdev


小结:
RK对WiFi驱动的初始化都在开机的时候完成了,在HAL层提供的接口虽然有调用,但是并未真正地去加载驱动。


参考:

Wifi模块全总结
在全志平台调试博通的wifi驱动(类似ap6212)                                                                     
                     

你可能感兴趣的:(子类__WiFi)