欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

【海思Hi3520D开发笔记】移植EC20(未完结)

程序员文章站 2022-04-30 10:24:10
...

环境:Ubuntu 12.04-64bit
硬件平台:Hi3520D_V100
关键词:Hi3520编译内核 移植EC20
摘要:介绍Hi3520 修改内核文件,制作内核镜像。使用EC20
参考资料:Quectel_LTE&5G_Linux_USB_Driver_User_Guide_V2.0.pdf

USB Serial Option Driver
1、Add VID and PID
In order to recognize the module, the module’s VID and PID information as below need to be added to the
file [KERNEL]/drivers/usb/serial/option.c.

static const struct usb_device_id option_ids[] = {
#if 1 //Added by Quectel
{ USB_DEVICE(0x2C7C, 0x0125) }, /* Quectel EC20 R2.0/EC20 R2.1/EC25/EG25-G/EM05 */
{ USB_DEVICE(0x2C7C, 0x0121) }, /* Quectel EC21/EG21-G */
{ USB_DEVICE(0x2C7C, 0x0191) }, /* Quectel EG91 */
{ USB_DEVICE(0x2C7C, 0x0195) }, /* Quectel EG95 */
{ USB_DEVICE(0x2C7C, 0x0306) }, /* Quectel EG06/EP06/EM06 */
{ USB_DEVICE(0x2C7C, 0x0512) }, /* Quectel EG12/EM12/EG18 */
{ USB_DEVICE(0x2C7C, 0x0296) }, /* Quectel BG96 */
{ USB_DEVICE(0x2C7C, 0x0700) }, /* Quectel BG95/BG77/BG600L-M3/BC69 */
{ USB_DEVICE(0x2C7C, 0x0435) }, /* Quectel AG35 */
{ USB_DEVICE(0x2C7C, 0x0415) }, /* Quectel AG15 */
{ USB_DEVICE(0x2C7C, 0x0452) }, /* Quectel AG520R */
{ USB_DEVICE(0x2C7C, 0x0455) }, /* Quectel AG550R */
{ USB_DEVICE(0x2C7C, 0x0620) }, /* Quectel EG20 */
{ USB_DEVICE(0x2C7C, 0x0800) }, /* Quectel RG500Q/RM500Q/RG510Q/RM510Q */
#endif

【海思Hi3520D开发笔记】移植EC20(未完结)

2、Add the Zero Packet Mechanism
As required by the USB protocol, the mechanism for processing zero packets needs to be added during
bulk-out transmission by adding the following statements.
 For Linux kernel version higher than 2.6.34, add the following statements to the 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 packet
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
return urb;
}

【海思Hi3520D开发笔记】移植EC20(未完结)

3、Add Reset-resume Mechanism
Some USB host controllers/USB hubs will lose power or be reset when MCU enters the Suspend/Sleep
mode, and cannot be used for USB resume after MCU exits from the Suspend/Sleep mode. The
reset-resume mechanism needs to be enabled by adding the following statements.
 For Linux kernel version lower than 3.5, add the following statements to the 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,
#if 1 //Added by Quectel
.reset_resume = usb_serial_resume,
#endif
.no_dynamic_id = 1,
.supports_autosuspend = 1,
}

【海思Hi3520D开发笔记】移植EC20(未完结)
4、Use MBIM, GobiNet or QMI_WWAN Driver
If MBIM, GobiNet or QMI_WWAN driver is required, add the following statements to prevent the module’s
interface 4 from being used as a USB serial device.
 For Linux kernel version higher than 2.6.30, add the following statements to the 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 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
/* Store device id so we can use it during attach. */
usb_set_serial_data(serial, (void *)id);
return 0;
}

【海思Hi3520D开发笔记】移植EC20(未完结)