ELF 1开发板默认支持移远的ec20,使用扩展板的PCIE接口连接。ec20模块支持多种拨号上网方式,如PPP,AT指令,GobiNet,QMI_WWAN等,接下来我们移植USB Serial Option Driver和GobiNet Driver,其中USB Serial Option Driver移植之后,我们就可以使用AT指令与模块进行通信,对模块进行配置或者获取模块状态信息,也可以使用AT指令进行拨号上网;移植GobiNet Driver之后,Gobinet将会创建一个网络设备(ethX)。
USB Serial Option Driver移植
一、添加模块VID和PID
在drivers/usb/serial/option.c文件中的usb_device_id option_ids[]中添加移远ec20模块VID和PID:
| #if 1 //Added by Quectel
{ USB_DEVICE(0x2C7C, 0x0125) }, /* Quectel EC20 R2.0/EC20 R2.1/EC25/EG25-G/EM05 */ #endif |
效果如下:
二、增加零包处理相关代码
在文件drivers/usb/serial/usb_wwan.c中的*usb_wwan_setup_urb函数中添加如下代码:
| #if 1
if (dir == USB_DIR_OUT) { struct usb_device_descriptor *desc = &serial->dev->descriptor; if (desc->idVendor == cpu_to_le16(0x2C7C)) urb->transfer_flags |= URB_ZERO_PACKET; } #endif |
效果如下:
三、增加休眠唤醒相关代码
在drivers/usb/serial/option.c文件中的usb_serial_driver option_1port_device结构体中添加:
| #if 1 //Added by Quectel
.reset_resume = usb_wwan_resume, #endif |
效果如下:
四、添加兼容处理
如果需要对MBIM,GobiNet或者QMI_WWAN拨号模式的支持,则需要做兼容处理,我们接下来会做GobiNet拨号方式的支持,所以需要做兼容处理:
在drivers/usb/serial/option.c文件中的int option_probe函数中增加:
| #if 1 //Added by Quectel
//Quectel modules’s interface 4 can be used as USB network device if (serial->dev->descriptor.idVendor == cpu_to_le16(0x2C7C)) { //some interfaces can be used as USB Network device (ecm, rndis, mbim) if (serial->interface->cur_altsetting->desc.bInterfaceClass != 0xFF) { return -ENODEV; } //interface 4 can be used as USB Network device (qmi) else if (serial->interface->cur_altsetting->desc.bInterfaceNumber >= 4) { return -ENODEV; } } #endif |
效果如下:
五、内核配置
在以下路径添加USB driver for GSM and CDMA modems:
| Device Drivers
->USB support ->USB Serial Converter support |
至此,USB Serial Option Driver驱动移植完成,编译之后,下载到开发板,在/dev/即可看到生成4个虚拟串口节点:
这4个接口都有其不同通信作用,比如ttyUSB0主要用于USBDM调试,ttyUSB1用于获取GPS数据,ttyUSB2用于AT指令交互,ttyUSB3用于ppp拨号。我们主要使用ttyUSB2串口,进行AT指令交互。
我们可以使用发送几条AT命令进行简单测试:
| root@ELF1:~# cat /dev/ttyUSB2 & //打开串口回显
root@ELF1:~# echo AT > /dev/ttyUSB2 //发送AT返回OK说明4G模块正常通信 root@ELF1:~# echo AT+CPIN? > /dev/ttyUSB2 //查询sim卡状态,显示ready说明正常通信 root@ELF1:~# echo AT+CSQ > /dev/ttyUSB2 //查信号质量 |
GobiNet Driver移植
移远ec20支持ppp、GobiNet、QMI_WWAN多种拨号上网方式,我们使用GobiNet方式拨号上网,接下来移植GobiNet Driver。
一、复制驱动源码
将ELF 1开发板资料包
1669