summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorMike Lockwood <lockwood@android.com>2011-06-01 22:17:36 -0400
committerDan Willemsen <dwillemsen@nvidia.com>2011-11-30 21:38:42 -0800
commit665b56b827822677080da0ab65bbb9ef3fdf56af (patch)
treed1da577ee397efb5a3aa84e9fe3a1ba2c391fde3 /drivers
parent64e69d682bbb8c8745bacb937a4bc15345a1b209 (diff)
USB: gadget: f_mtp: Add PTP variant of MTP USB function
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>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/usb/gadget/android.c27
-rw-r--r--drivers/usb/gadget/f_mtp.c40
2 files changed, 37 insertions, 30 deletions
diff --git a/drivers/usb/gadget/android.c b/drivers/usb/gadget/android.c
index 377df5b4d52e..ebe67666b20e 100644
--- a/drivers/usb/gadget/android.c
+++ b/drivers/usb/gadget/android.c
@@ -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,
diff --git a/drivers/usb/gadget/f_mtp.c b/drivers/usb/gadget/f_mtp.c
index 230dc8d788d9..a5b646394426 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;
@@ -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);
}