mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-08 20:07:46 +09:00
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>
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -18,10 +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
|
||||
|
||||
|
||||
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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user