Linux移植E20模块驱动步骤解析
发布日期:2021-07-19 12:30:13 浏览次数:11 分类:技术文章

本文共 4198 字,大约阅读时间需要 13 分钟。

以openwrt-hiwooya-stable 源码为例, 对应的内核为 linux-3.18.45。 当然, 如果您是其他

版本的 Linux 系统, 也可参考本章内容进行修改, 大同小异。
(1)添加VIDD和PID

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

static const struct usb_device_id option_ids[] = {
#if 1 //Added by Quectel{
USB_DEVICE(0x05C6, 0x9090) }, /* Quectel UC15 */{
USB_DEVICE(0x05C6, 0x9003) }, /* Quectel UC20 */{
USB_DEVICE(0x05C6, 0x9215) }, /* Quectel EC20 */{
USB_DEVICE(0x2C7C, 0x0125) }, /* Quectel EC25 */{
USB_DEVICE(0x2C7C, 0x0121) }, /* Quectel EC21 */#endif

[KERNEL]/drivers/usb/serial/qcserial.c

{
USB_DEVICE(0x05c6, 0x9215)}, /* Acer Gobi 2000 Modem device (VP413) */

[KERNEL]/drivers/net/usb/qmi_wwan.c

{
QMI_GOBI_DEVICE(0x05c6, 0x9215)}, /* Acer Gobi 2000 Modem device (VP413) */

(2)添加 Zero Packet 机制

在传输大量数据的时候, USB 协议需要添加处理 Zero Packet 的机制。
对于高于 2.6.34 的内核版本, 需要做如下修改。
File: [KERNEL]/drivers/usb/serial/usb_wwan.c

static struct urb *usb_wwan_setup_urb(struct usb_serial *serial, int endpoint,int dir, void *ctx, char *buf, int len,void (*callback) (struct urb *)){
……usb_fill_bulk_urb(urb, serial->dev,usb_sndbulkpipe(serial->dev, endpoint) | dir,buf, len, callback, ctx);#if 1 //Added by Quectel for Zero Packetif (dir == USB_DIR_OUT) {
struct usb_device_descriptor *desc = &serial->dev->descriptor;if (desc->idVendor == cpu_to_le16(0x05C6) && desc->idProduct == cpu_to_le16(0x9090))urb->transfer_flags |= URB_ZERO_PACKET;if (desc->idVendor == cpu_to_le16(0x05C6) && desc->idProduct == cpu_to_le16(0x9003))urb->transfer_flags |= URB_ZERO_PACKET;if (desc->idVendor == cpu_to_le16(0x05C6) && desc->idProduct == cpu_to_le16(0x9215))urb->transfer_flags |= URB_ZERO_PACKET;if (desc->idVendor == cpu_to_le16(0x2C7C))urb->transfer_flags |= URB_ZERO_PACKET;}#endifreturn urb;}

(3)添加 Reset Resume

对于一些 USB 控制器, 当主控进入休眠或者待机模式时, 它将掉电或者重启。 而当主控
退出休眠或者待机模式时, USB 主控将不能重启 USB 设备, 反而, 它将执行 Reset Resume,
因此我们需要添加如下内容。
对于高于 3.4 的内核版本, 需要做如下修改。
File: [KERNEL]/drivers/usb/serial/option.c

static struct usb_serial_driver option_1port_device = {
……#ifdef CONFIG_PM.suspend = usb_wwan_suspend,.resume = usb_wwan_resume,#if 1 //Added by Quectel.reset_resume = usb_wwan_resume,#endif#endif};

(4)使用 GobiNet 或者 QMI 驱动

对于高于 2.6.30 的内核版本, 需要做如下修改。
File: [KERNEL]/drivers/usb/serial/option.c

static int option_probe(struct usb_serial *serial, const struct usb_device_id *id) {
struct usb_wwan_intf_private *data;……#if 1 //Added by Quectel//Quectel UC20's interface 4 can be used as USB Network deviceif (serial->dev->descriptor.idVendor == cpu_to_le16(0x05C6) &&serial->dev->descriptor.idProduct == cpu_to_le16(0x9003)&& serial->interface->cur_altsetting->desc.bInterfaceNumber >= 4)return -ENODEV;//Quectel EC20's interface 4 can be used as USB Network deviceif (serial->dev->descriptor.idVendor == cpu_to_le16(0x05C6) &&serial->dev->descriptor.idProduct == cpu_to_le16(0x9215)&& serial->interface->cur_altsetting->desc.bInterfaceNumber >= 4)return -ENODEV;//Quectel EC25&EC21's interface 4 can be used as USB Network deviceif (serial->dev->descriptor.idVendor == cpu_to_le16(0x2C7C)&& serial->interface->cur_altsetting->desc.bInterfaceNumber >= 4)return -ENODEV;#endif/* Store device id so we can use it during attach. */usb_set_serial_data(serial, (void *)id);return 0;}

(5)修改内核配置

经过上面对源码的修改以后, 我们还需要进行相关内核的配置, 才能真正的支持 USB 串
口驱动。
总的来说, 我们需要将以下内容, 配置进内核即可。
输入make menuconfig
配置 kmod-usb-serial

Kernel modules --->USB Support ---><*> kmod-usb-serial..................... Support for USB-to-Serial converters

配置 kmod-usb-serial-option

Kernel modules --->USB Support ---><*> kmod-usb-serial-option................... Support for Option HSDPA modems

配置 kmod-usb-serial-wwan

Kernel modules --->USB Support --->-*- kmod-usb-serial-wwan..................... Support for GSM and CDMA modems

配置 kmod-usb-net

Kernel modules --->USB Support ---><*> kmod-usb-net............... Kernel modules for USB-to-Ethernet convertors

配置 usb-modeswitch

Utilities ---><*> usb-modeswitch................................ USB mode switching utility

(6)修改内核配置

输入 make kernel_menuconfig

Device Drivers --->[*] USB support ---><*> Support for Host-side USBDevice Drivers --->[*] Network device support ---><*> USB Network Adapters ---><*> Multi-purpose USB Networking Framework

转载地址:https://blog.csdn.net/jdsnpgxj/article/details/104940458 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:CC2640编译stack成功编译app失败的问题解决方法
下一篇:ubuntu如何安装openjdk8

发表评论

最新留言

初次前来,多多关照!
[***.217.46.12]2024年04月18日 10时40分12秒