Handle multiple ports
authorMichael Brown <mbrown@fensystems.co.uk>
Sun, 12 Mar 2006 19:28:40 +0000 (19:28 +0000)
committerMichael Brown <mbrown@fensystems.co.uk>
Sun, 12 Mar 2006 19:28:40 +0000 (19:28 +0000)
kernel/quickusb.h

index 4906d3c..369f896 100644 (file)
@@ -5,10 +5,41 @@
 #define QUICKUSB_BREQUESTTYPE_READ 0xc0
 #define QUICKUSB_BREQUESTTYPE_WRITE 0x40
 #define QUICKUSB_MAX_DATA_LEN 64
+
+#define QUICKUSB_WINDEX_GPPIO_DIR 0
+#define QUICKUSB_WINDEX_GPPIO_DATA 1
+
 #define QUICKUSB_TIMEOUT ( 1 * HZ )
 
 /**
- * quickusb_write_port_dir
+ * quickusb_read_port_dir - read GPPIO port output enables
+ *
+ * @usb: USB device
+ * @address: Port number
+ * @outputs: Output bit mask
+ *
+ * Returns 0 for success, or negative error number
+ */
+static inline int quickusb_read_port_dir ( struct usb_device *usb,
+                                          unsigned int address,
+                                          unsigned char *outputs ) {
+       int ret;
+       
+       ret =  usb_control_msg ( usb, usb_rcvctrlpipe ( usb, 0 ),
+                                QUICKUSB_BREQUEST,
+                                QUICKUSB_BREQUESTTYPE_READ,
+                                address, QUICKUSB_WINDEX_GPPIO_DIR,
+                                &outputs, sizeof ( outputs ),
+                                QUICKUSB_TIMEOUT );
+       if ( ret > 0 ) {
+               ret = 0;
+       }
+
+       return ret;
+}
+
+/**
+ * quickusb_write_port_dir - set GPPIO port output enables
  *
  * @usb: USB device
  * @address: Port number
@@ -23,7 +54,8 @@ static inline int quickusb_write_port_dir ( struct usb_device *usb,
 
        ret =  usb_control_msg ( usb, usb_sndctrlpipe ( usb, 0 ),
                                 QUICKUSB_BREQUEST,
-                                QUICKUSB_BREQUESTTYPE_WRITE, 0, 0,
+                                QUICKUSB_BREQUESTTYPE_WRITE,
+                                address, QUICKUSB_WINDEX_GPPIO_DIR,
                                 &outputs, sizeof ( outputs ),
                                 QUICKUSB_TIMEOUT );
 
@@ -52,8 +84,9 @@ static inline int quickusb_read_port ( struct usb_device *usb,
        
        ret =  usb_control_msg ( usb, usb_rcvctrlpipe ( usb, 0 ),
                                 QUICKUSB_BREQUEST,
-                                QUICKUSB_BREQUESTTYPE_READ, 0, 1, data, *len,
-                                QUICKUSB_TIMEOUT );
+                                QUICKUSB_BREQUESTTYPE_READ,
+                                address, QUICKUSB_WINDEX_GPPIO_DATA,
+                                data, *len, QUICKUSB_TIMEOUT );
        if ( ret > 0 ) {
                *len = ret;
                ret = 0;
@@ -80,8 +113,9 @@ static inline int quickusb_write_port ( struct usb_device *usb,
 
        ret =  usb_control_msg ( usb, usb_sndctrlpipe ( usb, 0 ),
                                 QUICKUSB_BREQUEST,
-                                QUICKUSB_BREQUESTTYPE_WRITE, 0, 1, data, *len,
-                                QUICKUSB_TIMEOUT );
+                                QUICKUSB_BREQUESTTYPE_WRITE,
+                                address, QUICKUSB_WINDEX_GPPIO_DATA,
+                                data, *len, QUICKUSB_TIMEOUT );
 
        if ( ret > 0 ) {
                *len = ret;