Re: [PATCH v4 3/5] usb: add options to identify the capabilities of OTG devices

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Apr 16, 2015 at 02:57:01PM +0800, Macpaul Lin wrote:
> Add independent options for identify the capabilities of
> ADP/SRP/HNP feature for OTG devices.
> 
> Signed-off-by: Macpaul Lin <macpaul@xxxxxxxxx>
> ---
> changes for v2:
>   - no change
> changes for v3:
>   - composite.h: add usb_gadget_customize_otg_desc() declaration.
>   - composite.c: replace static configuration of ADP/SRP/HNP capabilities
>     with runtime polling usb_gadget_customize_otg_desc().
> changes for v4:
>  - fix description of each git commits.
> 
>  drivers/usb/gadget/composite.c | 34 ++++++++++++++++++++++++++++++++++
>  include/linux/usb/composite.h  |  2 ++
>  2 files changed, 36 insertions(+)
> 
> diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
> index 4e3447b..81ef3f0 100644
> --- a/drivers/usb/gadget/composite.c
> +++ b/drivers/usb/gadget/composite.c
> @@ -1441,6 +1441,34 @@ static int fill_ext_prop(struct usb_configuration *c, int interface, u8 *buf)
>  	return 0;
>  }
>  
> +struct usb_otg_descriptor
> +*usb_gadget_customize_otg_desc(struct usb_gadget *gadget)
> +{
> +	struct usb_composite_dev	*cdev = get_gadget_data(gadget);
> +	struct usb_request		*req = cdev->req;
> +	struct usb_otg_descriptor	*otg_desc = req->buf;
> +	struct usb_otg_descriptor20	*otg_desc20 = req->buf;
> +
> +	otg_desc->bDescriptorType = USB_DT_OTG;
> +
> +	if (gadget_is_otg20(gadget)) { /* If supports OTG 2.0 */
> +		otg_desc->bLength = sizeof(*otg_desc20);
> +		otg_desc20->bcdOTG = cpu_to_le16(0x0200);
> +	} else { /* If only supports OTG 1.3 */
> +		otg_desc->bLength = sizeof(*otg_desc);
> +	}
> +
> +	if (gadget->adp_support)
> +		otg_desc->bmAttributes |= USB_OTG_ADP;
> +	if (gadget->hnp_support)
> +		otg_desc->bmAttributes |= USB_OTG_HNP;
> +	if (gadget->srp_support)
> +		otg_desc->bmAttributes |= USB_OTG_SRP;
> +
> +	return otg_desc;
> +}
> +EXPORT_SYMBOL_GPL(usb_gadget_customize_otg_desc);
> +

My idea is we decide otg descriptor at driver bind process (multi.c,
etc) , and copy the descriptor content to req->buf when the host request otg descriptor
(composite.c), what's your opinion?

struct usb_otg_descriptor
*usb_gadget_customize_otg_desc(struct usb_gadget *gadget, struct usb_otg_descriptor *otg_desc)
{
	otg_desc->bmAttributes = 0;

	if (gadget->adp_support)
		otg_desc->bmAttributes |= USB_OTG_ADP;
	if (gadget->hnp_support)
		otg_desc->bmAttributes |= USB_OTG_HNP;
	if (gadget->srp_support)
		otg_desc->bmAttributes |= USB_OTG_SRP;

	return otg_desc;
}

>  /*
>   * The setup() callback implements all the ep0 functionality that's
>   * not handled lower down, in hardware or the hardware driver(like
> @@ -1487,6 +1515,12 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
>  			goto unknown;
>  		switch (w_value >> 8) {
>  
> +		case USB_DT_OTG:
> +			usb_gadget_customize_otg_desc(gadget);
> +
> +			value = min_t(int, w_length,
> +				sizeof(struct usb_otg_descriptor));
> +			break;

		if (gadget_is_otg(gadget) || gadget_is_otg20(gadget)) {
			struct usb_configuration *config;

			config = list_first_entry(&cdev->configs,
					struct usb_configuration, list);
			if (!config)
				goto done;

			value = min_t(int, w_length,
				sizeof(struct usb_otg_descriptor));
			memcpy(req->buf, config->descriptors[0], value);
		}
>  		case USB_DT_DEVICE:
>  			cdev->desc.bNumConfigurations =
>  				count_configs(cdev, USB_DT_DEVICE);
> diff --git a/include/linux/usb/composite.h b/include/linux/usb/composite.h
> index 2511469..a867242 100644
> --- a/include/linux/usb/composite.h
> +++ b/include/linux/usb/composite.h
> @@ -507,6 +507,8 @@ extern struct usb_string *usb_gstrings_attach(struct usb_composite_dev *cdev,
>  extern int usb_string_ids_n(struct usb_composite_dev *c, unsigned n);
>  
>  extern void composite_disconnect(struct usb_gadget *gadget);
> +extern struct usb_otg_descriptor
> +		*usb_gadget_customize_otg_desc(struct usb_gadget *gadget);
>  extern int composite_setup(struct usb_gadget *gadget,
>  		const struct usb_ctrlrequest *ctrl);
>  extern void composite_suspend(struct usb_gadget *gadget);
> -- 
> 1.8.3.2
> 

-- 

Best Regards,
Peter Chen
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux