[PATCH] USB: Export IEEE-1284 device id in sysfs for usblp devices

I looked at the userspace code which uses the LPIOC_GET_DEVICE_ID ioctl
and I almost went blind. Let's export it in sysfs instead, and just as a
string instead of with a big-endian length at the beginning of it.

This also prints the message about finding the printer _after_ we know
the minor device number it's going to have, rather than reporting all
printers as 'usblp0'.

Signed-off-by: David Woodhouse <[EMAIL PROTECTED]>
Signed-off-by: Greg Kroah-Hartman <[EMAIL PROTECTED]>

---
commit a9714c845c0681a203a9ae22aa5165ec72c51d33
tree f08697d81eca4e6e877b0d3d3561f7f8bf8111e7
parent 318e479eb7ad9a948c6da381976d258464413816
author David Woodhouse <[EMAIL PROTECTED]> Fri, 23 Dec 2005 16:41:41 +0000
committer Greg Kroah-Hartman <[EMAIL PROTECTED]> Wed, 04 Jan 2006 13:51:44 -0800

 drivers/usb/class/usblp.c |   35 ++++++++++++++++++++++++++---------
 1 files changed, 26 insertions(+), 9 deletions(-)

diff --git a/drivers/usb/class/usblp.c b/drivers/usb/class/usblp.c
index 708a292..27e9404 100644
--- a/drivers/usb/class/usblp.c
+++ b/drivers/usb/class/usblp.c
@@ -850,6 +850,20 @@ static struct usb_class_driver usblp_cla
        .minor_base =   USBLP_MINOR_BASE,
 };
 
+static ssize_t usblp_show_ieee1284_id(struct device *dev, struct 
device_attribute *attr, char *buf)
+{
+       struct usb_interface *intf = to_usb_interface(dev);
+       struct usblp *usblp = usb_get_intfdata (intf);
+
+       if (usblp->device_id_string[0] == 0 &&
+           usblp->device_id_string[1] == 0)
+               return 0;
+
+       return sprintf(buf, "%s", usblp->device_id_string+2);
+}
+
+static DEVICE_ATTR(ieee1284_id, S_IRUGO, usblp_show_ieee1284_id, NULL);
+
 static int usblp_probe(struct usb_interface *intf,
                       const struct usb_device_id *id)
 {
@@ -934,20 +948,12 @@ static int usblp_probe(struct usb_interf
 
        /* Retrieve and store the device ID string. */
        usblp_cache_device_id_string(usblp);
+       device_create_file(&intf->dev, &dev_attr_ieee1284_id);
 
 #ifdef DEBUG
        usblp_check_status(usblp, 0);
 #endif
 
-       info("usblp%d: USB %sdirectional printer dev %d "
-               "if %d alt %d proto %d vid 0x%4.4X pid 0x%4.4X",
-               usblp->minor, usblp->bidir ? "Bi" : "Uni", dev->devnum,
-               usblp->ifnum,
-               usblp->protocol[usblp->current_protocol].alt_setting,
-               usblp->current_protocol,
-               le16_to_cpu(usblp->dev->descriptor.idVendor),
-               le16_to_cpu(usblp->dev->descriptor.idProduct));
-
        usb_set_intfdata (intf, usblp);
 
        usblp->present = 1;
@@ -958,11 +964,20 @@ static int usblp_probe(struct usb_interf
                goto abort_intfdata;
        }
        usblp->minor = intf->minor;
+       info("usblp%d: USB %sdirectional printer dev %d "
+               "if %d alt %d proto %d vid 0x%4.4X pid 0x%4.4X",
+               usblp->minor, usblp->bidir ? "Bi" : "Uni", dev->devnum,
+               usblp->ifnum,
+               usblp->protocol[usblp->current_protocol].alt_setting,
+               usblp->current_protocol,
+               le16_to_cpu(usblp->dev->descriptor.idVendor),
+               le16_to_cpu(usblp->dev->descriptor.idProduct));
 
        return 0;
 
 abort_intfdata:
        usb_set_intfdata (intf, NULL);
+       device_remove_file(&intf->dev, &dev_attr_ieee1284_id);
 abort:
        if (usblp) {
                if (usblp->writebuf)
@@ -1157,6 +1172,8 @@ static void usblp_disconnect(struct usb_
                BUG ();
        }
 
+       device_remove_file(&intf->dev, &dev_attr_ieee1284_id);
+
        down (&usblp_sem);
        down (&usblp->sem);
        usblp->present = 0;



-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_idv37&alloc_id865&op=click
_______________________________________________
linux-usb-devel@lists.sourceforge.net
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel

Reply via email to