RK3288 Android5.1 固定ttyUSB串口节点
修改内核把模块的ttyUSB端口枚举写固定
参考链接:https://blog.csdn.net/Mrdeath/article/details/107506452
该技术点实现的功能:
在rk3288 android5.1平台上,一个USB固定一个ttyUSB节点,例如有4个USB口,则USB0/1/2/3分别固定ttyUSB6/7/8/9.
实现思路:
根据USB的设备名去识别USB串口插入的是哪个U口,再不同的U口给他分配一个不同的节点,具体内容如下
当USB转串设备插入U口,驱动会识别到设备插入到的是哪个口,并把对应口的字符串保存到dev结构体里,对应保存的字符串的内容,可以在插拔USB串口的打印信息中看到:
USB转串设备插入第一个USB口,dev名字为2-1,插入第二个USB口名字为4-1.1 ,第三个为4-1.2,第四个为4-1.3 (第一个USB口为原生口,后三个为HUB扩出的口)
在usb-serial.c文件中的get_free_serial函数下,传入dev的name,根据这个name,给串口分配固定的节点:
diff --git a/kernel/drivers/usb/serial/usb-serial.c b/kernel/drivers/usb/serial/usb-serial.c
index 80d689f0fd..0b17b3e7cd 100644
--- a/kernel/drivers/usb/serial/usb-serial.c
+++ b/kernel/drivers/usb/serial/usb-serial.c
@@ -79,7 +79,7 @@ struct usb_serial *usb_serial_get_by_index(unsigned index)
}
static struct usb_serial *get_free_serial(struct usb_serial *serial,
- int num_ports, unsigned int *minor)
+ int num_ports, unsigned int *minor, char * dev_name)
{
unsigned int i, j;
int good_spot;
@@ -101,7 +101,23 @@ static struct usb_serial *get_free_serial(struct usb_serial *serial,
}
if (good_spot == 0)
continue;
-
+
+ if(!strcmp(dev_name,"2-1")) //USB0
+ {
+ i = 6;
+ }
+ else if(!strcmp(dev_name,"4-1.1"))
+ {
+ i = 7;
+ }
+ else if(!strcmp(dev_name,"4-1.2"))
+ {
+ i = 8;
+ }
+ else if(!strcmp(dev_name,"4-1.3"))
+ {
+ i = 9;
+ }
*minor = i;
j = 0;
dev_dbg(&serial->interface->dev, "%s - minor base = %d\n", __func__, *minor);
@@ -1055,8 +1071,9 @@ static int usb_serial_probe(struct usb_interface *interface,
* registered.
*/
serial->disconnected = 1;
+
- if (get_free_serial(serial, num_ports, &minor) == NULL) {
+ if (get_free_serial(serial, num_ports, &minor,dev_name(&port->serial->dev->dev)) == NULL) {
dev_err(ddev, "No more free serial devices\n");
goto probe_error;
}