diff mbox

[U-Boot,U-Boot,V2,5/9] usb: ums: add functions to set and get usb interface descriptor

Message ID 20170416155414.14746-6-eddie.cai.linux@gmail.com
State Superseded
Delegated to: Marek Vasut
Headers show

Commit Message

Eddie Cai April 16, 2017, 3:54 p.m. UTC
add functions to set and get usb interface descriptor, so people can
customize usb interface descriptor

Signed-off-by: Eddie Cai <eddie.cai.linux@gmail.com>
---
 drivers/usb/gadget/f_mass_storage.c | 18 ++++++++++++++++++
 include/f_mass_storage.h            |  2 ++
 2 files changed, 20 insertions(+)

Comments

Lukasz Majewski April 19, 2017, 3:29 p.m. UTC | #1
Hi Eddie,

> add functions to set and get usb interface descriptor, so people can
> customize usb interface descriptor

The f_mass_storage USB function is used through the g_dnl code:

./drivers/usb/gadget/g_dnl.c


Other gadget functions - like dfu and thor are using it.

Please consider following this scheme - for example look into the
Samsung's Thor protocol support at:

./drivers/usb/gadget/f_thor.c


Since we managed to add Thor (vendor specific protocol), then it should
be doable to add rockusb as well.

Another good example of this framework reuse is f_fastboot.c to support
Android fastboot protocol.

Please consider if rockchip could be added in the same manner.


