[AndroidO] [RK3399] -- 支持 CH341 驱动 -- 驱动模块的标准添加流程

为了支持CH341设备,移植驱动主要做了以下两个方面的内容:

  1. 配置内核选项,使内核支持CH341设备;
  2. 修改CH341的设备节点号,为了上层更方便的使用;

源码修改如下所示:

    1. 配置内核选项,支持CH341设备:

diff --git a/kernel/arch/arm64/configs/rockchip_defconfig b/kernel/arch/arm64/configs/rockchip_defconfig
index ef29417..7a82bc5 100644
--- a/kernel/arch/arm64/configs/rockchip_defconfig
+++ b/kernel/arch/arm64/configs/rockchip_defconfig
@@ -659,6 +659,8 @@ CONFIG_USB_DWC3=y
 CONFIG_USB_DWC2=y
 CONFIG_USB_SERIAL=y
 CONFIG_USB_SERIAL_GENERIC=y
+CONFIG_USB_SERIAL_CH341=y
+CONFIG_USB_SERIAL_PL2303=y
 CONFIG_USB_SERIAL_OPTION=y
 CONFIG_USB_TRANCEVIBRATOR=y
 CONFIG_USB_GADGET=y

    2. 修改CH341的设备节点号:

diff --git a/kernel/drivers/usb/serial/usb-serial.c b/kernel/drivers/usb/serial/usb-serial.c
index e7e29c7..ab6eca8 100644
--- a/kernel/drivers/usb/serial/usb-serial.c
+++ b/kernel/drivers/usb/serial/usb-serial.c
@@ -96,7 +96,10 @@ static int allocate_minors(struct usb_serial *serial, int num_ports)
        mutex_lock(&table_lock);
        for (i = 0; i < num_ports; ++i) {
                port = serial->port[i];
-               minor = idr_alloc(&serial_minors, port, 0, 0, GFP_KERNEL);
+               if(!strcmp(serial->type->description,"ch341-uart"))
+                       minor = idr_alloc(&serial_minors, port, 10, 0, GFP_KERNEL);
+               else
+                       minor = idr_alloc(&serial_minors, port, 0, 0, GFP_KERNEL);
                if (minor < 0)
                        goto error;
                port->minor = minor;

总结:

    驱动模块的标准添加流程如下:

  1. 驱动模块 Kconfig 文件的编写;
  2. make menuconfig, 使能该模块;
  3. make save defconfig, 保存所有的配置到 defconfig 文件;
  4. cp defconfig kernel/arh/arm64/configs/rockchip_defconfig;

 

你可能感兴趣的:(AndroidO,RK3399)