How To Tune The SDIO Wifi PDF

Download as pdf or txt
Download as pdf or txt
You are on page 1of 16

Amlogic Application Notes

Application Notes

How to tune the SDIO wifi


Revision 0.1

Amlogic, Inc.
3930 Freedom Circle
Santa Clara, CA 95054
U.S.A.
www.amlogic.com

Legal Notices
© 2013 Amlogic, Inc. All rights reserved. Amlogic ® is registered trademarks of Amlogic, Inc. All other
registered trademarks, trademarks and service marks are property of their respective owners.

This document is Amlogic Company confidential and is not intended for any external distribution.

Amlogic Confidential 1/16


Amlogic Application Notes

Table of Contents

Table of Contents................................................................................................................................................................... 2
1. Overview.............................................................................................................................................................................4
1.1 Purpose of this document........................................................................................................................................... 4
2. Software operation............................................................................................................................................................ 5
2.1 Kernel 配置.................................................................................................................................................................. 5
config 文件 配置.............................................................................................................................................................5
BSP 文件配置................................................................................................................................................................. 5
2.2 Rootfs 配置(android 4.1)............................................................................................................................................ 7
Init.rc 配置......................................................................................................................................................................7
BoadConfig.mk 配置...................................................................................................................................................... 9
xxxx.mk 配置..................................................................................................................................................................9
2.3 Rootfs 配置(android 4.2)..................................................................................................................................... 10
Init.rc 配置................................................................................................................................................................... 11
Xxxx.mk.........................................................................................................................................................................11
3. Sample.............................................................................................................................................................................. 12
3.1 Android 4.1 AP6181 移植......................................................................................................................................... 12

Amlogic Confidential 2/16


Amlogic Application Notes

Revision history

Revision Date Owner Changes


0.1 January 11, 2013 Jiamin

Amlogic Confidential 3/16


Amlogic Application Notes

1. Overview
1.1 Purpose of this document
This document tells users how to tune the SDIO wifi

Amlogic Confidential 4/16


Amlogic Application Notes

2. Software operation
2.1 Kernel 配置

Kernel 的配置主要是修改 common/customer 目录下对应的 deconfig 文件和 BSP 文件。

config 文件 配置
CONFIG_AM_WIFI=y
CONFIG_AM_WIFI_SD_MMC=y
CONFIG_SDIO_DHD_CDC_WIFI_40181_MODULE=m
CONFIG_SDIO_DHD_CDC_WIFI_AP6xxx_MODULE=m(4.1 上的 AP6xxx 使用该 config)
CONFIG_BCM40181_WIFI=y
CONFIG_SDIO_HARD_IRQ=n
CONFIG_BCM40181_HW_OOB=y
CONFIG_BCM40181_OOB_INTR_ONLY=y
CONFIG_BCM40181_POWER_ALWAYS_ON=y(这个 config,只有在硬件上支持系统休眠时,能对 wifi 持续供
电的情况下,才添加)

BSP 文件配置
SDIO 卡配置

红色部分是 SDIO 卡设置


static struct aml_card_info meson_card_info[] = {
[0] = {
.name = "sd_card",
.work_mode = CARD_HW_MODE,
.io_pad_type = SDHC_CARD_0_5,
.card_ins_en_reg = CARD_GPIO_ENABLE,
.card_ins_en_mask = PREG_IO_29_MASK,
.card_ins_input_reg = CARD_GPIO_INPUT,
.card_ins_input_mask = PREG_IO_29_MASK,
.card_power_en_reg = CARD_GPIO_ENABLE,
.card_power_en_mask = PREG_IO_31_MASK,
.card_power_output_reg = CARD_GPIO_OUTPUT,
.card_power_output_mask = PREG_IO_31_MASK,
.card_power_en_lev = 0,
.card_wp_en_reg = 0,
.card_wp_en_mask = 0,
.card_wp_input_reg = 0,

Amlogic Confidential 5/16


Amlogic Application Notes

.card_wp_input_mask = 0,
.card_extern_init = 0,
},
#if 1
[1] = {
.name = "sdio_card",
.work_mode = CARD_HW_MODE,
.io_pad_type = SDHC_GPIOX_0_9,
.card_ins_en_reg = 0,
.card_ins_en_mask = 0,
.card_ins_input_reg = 0,
.card_ins_input_mask = 0,
.card_power_en_reg = 0,
.card_power_en_mask = 0,
.card_power_output_reg = 0,
.card_power_output_mask = 0,
.card_power_en_lev = 0,
.card_wp_en_reg = 0,
.card_wp_en_mask = 0,
.card_wp_input_reg = 0,
.card_wp_input_mask = 0,
.card_extern_init = sdio_extern_init,
},
#endif
};

