mirror of https://gitee.com/openkylin/linux.git
usb: core: add a 'type' parameter to usb_get_status()
This new 'type' parameter will allows interested drivers to request for PTM status or Standard status. Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
d9e1e1484a
commit
2e43f0fe37
|
@ -919,6 +919,7 @@ int usb_get_device_descriptor(struct usb_device *dev, unsigned int size)
|
||||||
* usb_get_status - issues a GET_STATUS call
|
* usb_get_status - issues a GET_STATUS call
|
||||||
* @dev: the device whose status is being checked
|
* @dev: the device whose status is being checked
|
||||||
* @recip: USB_RECIP_*; for device, interface, or endpoint
|
* @recip: USB_RECIP_*; for device, interface, or endpoint
|
||||||
|
* @type: USB_STATUS_TYPE_*; for standard or PTM status types
|
||||||
* @target: zero (for device), else interface or endpoint number
|
* @target: zero (for device), else interface or endpoint number
|
||||||
* @data: pointer to two bytes of bitmap data
|
* @data: pointer to two bytes of bitmap data
|
||||||
* Context: !in_interrupt ()
|
* Context: !in_interrupt ()
|
||||||
|
@ -937,24 +938,56 @@ int usb_get_device_descriptor(struct usb_device *dev, unsigned int size)
|
||||||
* Returns 0 and the status value in *@data (in host byte order) on success,
|
* Returns 0 and the status value in *@data (in host byte order) on success,
|
||||||
* or else the status code from the underlying usb_control_msg() call.
|
* or else the status code from the underlying usb_control_msg() call.
|
||||||
*/
|
*/
|
||||||
int usb_get_status(struct usb_device *dev, int recip, int target, void *data)
|
int usb_get_status(struct usb_device *dev, int recip, int type, int target,
|
||||||
|
void *data)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
__le16 *status = kmalloc(sizeof(*status), GFP_KERNEL);
|
void *status;
|
||||||
|
int length;
|
||||||
|
|
||||||
|
switch (type) {
|
||||||
|
case USB_STATUS_TYPE_STANDARD:
|
||||||
|
length = 2;
|
||||||
|
break;
|
||||||
|
case USB_STATUS_TYPE_PTM:
|
||||||
|
if (recip != USB_RECIP_DEVICE)
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
|
length = 4;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
status = kmalloc(length, GFP_KERNEL);
|
||||||
if (!status)
|
if (!status)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
|
ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
|
||||||
USB_REQ_GET_STATUS, USB_DIR_IN | recip, USB_STATUS_TYPE_STANDARD,
|
USB_REQ_GET_STATUS, USB_DIR_IN | recip, USB_STATUS_TYPE_STANDARD,
|
||||||
target, status, sizeof(*status), USB_CTRL_GET_TIMEOUT);
|
target, status, length, USB_CTRL_GET_TIMEOUT);
|
||||||
|
|
||||||
if (ret == 2) {
|
switch (ret) {
|
||||||
*(u16 *) data = le16_to_cpu(*status);
|
case 4:
|
||||||
ret = 0;
|
if (type != USB_STATUS_TYPE_PTM) {
|
||||||
} else if (ret >= 0) {
|
ret = -EIO;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
*(u32 *) data = le32_to_cpu(*(__le32 *) status);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
if (type != USB_STATUS_TYPE_STANDARD) {
|
||||||
|
ret = -EIO;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
*(u16 *) data = le16_to_cpu(*(__le16 *) status);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
ret = -EIO;
|
ret = -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
kfree(status);
|
kfree(status);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1766,12 +1766,13 @@ extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
|
||||||
extern int usb_get_descriptor(struct usb_device *dev, unsigned char desctype,
|
extern int usb_get_descriptor(struct usb_device *dev, unsigned char desctype,
|
||||||
unsigned char descindex, void *buf, int size);
|
unsigned char descindex, void *buf, int size);
|
||||||
extern int usb_get_status(struct usb_device *dev,
|
extern int usb_get_status(struct usb_device *dev,
|
||||||
int recip, int target, void *data);
|
int recip, int type, int target, void *data);
|
||||||
|
|
||||||
static inline int usb_get_std_status(struct usb_device *dev,
|
static inline int usb_get_std_status(struct usb_device *dev,
|
||||||
int recip, int target, void *data)
|
int recip, int target, void *data)
|
||||||
{
|
{
|
||||||
return usb_get_status(dev, recip, target, data);
|
return usb_get_status(dev, recip, USB_STATUS_TYPE_STANDARD, target,
|
||||||
|
data);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern int usb_string(struct usb_device *dev, int index,
|
extern int usb_string(struct usb_device *dev, int index,
|
||||||
|
|
Loading…
Reference in New Issue