diff options
-rw-r--r-- | drivers/usb/gadget/android.c | 27 | ||||
-rw-r--r-- | drivers/usb/gadget/f_mtp.c | 40 | ||||
-rw-r--r-- | include/linux/usb/f_mtp.h | 5 |
3 files changed, 37 insertions, 35 deletions
diff --git a/drivers/usb/gadget/android.c b/drivers/usb/gadget/android.c index c78d5727641..0ce6c8045a4 100644 --- a/drivers/usb/gadget/android.c +++ b/drivers/usb/gadget/android.c @@ -290,7 +290,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, @@ -489,6 +505,14 @@ static struct android_usb_function rndis_function = { .attributes = rndis_function_attributes, }; +/* 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 mass_storage_function_config { struct fsg_config fsg; @@ -659,6 +683,7 @@ static struct android_usb_function *supported_functions[] = { &adb_function, &acm_function, &mtp_function, + &ptp_function, &rndis_function, &mass_storage_function, &accessory_function, diff --git a/drivers/usb/gadget/f_mtp.c b/drivers/usb/gadget/f_mtp.c index 77e9e6edb70..37bfffe0f44 100644 --- a/drivers/usb/gadget/f_mtp.c +++ b/drivers/usb/gadget/f_mtp.c @@ -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; @@ -918,20 +915,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; @@ -1000,7 +983,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); @@ -1012,8 +994,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 @@ -1109,8 +1090,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) ? @@ -1232,7 +1212,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; @@ -1253,18 +1233,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); } diff --git a/include/linux/usb/f_mtp.h b/include/linux/usb/f_mtp.h index 3f1795def0a..3c6a58bd4ec 100644 --- a/include/linux/usb/f_mtp.h +++ b/include/linux/usb/f_mtp.h @@ -18,9 +18,6 @@ #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 #include <linux/ioctl.h> @@ -69,8 +66,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) /* Sends the specified file range to the host, |