wifi 32K 时钟设置


static void wifi_clock_enable(int is_on)
{
//set clk 32k for wifi
//GPIOX_12 (CLK_OUT3) //reg : 108b sr_sl:22-25 div:13-19 enable:21

gpio_set_status(PAD_GPIOX_12,gpio_status_out); //set GPIOX_12 out


aml_set_reg32_mask(P_HHI_GEN_CLK_CNTL2,1<<22);//set clk source
aml_clr_reg32_mask(P_HHI_GEN_CLK_CNTL2,0x3f<<13);//set div ==1
aml_set_reg32_mask(P_HHI_GEN_CLK_CNTL2,1<<21);//set enable clk
aml_set_reg32_mask(P_PERIPHS_PIN_MUX_3,0x1<<21);//set mode GPIOX_12-->CLK_OUT3
}

WIFI 上电引脚,中断引脚 gpio 设置,以及 sdio 接口的内部上拉设置


static void wifi_gpio_init(void)
{
//set status
//WIFI_EN WIFI_PWREN WLAN_RST --->out :0
gpio_set_status(PAD_GPIOC_8,gpio_status_out);
//WIFI_WAKE -->1GPIOX_11 in :
gpio_set_status(PAD_GPIOX_11,gpio_status_in);

Amlogic Confidential 6/16


Amlogic Application Notes

//set pull-up
aml_clr_reg32_mask(P_PAD_PULL_UP_REG4,0xf|1<<8|1<<9|1<<11|1<<12);
aml_clr_reg32_mask(P_PAD_PULL_UP_REG2,1<<7|1<<8|1<<9);
}

WIFI 上电函数

void extern_wifi_set_enable(int is_on)


{
DBG_LINE_INFO();
gpio_set_status(PAD_GPIOC_8,gpio_status_out);//set wifi_en gpio mode out
if(is_on){
gpio_out(PAD_GPIOC_8,1);
printk("WIFI Enable! \n");
}
else{
gpio_out(PAD_GPIOC_8,0);
printk("WIFI Disenable! \n");
}
}

WIFI wake 中断设置

在 sdio_extern_init 函数中添加
gpio_set_status(PAD_GPIOX_11,gpio_status_in);
gpio_irq_set(PAD_GPIOX_11,GPIO_IRQ(4,GPIO_IRQ_HIGH));

