USB: gadget: f_accessory: Add ioctl to detect USB accessory attached at boot
Mike Lockwood [Thu, 21 Jul 2011 18:39:17 +0000 (11:39 -0700)]
Signed-off-by: Mike Lockwood <lockwood@android.com>

drivers/usb/gadget/f_accessory.c
include/linux/usb/f_accessory.h

index 873ab2e..05e65e5 100644 (file)
@@ -75,6 +75,9 @@ struct acc_dev {
        /* for acc_complete_set_string */
        int string_index;
 
+       /* set to 1 if we have a pending start request */
+       int start_requested;
+
        /* synchronize access to our device file */
        atomic_t open_excl;
 
@@ -505,6 +508,8 @@ static long acc_ioctl(struct file *fp, unsigned code, unsigned long value)
        case ACCESSORY_GET_STRING_SERIAL:
                src = dev->serial;
                break;
+       case ACCESSORY_IS_START_REQUESTED:
+               return dev->start_requested;
        }
        if (!src)
                return -EINVAL;
@@ -572,6 +577,7 @@ static int acc_ctrlrequest(struct usb_composite_dev *cdev,
 
        if (b_requestType == (USB_DIR_OUT | USB_TYPE_VENDOR)) {
                if (b_request == ACCESSORY_START) {
+                       dev->start_requested = 1;
                        schedule_delayed_work(
                                &dev->work, msecs_to_jiffies(10));
                        value = 0;
@@ -593,6 +599,7 @@ static int acc_ctrlrequest(struct usb_composite_dev *cdev,
                        memset(dev->version, 0, sizeof(dev->version));
                        memset(dev->uri, 0, sizeof(dev->uri));
                        memset(dev->serial, 0, sizeof(dev->serial));
+                       dev->start_requested = 0;
                }
        }
 
@@ -624,6 +631,8 @@ acc_function_bind(struct usb_configuration *c, struct usb_function *f)
 
        DBG(cdev, "acc_function_bind dev: %p\n", dev);
 
+       dev->start_requested = 0;
+
        /* allocate interface ID(s) */
        id = usb_interface_id(c, f);
        if (id < 0)
index ebcc5f3..5b2dcf9 100644 (file)
@@ -77,5 +77,7 @@
 #define ACCESSORY_GET_STRING_VERSION        _IOW('M', 4, char[256])
 #define ACCESSORY_GET_STRING_URI            _IOW('M', 5, char[256])
 #define ACCESSORY_GET_STRING_SERIAL         _IOW('M', 6, char[256])
+/* returns 1 if there is a start request pending */
+#define ACCESSORY_IS_START_REQUESTED        _IO('M', 7)
 
 #endif /* __LINUX_USB_F_ACCESSORY_H */