Added quickusb_{read,write}_setting (untested)
authorMichael Brown <mbrown@fensystems.co.uk>
Mon, 13 Mar 2006 12:55:09 +0000 (12:55 +0000)
committerMichael Brown <mbrown@fensystems.co.uk>
Mon, 13 Mar 2006 12:55:09 +0000 (12:55 +0000)
kernel/quickusb.h

index 136c5ad..89aae16 100644 (file)
@@ -5,7 +5,8 @@
 
 #include <linux/ioctl.h>
 
-#define QUICKUSB_BREQUEST 0xb3
+#define QUICKUSB_BREQUEST_SETTING 0xb0
+#define QUICKUSB_BREQUEST_GPPIO 0xb3
 #define QUICKUSB_BREQUESTTYPE_READ 0xc0
 #define QUICKUSB_BREQUESTTYPE_WRITE 0x40
 #define QUICKUSB_MAX_DATA_LEN 64
 
 #define QUICKUSB_TIMEOUT ( 1 * HZ )
 
+/**
+ * quickusb_read_setting - read device setting
+ *
+ * @usb: USB device
+ * @address: Setting address
+ * @setting: Value of the setting
+ *
+ * Returns 0 for success, or negative error number
+ */
+static inline int quickusb_read_setting ( struct usb_device *usb,
+                                         unsigned int address,
+                                         uint16_t *setting ) {
+       int ret;
+
+       ret =  usb_control_msg ( usb, usb_rcvctrlpipe ( usb, 0 ),
+                                QUICKUSB_BREQUEST_SETTING,
+                                QUICKUSB_BREQUESTTYPE_READ,
+                                0, address,
+                                setting, sizeof ( *setting ),
+                                QUICKUSB_TIMEOUT );
+       if ( ret > 0 ) {
+               ret = 0;
+       }
+
+       return ret;
+}
+
+/**
+ * quickusb_write_setting - write device setting
+ *
+ * @usb: USB device
+ * @address: Setting address
+ * @setting: Value of the setting
+ *
+ * Returns 0 for success, or negative error number
+ */
+static inline int quickusb_write_setting ( struct usb_device *usb,
+                                          unsigned int address,
+                                          uint16_t setting ) {
+       int ret;
+
+       ret =  usb_control_msg ( usb, usb_sndctrlpipe ( usb, 0 ),
+                                QUICKUSB_BREQUEST_SETTING,
+                                QUICKUSB_BREQUESTTYPE_WRITE,
+                                0, address,
+                                &setting, sizeof ( setting ),
+                                QUICKUSB_TIMEOUT );
+       if ( ret > 0 ) {
+               ret = 0;
+       }
+
+       return ret;
+}
+
 /**
  * quickusb_read_port_dir - read GPPIO port output enables
  *
  */
 static inline int quickusb_read_port_dir ( struct usb_device *usb,
                                           unsigned int address,
-                                          unsigned char *outputs ) {
+                                          uint8_t *outputs ) {
        int ret;
        
        ret =  usb_control_msg ( usb, usb_rcvctrlpipe ( usb, 0 ),
-                                QUICKUSB_BREQUEST,
+                                QUICKUSB_BREQUEST_GPPIO,
                                 QUICKUSB_BREQUESTTYPE_READ,
                                 address, QUICKUSB_WINDEX_GPPIO_DIR,
                                 outputs, sizeof ( *outputs ),
@@ -53,11 +108,11 @@ static inline int quickusb_read_port_dir ( struct usb_device *usb,
  */
 static inline int quickusb_write_port_dir ( struct usb_device *usb,
                                            unsigned int address,
-                                           unsigned char outputs ) {
+                                           uint8_t outputs ) {
        int ret;
 
        ret =  usb_control_msg ( usb, usb_sndctrlpipe ( usb, 0 ),
-                                QUICKUSB_BREQUEST,
+                                QUICKUSB_BREQUEST_GPPIO,
                                 QUICKUSB_BREQUESTTYPE_WRITE,
                                 address, QUICKUSB_WINDEX_GPPIO_DIR,
                                 &outputs, sizeof ( outputs ),
@@ -82,12 +137,11 @@ static inline int quickusb_write_port_dir ( struct usb_device *usb,
  */
 static inline int quickusb_read_port ( struct usb_device *usb,
                                       unsigned int address,
-                                      unsigned char *data,
-                                      size_t *len ) {
+                                      void *data, size_t *len ) {
        int ret;
        
        ret =  usb_control_msg ( usb, usb_rcvctrlpipe ( usb, 0 ),
-                                QUICKUSB_BREQUEST,
+                                QUICKUSB_BREQUEST_GPPIO,
                                 QUICKUSB_BREQUESTTYPE_READ,
                                 address, QUICKUSB_WINDEX_GPPIO_DATA,
                                 data, *len, QUICKUSB_TIMEOUT );
@@ -111,12 +165,11 @@ static inline int quickusb_read_port ( struct usb_device *usb,
  */
 static inline int quickusb_write_port ( struct usb_device *usb,
                                        unsigned int address,
-                                       unsigned char *data,
-                                       size_t *len ) {
+                                       void *data, size_t *len ) {
        int ret;
 
        ret =  usb_control_msg ( usb, usb_sndctrlpipe ( usb, 0 ),
-                                QUICKUSB_BREQUEST,
+                                QUICKUSB_BREQUEST_GPPIO,
                                 QUICKUSB_BREQUESTTYPE_WRITE,
                                 address, QUICKUSB_WINDEX_GPPIO_DATA,
                                 data, *len, QUICKUSB_TIMEOUT );