K230 SDK IoT WiFi AiW4211LV10驱动开发指南
1. 功能介绍
AiW4211LV10是一款低功耗IoT WiFi芯片,我司采用该芯片平台设计了一款AiW4211LV10开发板,该开发板可插入K230 EVB板的TF卡插槽实现接入。K230 EVB加载AiW4211LV10驱动之后,可以生成wlan0无线网卡,实现网络数据通信。
2. 模块依赖
硬件上依赖AiW4211LV10开发板,依赖K230 EVB开发板,K230 EVB为WiFi提供电源及中断检测连线。
软件上依赖于K230 SDIO主控驱动,依赖GPIO驱动的完备,需要emmc引导启动实现。
2.1 操作系统
当前驱动支持linux 4.9、linux 4.17和linux 5.10.4
2.2 硬件环境
K230 EVB开发板设置emmc启动,空出TF卡插槽用于AiW4211LV10开发板接入。
K230 EVB开发板飞线到AiW4211LV10开发板排针。连接关系如下:
表 2-1 飞线关系
Link1 | Link2 | Link3 | Link4 | Link5 | |
---|---|---|---|---|---|
K230排针 | J5 PIN16 (5V) | J8 PIN9 (GPIO34) | |||
WiFi排针 | J6 PIN1 (5V) | J2 PIN3 (SDIO_INT_OUT) | J2 PIN4 (TX) | J2 PIN5 (RX) | J2 PIN6 (GND) |
TTL-USB | RX | TX | GND |
备注:TTL-USB与WiFi的连线主要是为了观察WiFi的固件输出,可以不连接
3. 模块配置
3.1 设备树修改
3.1.1 配置引脚function
修改uboot设备树arch/riscv/dts/k230_evb.dts,配置K230 EVB IO52引脚功能为GPIO,方向为input:
&iomux {
pinctrl-names = "default";
pinctrl-0 = <&pins>;
pins: iomux_pins {
pinctrl-single,pins = <
......
(IO52) ( 0 <<SEL | 0<<SL | BANK_VOLTAGE_IO50_IO61<<MSC | 1<<IE | 0<<OE | 0<<PU | 1<<PD | 7<<DS | 0<<ST )
}
}
3.1.2 配置GPIO控制器
修改linux设备树arch/riscv/boot/dts/kendryte/gpio_provider.dtsi,配置K230 EVB GPIO52控制器:
/ {
......
gpio52: gpio52@9140c000 {
#address-cells = <1>;
#size-cells = <0>;
compatible = "canaan,k230-apb-gpio";
reg = <0x0 0x9140c000 0x0 0x1000>;
interrupt-controller;
interrupt-parent = <&intc>;
#interrupt-cells = <2>;
interrupts = <84 IRQ_TYPE_EDGE_RISING>;
port52: gpio-controller@0 {
gpio-controller;
#gpio-cells = <2>;
nr-gpios = <1>;
reg-bank = <0>;
id = <52>;
};
};
};
3.1.3 配置SDHCI1参数
修改linux设备树arch/riscv/boot/dts/kendryte/k230_evb.dtsi,配置对应sdio主控参数:
sdcard: sdhci1@91581000 {
compatible = "snps,dwcmshc-sdhci";
reg = <0x0 0x91581000 0x0 0x1000>;
interrupt-parent = <&intc>;
interrupts = <144>;
interrupt-names = "sdhci1irq";
clocks = <&dummy_sd>,<&dummy_sd>;
clock-names = "core", "bus";
max-frequency = <50000000>;
bus-width = <4>;
//cd-gpios = <>;
no-1-8-v;
cap-sd-highspeed;
sdhci,auto-cmd12;
status = "okay";
};
3.2 内核配置 项
通过内核配置将AiW4211LV10驱动编译为内核模块,并将必要的协议及驱动编入内核。
使能kprobes:
> General architecture-dependent options
|| [*] Kprobes
将cfg80211编入内核,注意需要选中 cfg80211 wireless extensions compatibility:
> Networking support > Wireless
│ --- Wireless │ │
│ │ <*> cfg80211 - wireless configuration API │ │
│ │ [ ] nl80211 testmode command │ │
│ │ [ ] enable developer warnings │ │
│ │ [ ] cfg80211 certification onus │ │
│ │ [*] enable powersave by default │ │
│ │ [ ] cfg80211 DebugFS entries │ │
│ │ [*] support CRDA │ │
│ │ [*] cfg80211 wireless extensions compatibility │ │
│ │ [ ] lib80211 debugging messages │ │
│ │ < > Generic IEEE 802.11 Networking Stack (mac80211)
将AiW4211LV10驱动编译成内核模块,注意需要选中 IEEE 802.11 for Host AP (Prism2/2.5/3 and WEP/TKIP/CCMP):
> Device Drivers > Network device support > Wireless LAN
│ --- Wireless LAN │ │
│ │ [ ] mac80211-based legacy WDS support │ │
│ │ [ ] ADMtek devices │ │
│ │ [*] Aich devices │ │
│ │ <M> Aich AiW4211LV10 (SDIO) support │
│ │ [ ] Atheros/Qualcomm devices │ │
│ │ [ ] Atmel devices │ │
│ │ [ ] Broadcom devices │ │
│ │ [ ] Cisco devices │ │
│ │ [ ] Intel devices │ │
│ │ [*] Intersil devices │ │
│ │ <*> IEEE 802.11 for Host AP (Prism2/2.5/3 and WEP/TKIP/CCMP)
│ │ [ ] Support downloading firmware images with Host AP driver │ │
│ │ [ ] Marvell devices │ │
│ │ [ ] MediaTek devices │ │
│ │ [ ] Microchip devices
3.3 SDIO主控增加扫描接口
AiW4211LV10驱动需要依据WiFi所接入的槽位发起SDIO扫描,因此特封装plat_sdio_rescan接口函数。修改drivers/mmc/host/sdhci-of-dwcmshc.c文件如下:
static unsigned int slot_index = 0;
static struct mmc_host \*__mmc__host[3] = {NULL};
int plat_sdio_rescan(int slot)
{
struct mmc_host \*mmc = \__mmc__host[slot];
if (mmc == NULL) {
pr_err("invalid mmc, please check the argument\\n");
return -EINVAL;
}
mmc_detect_change(mmc, 0);
return 0;
}
static int dwcmshc_probe(struct platform_device \*pdev)
{
......
priv->bus_clk = devm_clk_get(&pdev-\>dev, "bus");
if (!IS_ERR(priv->bus_clk))
clk_prepare_enable(priv->bus_clk);
__mmc__host[slot_index++] = host->mmc;
err = mmc_of_parse(host->mmc);
if (err)
goto err_clk;
......
}
4. 模块编译
在SDK顶层执行make linux,随内核一同编译,ko临时存储在output/k230_evb_defconfig/little/linux/drivers/net/wireless/aich/aiw4211lv10/目录。
5. 模块启动
5.1 WiFi固件
在K230 SDK当中WiFi固件AiW4211L_demo_allinone.bin以二进制文件形式提供,如需源码请联系我们。
固件存储路径:k230_sdk/src/little/utils/firmware/AiW4211L_demo_allinone.bin