Hi,

This patch against the 2.5.8-pre3 kernel adds /proc/tty support for all
of the usb serial drivers.  This is something I wanted to add for a
while, and only recently realized that the tty layer offered a very easy
interface for this (supply a read_proc or write_proc function pointer,
and the tty layer will create and handle the proper proc file for your
driver.)

The output of the file right now looks something like this with a bunch
of devices connected:
----
[greg@blue serial]# cat /proc/tty/driver/usb-serial 
usbserinfo:1.0 driver:v1.5
0: module:io_edgeport name:"Edgeport 4 port adapter" vendor:1608 product:0001 
num_ports:4 port:1 path:usb-00:1f.2-1
1: module:io_edgeport name:"Edgeport 4 port adapter" vendor:1608 product:0001 
num_ports:4 port:2 path:usb-00:1f.2-1
2: module:io_edgeport name:"Edgeport 4 port adapter" vendor:1608 product:0001 
num_ports:4 port:3 path:usb-00:1f.2-1
3: module:io_edgeport name:"Edgeport 4 port adapter" vendor:1608 product:0001 
num_ports:4 port:4 path:usb-00:1f.2-1
4: module:keyspan_pda name:"Keyspan PDA" vendor:06cd product:0104 num_ports:1 port:1 
path:usb-00:1f.2-2.3
5: module:whiteheat name:"Connect Tech - WhiteHEAT" vendor:0710 product:8001 
num_ports:4 port:1 path:usb-01:0d.0-2
6: module:whiteheat name:"Connect Tech - WhiteHEAT" vendor:0710 product:8001 
num_ports:4 port:2 path:usb-01:0d.0-2
7: module:whiteheat name:"Connect Tech - WhiteHEAT" vendor:0710 product:8001 
num_ports:4 port:3 path:usb-01:0d.0-2
8: module:whiteheat name:"Connect Tech - WhiteHEAT" vendor:0710 product:8001 
num_ports:4 port:4 path:usb-01:0d.0-2
9: module:visor name:"Handspring Visor / Palm 4.0 / Cli� 4.x" vendor:082d product:0100 
num_ports:2 port:1 path:usb-01:0d.0-1
10: module:visor name:"Handspring Visor / Palm 4.0 / Cli� 4.x" vendor:082d 
product:0100 num_ports:2 port:2 path:usb-01:0d.0-1
----

If anyone has anything else in the struct usb_serial or struct
usb_serial_port variables that they would like to see exported through
this interface, please let me know.

thanks,

greg k-h


diff -Nru a/drivers/usb/serial/usbserial.c b/drivers/usb/serial/usbserial.c
--- a/drivers/usb/serial/usbserial.c    Wed Apr 10 17:03:50 2002
+++ b/drivers/usb/serial/usbserial.c    Wed Apr 10 17:03:50 2002
@@ -15,6 +15,10 @@
  *
  * See Documentation/usb/usb-serial.txt for more information on using this driver
  *
+ * (04/10/2002) gkh
+ *     added serial_read_proc function which creates a
+ *     /proc/tty/driver/usb-serial file.
+ *
  * (03/27/2002) gkh
  *     Got USB serial console code working properly and merged into the main
  *     version of the tree.  Thanks to Randy Dunlap for the initial version
@@ -340,7 +344,7 @@
 /*
  * Version Information
  */
-#define DRIVER_VERSION "v1.4"
+#define DRIVER_VERSION "v1.5"
 #define DRIVER_AUTHOR "Greg Kroah-Hartman, [EMAIL PROTECTED], 
http://www.kroah.com/linux-usb/";
 #define DRIVER_DESC "USB Serial Driver core"
 
@@ -844,6 +848,48 @@
                generic_shutdown(serial);
 }
 
+static int serial_read_proc (char *page, char **start, off_t off, int count, int 
+*eof, void *data)
+{
+       struct usb_serial *serial;
+       int length = 0;
+       int i;
+       off_t begin = 0;
+       char tmp[40];
+
+       dbg(__FUNCTION__);
+       length += sprintf (page, "usbserinfo:1.0 driver:%s\n", DRIVER_VERSION);
+       for (i = 0; i < SERIAL_TTY_MINORS && length < PAGE_SIZE; ++i) {
+               serial = get_serial_by_minor(i);
+               if (serial == NULL)
+                       continue;
+
+               length += sprintf (page+length, "%d:", i);
+               if (serial->type->owner)
+                       length += sprintf (page+length, " module:%s", 
+serial->type->owner->name);
+               length += sprintf (page+length, " name:\"%s\"", serial->type->name);
+               length += sprintf (page+length, " vendor:%04x product:%04x", 
+serial->vendor, serial->product);
+               length += sprintf (page+length, " num_ports:%d", serial->num_ports);
+               length += sprintf (page+length, " port:%d", i - serial->minor + 1);
+
+               usb_make_path(serial->dev, tmp, sizeof(tmp));
+               length += sprintf (page+length, " path:%s", tmp);
+                       
+               length += sprintf (page+length, "\n");
+               if ((length + begin) > (off + count))
+                       goto done;
+               if ((length + begin) < off) {
+                       begin += length;
+                       length = 0;
+               }
+       }
+       *eof = 1;
+done:
+       if (off >= (length + begin))
+               return 0;
+       *start = page + (off-begin);
+       return ((count < begin+length-off) ? count : begin+length-off);
+}
+
 /*****************************************************************************
  * generic devices specific driver functions
  *****************************************************************************/
@@ -1491,6 +1537,7 @@
        unthrottle:             serial_unthrottle,
        break_ctl:              serial_break,
        chars_in_buffer:        serial_chars_in_buffer,
+       read_proc:              serial_read_proc,
 };
 
 

_______________________________________________
[EMAIL PROTECTED]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel

Reply via email to