ELF?1開發(fā)板默認(rèn)支持移遠(yuǎn)的ec20,使用擴(kuò)展板的PCIE接口連接。ec20模塊支持多種撥號上網(wǎng)方式,如PPP,AT指令,GobiNet,QMI_WWAN等,接下來我們移植USB Serial Option Driver和GobiNet Driver,其中USB Serial Option Driver移植之后,我們就可以使用AT指令與模塊進(jìn)行通信,對模塊進(jìn)行配置或者獲取模塊狀態(tài)信息,也可以使用AT指令進(jìn)行撥號上網(wǎng);移植GobiNet Driver之后,Gobinet將會創(chuàng)建一個網(wǎng)絡(luò)設(shè)備(ethX)。
USB Serial Option Driver移植
一、添加模塊VID和PID
在drivers/usb/serial/option.c文件中的usb_device_id option_ids[]中添加移遠(yuǎn)ec20模塊VID和PID:
#if 1 //Added by Quectel
{ USB_DEVICE(0x2C7C, 0x0125) }, /* Quectel EC20 R2.0/EC20 R2.1/EC25/EG25-G/EM05 */ #endif |
效果如下:
二、增加零包處理相關(guān)代碼
在文件drivers/usb/serial/usb_wwan.c中的*usb_wwan_setup_urb函數(shù)中添加如下代碼:
#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 |
效果如下:
三、增加休眠喚醒相關(guān)代碼
在drivers/usb/serial/option.c文件中的usb_serial_driver option_1port_device結(jié)構(gòu)體中添加:
#if 1 //Added by Quectel
.reset_resume = usb_wwan_resume, #endif |
效果如下:
四、添加兼容處理
如果需要對MBIM,GobiNet或者QMI_WWAN撥號模式的支持,則需要做兼容處理,我們接下來會做GobiNet撥號方式的支持,所以需要做兼容處理:
在drivers/usb/serial/option.c文件中的int option_probe函數(shù)中增加:
#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 |
效果如下:
五、內(nèi)核配置
在以下路徑添加USB driver for GSM and CDMA modems:
Device Drivers
->USB support ->USB Serial Converter support |
至此,USB Serial Option Driver驅(qū)動移植完成,編譯之后,下載到開發(fā)板,在/dev/即可看到生成4個虛擬串口節(jié)點(diǎn):
這4個接口都有其不同通信作用,比如ttyUSB0主要用于USBDM調(diào)試,ttyUSB1用于獲取GPS數(shù)據(jù),ttyUSB2用于AT指令交互,ttyUSB3用于ppp撥號。我們主要使用ttyUSB2串口,進(jìn)行AT指令交互。
我們可以使用發(fā)送幾條AT命令進(jìn)行簡單測試:
root@ELF1:~# cat /dev/ttyUSB2 &??????????????????????//打開串口回顯
root@ELF1:~# echo AT > /dev/ttyUSB2?????????????????//發(fā)送AT返回OK說明4G模塊正常通信 root@ELF1:~# echo AT+CPIN??> ?/dev/ttyUSB2???????//查詢sim卡狀態(tài),顯示ready說明正常通信 root@ELF1:~# echo AT+CSQ?> /dev/ttyUSB2??????????//查信號質(zhì)量 |
GobiNet Driver移植
移遠(yuǎn)ec20支持ppp、GobiNet、QMI_WWAN多種撥號上網(wǎng)方式,我們使用GobiNet方式撥號上網(wǎng),接下來移植GobiNet Driver。
一、復(fù)制驅(qū)動源碼
將ELF 1開發(fā)板資料包