USB: gadget: f_mtp: Add PTP variant of MTP USB function
authorMike Lockwood <lockwood@android.com>
Thu, 2 Jun 2011 02:17:36 +0000 (22:17 -0400)
committerMike Lockwood <lockwood@android.com>
Sat, 18 Jun 2011 02:27:20 +0000 (22:27 -0400)
This is the same as MTP but with PTP interface descriptor.
Also removed obsolete ioctl for switching between MTP and PTP mode

Signed-off-by: Mike Lockwood <lockwood@android.com>
drivers/usb/gadget/android.c
drivers/usb/gadget/f_mtp.c
include/linux/usb/f_mtp.h

index 377df5b4d52e25afdc97b43ad2be2684c0ee64cc..ebe67666b20e77187bc0e65bf42d8e5681fc71f0 100644 (file)
@@ -294,7 +294,23 @@ static void mtp_function_cleanup(struct android_usb_function *f)
 
 static int mtp_function_bind_config(struct android_usb_function *f, struct usb_configuration *c)
 {
-       return mtp_bind_config(c);
+       return mtp_bind_config(c, false);
+}
+
+static int ptp_function_init(struct android_usb_function *f, struct usb_composite_dev *cdev)
+{
+       /* nothing to do - initialization is handled by mtp_function_init */
+       return 0;
+}
+
+static void ptp_function_cleanup(struct android_usb_function *f)
+{
+       /* nothing to do - cleanup is handled by mtp_function_cleanup */
+}
+
+static int ptp_function_bind_config(struct android_usb_function *f, struct usb_configuration *c)
+{
+       return mtp_bind_config(c, true);
 }
 
 static int mtp_function_ctrlrequest(struct android_usb_function *f,
@@ -312,6 +328,14 @@ static struct android_usb_function mtp_function = {
        .ctrlrequest    = mtp_function_ctrlrequest,
 };
 
+/* PTP function is same as MTP with slightly different interface descriptor */
+static struct android_usb_function ptp_function = {
+       .name           = "ptp",
+       .init           = ptp_function_init,
+       .cleanup        = ptp_function_cleanup,
+       .bind_config    = ptp_function_bind_config,
+};
+
 
 struct rndis_function_config {
        u8      ethaddr[ETH_ALEN];
@@ -623,6 +647,7 @@ static struct android_usb_function *supported_functions[] = {
        &adb_function,
        &acm_function,
        &mtp_function,
+       &ptp_function,
        &rndis_function,
        &mass_storage_function,
        &accessory_function,
index 230dc8d788d95a8d55e7d3721524202cb57ef9f4..a5b646394426974230b39958e55a7b4515e134df 100644 (file)
@@ -74,9 +74,6 @@ struct mtp_dev {
        struct usb_composite_dev *cdev;
        spinlock_t lock;
 
-       /* appear as MTP or PTP when enumerating */
-       int interface_mode;
-
        struct usb_ep *ep_in;
        struct usb_ep *ep_out;
        struct usb_ep *ep_intr;
@@ -888,20 +885,6 @@ static long mtp_ioctl(struct file *fp, unsigned code, unsigned long value)
                ret = dev->xfer_result;
                break;
        }
-       case MTP_SET_INTERFACE_MODE:
-               if (value == MTP_INTERFACE_MODE_MTP ||
-                       value == MTP_INTERFACE_MODE_PTP) {
-                       dev->interface_mode = value;
-                       if (value == MTP_INTERFACE_MODE_PTP) {
-                               dev->function.descriptors = fs_ptp_descs;
-                               dev->function.hs_descriptors = hs_ptp_descs;
-                       } else {
-                               dev->function.descriptors = fs_mtp_descs;
-                               dev->function.hs_descriptors = hs_mtp_descs;
-                       }
-                       ret = 0;
-               }
-               break;
        case MTP_SEND_EVENT:
        {
                struct mtp_event        event;
@@ -970,7 +953,6 @@ static struct miscdevice mtp_device = {
 static int mtp_ctrlrequest(struct usb_composite_dev *cdev,
                                const struct usb_ctrlrequest *ctrl)
 {
-       struct mtp_dev *dev = _mtp_dev;
        int     value = -EOPNOTSUPP;
        u16     w_index = le16_to_cpu(ctrl->wIndex);
        u16     w_value = le16_to_cpu(ctrl->wValue);
@@ -982,8 +964,7 @@ static int mtp_ctrlrequest(struct usb_composite_dev *cdev,
                        w_value, w_index, w_length);
 
        /* Handle MTP OS string */
-       if (dev->interface_mode == MTP_INTERFACE_MODE_MTP
-                       && ctrl->bRequestType ==
+       if (ctrl->bRequestType ==
                        (USB_DIR_IN | USB_TYPE_STANDARD | USB_RECIP_DEVICE)
                        && ctrl->bRequest == USB_REQ_GET_DESCRIPTOR
                        && (w_value >> 8) == USB_DT_STRING
@@ -1078,8 +1059,7 @@ static int mtp_function_setup(struct usb_function *f,
                DBG(cdev, "vendor request: %d index: %d value: %d length: %d\n",
                        ctrl->bRequest, w_index, w_value, w_length);
 
-               if (dev->interface_mode == MTP_INTERFACE_MODE_MTP
-                               && ctrl->bRequest == 1
+               if (ctrl->bRequest == 1
                                && (ctrl->bRequestType & USB_DIR_IN)
                                && (w_index == 4 || w_index == 5)) {
                        value = (w_length < sizeof(mtp_ext_config_desc) ?
@@ -1201,7 +1181,7 @@ static void mtp_function_disable(struct usb_function *f)
        VDBG(cdev, "%s disabled\n", dev->function.name);
 }
 
-static int mtp_bind_config(struct usb_configuration *c)
+static int mtp_bind_config(struct usb_configuration *c, bool ptp_config)
 {
        struct mtp_dev *dev = _mtp_dev;
        int ret = 0;
@@ -1219,18 +1199,20 @@ static int mtp_bind_config(struct usb_configuration *c)
 
        dev->cdev = c->cdev;
        dev->function.name = "mtp";
-       dev->function.strings = mtp_strings,
-       dev->function.descriptors = fs_mtp_descs;
-       dev->function.hs_descriptors = hs_mtp_descs;
+       dev->function.strings = mtp_strings;
+       if (ptp_config) {
+               dev->function.descriptors = fs_ptp_descs;
+               dev->function.hs_descriptors = hs_ptp_descs;
+       } else {
+               dev->function.descriptors = fs_mtp_descs;
+               dev->function.hs_descriptors = hs_mtp_descs;
+       }
        dev->function.bind = mtp_function_bind;
        dev->function.unbind = mtp_function_unbind;
        dev->function.setup = mtp_function_setup;
        dev->function.set_alt = mtp_function_set_alt;
        dev->function.disable = mtp_function_disable;
 
-       /* MTP mode by default */
-       dev->interface_mode = MTP_INTERFACE_MODE_MTP;
-
        return usb_add_function(c, &dev->function);
 }
 
index e4fd88066389d40cb8fc37fe536cdf19fe9d7464..fdf828c4925046815b2695427d539750961044a5 100644 (file)
 #ifndef __LINUX_USB_F_MTP_H
 #define __LINUX_USB_F_MTP_H
 
-/* Constants for MTP_SET_INTERFACE_MODE */
-#define MTP_INTERFACE_MODE_MTP  0
-#define MTP_INTERFACE_MODE_PTP  1
-
 
 struct mtp_file_range {
        /* file descriptor for file to transfer */
@@ -45,8 +41,6 @@ struct mtp_event {
  * The file is created if it does not exist.
  */
 #define MTP_RECEIVE_FILE           _IOW('M', 1, struct mtp_file_range)
-/* Sets the driver mode to either MTP or PTP */
-#define MTP_SET_INTERFACE_MODE     _IOW('M', 2, int)
 /* Sends an event to the host via the interrupt endpoint */
 #define MTP_SEND_EVENT             _IOW('M', 3, struct mtp_event)