如何在linux 上添加合宙4G 驱动

驱动,内核

   Air720正常启动后,通过USB连接到linux设备上,驱动正常加载后会产生如下设备:

   1.Air720 系列 (1802/1802S)

2.Air720U系列(8910)



一、修改驱动

   
    首先需要对Linux内核驱动做一定的修改,使操作系统能够支持Air720

    1.Add VID add PID

    File: [KERNEL]/drivers/usb/serial/option.c

static const struct usb_device_id option_ids[] = {
    //+add by airm2m for Air72x
  { USB_DEVICE(0x1782, 0x4e00) }, /* 720U 系列*/
    { USB_DEVICE(0x1286, 0x4e3d) }, /* 720 系列*/
     //-add by airm2m for Air72x
 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_COLT) },
    { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_RICOLA) },
    { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_RICOLA_LIGHT) },
    { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_RICOLA_QUAD) },
    { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_RICOLA_QUAD_LIGHT) },   

    

    2. Add the Zero Packet Mechanism   

    ⦁For linux Kernel Version newer than 2.6.34:
     File: [KERNEL]/drivers/usb/serial/usb_wwan.c
static struct urb *usb_wwan_setup_urb(struct usb_serial_port *port,
                      int endpoint,                                                             
                      int dir, void *ctx, char *buf, int len,
                      void (*callback) (struct urb *))
{
    struct usb_serial *serial = port->serial;
    struct urb *urb;
    urb = usb_alloc_urb(0, GFP_KERNEL); /* No ISO */
    if (!urb)
        return NULL;
    usb_fill_bulk_urb(urb, serial->dev,
              usb_sndbulkpipe(serial->dev, endpoint) | dir,
              buf, len, callback, ctx);
    //+add by airm2m for Air72x
    if(dir == USB_DIR_OUT){
        struct usb_device_descriptor *desc = &serial->dev->descriptor;
        if((desc->idVendor == cpu_to_le16(0x1286) && desc->idProduct == cpu_to_le16(0x4e3d)) ) /* 720 系列*/
        {
            urb->transfer_flags |= URB_ZERO_PACKET;
        }
        if((desc->idVendor == cpu_to_le16(0x1782) && desc->idProduct == cpu_to_le16(0x4e00)) ) /* 720U 系列*/
            urb->transfer_flags |= URB_ZERO_PACKET;
        }
    }
    //-add by airm2m for Air72x
        {
    return urb;
}

    ⦁For linux Kernel Version older than 2.6.35:

    File: [KERNEL]/drivers/usb/serial/option.c

static struct urb *option_setup_urb(struct usb_serial *serial, int endpoint,
int dir, void *ctx, char *buf, int len,
void (*callback)(struct urb *))
{
......
/* Fill URB using supplied data. */
usb_fill_bulk_urb(urb, serial->dev,
      usb_sndbulkpipe(serial->dev, endpoint) | dir,
      buf, len, callback, ctx);
//+add by airm2m for Air72x
if(dir == USB_DIR_OUT)
{
        struct usb_device_descriptor *desc = &serial->dev->descriptor;
        if(desc->idVendor == cpu_to_le16(0x1286) && desc->idProduct == cpu_to_le16(0x4e3d)) /* 720 系列*/
        {
            urb->transfer_flags |= URB_ZERO_PACKET;
        }
        if(desc->idVendor == cpu_to_le16(0x1782) && desc->idProduct == cpu_to_le16(0x4e00)) /* 720U 系列*/
        {
            urb->transfer_flags |= URB_ZERO_PACKET;
        }

}
//-add by airm2m for Air72x
return urb;
}

     3. Add Reset Resume

    ⦁For linux Kernel Version newer than 3.4:
       File: [KERNEL]/drivers/usb/serial/option.c
static struct usb_serial_driver option_1port_device = {
    .driver = {                                                                                                  
        .owner =    THIS_MODULE,
        .name =     "option1",
    },   
    ....
#ifdef CONFIG_PM
    .suspend           = usb_wwan_suspend,
    .resume            = usb_wwan_resume,
    //+add by airm2m for Air720
    .reset_resume      = usb_wwan_resume,
    //-add by airm2m for Air720
#endif

};

    ⦁For linux Kernel Version older than 3.5:
    File: [kernel]/drivers/usb/serial/usb-serial.c
/* Driver structure we register with the USB core */
static struct usb_driver usb_serial_driver = {
.name ="usbserial",
.probe =usb_serial_probe,
.disconnect =usb_serial_disconnect,
.suspend =usb_serial_suspend,
.resume =usb_serial_resume,
 //+add by airm2m for Air72x
          .reset_resume      = usb_serial_resume,
          //-add by airm2m for Air72x
.no_dynamic_id = 1,
};

    4. Modify Kernel Configuration

    Step 1:
    cd <your kernel directory>
    Step 2:
    make menuconfig
    Step 3:Enable CONFIG_USB_SERIAL_OPTION
[*] Device Drivers →
  [*] USB Support →
    [*] USB Serial Converter support →
      [*] USB driver for GSM and CDMA modems

attachments-2018-09-UvLI6qjo5b8b7c3fabe04.png

    Step 4:Configure Kernel to Support PPP
[*] Device Drivers →
  [*] Network device support →
    [*] PPP (point-to-point protocol) support

attachments-2018-09-0MkDlKPS5b8b7cde500a3.png


   5.编译内核

    make    
    将编译好的内核下载到开发板。

    

 二、模块测试

    将重新编译好的内核下载到开发板之后,待系统重新启动,如果是带RNDIS网卡的驱动,在/dev/目录下会出现如下设备节点:



Air720的AT端口是/dev/ttyUSB2,现在你可以使用UART端口工具如“minicom”或“busybox microcom”测试AT功能,结果如下:
attachments-2018-09-VciAwk855b8b81601e624.png
  • 发表于 2019-08-06 14:18
  • 阅读 ( 6195 )

你可能感兴趣的文章

相关问题

0 条评论

请先 登录 后评论
不写代码的码农
梁健

软件工程师

11 篇文章

作家榜 »

  1. 技术销售Delectate 43 文章
  2. 陈夏 26 文章
  3. 国梁 24 文章
  4. miuser 21 文章
  5. 晨旭 20 文章
  6. 朱天华 19 文章
  7. 金艺 19 文章
  8. 杨奉武 18 文章