> 
> Signed-off-by: Eddie Cai <eddie.cai.linux@gmail.com>
> ---
>  drivers/usb/gadget/f_mass_storage.c | 18 ++++++++++++++++++
>  include/f_mass_storage.h            |  2 ++
>  2 files changed, 20 insertions(+)
> 
> diff --git a/drivers/usb/gadget/f_mass_storage.c
> b/drivers/usb/gadget/f_mass_storage.c index faf875e..333f069 100644
> --- a/drivers/usb/gadget/f_mass_storage.c
> +++ b/drivers/usb/gadget/f_mass_storage.c
> @@ -2870,6 +2870,24 @@ static int fsg_bind_config(struct
> usb_composite_dev *cdev, return rc;
>  }
>  
> +struct usb_interface_descriptor
> *fsg_get_usb_interface_descriptor(void) +{

To adjust the usb descriptor one can use:

g_dnl_bind_fixup() function (defined at g_dnl.c).

It is used to adjust information added to USB file descriptor - e.g.
board/samsung/common/gadget.c or board/siemens/common/factoryreset.c

> +	return &fsg_intf_desc;
> +}
> +
> +void fsg_set_usb_interface_descriptor(struct
> usb_interface_descriptor *desc) +{
> +	if (desc) {
> +		fsg_intf_desc.bLength = desc->bLength;
> +		fsg_intf_desc.bDescriptorType =
> desc->bDescriptorType;
> +		fsg_intf_desc.bNumEndpoints = desc->bNumEndpoints;
> +		fsg_intf_desc.bInterfaceClass =
> desc->bInterfaceClass;
> +		fsg_intf_desc.bInterfaceSubClass =
> desc->bInterfaceSubClass;
> +		fsg_intf_desc.bInterfaceProtocol =
> desc->bInterfaceProtocol;
> +		fsg_intf_desc.iInterface = desc->iInterface;
> +	}
> +}
> +
>  int fsg_add(struct usb_configuration *c)
>  {
>  	struct fsg_common *fsg_common;
> diff --git a/include/f_mass_storage.h b/include/f_mass_storage.h
> index df6ea33..0cf29df 100644
> --- a/include/f_mass_storage.h
> +++ b/include/f_mass_storage.h
> @@ -500,6 +500,8 @@ struct fsg_dev {
>  	struct usb_ep		*bulk_out;
>  };
>  
> +struct usb_interface_descriptor
> *fsg_get_usb_interface_descriptor(void); +void
> fsg_set_usb_interface_descriptor(struct usb_interface_descriptor
> *desc); int sleep_thread(struct fsg_common *common); int
> do_scsi_command(struct fsg_common *common); 




Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd@denx.de
Eddie Cai April 20, 2017, 12:55 a.m. UTC | #2
Hi Lukasz

2017-04-19 23:29 GMT+08:00 Lukasz Majewski <lukma@denx.de>:
> Hi Eddie,
>
>> add functions to set and get usb interface descriptor, so people can
>> customize usb interface descriptor
>
> The f_mass_storage USB function is used through the g_dnl code:
>
> ./drivers/usb/gadget/g_dnl.c
>
>
> Other gadget functions - like dfu and thor are using it.
>
> Please consider following this scheme - for example look into the
> Samsung's Thor protocol support at:
>
> ./drivers/usb/gadget/f_thor.c
>
>
> Since we managed to add Thor (vendor specific protocol), then it should
> be doable to add rockusb as well.
>
> Another good example of this framework reuse is f_fastboot.c to support
> Android fastboot protocol.
>
> Please consider if rockchip could be added in the same manner.
That is the same way i did in my V1 patches.  can you review my V1 patches
again and give some comment? that will be easy for me to address your comments
at the same time.
https://lists.denx.de/pipermail/u-boot/2017-March/283730.html
>
>
>>
>> Signed-off-by: Eddie Cai <eddie.cai.linux@gmail.com>
>> ---
>>  drivers/usb/gadget/f_mass_storage.c | 18 ++++++++++++++++++
>>  include/f_mass_storage.h            |  2 ++
>>  2 files changed, 20 insertions(+)
>>
>> diff --git a/drivers/usb/gadget/f_mass_storage.c
>> b/drivers/usb/gadget/f_mass_storage.c index faf875e..333f069 100644
>> --- a/drivers/usb/gadget/f_mass_storage.c
>> +++ b/drivers/usb/gadget/f_mass_storage.c
>> @@ -2870,6 +2870,24 @@ static int fsg_bind_config(struct
>> usb_composite_dev *cdev, return rc;
>>  }
>>
>> +struct usb_interface_descriptor
>> *fsg_get_usb_interface_descriptor(void) +{
>
> To adjust the usb descriptor one can use:
>
> g_dnl_bind_fixup() function (defined at g_dnl.c).
>
> It is used to adjust information added to USB file descriptor - e.g.
> board/samsung/common/gadget.c or board/siemens/common/factoryreset.c
>
>> +     return &fsg_intf_desc;
>> +}
>> +
>> +void fsg_set_usb_interface_descriptor(struct
>> usb_interface_descriptor *desc) +{
>> +     if (desc) {
>> +             fsg_intf_desc.bLength = desc->bLength;
>> +             fsg_intf_desc.bDescriptorType =
>> desc->bDescriptorType;
>> +             fsg_intf_desc.bNumEndpoints = desc->bNumEndpoints;
>> +             fsg_intf_desc.bInterfaceClass =
>> desc->bInterfaceClass;
>> +             fsg_intf_desc.bInterfaceSubClass =
>> desc->bInterfaceSubClass;
>> +             fsg_intf_desc.bInterfaceProtocol =
>> desc->bInterfaceProtocol;
>> +             fsg_intf_desc.iInterface = desc->iInterface;
>> +     }
>> +}
>> +
>>  int fsg_add(struct usb_configuration *c)
>>  {
>>       struct fsg_common *fsg_common;
>> diff --git a/include/f_mass_storage.h b/include/f_mass_storage.h
>> index df6ea33..0cf29df 100644
>> --- a/include/f_mass_storage.h
>> +++ b/include/f_mass_storage.h
>> @@ -500,6 +500,8 @@ struct fsg_dev {
>>       struct usb_ep           *bulk_out;
>>  };
>>
>> +struct usb_interface_descriptor
>> *fsg_get_usb_interface_descriptor(void); +void
>> fsg_set_usb_interface_descriptor(struct usb_interface_descriptor
>> *desc); int sleep_thread(struct fsg_common *common); int
>> do_scsi_command(struct fsg_common *common);
>
>
>
>
> Best regards,
>
> Lukasz Majewski
>
> --
>
> DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
> HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
> Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd@denx.de
diff mbox

Patch

diff --git a/drivers/usb/gadget/f_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c
index faf875e..333f069 100644
--- a/drivers/usb/gadget/f_mass_storage.c
+++ b/drivers/usb/gadget/f_mass_storage.c
@@ -2870,6 +2870,24 @@  static int fsg_bind_config(struct usb_composite_dev *cdev,
 	return rc;
 }
 
+struct usb_interface_descriptor *fsg_get_usb_interface_descriptor(void)
+{
+	return &fsg_intf_desc;
+}
+
+void fsg_set_usb_interface_descriptor(struct usb_interface_descriptor *desc)
+{
+	if (desc) {
+		fsg_intf_desc.bLength = desc->bLength;
+		fsg_intf_desc.bDescriptorType = desc->bDescriptorType;
+		fsg_intf_desc.bNumEndpoints = desc->bNumEndpoints;
+		fsg_intf_desc.bInterfaceClass = desc->bInterfaceClass;
+		fsg_intf_desc.bInterfaceSubClass = desc->bInterfaceSubClass;
+		fsg_intf_desc.bInterfaceProtocol = desc->bInterfaceProtocol;
+		fsg_intf_desc.iInterface = desc->iInterface;
+	}
+}
+
 int fsg_add(struct usb_configuration *c)
 {
 	struct fsg_common *fsg_common;
diff --git a/include/f_mass_storage.h b/include/f_mass_storage.h
index df6ea33..0cf29df 100644
--- a/include/f_mass_storage.h
+++ b/include/f_mass_storage.h
@@ -500,6 +500,8 @@  struct fsg_dev {
 	struct usb_ep		*bulk_out;
 };
 
+struct usb_interface_descriptor *fsg_get_usb_interface_descriptor(void);
+void fsg_set_usb_interface_descriptor(struct usb_interface_descriptor *desc);
 int sleep_thread(struct fsg_common *common);
 int do_scsi_command(struct fsg_common *common);