USB: gadget: f_accessory: New gadget driver for android USB accesories

Signed-off-by: Mike Lockwood <lockwood@android.com>

USB: gadget: f_accessory: Misc improvements and cleanup:

- Add URI string

- Replace type string with a description string

- Add a control call to retrieve accessory protocol version (currently 1)

- Driver read() and write() calls now fail after USB disconnect until
  driver file is closed and reopened.

- Misc cleanup work

Signed-off-by: Mike Lockwood <lockwood@android.com>

USB: gadget: f_accessory: Clear accessory strings when USB is disconnected

Signed-off-by: Mike Lockwood <lockwood@android.com>

USB: gadget: f_accessory: Clear previous strings on ACCESSORY_GET_PROTOCOL

Clearing strings on disconnect does not work since we may receive
a disconnect on some devices when transitioning into accessory mode.
We require an accessory to send ACCESSORY_GET_PROTOCOL before
sending any strings, so any strings from a previous session will be cleared.

Signed-off-by: Mike Lockwood <lockwood@android.com>

USB: gadget: f_accessory: Clear disconnected flag when driver file is opened

Fixes a race condition that can occur when entering accessory mode.

Signed-off-by: Mike Lockwood <lockwood@android.com>

USB: gadget: f_accessory: Add string for accessory's unique serial number

Signed-off-by: Mike Lockwood <lockwood@android.com>

USB: gadget: f_accessory: Set bNumEndpoints to correct value of 2

Change-Id: I24f4e36f196d45436e0573301500c3b93215953d
Signed-off-by: Mike Lockwood <lockwood@android.com>
diff --git a/drivers/usb/gadget/android.c b/drivers/usb/gadget/android.c
index eb6af6d..2ebc818 100644
--- a/drivers/usb/gadget/android.c
+++ b/drivers/usb/gadget/android.c
@@ -430,6 +430,19 @@
 			}
 		}
 #endif
+#ifdef CONFIG_USB_ANDROID_ACCESSORY
+		if (!strcmp(f->name, "accessory") && enable) {
+			struct usb_function		*func;
+
+		    /* disable everything else (and keep adb for now) */
+			list_for_each_entry(func, &android_config_driver.functions, list) {
+				if (strcmp(func->name, "accessory")
+					&& strcmp(func->name, "adb")) {
+					usb_function_set_enabled(func, 0);
+				}
+			}
+        }
+#endif
 
 		update_dev_desc(dev);