2.2 Rootfs 配置(android


(android 4.1)
对于 rootfs 上的设置,主要在 device/amlogic/xxxx(对应的项目名)目录下,对以下三个文件进行修改:
1. init.rc
2. BoardConfig.mk
3. Xxx.mk

Init .rc 配置
Init.rc

创建一些 wifi 使用的配置目录


on post-fs-data
mkdir /data/misc/wifi 0770 wifi wifi
mkdir /data/misc/wifi/sockets 0770 wifi wifi
chmod 0770 /data/misc/wifi
chmod 0660 /data/misc/wifi/wpa_supplicant.conf

Amlogic Confidential 7/16


Amlogic Application Notes

chown wifi wifi /data/misc/wifi


chown wifi wifi /data/misc/wifi/sockets
chown wifi wifi /data/misc/wifi/wpa_supplicant.conf

on boot
setprop wifi.interface wlan0
mkdir /data/misc/dhcp 0770 dhcp dhcp
chmod 0770 /data/misc/dhcp

添加 wifi 相关的 service

service wpa_supplicant /system/bin/wpa_supplicant \


-iwlan0 -Dnl80211 -c/data/misc/wifi/wpa_supplicant.conf -e/data/misc/wifi/entropy.bin
# user wifi
# group wifi inet keystore
class main
socket wpa_wlan0 dgram 0660 wifi wifi
disabled
oneshot

service dhcpcd_wlan0 /system/bin/dhcpcd -ABKL


class main
group dhcp system
disabled
oneshot

需要支持 p2p 的话则需添加


service p2p_supplicant /system/bin/wpa_supplicant \
-iwlan0 -Dnl80211 -c/data/misc/wifi/wpa_supplicant.conf \
-N -ip2p0 -Dnl80211 -c/data/misc/wifi/p2p_supplicant.conf -e/data/misc/wifi/entropy.bin -
puse_p2p_group_interface=1
# user wifi
# group wifi inet keystore
class main
socket wpa_wlan0 dgram 0660 wifi wifi
disabled
oneshot

service dhcpcd_p2p /system/bin/dhcpcd -ABKL


class main
group dhcp system
disabled
oneshot

hostap 服务添加
service hostapd /system/bin/hostapd_wps /data/misc/wifi/hostapd.conf

Amlogic Confidential 8/16


Amlogic Application Notes

class main
disabled
oneshot

BoadConfig .mk 配置
BoadConfig.mk

指定 wifi 驱动的名字,以及 firmware 的位置


WIFI_DRIVER := bcm40183
WIFI_DRIVER_MODULE_PATH := /system/lib/dhd.ko
WIFI_DRIVER_MODULE_NAME := dhd
WIFI_DRIVER_MODULE_ARG := "firmware_path=/etc/wifi/40183/fw_bcm40183b2.bin
nvram_path=/etc/wifi/40183/nvram.txt"
WIFI_DRIVER_FW_PATH_STA :=/etc/wifi/40183/fw_bcm40183b2.bin
WIFI_DRIVER_FW_PATH_AP :=/etc/wifi/40183/fw_bcm40183b2_apsta.bin
WIFI_DRIVER_FW_PATH_P2P :=/etc/wifi/40183/fw_bcm40183b2_p2p.bin

#WIFI_DRIVER := bcm40181
#WIFI_DRIVER_MODULE_PATH := /system/lib/dhd.ko
#WIFI_DRIVER_MODULE_NAME := dhd
#WIFI_DRIVER_MODULE_ARG := "firmware_path=/etc/wifi/40181/fw_bcm40181a2.bin
nvram_path=/etc/wifi/40181/nvram.txt"
#WIFI_DRIVER_FW_PATH_STA :=/etc/wifi/40181/fw_bcm40181a2.bin
#WIFI_DRIVER_FW_PATH_AP :=/etc/wifi/40181/fw_bcm40181a2_apsta.bin
#WIFI_DRIVER_FW_PATH_P2P :=/etc/wifi/40181/fw_bcm40181a2_p2p.bin

BOARD_WLAN_DEVICE := bcmdhd
WIFI_DRIVER_FW_PATH_PARAM := "/sys/module/dhd/parameters/firmware_path"

WPA_SUPPLICANT 设置

WPA_SUPPLICANT_VERSION := VER_0_8_X
BOARD_WPA_SUPPLICANT_DRIVER := NL80211
BOARD_WPA_SUPPLICANT_PRIVATE_LIB := lib_driver_cmd_bcmdhd
BOARD_HOSTAPD_DRIVER := NL80211
BOARD_HOSTAPD_PRIVATE_LIB := lib_driver_cmd_bcmdhd

xxxx.mk 配置
xxx.mk

wifi firmware 以及 wpa_supplicant.conf 拷贝


# WiFi
PRODUCT_PACKAGES += \

Amlogic Confidential 9/16


Amlogic Application Notes

40183/nvram.txt \
40183/fw_bcm40183b2.bin \
40183/fw_bcm40183b2_apsta.bin \
40183/fw_bcm40183b2_p2p.bin \
wl \
dhd \
wpa_supplicant.conf

PRODUCT_PACKAGES += \
40181/nvram.txt \
40181/fw_bcm40181a2.bin \
40181/fw_bcm40181a2_apsta.bin \
40181/fw_bcm40181a2_p2p.bin \
wl \
dhd \
wpa_supplicant.conf

AP6xxx 模块的 firmware 都放在 hardware/amlogic/wifi/AP6xxx 目录下,以下是 AP6181 的 firmware 拷贝,其


他模块也按照相应的目录进行拷贝

PRODUCT_COPY_FILES += hardware/amlogic/wifi/AP6xxx/AP6181/Wi-
Fi/fw_bcm40181a2.bin:system/etc/wifi/40181/fw_bcm40181a2.bin
PRODUCT_COPY_FILES += hardware/amlogic/wifi/AP6xxx/AP6181/Wi-
Fi/fw_bcm40181a2_apsta.bin:system/etc/wifi/40181/fw_bcm40181a2_apsta.bin
PRODUCT_COPY_FILES += hardware/amlogic/wifi/AP6xxx/AP6181/Wi-
Fi/fw_bcm40181a2_p2p.bin:system/etc/wifi/40181/fw_bcm40181a2_p2p.bin
PRODUCT_COPY_FILES += hardware/amlogic/wifi/AP6xxx/AP6181/Wi-
Fi/nvram_ap6181.txt:system/etc/wifi/40181/nvram.txt

添加 wifi 的 xml 文件
PRODUCT_COPY_FILES += \
frameworks/native/data/etc/android.hardware.wifi.xml:system/etc/permissions/android.hardware.wifi.xml \
frameworks/native/data/etc/android.hardware.wifi.direct.xml:system/etc/permissions/android.hardware.wifi.dire
ct.xml \
(注:android.hardware.wifi.direct.xml 需要平台支持 wifi p2p 才添加)

拷贝驱动模块
PRODUCT_COPY_FILES += $(LOCAL_PATH)/dhd.ko:system/lib/dhd.ko

2.3 Rootfs 配置(android


android 4.2
4.2)
Android 4.2 中很多 wifi 公共性的配置已经放在 device/amlogic/common/wifi.mk 中了,所以我们只需要配置两
个文件:init.rc 和 xxxx.mk

Amlogic Confidential 10/16


10/
Amlogic Application Notes

Init.rc 配置
Init.rc 配置与 android 4.1 一样,请参考 4.1 的配置

Xxxx.mk

若平台的 wifi 芯片是 40181


则配置为
WIFI_MODULE := bcm40181
include device/amlogic/common/wifi.mk

若平台的 wifi 芯片是 40183


则配置为
WIFI_MODULE := bcm40183
include device/amlogic/common/wifi.mk

Amlogic Confidential 11/16


11/
Amlogic Application Notes

3. Sample
3.1 Android 4.1 AP6181 移植

Config 文件修改

添加 Sdio wifi 相关的 config,请参考 2.1 Kernel 配置的 config 文件配置这一节

BSP 文件修改

这里 wifi_wake 脚是 GPIOX11,wifi_en 脚是 GPIOAO3

Wifi_wake 中断设置以及 sdio 卡设置


static void sdio_extern_init(void)
{
gpio_set_status(PAD_GPIOX_11,gpio_status_in);
gpio_irq_set(PAD_GPIOX_11,GPIO_IRQ(4,GPIO_IRQ_HIGH));

#ifdef CONFIG_AM_WIFI
extern_wifi_set_enable(1);
#endif
}

static struct aml_card_info meson_card_info[] = {


[0] = {
.name = "sd_card",
.work_mode = CARD_HW_MODE,
.io_pad_type = SDHC_CARD_0_5,
.card_ins_en_reg = CARD_GPIO_ENABLE,
.card_ins_en_mask = PREG_IO_29_MASK,
.card_ins_input_reg = CARD_GPIO_INPUT,
.card_ins_input_mask = PREG_IO_29_MASK,
.card_power_en_reg = CARD_GPIO_ENABLE,
.card_power_en_mask = PREG_IO_31_MASK,
.card_power_output_reg = CARD_GPIO_OUTPUT,
.card_power_output_mask = PREG_IO_31_MASK,
.card_power_en_lev = 0,
.card_wp_en_reg = 0,
.card_wp_en_mask = 0,
.card_wp_input_reg = 0,
.card_wp_input_mask = 0,
.card_extern_init = 0,
},

Amlogic Confidential 12/16


12/
Amlogic Application Notes

#if 1
[1] = {
.name = "sdio_card",
.work_mode = CARD_HW_MODE,
.io_pad_type = SDHC_GPIOX_0_9,
.card_ins_en_reg = 0,
.card_ins_en_mask = 0,
.card_ins_input_reg = 0,
.card_ins_input_mask = 0,
.card_power_en_reg = 0,
.card_power_en_mask = 0,
.card_power_output_reg = 0,
.card_power_output_mask = 0,
.card_power_en_lev = 0,
.card_wp_en_reg = 0,
.card_wp_en_mask = 0,
.card_wp_input_reg = 0,
.card_wp_input_mask = 0,
.card_extern_init = sdio_extern_init,
},
#endif
};

时钟及上电 GPIO 设置

static void wifi_gpio_init(void)


{
//set status
//WIFI_EN WIFI_PWREN WLAN_RST --->out :0
gpio_set_status(PAD_GPIOAO_3,gpio_status_out);
//WIFI_WAKE -->1GPIOX_11 in :
gpio_set_status(PAD_GPIOX_11,gpio_status_in);
//set pull-up
aml_clr_reg32_mask(P_PAD_PULL_UP_REG4,0xf|1<<8|1<<9|1<<11|1<<12);
aml_clr_reg32_mask(P_PAD_PULL_UP_REG2,1<<7|1<<8|1<<9);
}

static void wifi_clock_enable(int is_on)


{
//set clk 32k for wifi
//GPIOX_12 (CLK_OUT3) //reg : 108b sr_sl:22-25 div:13-19 enable:21
DBG_LINE_INFO();

gpio_set_status(PAD_GPIOX_12,gpio_status_out); //set GPIOX_12 out


aml_set_reg32_mask(P_HHI_GEN_CLK_CNTL2,1<<22);//set clk source
aml_clr_reg32_mask(P_HHI_GEN_CLK_CNTL2,0x3f<<13);//set div ==1
aml_set_reg32_mask(P_HHI_GEN_CLK_CNTL2,1<<21);//set enable clk
aml_set_reg32_mask(P_PERIPHS_PIN_MUX_3,0x1<<21);//set mode GPIOX_12-->CLK_OUT3
}

Amlogic Confidential 13/16


13/
Amlogic Application Notes

void extern_wifi_set_enable(int is_on)


{
DBG_LINE_INFO();
gpio_set_status(PAD_GPIOAO_3,gpio_status_out);//set wifi_en gpio mode out
if(is_on){
gpio_out(PAD_GPIOAO_3,1);
printk("WIFI Enable! \n");
}
else{
gpio_out(PAD_GPIOAO_3,0);
printk("WIFI Disenable! \n");
}
}
EXPORT_SYMBOL(extern_wifi_set_enable);

.....

void wifi_dev_init(void)
{
DBG_LINE_INFO();
wifi_clock_enable(1);
udelay(200);
wifi_gpio_init();

在 meson_init_machine 函数中添加 wifi_dev_init 函数调用

BoardConfig.mk 修改

WIFI_DRIVER := bcm40181
WIFI_DRIVER_MODULE_PATH := /system/lib/dhd.ko
WIFI_DRIVER_MODULE_NAME := dhd
WIFI_DRIVER_MODULE_ARG := "firmware_path=/etc/wifi/40181/fw_bcm40181a2.bin
nvram_path=/etc/wifi/40181/nvram.txt"
WIFI_DRIVER_FW_PATH_STA :=/etc/wifi/40181/fw_bcm40181a2.bin
WIFI_DRIVER_FW_PATH_AP :=/etc/wifi/40181/fw_bcm40181a2_apsta.bin
WIFI_DRIVER_FW_PATH_P2P :=/etc/wifi/40181/fw_bcm40181a2_p2p.bin

BOARD_WLAN_DEVICE := bcmdhd
WIFI_DRIVER_FW_PATH_PARAM := "/sys/module/dhd/parameters/firmware_path"

WPA_SUPPLICANT_VERSION := VER_0_8_X
BOARD_WPA_SUPPLICANT_DRIVER := NL80211
BOARD_WPA_SUPPLICANT_PRIVATE_LIB := lib_driver_cmd_bcmdhd
BOARD_HOSTAPD_DRIVER := NL80211
BOARD_HOSTAPD_PRIVATE_LIB := lib_driver_cmd_bcmdhd

Amlogic Confidential 14/16


14/
Amlogic Application Notes

xxxx.mk 修改

# WiFi
PRODUCT_PACKAGES += \
40181/nvram.txt \
40181/fw_bcm40181a2.bin \
40181/fw_bcm40181a2_apsta.bin \
40181/fw_bcm40181a2_p2p.bin \
wl \
dhd \
wpa_supplicant.conf

PRODUCT_COPY_FILES += \
frameworks/native/data/etc/android.hardware.wifi.xml:system/etc/permissions/android.hardware.wifi.xml \
frameworks/native/data/etc/android.hardware.wifi.direct.xml:system/etc/permissions/android.hardware.wifi.dire
ct.xml \

PRODUCT_COPY_FILES += hardware/amlogic/wifi/AP6xxx/AP6181/Wi-
Fi/fw_bcm40181a2.bin:system/etc/wifi/40181/fw_bcm40181a2.bin
PRODUCT_COPY_FILES += hardware/amlogic/wifi/AP6xxx/AP6181/Wi-
Fi/fw_bcm40181a2_apsta.bin:system/etc/wifi/40181/fw_bcm40181a2_apsta.bin
PRODUCT_COPY_FILES += hardware/amlogic/wifi/AP6xxx/AP6181/Wi-
Fi/fw_bcm40181a2_p2p.bin:system/etc/wifi/40181/fw_bcm40181a2_p2p.bin
PRODUCT_COPY_FILES += hardware/amlogic/wifi/AP6xxx/AP6181/Wi-
Fi/nvram_ap6181.txt:system/etc/wifi/40181/nvram.txt

PRODUCT_COPY_FILES += $(LOCAL_PATH)/dhd.ko:system/lib/dhd.ko

Init.rc 修改

on post-fs-data
mkdir /data/misc/wifi 0770 wifi wifi
mkdir /data/misc/wifi/sockets 0770 wifi wifi
chmod 0770 /data/misc/wifi
chmod 0660 /data/misc/wifi/wpa_supplicant.conf
chown wifi wifi /data/misc/wifi
chown wifi wifi /data/misc/wifi/sockets
chown wifi wifi /data/misc/wifi/wpa_supplicant.conf

on boot
setprop wifi.interface wlan0
mkdir /data/misc/dhcp 0770 dhcp dhcp
chmod 0770 /data/misc/dhcp

Amlogic Confidential 15/16


15/
Amlogic Application Notes

Service 添加
service p2p_supplicant /system/bin/wpa_supplicant \
-iwlan0 -Dnl80211 -c/data/misc/wifi/wpa_supplicant.conf \
-N -ip2p0 -Dnl80211 -c/data/misc/wifi/p2p_supplicant.conf -e/data/misc/wifi/entropy.bin -
puse_p2p_group_interface=1
# user wifi
# group wifi inet keystore
class main
socket wpa_wlan0 dgram 0660 wifi wifi
disabled
oneshot

service wpa_supplicant /system/bin/wpa_supplicant \


-iwlan0 -Dnl80211 -c/data/misc/wifi/wpa_supplicant.conf -e/data/misc/wifi/entropy.bin
# user wifi
# group wifi inet keystore
class main
socket wpa_wlan0 dgram 0660 wifi wifi
disabled
oneshot

service hostapd /system/bin/hostapd_wps /data/misc/wifi/hostapd.conf


class main
disabled
oneshot

service dhcpcd_wlan0 /system/bin/dhcpcd -ABKL


class main
group dhcp system
disabled
oneshot

service dhcpcd_p2p /system/bin/dhcpcd -ABKL


class main
group dhcp system
disabled
oneshot

service iprenew_wlan0 /system/bin/dhcpcd -n


class main
disabled
oneshot

service iprenew_p2p /system/bin/dhcpcd -n


class main
disabled
oneshot

Amlogic Confidential 16/16


16/

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy