diff mbox

usb: gadget: USB3 support to the legacy printer driver

Message ID 546A829A.8030106@linaro.org
State New
Headers show

Commit Message

Jorge Ramirez-Ortiz Nov. 17, 2014, 11:19 p.m. UTC
Hi,

This patch adds USB3 support to the legacy gadget printer driver.
Applies cleanly on fc14f9c Linux 3.18-rc5.

Please could it be considered for inclusion?

regards,
Jorge



From f46d9b0d2160b30f14dee104657de865e9e2bc38 Mon Sep 17 00:00:00 2001
From: Jorge Ramirez-Ortiz <jorge.ramirez-ortiz@linaro.org>
Date: Thu, 25 Sep 2014 16:17:20 -0400
Subject: [PATCH] usb: gadget: add USB3 support to the printer driver

Add SS descriptors to support the capabilities provided by USB3 controller
drivers; unit tests run using PLX 3380 [max transfer speed measured of 1Gbps]

This driver will fallback to lower operating modes when the higher ones are
not available.

Signed-off-by: Jorge Ramirez-Ortiz <jorge.ramirez-ortiz@linaro.org>
---
 drivers/usb/gadget/legacy/printer.c | 66 +++++++++++++++++++++++++++++++++----
 1 file changed, 60 insertions(+), 6 deletions(-)

Comments

Felipe Balbi Nov. 18, 2014, 12:30 a.m. UTC | #1
Hi,

On Mon, Nov 17, 2014 at 06:19:54PM -0500, Jorge Ramirez-Ortiz wrote:
> Hi,
> 
> This patch adds USB3 support to the legacy gadget printer driver.
> Applies cleanly on fc14f9c Linux 3.18-rc5.
> 
> Please could it be considered for inclusion?

sure, if you send it properly (see Documentation/SubmittingPatches),
provide logs of your tests with a recent kernel (v3.18-rc5 would be just
awesome) and Cc myself on your resubmission.

> diff --git a/drivers/usb/gadget/legacy/printer.c b/drivers/usb/gadget/legacy/printer.c
> index 6474081..625d905 100644
> --- a/drivers/usb/gadget/legacy/printer.c
> +++ b/drivers/usb/gadget/legacy/printer.c
> @@ -3,6 +3,7 @@
>   *
>   * Copyright (C) 2003-2005 David Brownell
>   * Copyright (C) 2006 Craig W. Nadler
> + * Copyright (C) 2014 Linaro.org

I don't think the minimal change below constitutes enough to merit the
copyright. If your lawyers tell you otherwise, let me know.

Greg, what's Linux Foundation's lawyers take on this ?

> @@ -208,6 +209,43 @@ static struct usb_descriptor_header *hs_printer_function[] = {
>         NULL
>  };
>  
> +/*
> + * Added endpoint descriptors for 3.0 devices
> + */
> +
> +static struct usb_endpoint_descriptor ss_ep_in_desc = {
> +       .bLength =              USB_DT_ENDPOINT_SIZE,
> +       .bDescriptorType =      USB_DT_ENDPOINT,
> +       .bmAttributes =         USB_ENDPOINT_XFER_BULK,
> +       .wMaxPacketSize =       cpu_to_le16(1024),
> +};
> +
> +struct usb_ss_ep_comp_descriptor ss_ep_in_comp_desc = {
> +       .bLength =              sizeof(ss_ep_in_comp_desc),
> +       .bDescriptorType =      USB_DT_SS_ENDPOINT_COMP,
> +};
> +
> +static struct usb_endpoint_descriptor ss_ep_out_desc = {
> +       .bLength =              USB_DT_ENDPOINT_SIZE,
> +       .bDescriptorType =      USB_DT_ENDPOINT,
> +       .bmAttributes =         USB_ENDPOINT_XFER_BULK,
> +       .wMaxPacketSize =       cpu_to_le16(1024),
> +};
> +
> +struct usb_ss_ep_comp_descriptor ss_ep_out_comp_desc = {
> +       .bLength =              sizeof(ss_ep_out_comp_desc),
> +       .bDescriptorType =      USB_DT_SS_ENDPOINT_COMP,
> +};
> +
> +static struct usb_descriptor_header *ss_printer_function[] = {
> +       (struct usb_descriptor_header *) &intf_desc,
> +       (struct usb_descriptor_header *) &ss_ep_in_desc,
> +       (struct usb_descriptor_header *) &ss_ep_in_comp_desc,
> +       (struct usb_descriptor_header *) &ss_ep_out_desc,
> +       (struct usb_descriptor_header *) &ss_ep_out_comp_desc,
> +       NULL
> +};
> +
>  static struct usb_otg_descriptor otg_descriptor = {
>         .bLength =              sizeof otg_descriptor,
>         .bDescriptorType =      USB_DT_OTG,
> @@ -220,7 +258,20 @@ static const struct usb_descriptor_header *otg_desc[] = {
>  };
>  
>  /* maxpacket and other transfer characteristics vary by speed. */
> -#define ep_desc(g, hs, fs) (((g)->speed == USB_SPEED_HIGH)?(hs):(fs))
> +static inline struct usb_endpoint_descriptor *ep_desc(struct usb_gadget *gadget,
> +                                       struct usb_endpoint_descriptor *fs,
> +                                       struct usb_endpoint_descriptor *hs,
> +                                       struct usb_endpoint_descriptor *ss)
> +{
> +       struct usb_endpoint_descriptor *d = fs;
> +
> +       if (gadget->speed == USB_SPEED_SUPER)
> +               d = ss;
> +       else if (gadget->speed == USB_SPEED_HIGH)
> +               d = hs;

what happened to good old switch ?

> +       return d;
> +}
>  
>  /*-------------------------------------------------------------------------*/
>  
> @@ -793,11 +844,12 @@ set_printer_interface(struct printer_dev *dev)
>  {
>         int                     result = 0;
>  
> -       dev->in_ep->desc = ep_desc(dev->gadget, &hs_ep_in_desc, &fs_ep_in_desc);
> +       dev->in_ep->desc = ep_desc(dev->gadget, &fs_ep_in_desc, &hs_ep_in_desc,
> +                                                               &ss_ep_in_desc);

Fix your indentation.

>         dev->in_ep->driver_data = dev;
>  
> -       dev->out_ep->desc = ep_desc(dev->gadget, &hs_ep_out_desc,
> -                                   &fs_ep_out_desc);
> +       dev->out_ep->desc = ep_desc(dev->gadget, &fs_ep_out_desc,
> +                                       &hs_ep_out_desc, &ss_ep_out_desc);
>         dev->out_ep->driver_data = dev;
>  
>         result = usb_ep_enable(dev->in_ep);
> @@ -1016,9 +1068,11 @@ autoconf_fail:
>         /* assumes that all endpoints are dual-speed */
>         hs_ep_in_desc.bEndpointAddress = fs_ep_in_desc.bEndpointAddress;
>         hs_ep_out_desc.bEndpointAddress = fs_ep_out_desc.bEndpointAddress;
> +       ss_ep_in_desc.bEndpointAddress = fs_ep_in_desc.bEndpointAddress;
> +       ss_ep_out_desc.bEndpointAddress = fs_ep_out_desc.bEndpointAddress;
>  
>         ret = usb_assign_descriptors(f, fs_printer_function,
> -                       hs_printer_function, NULL);
> +                                    hs_printer_function, ss_printer_function);

why do you change indentation when adding just one extra argument ?
Greg KH Nov. 18, 2014, 12:54 a.m. UTC | #2
On Mon, Nov 17, 2014 at 06:30:28PM -0600, Felipe Balbi wrote:
> Hi,
> 
> On Mon, Nov 17, 2014 at 06:19:54PM -0500, Jorge Ramirez-Ortiz wrote:
> > Hi,
> > 
> > This patch adds USB3 support to the legacy gadget printer driver.
> > Applies cleanly on fc14f9c Linux 3.18-rc5.
> > 
> > Please could it be considered for inclusion?
> 
> sure, if you send it properly (see Documentation/SubmittingPatches),
> provide logs of your tests with a recent kernel (v3.18-rc5 would be just
> awesome) and Cc myself on your resubmission.
> 
> > diff --git a/drivers/usb/gadget/legacy/printer.c b/drivers/usb/gadget/legacy/printer.c
> > index 6474081..625d905 100644
> > --- a/drivers/usb/gadget/legacy/printer.c
> > +++ b/drivers/usb/gadget/legacy/printer.c
> > @@ -3,6 +3,7 @@
> >   *
> >   * Copyright (C) 2003-2005 David Brownell
> >   * Copyright (C) 2006 Craig W. Nadler
> > + * Copyright (C) 2014 Linaro.org
> 
> I don't think the minimal change below constitutes enough to merit the
> copyright. If your lawyers tell you otherwise, let me know.
> 
> Greg, what's Linux Foundation's lawyers take on this ?

I'm not going to speak for the Linux Foundation here (we have no
in-house lawyers), but I have been advised that you need to modify/add
at least 1/3 of the file before you can add your copyright notice to a
file.  That's the rule I go by, and numerous lawyers I have asked about
this say it is a safe rule to follow.

Linaro should also be following those rules, last I checked with them,
so Jorge, you should go back and ask for clarification.

But then there's the issue that copyright notices in files really don't
mean anything, but I'm not going to get into that discussion right now :)

thanks,

greg k-h
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
Jorge Ramirez-Ortiz Nov. 18, 2014, 1:14 a.m. UTC | #3
On 11/17/2014 07:54 PM, Greg KH wrote:
> On Mon, Nov 17, 2014 at 06:30:28PM -0600, Felipe Balbi wrote:
>> Hi,
>>
>> On Mon, Nov 17, 2014 at 06:19:54PM -0500, Jorge Ramirez-Ortiz wrote:
>>> Hi,
>>>
>>> This patch adds USB3 support to the legacy gadget printer driver.
>>> Applies cleanly on fc14f9c Linux 3.18-rc5.
>>>
>>> Please could it be considered for inclusion?
>> sure, if you send it properly (see Documentation/SubmittingPatches),
>> provide logs of your tests with a recent kernel (v3.18-rc5 would be just
>> awesome) and Cc myself on your resubmission.
>>
>>> diff --git a/drivers/usb/gadget/legacy/printer.c b/drivers/usb/gadget/legacy/printer.c
>>> index 6474081..625d905 100644
>>> --- a/drivers/usb/gadget/legacy/printer.c
>>> +++ b/drivers/usb/gadget/legacy/printer.c
>>> @@ -3,6 +3,7 @@
>>>   *
>>>   * Copyright (C) 2003-2005 David Brownell
>>>   * Copyright (C) 2006 Craig W. Nadler
>>> + * Copyright (C) 2014 Linaro.org
>> I don't think the minimal change below constitutes enough to merit the
>> copyright. If your lawyers tell you otherwise, let me know.
>>
>> Greg, what's Linux Foundation's lawyers take on this ?
> I'm not going to speak for the Linux Foundation here (we have no
> in-house lawyers), but I have been advised that you need to modify/add
> at least 1/3 of the file before you can add your copyright notice to a
> file.  That's the rule I go by, and numerous lawyers I have asked about
> this say it is a safe rule to follow.
>
> Linaro should also be following those rules, last I checked with them,
> so Jorge, you should go back and ask for clarification.

Yes, let's drop the copyright - my fault.

>
> But then there's the issue that copyright notices in files really don't
> mean anything, but I'm not going to get into that discussion right now :)
>
> thanks,
>
> greg k-h

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
diff mbox

Patch

diff --git a/drivers/usb/gadget/legacy/printer.c b/drivers/usb/gadget/legacy/printer.c
index 6474081..625d905 100644
--- a/drivers/usb/gadget/legacy/printer.c
+++ b/drivers/usb/gadget/legacy/printer.c
@@ -3,6 +3,7 @@ 
  *
  * Copyright (C) 2003-2005 David Brownell
  * Copyright (C) 2006 Craig W. Nadler
+ * Copyright (C) 2014 Linaro.org
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -208,6 +209,43 @@  static struct usb_descriptor_header *hs_printer_function[] = {
        NULL
 };
 
+/*
+ * Added endpoint descriptors for 3.0 devices
+ */
+
+static struct usb_endpoint_descriptor ss_ep_in_desc = {
+       .bLength =              USB_DT_ENDPOINT_SIZE,
+       .bDescriptorType =      USB_DT_ENDPOINT,
+       .bmAttributes =         USB_ENDPOINT_XFER_BULK,
+       .wMaxPacketSize =       cpu_to_le16(1024),
+};
+
+struct usb_ss_ep_comp_descriptor ss_ep_in_comp_desc = {
+       .bLength =              sizeof(ss_ep_in_comp_desc),
+       .bDescriptorType =      USB_DT_SS_ENDPOINT_COMP,
+};
+
+static struct usb_endpoint_descriptor ss_ep_out_desc = {
+       .bLength =              USB_DT_ENDPOINT_SIZE,
+       .bDescriptorType =      USB_DT_ENDPOINT,
+       .bmAttributes =         USB_ENDPOINT_XFER_BULK,
+       .wMaxPacketSize =       cpu_to_le16(1024),
+};
+
+struct usb_ss_ep_comp_descriptor ss_ep_out_comp_desc = {
+       .bLength =              sizeof(ss_ep_out_comp_desc),
+       .bDescriptorType =      USB_DT_SS_ENDPOINT_COMP,
+};
+
+static struct usb_descriptor_header *ss_printer_function[] = {
+       (struct usb_descriptor_header *) &intf_desc,
+       (struct usb_descriptor_header *) &ss_ep_in_desc,
+       (struct usb_descriptor_header *) &ss_ep_in_comp_desc,
+       (struct usb_descriptor_header *) &ss_ep_out_desc,
+       (struct usb_descriptor_header *) &ss_ep_out_comp_desc,
+       NULL
+};
+
 static struct usb_otg_descriptor otg_descriptor = {
        .bLength =              sizeof otg_descriptor,
        .bDescriptorType =      USB_DT_OTG,
@@ -220,7 +258,20 @@  static const struct usb_descriptor_header *otg_desc[] = {
 };
 
 /* maxpacket and other transfer characteristics vary by speed. */
-#define ep_desc(g, hs, fs) (((g)->speed == USB_SPEED_HIGH)?(hs):(fs))
+static inline struct usb_endpoint_descriptor *ep_desc(struct usb_gadget *gadget,
+                                       struct usb_endpoint_descriptor *fs,
+                                       struct usb_endpoint_descriptor *hs,
+                                       struct usb_endpoint_descriptor *ss)
+{
+       struct usb_endpoint_descriptor *d = fs;
+
+       if (gadget->speed == USB_SPEED_SUPER)
+               d = ss;
+       else if (gadget->speed == USB_SPEED_HIGH)
+               d = hs;
+
+       return d;
+}
 
 /*-------------------------------------------------------------------------*/
 
@@ -793,11 +844,12 @@  set_printer_interface(struct printer_dev *dev)
 {
        int                     result = 0;
 
-       dev->in_ep->desc = ep_desc(dev->gadget, &hs_ep_in_desc, &fs_ep_in_desc);
+       dev->in_ep->desc = ep_desc(dev->gadget, &fs_ep_in_desc, &hs_ep_in_desc,
+                                                               &ss_ep_in_desc);
        dev->in_ep->driver_data = dev;
 
-       dev->out_ep->desc = ep_desc(dev->gadget, &hs_ep_out_desc,
-                                   &fs_ep_out_desc);
+       dev->out_ep->desc = ep_desc(dev->gadget, &fs_ep_out_desc,
+                                       &hs_ep_out_desc, &ss_ep_out_desc);
        dev->out_ep->driver_data = dev;
 
        result = usb_ep_enable(dev->in_ep);
@@ -1016,9 +1068,11 @@  autoconf_fail:
        /* assumes that all endpoints are dual-speed */
        hs_ep_in_desc.bEndpointAddress = fs_ep_in_desc.bEndpointAddress;
        hs_ep_out_desc.bEndpointAddress = fs_ep_out_desc.bEndpointAddress;
+       ss_ep_in_desc.bEndpointAddress = fs_ep_in_desc.bEndpointAddress;
+       ss_ep_out_desc.bEndpointAddress = fs_ep_out_desc.bEndpointAddress;
 
        ret = usb_assign_descriptors(f, fs_printer_function,
-                       hs_printer_function, NULL);
+                                    hs_printer_function, ss_printer_function);
        if (ret)
                return ret;
 
@@ -1253,7 +1307,7 @@  static __refdata struct usb_composite_driver printer_driver = {
        .name           = shortname,
        .dev            = &device_desc,
        .strings        = dev_strings,
-       .max_speed      = USB_SPEED_HIGH,
+       .max_speed      = USB_SPEED_SUPER,
        .bind           = printer_bind,
        .unbind         = printer_unbind,
 };