我们在安卓设备上经常会用到usb转串口的设备,而usb转串口的设备生成的设备号是按usb枚举的顺序生成的,所以同一个usb设备每次开机之后生成的串口序号可能不相同,通过下面的补丁可以解决这个问题。
Index: kernel/drivers/usb/serial/usb-serial.c
===================================================================
--- kernel/drivers/usb/serial/usb-serial.c (revision 1851)
+++ kernel/drivers/usb/serial/usb-serial.c (working copy)
@@ -85,20 +85,74 @@
return port;
}
-static int allocate_minors(struct usb_serial *serial, int num_ports)
+static int allocate_minors(struct usb_serial *serial, int num_ports,char * dev_name)
{
struct usb_serial_port *port;
unsigned int i, j;
- int minor;
+ int minor,tmpmiior;
dev_dbg(&serial->interface->dev, "%s %d\n", __func__, num_ports);
mutex_lock(&table_lock);
+printk("dev_name = %s\n",dev_name);
for (i = 0; i < num_ports; ++i) {
port = serial->port[i];
- minor = idr_alloc(&serial_minors, port, 0, 0, GFP_KERNEL);
- if (minor < 0)
- goto error;
+
+ printk("num_ports = %d\n",num_ports);
+
+ if(!strcmp(dev_name,"2-1.7")) //USB0
+ {
+ minor = idr_alloc(&serial_minors, port, 0, 4, GFP_KERNEL);
+ if (minor < 0)
+ goto error;
+ }
+ else
+ {
+
+ if(!strcmp(dev_name,"1-1.1")) //USB0
+ {
+ minor = 5;
+ }
+ else if(!strcmp(dev_name,"2-1.6.1")) //USB0
+ {
+ minor = 6;
+ }
+
+ else if(!strcmp(dev_name,"2-1.5.1")) //USB0
+ {
+ minor = 7;
+ }
+
+ else if(!strcmp(dev_name,"2-1.4.1")) //USB0
+ {
+ minor = 8;
+ }
+ else if(!strcmp(dev_name,"2-1.3.1"))
+ {
+ minor = 9;
+ }
+ else if(!strcmp(dev_name,"2-1.2.1"))
+ {
+ minor = 10;
+ }
+ else if(!strcmp(dev_name,"2-1.1.1"))
+ {
+ minor = 11;
+ }
+
+ tmpmiior=idr_alloc(&serial_minors, port, 5, 20, GFP_KERNEL);
+ if (minor < 0)
+ goto error;
+
+ }
+ /* else if(!strcmp(dev_name,"2-1.7"))
+ {
+ i = 7;
+ }*/
+ //minor = idr_alloc(&serial_minors, port, 0, 0, GFP_KERNEL);
+ //if (minor < 0)
+ // goto error;
+
port->minor = minor;
port->port_number = i;
}
@@ -1058,7 +1112,7 @@
*/
serial->disconnected = 1;
- if (allocate_minors(serial, num_ports)) {
+ if (allocate_minors(serial, num_ports,dev_name(&port->serial->dev->dev))) {
dev_err(ddev, "No more free serial minor numbers\n");
goto probe_error;
}