All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4 00/23] usb gadget update for OTG 2.0
@ 2015-06-17  5:43 Li Jun
       [not found] ` <1434519835-27745-1-git-send-email-jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
  0 siblings, 1 reply; 36+ messages in thread
From: Li Jun @ 2015-06-17  5:43 UTC (permalink / raw)
  To: gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r, balbi-l0cyMroinI0,
	peter.chen-KZfg59tc24xl57MIdRCFDg,
	robh+dt-DgEjT+Ai2ygdnm+yROfE0A
  Cc: linux-usb-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA, pawel.moll-5wv7dgnIgG8,
	mark.rutland-5wv7dgnIgG8, macpaul-Re5JQEeQqe8AvxtiuMwx3w,
	rogerq-l0cyMroinI0, Li Jun

Changes for v4:
- Add usb_otg_caps structure for all otg related capability attributes.
- Use one interface: of_usb_get_otg_caps to get all otg capabilities
  from DT, including otg_rev, hnp/srp/adp support.
- Add usb_otg_descriptor_alloc interface to allocate otg descriptor
  for better code sharing.
- Improve description of dt-binding doc. 

Changes for v3:
- For simple, add one more otg descriptor structure: usb_otg20_descriptor for OTG 2.0
  and later release as Alan suggested. 
- Use disable flags for OTG features property.
- Move out memory allocation from usb_otg_descriptor_init() to its caller. 

This is a follow-up of Macpaul Lin's previous patchset to resolve usb
gadget driver working with OTG 2.0, and set otg features by not only
usb driver config but also usb hardware property in DT, main changes:
1. Add usb_otg20_descriptor definition for OTG 2.0 which introduces bcdOTG
   field for otg revision, bcdOTG can be passed via device tree.
2. OTG features(SRP/HNP/ADP) can be decided by combination of usb HW
   properties and usb driver config.
3. Change the chipidea usb driver to use the updated mechanism.
4. Remove static usb otg descriptor definition, but allocate and init it
   according to otg capabilities in each gadget driver, if otg capabilities
   is not defined for legacy platforms, the usb otg descriptor content is
   kept the same as current static definition.

Li Jun (19):
  usb: otg: add usb_otg_caps structure for otg capabilities
  doc: dt-binding: usb: add otg related properties
  usb: common: add API to get usb otg features from device tree
  usb: chipidea: set usb gadeget's otg capabilities
  usb: chipidea: update ci_otg_is_fsm_mode conditions
  usb: gadget: add usb otg descriptor allocate and init interface
  usb: gadget: configfs: allocate and init otg descriptor by otg
    capabilities
  usb: gadget: ether: allocate and init otg descriptor by otg
    capabilities
  usb: gadget: acm_ms: allocate and init otg descriptor by otg
    capabilities
  usb: gadget: audio: allocate and init otg descriptor by otg
    capabilities
  usb: gadget: cdc2: allocate and init otg descriptor by otg
    capabilities
  usb: gadget: g_ffs: allocate and init otg descriptor by otg
    capabilities
  usb: gadget: hid: allocate and init otg descriptor by otg capabilities
  usb: gadget: mass_storage: allocate and init otg descriptor by otg
    capabilities
  usb: gadget: multi: allocate and init otg descriptor by otg
    capabilities
  usb: gadget: ncm: allocate and init otg descriptor by otg capabilities
  usb: gadget: printer: allocate and init otg descriptor by otg
    capabilities
  usb: gadget: serial: allocate and init otg descriptor by otg
    capabilities
  usb: gadget: zero: allocate and init otg descriptor by otg
    capabilities

Macpaul Lin (4):
  usb: add usb_otg20_descriptor for OTG 2.0 and above
  usb: add USB_OTG_ADP definition
  usb: add usb_otg_caps to usb_gadget structure.
  usb: gadget: composite: add USB_DT_OTG request handling

 Documentation/devicetree/bindings/usb/generic.txt | 15 ++++++
 drivers/usb/chipidea/ci.h                         |  5 +-
 drivers/usb/chipidea/core.c                       |  3 ++
 drivers/usb/chipidea/debug.c                      |  1 +
 drivers/usb/chipidea/udc.c                        |  7 ++-
 drivers/usb/common/common.c                       | 29 ++++++++++++
 drivers/usb/gadget/composite.c                    | 27 +++++++++++
 drivers/usb/gadget/config.c                       | 56 +++++++++++++++++++++++
 drivers/usb/gadget/configfs.c                     | 29 ++++++++----
 drivers/usb/gadget/legacy/acm_ms.c                | 29 ++++++------
 drivers/usb/gadget/legacy/audio.c                 | 28 ++++++------
 drivers/usb/gadget/legacy/cdc2.c                  | 29 ++++++------
 drivers/usb/gadget/legacy/ether.c                 | 38 +++++++++------
 drivers/usb/gadget/legacy/g_ffs.c                 | 29 ++++++------
 drivers/usb/gadget/legacy/hid.c                   | 30 ++++++------
 drivers/usb/gadget/legacy/mass_storage.c          | 29 ++++++------
 drivers/usb/gadget/legacy/multi.c                 | 39 ++++++++++------
 drivers/usb/gadget/legacy/ncm.c                   | 28 ++++++------
 drivers/usb/gadget/legacy/printer.c               | 25 +++++-----
 drivers/usb/gadget/legacy/serial.c                | 29 ++++++------
 drivers/usb/gadget/legacy/zero.c                  | 32 ++++++-------
 include/linux/usb/chipidea.h                      |  1 +
 include/linux/usb/gadget.h                        |  6 +++
 include/linux/usb/of.h                            |  7 +++
 include/linux/usb/otg.h                           | 15 ++++++
 include/uapi/linux/usb/ch9.h                      | 12 +++++
 26 files changed, 392 insertions(+), 186 deletions(-)

-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [PATCH v4 01/23] usb: add usb_otg20_descriptor for OTG 2.0 and above
       [not found] ` <1434519835-27745-1-git-send-email-jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
@ 2015-06-17  5:43   ` Li Jun
  2015-06-17  5:43   ` [PATCH v4 02/23] usb: add USB_OTG_ADP definition Li Jun
                     ` (21 subsequent siblings)
  22 siblings, 0 replies; 36+ messages in thread
From: Li Jun @ 2015-06-17  5:43 UTC (permalink / raw)
  To: gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r, balbi-l0cyMroinI0,
	peter.chen-KZfg59tc24xl57MIdRCFDg,
	robh+dt-DgEjT+Ai2ygdnm+yROfE0A
  Cc: linux-usb-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA, pawel.moll-5wv7dgnIgG8,
	mark.rutland-5wv7dgnIgG8, macpaul-Re5JQEeQqe8AvxtiuMwx3w,
	rogerq-l0cyMroinI0, Li Jun

From: Macpaul Lin <macpaul-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>

OTG 2.0 introduces bcdOTG in otg descriptor to identify the OTG and EH
supplement release number with which the OTG device is compliant, this
patch adds structure usb_otg20_descriptor for OTG 2.0 and above.

Signed-off-by: Macpaul Lin <macpaul-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Signed-off-by: Li Jun <jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
Reviewed-by: Roger Quadros <rogerq-l0cyMroinI0@public.gmane.org>
---
 include/uapi/linux/usb/ch9.h | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/include/uapi/linux/usb/ch9.h b/include/uapi/linux/usb/ch9.h
index aa33fd1..aec6899 100644
--- a/include/uapi/linux/usb/ch9.h
+++ b/include/uapi/linux/usb/ch9.h
@@ -674,6 +674,17 @@ struct usb_otg_descriptor {
 	__u8  bmAttributes;	/* support for HNP, SRP, etc */
 } __attribute__ ((packed));
 
+/* USB_DT_OTG (from OTG 2.0 supplement) */
+struct usb_otg20_descriptor {
+	__u8  bLength;
+	__u8  bDescriptorType;
+
+	__u8  bmAttributes;	/* support for HNP, SRP and ADP, etc */
+	__le16 bcdOTG;		/* OTG and EH supplement release number
+				 * in binary-coded decimal(i.e. 2.0 is 0200H)
+				 */
+} __attribute__ ((packed));
+
 /* from usb_otg_descriptor.bmAttributes */
 #define USB_OTG_SRP		(1 << 0)
 #define USB_OTG_HNP		(1 << 1)	/* swap host/device roles */
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH v4 02/23] usb: add USB_OTG_ADP definition
       [not found] ` <1434519835-27745-1-git-send-email-jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
  2015-06-17  5:43   ` [PATCH v4 01/23] usb: add usb_otg20_descriptor for OTG 2.0 and above Li Jun
@ 2015-06-17  5:43   ` Li Jun
  2015-06-17  5:43   ` [PATCH v4 03/23] usb: otg: add usb_otg_caps structure for otg capabilities Li Jun
                     ` (20 subsequent siblings)
  22 siblings, 0 replies; 36+ messages in thread
From: Li Jun @ 2015-06-17  5:43 UTC (permalink / raw)
  To: gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r, balbi-l0cyMroinI0,
	peter.chen-KZfg59tc24xl57MIdRCFDg,
	robh+dt-DgEjT+Ai2ygdnm+yROfE0A
  Cc: linux-usb-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA, pawel.moll-5wv7dgnIgG8,
	mark.rutland-5wv7dgnIgG8, macpaul-Re5JQEeQqe8AvxtiuMwx3w,
	rogerq-l0cyMroinI0, Li Jun

From: Macpaul Lin <macpaul-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>

Add USB_OTG_ADP definition for usb_otg_descriptor.bmAttributes.

Signed-off-by: Macpaul Lin <macpaul-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Signed-off-by: Li Jun <jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
Acked-by: Peter Chen <peter.chen-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
---
 include/uapi/linux/usb/ch9.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/uapi/linux/usb/ch9.h b/include/uapi/linux/usb/ch9.h
index aec6899..f7adc6e 100644
--- a/include/uapi/linux/usb/ch9.h
+++ b/include/uapi/linux/usb/ch9.h
@@ -688,6 +688,7 @@ struct usb_otg20_descriptor {
 /* from usb_otg_descriptor.bmAttributes */
 #define USB_OTG_SRP		(1 << 0)
 #define USB_OTG_HNP		(1 << 1)	/* swap host/device roles */
+#define USB_OTG_ADP		(1 << 2)	/* support ADP */
 
 /*-------------------------------------------------------------------------*/
 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH v4 03/23] usb: otg: add usb_otg_caps structure for otg capabilities
       [not found] ` <1434519835-27745-1-git-send-email-jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
  2015-06-17  5:43   ` [PATCH v4 01/23] usb: add usb_otg20_descriptor for OTG 2.0 and above Li Jun
  2015-06-17  5:43   ` [PATCH v4 02/23] usb: add USB_OTG_ADP definition Li Jun
@ 2015-06-17  5:43   ` Li Jun
       [not found]     ` <1434519835-27745-4-git-send-email-jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
  2015-06-17  5:43   ` [PATCH v4 04/23] usb: add usb_otg_caps to usb_gadget structure Li Jun
                     ` (19 subsequent siblings)
  22 siblings, 1 reply; 36+ messages in thread
From: Li Jun @ 2015-06-17  5:43 UTC (permalink / raw)
  To: gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r, balbi-l0cyMroinI0,
	peter.chen-KZfg59tc24xl57MIdRCFDg,
	robh+dt-DgEjT+Ai2ygdnm+yROfE0A
  Cc: linux-usb-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA, pawel.moll-5wv7dgnIgG8,
	mark.rutland-5wv7dgnIgG8, macpaul-Re5JQEeQqe8AvxtiuMwx3w,
	rogerq-l0cyMroinI0, Li Jun

This patch adds a structure usb_otg_caps to cover all otg related
capabilities of the device, including otg revision, and if hnp/srp/adp
is supported.

Signed-off-by: Li Jun <jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
---
 include/linux/usb/otg.h | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/include/linux/usb/otg.h b/include/linux/usb/otg.h
index 52661c5..bd1dcf8 100644
--- a/include/linux/usb/otg.h
+++ b/include/linux/usb/otg.h
@@ -41,6 +41,21 @@ struct usb_otg {
 
 };
 
+/**
+ * struct usb_otg_caps - describes the otg capabilities of the device
+ * @otg_rev: The OTG revision number the device is compliant with, it's
+ *		in binary-coded decimal (i.e. 2.0 is 0200H).
+ * @hnp_support: Indicates if the device supports HNP.
+ * @srp_support: Indicates if the device supports SRP.
+ * @adp_support: Indicates if the device supports ADP.
+ */
+struct usb_otg_caps {
+	u16 otg_rev;
+	bool hnp_support;
+	bool srp_support;
+	bool adp_support;
+};
+
 extern const char *usb_otg_state_string(enum usb_otg_state state);
 
 /* Context: can sleep */
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH v4 04/23] usb: add usb_otg_caps to usb_gadget structure.
       [not found] ` <1434519835-27745-1-git-send-email-jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
                     ` (2 preceding siblings ...)
  2015-06-17  5:43   ` [PATCH v4 03/23] usb: otg: add usb_otg_caps structure for otg capabilities Li Jun
@ 2015-06-17  5:43   ` Li Jun
       [not found]     ` <1434519835-27745-5-git-send-email-jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
  2015-06-17  5:43   ` [PATCH v4 05/23] usb: gadget: composite: add USB_DT_OTG request handling Li Jun
                     ` (18 subsequent siblings)
  22 siblings, 1 reply; 36+ messages in thread
From: Li Jun @ 2015-06-17  5:43 UTC (permalink / raw)
  To: gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r, balbi-l0cyMroinI0,
	peter.chen-KZfg59tc24xl57MIdRCFDg,
	robh+dt-DgEjT+Ai2ygdnm+yROfE0A
  Cc: linux-usb-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA, pawel.moll-5wv7dgnIgG8,
	mark.rutland-5wv7dgnIgG8, macpaul-Re5JQEeQqe8AvxtiuMwx3w,
	rogerq-l0cyMroinI0, Li Jun

From: Macpaul Lin <macpaul-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>

Add usb_otg_caps pointer to usb_gadget structure to indicate its
otg capabilities.

Signed-off-by: Macpaul Lin <macpaul-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Signed-off-by: Li Jun <jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
---
 include/linux/usb/gadget.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
index 4f3dfb7..6b39087 100644
--- a/include/linux/usb/gadget.h
+++ b/include/linux/usb/gadget.h
@@ -511,6 +511,7 @@ struct usb_gadget_ops {
  * @dev: Driver model state for this abstract device.
  * @out_epnum: last used out ep number
  * @in_epnum: last used in ep number
+ * @otg_caps: OTG capabilities of this gadget.
  * @sg_supported: true if we can handle scatter-gather
  * @is_otg: True if the USB device port uses a Mini-AB jack, so that the
  *	gadget driver must provide a USB OTG descriptor.
@@ -559,6 +560,7 @@ struct usb_gadget {
 	struct device			dev;
 	unsigned			out_epnum;
 	unsigned			in_epnum;
+	struct usb_otg_caps		*otg_caps;
 
 	unsigned			sg_supported:1;
 	unsigned			is_otg:1;
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH v4 05/23] usb: gadget: composite: add USB_DT_OTG request handling
       [not found] ` <1434519835-27745-1-git-send-email-jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
                     ` (3 preceding siblings ...)
  2015-06-17  5:43   ` [PATCH v4 04/23] usb: add usb_otg_caps to usb_gadget structure Li Jun
@ 2015-06-17  5:43   ` Li Jun
  2015-06-17  5:43   ` [PATCH v4 06/23] doc: dt-binding: usb: add otg related properties Li Jun
                     ` (17 subsequent siblings)
  22 siblings, 0 replies; 36+ messages in thread
From: Li Jun @ 2015-06-17  5:43 UTC (permalink / raw)
  To: gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r, balbi-l0cyMroinI0,
	peter.chen-KZfg59tc24xl57MIdRCFDg,
	robh+dt-DgEjT+Ai2ygdnm+yROfE0A
  Cc: linux-usb-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA, pawel.moll-5wv7dgnIgG8,
	mark.rutland-5wv7dgnIgG8, macpaul-Re5JQEeQqe8AvxtiuMwx3w,
	rogerq-l0cyMroinI0, Li Jun

From: Macpaul Lin <macpaul-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>

Copy usb_otg_descriptor from config's descriptor if host requests
USB_DT_OTG.

Signed-off-by: Macpaul Lin <macpaul-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Signed-off-by: Li Jun <jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
Reviewed-by: Roger Quadros <rogerq-l0cyMroinI0@public.gmane.org>
---
 drivers/usb/gadget/composite.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
index 4e3447b..2c1c6eb 100644
--- a/drivers/usb/gadget/composite.c
+++ b/drivers/usb/gadget/composite.c
@@ -19,6 +19,7 @@
 #include <linux/utsname.h>
 
 #include <linux/usb/composite.h>
+#include <linux/usb/otg.h>
 #include <asm/unaligned.h>
 
 #include "u_os_desc.h"
@@ -1534,6 +1535,32 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
 				value = min(w_length, (u16) value);
 			}
 			break;
+		case USB_DT_OTG:
+			if (gadget_is_otg(gadget)) {
+				struct usb_configuration *config;
+				int otg_desc_len = 0;
+
+				if (cdev->config)
+					config = cdev->config;
+				else
+					config = list_first_entry(
+							&cdev->configs,
+						struct usb_configuration, list);
+				if (!config)
+					goto done;
+
+				if (gadget->otg_caps &&
+					(gadget->otg_caps->otg_rev >= 0x0200))
+					otg_desc_len += sizeof(
+						struct usb_otg20_descriptor);
+				else
+					otg_desc_len += sizeof(
+						struct usb_otg_descriptor);
+
+				value = min_t(int, w_length, otg_desc_len);
+				memcpy(req->buf, config->descriptors[0], value);
+			}
+			break;
 		}
 		break;
 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH v4 06/23] doc: dt-binding: usb: add otg related properties
       [not found] ` <1434519835-27745-1-git-send-email-jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
                     ` (4 preceding siblings ...)
  2015-06-17  5:43   ` [PATCH v4 05/23] usb: gadget: composite: add USB_DT_OTG request handling Li Jun
@ 2015-06-17  5:43   ` Li Jun
       [not found]     ` <1434519835-27745-7-git-send-email-jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
  2015-06-17  5:43   ` [PATCH v4 07/23] usb: common: add API to get usb otg features from device tree Li Jun
                     ` (16 subsequent siblings)
  22 siblings, 1 reply; 36+ messages in thread
From: Li Jun @ 2015-06-17  5:43 UTC (permalink / raw)
  To: gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r, balbi-l0cyMroinI0,
	peter.chen-KZfg59tc24xl57MIdRCFDg,
	robh+dt-DgEjT+Ai2ygdnm+yROfE0A
  Cc: linux-usb-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA, pawel.moll-5wv7dgnIgG8,
	mark.rutland-5wv7dgnIgG8, macpaul-Re5JQEeQqe8AvxtiuMwx3w,
	rogerq-l0cyMroinI0, Li Jun

Add otg version, srp, hnp and adp support for usb OTG port, then those OTG
features don't have to be decided by usb gadget drivers.

Signed-off-by: Li Jun <jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
---
 Documentation/devicetree/bindings/usb/generic.txt | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/Documentation/devicetree/bindings/usb/generic.txt b/Documentation/devicetree/bindings/usb/generic.txt
index 477d5bb..bba8257 100644
--- a/Documentation/devicetree/bindings/usb/generic.txt
+++ b/Documentation/devicetree/bindings/usb/generic.txt
@@ -11,6 +11,19 @@ Optional properties:
 			"peripheral" and "otg". In case this attribute isn't
 			passed via DT, USB DRD controllers should default to
 			OTG.
+ - otg-rev: tells usb driver the release number of the OTG and EH supplement
+			with which the device and its descriptors are compliant,
+			in binary-coded decimal (i.e. 2.0 is 0200H). This
+			property is used if any real OTG features(HNP/SRP/ADP)
+			is enabled, if ADP is required, otg-rev should be
+			0x0200 or above.
+ - hnp-disable: tells OTG controllers we want to disable OTG HNP, normally HNP
+			is the basic function of real OTG except you want it
+			to be a srp-capable only B device.
+ - srp-disable: tells OTG controllers we want to disable OTG SRP, SRP is
+			optional for OTG device.
+ - adp-disable: tells OTG controllers we want to disable OTG ADP, ADP is
+			optional for OTG device.
 
 This is an attribute to a USB controller such as:
 
@@ -21,4 +34,6 @@ dwc3@4a030000 {
 	usb-phy = <&usb2_phy>, <&usb3,phy>;
 	maximum-speed = "super-speed";
 	dr_mode = "otg";
+	otg-rev = <0x0200>;
+	adp-disable;
 };
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH v4 07/23] usb: common: add API to get usb otg features from device tree
       [not found] ` <1434519835-27745-1-git-send-email-jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
                     ` (5 preceding siblings ...)
  2015-06-17  5:43   ` [PATCH v4 06/23] doc: dt-binding: usb: add otg related properties Li Jun
@ 2015-06-17  5:43   ` Li Jun
       [not found]     ` <1434519835-27745-8-git-send-email-jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
  2015-06-17  5:43   ` [PATCH v4 08/23] usb: chipidea: set usb gadeget's otg capabilities Li Jun
                     ` (15 subsequent siblings)
  22 siblings, 1 reply; 36+ messages in thread
From: Li Jun @ 2015-06-17  5:43 UTC (permalink / raw)
  To: gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r, balbi-l0cyMroinI0,
	peter.chen-KZfg59tc24xl57MIdRCFDg,
	robh+dt-DgEjT+Ai2ygdnm+yROfE0A
  Cc: linux-usb-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA, pawel.moll-5wv7dgnIgG8,
	mark.rutland-5wv7dgnIgG8, macpaul-Re5JQEeQqe8AvxtiuMwx3w,
	rogerq-l0cyMroinI0, Li Jun

Check property of usb hardware to get otg version and if SRP, HNP and ADP
are supported.

Signed-off-by: Li Jun <jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
---
 drivers/usb/common/common.c | 29 +++++++++++++++++++++++++++++
 include/linux/usb/of.h      |  7 +++++++
 2 files changed, 36 insertions(+)

diff --git a/drivers/usb/common/common.c b/drivers/usb/common/common.c
index b530fd4..b846172 100644
--- a/drivers/usb/common/common.c
+++ b/drivers/usb/common/common.c
@@ -154,6 +154,35 @@ bool of_usb_host_tpl_support(struct device_node *np)
 	return false;
 }
 EXPORT_SYMBOL_GPL(of_usb_host_tpl_support);
+
+/**
+ * of_usb_get_otg_caps - to get usb otg capabilities according to
+ * the passed properties in DT.
+ * @np: Pointer to the given device_node
+ * @otg_caps: Pointer to the target usb_otg_caps to be set
+ *
+ * The function gets and sets the otg capabilities
+ */
+void of_usb_get_otg_caps(struct device_node *np, struct usb_otg_caps *otg_caps)
+{
+	u32 otg_rev;
+
+	if (!otg_caps)
+		return;
+
+	if (!of_property_read_u32(np, "otg-rev", &otg_rev)) {
+		otg_caps->otg_rev = otg_rev;
+		if (!of_find_property(np, "hnp-disable", NULL))
+			otg_caps->hnp_support = true;
+		if (!of_find_property(np, "srp-disable", NULL))
+			otg_caps->hnp_support = true;
+		if (!of_find_property(np, "adp-disable", NULL) &&
+					(otg_caps->otg_rev >= 0x0200))
+			otg_caps->hnp_support = true;
+	}
+}
+EXPORT_SYMBOL_GPL(of_usb_get_otg_caps);
+
 #endif
 
 MODULE_LICENSE("GPL");
diff --git a/include/linux/usb/of.h b/include/linux/usb/of.h
index cfe0528..bbf302b9 100644
--- a/include/linux/usb/of.h
+++ b/include/linux/usb/of.h
@@ -15,6 +15,8 @@
 enum usb_dr_mode of_usb_get_dr_mode(struct device_node *np);
 enum usb_device_speed of_usb_get_maximum_speed(struct device_node *np);
 bool of_usb_host_tpl_support(struct device_node *np);
+void of_usb_get_otg_caps(struct device_node *np,
+			struct usb_otg_caps *otg_caps);
 #else
 static inline enum usb_dr_mode of_usb_get_dr_mode(struct device_node *np)
 {
@@ -30,6 +32,11 @@ static inline bool of_usb_host_tpl_support(struct device_node *np)
 {
 	return false;
 }
+static inline void of_usb_get_otg_caps(struct device_node *np,
+				struct usb_otg_caps *otg_caps)
+{
+
+}
 #endif
 
 #if IS_ENABLED(CONFIG_OF) && IS_ENABLED(CONFIG_USB_SUPPORT)
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH v4 08/23] usb: chipidea: set usb gadeget's otg capabilities
       [not found] ` <1434519835-27745-1-git-send-email-jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
                     ` (6 preceding siblings ...)
  2015-06-17  5:43   ` [PATCH v4 07/23] usb: common: add API to get usb otg features from device tree Li Jun
@ 2015-06-17  5:43   ` Li Jun
  2015-06-17  5:43   ` [PATCH v4 09/23] usb: chipidea: update ci_otg_is_fsm_mode conditions Li Jun
                     ` (14 subsequent siblings)
  22 siblings, 0 replies; 36+ messages in thread
From: Li Jun @ 2015-06-17  5:43 UTC (permalink / raw)
  To: gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r, balbi-l0cyMroinI0,
	peter.chen-KZfg59tc24xl57MIdRCFDg,
	robh+dt-DgEjT+Ai2ygdnm+yROfE0A
  Cc: linux-usb-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA, pawel.moll-5wv7dgnIgG8,
	mark.rutland-5wv7dgnIgG8, macpaul-Re5JQEeQqe8AvxtiuMwx3w,
	rogerq-l0cyMroinI0, Li Jun

Set gadget's otg capabilities according to controller's capability and otg
properties in device tree.

Signed-off-by: Li Jun <jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
---
 drivers/usb/chipidea/core.c  | 3 +++
 drivers/usb/chipidea/udc.c   | 7 ++++++-
 include/linux/usb/chipidea.h | 1 +
 3 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/chipidea/core.c b/drivers/usb/chipidea/core.c
index 74fea4f..ccc57e1 100644
--- a/drivers/usb/chipidea/core.c
+++ b/drivers/usb/chipidea/core.c
@@ -588,6 +588,9 @@ static int ci_get_platdata(struct device *dev,
 				of_usb_host_tpl_support(dev->of_node);
 	}
 
+	if (platdata->dr_mode == USB_DR_MODE_OTG)
+		of_usb_get_otg_caps(dev->of_node, &platdata->ci_otg_caps);
+
 	if (of_usb_get_maximum_speed(dev->of_node) == USB_SPEED_FULL)
 		platdata->flags |= CI_HDRC_FORCE_FULLSPEED;
 
diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c
index 764f668..c75dc82 100644
--- a/drivers/usb/chipidea/udc.c
+++ b/drivers/usb/chipidea/udc.c
@@ -1834,8 +1834,13 @@ static int udc_start(struct ci_hdrc *ci)
 	ci->gadget.ops          = &usb_gadget_ops;
 	ci->gadget.speed        = USB_SPEED_UNKNOWN;
 	ci->gadget.max_speed    = USB_SPEED_HIGH;
-	ci->gadget.is_otg       = ci->is_otg ? 1 : 0;
 	ci->gadget.name         = ci->platdata->name;
+	ci->gadget.otg_caps	= &ci->platdata->ci_otg_caps;
+
+	if (ci->gadget.otg_caps->hnp_support ||
+		ci->gadget.otg_caps->srp_support ||
+			ci->gadget.otg_caps->adp_support)
+		ci->gadget.is_otg = 1;
 
 	INIT_LIST_HEAD(&ci->gadget.ep_list);
 
diff --git a/include/linux/usb/chipidea.h b/include/linux/usb/chipidea.h
index ab94f78..e10cefc 100644
--- a/include/linux/usb/chipidea.h
+++ b/include/linux/usb/chipidea.h
@@ -34,6 +34,7 @@ struct ci_hdrc_platform_data {
 #define CI_HDRC_CONTROLLER_STOPPED_EVENT	1
 	void	(*notify_event) (struct ci_hdrc *ci, unsigned event);
 	struct regulator	*reg_vbus;
+	struct usb_otg_caps	ci_otg_caps;
 	bool			tpl_support;
 };
 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH v4 09/23] usb: chipidea: update ci_otg_is_fsm_mode conditions
       [not found] ` <1434519835-27745-1-git-send-email-jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
                     ` (7 preceding siblings ...)
  2015-06-17  5:43   ` [PATCH v4 08/23] usb: chipidea: set usb gadeget's otg capabilities Li Jun
@ 2015-06-17  5:43   ` Li Jun
  2015-06-17  5:43   ` [PATCH v4 10/23] usb: gadget: add usb otg descriptor allocate and init interface Li Jun
                     ` (13 subsequent siblings)
  22 siblings, 0 replies; 36+ messages in thread
From: Li Jun @ 2015-06-17  5:43 UTC (permalink / raw)
  To: gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r, balbi-l0cyMroinI0,
	peter.chen-KZfg59tc24xl57MIdRCFDg,
	robh+dt-DgEjT+Ai2ygdnm+yROfE0A
  Cc: linux-usb-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA, pawel.moll-5wv7dgnIgG8,
	mark.rutland-5wv7dgnIgG8, macpaul-Re5JQEeQqe8AvxtiuMwx3w,
	rogerq-l0cyMroinI0, Li Jun

After introduce usb otg properties, update ci_otg_is_fsm_mode conditions
to be depending on both usb hardware properties and usb driver config,
also resolve a compile issue in debug.c after the API change.

Signed-off-by: Li Jun <jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
---
 drivers/usb/chipidea/ci.h    | 5 ++++-
 drivers/usb/chipidea/debug.c | 1 +
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/chipidea/ci.h b/drivers/usb/chipidea/ci.h
index 6d6200e..f243f0b 100644
--- a/drivers/usb/chipidea/ci.h
+++ b/drivers/usb/chipidea/ci.h
@@ -406,8 +406,11 @@ static inline u32 hw_test_and_write(struct ci_hdrc *ci, enum ci_hw_regs reg,
 static inline bool ci_otg_is_fsm_mode(struct ci_hdrc *ci)
 {
 #ifdef CONFIG_USB_OTG_FSM
+	struct usb_otg_caps *otg_caps = &ci->platdata->ci_otg_caps;
+
 	return ci->is_otg && ci->roles[CI_ROLE_HOST] &&
-					ci->roles[CI_ROLE_GADGET];
+		ci->roles[CI_ROLE_GADGET] && (otg_caps->srp_support ||
+		otg_caps->hnp_support || otg_caps->adp_support);
 #else
 	return false;
 #endif
diff --git a/drivers/usb/chipidea/debug.c b/drivers/usb/chipidea/debug.c
index 5b7061a..3869c6d 100644
--- a/drivers/usb/chipidea/debug.c
+++ b/drivers/usb/chipidea/debug.c
@@ -10,6 +10,7 @@
 #include <linux/usb/phy.h>
 #include <linux/usb/otg.h>
 #include <linux/usb/otg-fsm.h>
+#include <linux/usb/chipidea.h>
 
 #include "ci.h"
 #include "udc.h"
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH v4 10/23] usb: gadget: add usb otg descriptor allocate and init interface
       [not found] ` <1434519835-27745-1-git-send-email-jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
                     ` (8 preceding siblings ...)
  2015-06-17  5:43   ` [PATCH v4 09/23] usb: chipidea: update ci_otg_is_fsm_mode conditions Li Jun
@ 2015-06-17  5:43   ` Li Jun
       [not found]     ` <1434519835-27745-11-git-send-email-jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
  2015-06-17  5:43   ` [PATCH v4 11/23] usb: gadget: configfs: allocate and init otg descriptor by otg capabilities Li Jun
                     ` (12 subsequent siblings)
  22 siblings, 1 reply; 36+ messages in thread
From: Li Jun @ 2015-06-17  5:43 UTC (permalink / raw)
  To: gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r, balbi-l0cyMroinI0,
	peter.chen-KZfg59tc24xl57MIdRCFDg,
	robh+dt-DgEjT+Ai2ygdnm+yROfE0A
  Cc: linux-usb-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA, pawel.moll-5wv7dgnIgG8,
	mark.rutland-5wv7dgnIgG8, macpaul-Re5JQEeQqe8AvxtiuMwx3w,
	rogerq-l0cyMroinI0, Li Jun

Allocate usb otg descriptor and initialize it according to gadget's otg
capabilities, if usb_otg_caps is not set, keep settings as current gadget
drivers. With this 2 new interfaces, gadget can use usb_otg_descriptor
for OTG 1.x, and usb_otg20_descriptor for OTG 2.0 or above, and otg
features can be decided by the combination of usb hardware property
and driver config.

Signed-off-by: Li Jun <jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
---
 drivers/usb/gadget/config.c | 56 +++++++++++++++++++++++++++++++++++++++++++++
 include/linux/usb/gadget.h  |  4 ++++
 2 files changed, 60 insertions(+)

diff --git a/drivers/usb/gadget/config.c b/drivers/usb/gadget/config.c
index 34e12fc..0fafa7a 100644
--- a/drivers/usb/gadget/config.c
+++ b/drivers/usb/gadget/config.c
@@ -20,6 +20,7 @@
 #include <linux/usb/ch9.h>
 #include <linux/usb/gadget.h>
 #include <linux/usb/composite.h>
+#include <linux/usb/otg.h>
 
 /**
  * usb_descriptor_fillbuf - fill buffer with descriptors
@@ -195,3 +196,58 @@ void usb_free_all_descriptors(struct usb_function *f)
 	usb_free_descriptors(f->ss_descriptors);
 }
 EXPORT_SYMBOL_GPL(usb_free_all_descriptors);
+
+struct usb_descriptor_header *usb_otg_descriptor_alloc(
+				struct usb_gadget *gadget)
+{
+	struct usb_descriptor_header *otg_desc;
+	unsigned length = 0;
+
+	if (gadget->otg_caps && (gadget->otg_caps->otg_rev >= 0x0200))
+		length = sizeof(struct usb_otg20_descriptor);
+	else
+		length = sizeof(struct usb_otg_descriptor);
+
+	otg_desc = kzalloc(length, GFP_KERNEL);
+	return otg_desc;
+}
+EXPORT_SYMBOL_GPL(usb_otg_descriptor_alloc);
+
+int usb_otg_descriptor_init(struct usb_gadget *gadget,
+		struct usb_descriptor_header *otg_desc)
+{
+	struct usb_otg_descriptor *otg1x_desc;
+	struct usb_otg20_descriptor *otg20_desc;
+	struct usb_otg_caps *otg_caps = gadget->otg_caps;
+	u8 otg_attributes = 0;
+
+	if (!otg_desc)
+		return -EINVAL;
+
+	if (otg_caps && otg_caps->otg_rev) {
+		if (otg_caps->hnp_support)
+			otg_attributes |= USB_OTG_HNP;
+		if (otg_caps->srp_support)
+			otg_attributes |= USB_OTG_SRP;
+		if (otg_caps->adp_support && (otg_caps->otg_rev >= 0x0200))
+			otg_attributes |= USB_OTG_ADP;
+	} else {
+		otg_attributes = USB_OTG_SRP | USB_OTG_HNP;
+	}
+
+	if (otg_caps && (otg_caps->otg_rev >= 0x0200)) {
+		otg20_desc = (struct usb_otg20_descriptor *)otg_desc;
+		otg20_desc->bLength = sizeof(struct usb_otg20_descriptor);
+		otg20_desc->bDescriptorType = USB_DT_OTG;
+		otg20_desc->bmAttributes = otg_attributes;
+		otg20_desc->bcdOTG = cpu_to_le16(otg_caps->otg_rev);
+	} else {
+		otg1x_desc = (struct usb_otg_descriptor *)otg_desc;
+		otg1x_desc->bLength = sizeof(struct usb_otg_descriptor);
+		otg1x_desc->bDescriptorType = USB_DT_OTG;
+		otg1x_desc->bmAttributes = otg_attributes;
+	}
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(usb_otg_descriptor_init);
diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
index 6b39087..5f65bd2 100644
--- a/include/linux/usb/gadget.h
+++ b/include/linux/usb/gadget.h
@@ -1004,6 +1004,10 @@ int usb_assign_descriptors(struct usb_function *f,
 		struct usb_descriptor_header **ss);
 void usb_free_all_descriptors(struct usb_function *f);
 
+struct usb_descriptor_header *usb_otg_descriptor_alloc(
+				struct usb_gadget *gadget);
+int usb_otg_descriptor_init(struct usb_gadget *gadget,
+		struct usb_descriptor_header *otg_desc);
 /*-------------------------------------------------------------------------*/
 
 /* utility to simplify map/unmap of usb_requests to/from DMA */
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH v4 11/23] usb: gadget: configfs: allocate and init otg descriptor by otg capabilities
       [not found] ` <1434519835-27745-1-git-send-email-jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
                     ` (9 preceding siblings ...)
  2015-06-17  5:43   ` [PATCH v4 10/23] usb: gadget: add usb otg descriptor allocate and init interface Li Jun
@ 2015-06-17  5:43   ` Li Jun
       [not found]     ` <1434519835-27745-12-git-send-email-jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
  2015-06-17  5:43   ` [PATCH v4 12/23] usb: gadget: ether: " Li Jun
                     ` (11 subsequent siblings)
  22 siblings, 1 reply; 36+ messages in thread
From: Li Jun @ 2015-06-17  5:43 UTC (permalink / raw)
  To: gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r, balbi-l0cyMroinI0,
	peter.chen-KZfg59tc24xl57MIdRCFDg,
	robh+dt-DgEjT+Ai2ygdnm+yROfE0A
  Cc: linux-usb-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA, pawel.moll-5wv7dgnIgG8,
	mark.rutland-5wv7dgnIgG8, macpaul-Re5JQEeQqe8AvxtiuMwx3w,
	rogerq-l0cyMroinI0, Li Jun

Allocate and initialize usb otg descriptor according to gadget otg
capabilities, add it for each usb configurations, free it while
composite unbind. If otg capability is not defined, keep its otg
descriptor unchanged.

Signed-off-by: Li Jun <jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
---
 drivers/usb/gadget/configfs.c | 29 ++++++++++++++++++++---------
 1 file changed, 20 insertions(+), 9 deletions(-)

diff --git a/drivers/usb/gadget/configfs.c b/drivers/usb/gadget/configfs.c
index 0495c94..c7b62ef 100644
--- a/drivers/usb/gadget/configfs.c
+++ b/drivers/usb/gadget/configfs.c
@@ -41,6 +41,8 @@ int check_user_usb_string(const char *name,
 #define MAX_NAME_LEN	40
 #define MAX_USB_STRING_LANGS 2
 
+static const struct usb_descriptor_header *otg_desc[2];
+
 struct gadget_info {
 	struct config_group group;
 	struct config_group functions_group;
@@ -55,9 +57,6 @@ struct gadget_info {
 	struct list_head available_func;
 
 	const char *udc_name;
-#ifdef CONFIG_USB_OTG
-	struct usb_otg_descriptor otg;
-#endif
 	struct usb_composite_driver composite;
 	struct usb_composite_dev cdev;
 	bool use_os_desc;
@@ -1376,6 +1375,19 @@ static int configfs_composite_bind(struct usb_gadget *gadget,
 		memcpy(cdev->qw_sign, gi->qw_sign, OS_STRING_QW_SIGN_LEN);
 	}
 
+	if (gadget_is_otg(gadget) && !otg_desc[0]) {
+		struct usb_descriptor_header *usb_desc;
+
+		usb_desc = usb_otg_descriptor_alloc(gadget);
+		if (!usb_desc) {
+			ret = -ENOMEM;
+			goto err_comp_cleanup;
+		}
+		usb_otg_descriptor_init(gadget, usb_desc);
+		otg_desc[0] = usb_desc;
+		otg_desc[1] = NULL;
+	}
+
 	/* Go through all configs, attach all functions */
 	list_for_each_entry(c, &gi->cdev.configs, list) {
 		struct config_usb_cfg *cfg;
@@ -1383,6 +1395,9 @@ static int configfs_composite_bind(struct usb_gadget *gadget,
 		struct usb_function *tmp;
 		struct gadget_config_name *cn;
 
+		if (gadget_is_otg(gadget))
+			c->descriptors = otg_desc;
+
 		cfg = container_of(c, struct config_usb_cfg, c);
 		if (!list_empty(&cfg->string_list)) {
 			i = 0;
@@ -1437,6 +1452,8 @@ static void configfs_composite_unbind(struct usb_gadget *gadget)
 	cdev = get_gadget_data(gadget);
 	gi = container_of(cdev, struct gadget_info, cdev);
 
+	kfree(otg_desc[0]);
+	otg_desc[0] = NULL;
 	purge_configs_funcs(gi);
 	composite_dev_cleanup(cdev);
 	usb_ep_autoconfig_reset(cdev->gadget);
@@ -1510,12 +1527,6 @@ static struct config_group *gadgets_make(
 	if (!gi->composite.gadget_driver.function)
 		goto err;
 
-#ifdef CONFIG_USB_OTG
-	gi->otg.bLength = sizeof(struct usb_otg_descriptor);
-	gi->otg.bDescriptorType = USB_DT_OTG;
-	gi->otg.bmAttributes = USB_OTG_SRP | USB_OTG_HNP;
-#endif

^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH v4 12/23] usb: gadget: ether: allocate and init otg descriptor by otg capabilities
       [not found] ` <1434519835-27745-1-git-send-email-jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
                     ` (10 preceding siblings ...)
  2015-06-17  5:43   ` [PATCH v4 11/23] usb: gadget: configfs: allocate and init otg descriptor by otg capabilities Li Jun
@ 2015-06-17  5:43   ` Li Jun
       [not found]     ` <1434519835-27745-13-git-send-email-jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
  2015-06-17  5:43   ` [PATCH v4 13/23] usb: gadget: acm_ms: " Li Jun
                     ` (10 subsequent siblings)
  22 siblings, 1 reply; 36+ messages in thread
From: Li Jun @ 2015-06-17  5:43 UTC (permalink / raw)
  To: gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r, balbi-l0cyMroinI0,
	peter.chen-KZfg59tc24xl57MIdRCFDg,
	robh+dt-DgEjT+Ai2ygdnm+yROfE0A
  Cc: linux-usb-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA, pawel.moll-5wv7dgnIgG8,
	mark.rutland-5wv7dgnIgG8, macpaul-Re5JQEeQqe8AvxtiuMwx3w,
	rogerq-l0cyMroinI0, Li Jun

Allocate and initialize usb otg descriptor according to gadget otg
capabilities, add it for each usb configurations, free it while
composite unbind. If otg capability is not defined, keep its otg
descriptor unchanged.

Signed-off-by: Li Jun <jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
---
 drivers/usb/gadget/legacy/ether.c | 38 ++++++++++++++++++++++++--------------
 1 file changed, 24 insertions(+), 14 deletions(-)

diff --git a/drivers/usb/gadget/legacy/ether.c b/drivers/usb/gadget/legacy/ether.c
index a3323dc..06f4a30 100644
--- a/drivers/usb/gadget/legacy/ether.c
+++ b/drivers/usb/gadget/legacy/ether.c
@@ -171,20 +171,7 @@ static struct usb_device_descriptor device_desc = {
 	.bNumConfigurations =	1,
 };
 
-static struct usb_otg_descriptor otg_descriptor = {
-	.bLength =		sizeof otg_descriptor,
-	.bDescriptorType =	USB_DT_OTG,
-
-	/* REVISIT SRP-only hardware is possible, although
-	 * it would not be called "OTG" ...
-	 */
-	.bmAttributes =		USB_OTG_SRP | USB_OTG_HNP,
-};
-
-static const struct usb_descriptor_header *otg_desc[] = {
-	(struct usb_descriptor_header *) &otg_descriptor,
-	NULL,
-};
+static const struct usb_descriptor_header *otg_desc[2];
 
 static struct usb_string strings_dev[] = {
 	[USB_GADGET_MANUFACTURER_IDX].s = "",
@@ -229,6 +216,16 @@ static int rndis_do_config(struct usb_configuration *c)
 	/* FIXME alloc iConfiguration string, set it in c->strings */
 
 	if (gadget_is_otg(c->cdev->gadget)) {
+		if (!otg_desc[0]) {
+			struct usb_descriptor_header *usb_desc;
+
+			usb_desc = usb_otg_descriptor_alloc(c->cdev->gadget);
+			if (!usb_desc)
+				return -ENOMEM;
+			usb_otg_descriptor_init(c->cdev->gadget, usb_desc);
+			otg_desc[0] = usb_desc;
+			otg_desc[1] = NULL;
+		}
 		c->descriptors = otg_desc;
 		c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
 	}
@@ -271,6 +268,16 @@ static int eth_do_config(struct usb_configuration *c)
 	/* FIXME alloc iConfiguration string, set it in c->strings */
 
 	if (gadget_is_otg(c->cdev->gadget)) {
+		if (!otg_desc[0]) {
+			struct usb_descriptor_header *usb_desc;
+
+			usb_desc = usb_otg_descriptor_alloc(c->cdev->gadget);
+			if (!usb_desc)
+				return -ENOMEM;
+			usb_otg_descriptor_init(c->cdev->gadget, usb_desc);
+			otg_desc[0] = usb_desc;
+			otg_desc[1] = NULL;
+		}
 		c->descriptors = otg_desc;
 		c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
 	}
@@ -463,6 +470,9 @@ static int eth_unbind(struct usb_composite_dev *cdev)
 		usb_put_function(f_geth);
 		usb_put_function_instance(fi_geth);
 	}
+	kfree(otg_desc[0]);
+	otg_desc[0] = NULL;
+
 	return 0;
 }
 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH v4 13/23] usb: gadget: acm_ms: allocate and init otg descriptor by otg capabilities
       [not found] ` <1434519835-27745-1-git-send-email-jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
                     ` (11 preceding siblings ...)
  2015-06-17  5:43   ` [PATCH v4 12/23] usb: gadget: ether: " Li Jun
@ 2015-06-17  5:43   ` Li Jun
       [not found]     ` <1434519835-27745-14-git-send-email-jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
  2015-06-17  5:43   ` [PATCH v4 14/23] usb: gadget: audio: " Li Jun
                     ` (9 subsequent siblings)
  22 siblings, 1 reply; 36+ messages in thread
From: Li Jun @ 2015-06-17  5:43 UTC (permalink / raw)
  To: gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r, balbi-l0cyMroinI0,
	peter.chen-KZfg59tc24xl57MIdRCFDg,
	robh+dt-DgEjT+Ai2ygdnm+yROfE0A
  Cc: linux-usb-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA, pawel.moll-5wv7dgnIgG8,
	mark.rutland-5wv7dgnIgG8, macpaul-Re5JQEeQqe8AvxtiuMwx3w,
	rogerq-l0cyMroinI0, Li Jun

Allocate and initialize usb otg descriptor according to gadget otg
capabilities, add it for each usb configurations, free it while
composite unbind. If otg capability is not defined, keep its otg
descriptor unchanged.

Signed-off-by: Li Jun <jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
---
 drivers/usb/gadget/legacy/acm_ms.c | 29 ++++++++++++++---------------
 1 file changed, 14 insertions(+), 15 deletions(-)

diff --git a/drivers/usb/gadget/legacy/acm_ms.c b/drivers/usb/gadget/legacy/acm_ms.c
index 1194b09..f9b7b31 100644
--- a/drivers/usb/gadget/legacy/acm_ms.c
+++ b/drivers/usb/gadget/legacy/acm_ms.c
@@ -58,21 +58,7 @@ static struct usb_device_descriptor device_desc = {
 	/*.bNumConfigurations =	DYNAMIC*/
 };
 
-static struct usb_otg_descriptor otg_descriptor = {
-	.bLength =		sizeof otg_descriptor,
-	.bDescriptorType =	USB_DT_OTG,
-
-	/*
-	 * REVISIT SRP-only hardware is possible, although
-	 * it would not be called "OTG" ...
-	 */
-	.bmAttributes =		USB_OTG_SRP | USB_OTG_HNP,
-};
-
-static const struct usb_descriptor_header *otg_desc[] = {
-	(struct usb_descriptor_header *) &otg_descriptor,
-	NULL,
-};
+static const struct usb_descriptor_header *otg_desc[2];
 
 /* string IDs are assigned dynamically */
 static struct usb_string strings_dev[] = {
@@ -127,6 +113,16 @@ static int acm_ms_do_config(struct usb_configuration *c)
 	int	status;
 
 	if (gadget_is_otg(c->cdev->gadget)) {
+		if (!otg_desc[0]) {
+			struct usb_descriptor_header *usb_desc;
+
+			usb_desc = usb_otg_descriptor_alloc(c->cdev->gadget);
+			if (!usb_desc)
+				return -ENOMEM;
+			usb_otg_descriptor_init(c->cdev->gadget, usb_desc);
+			otg_desc[0] = usb_desc;
+			otg_desc[1] = NULL;
+		}
 		c->descriptors = otg_desc;
 		c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
 	}
@@ -255,6 +251,9 @@ static int acm_ms_unbind(struct usb_composite_dev *cdev)
 	usb_put_function_instance(fi_msg);
 	usb_put_function(f_acm);
 	usb_put_function_instance(f_acm_inst);
+	kfree(otg_desc[0]);
+	otg_desc[0] = NULL;
+
 	return 0;
 }
 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH v4 14/23] usb: gadget: audio: allocate and init otg descriptor by otg capabilities
       [not found] ` <1434519835-27745-1-git-send-email-jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
                     ` (12 preceding siblings ...)
  2015-06-17  5:43   ` [PATCH v4 13/23] usb: gadget: acm_ms: " Li Jun
@ 2015-06-17  5:43   ` Li Jun
  2015-06-17  5:43   ` [PATCH v4 15/23] usb: gadget: cdc2: " Li Jun
                     ` (8 subsequent siblings)
  22 siblings, 0 replies; 36+ messages in thread
From: Li Jun @ 2015-06-17  5:43 UTC (permalink / raw)
  To: gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r, balbi-l0cyMroinI0,
	peter.chen-KZfg59tc24xl57MIdRCFDg,
	robh+dt-DgEjT+Ai2ygdnm+yROfE0A
  Cc: linux-usb-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA, pawel.moll-5wv7dgnIgG8,
	mark.rutland-5wv7dgnIgG8, macpaul-Re5JQEeQqe8AvxtiuMwx3w,
	rogerq-l0cyMroinI0, Li Jun

Allocate and initialize usb otg descriptor according to gadget otg
capabilities, add it for each usb configurations, free it while
composite unbind. If otg capability is not defined, keep its otg
descriptor unchanged.

Signed-off-by: Li Jun <jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
---
 drivers/usb/gadget/legacy/audio.c | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/drivers/usb/gadget/legacy/audio.c b/drivers/usb/gadget/legacy/audio.c
index f289caf..a30b23b 100644
--- a/drivers/usb/gadget/legacy/audio.c
+++ b/drivers/usb/gadget/legacy/audio.c
@@ -150,20 +150,7 @@ static struct usb_device_descriptor device_desc = {
 	.bNumConfigurations =	1,
 };
 
-static struct usb_otg_descriptor otg_descriptor = {
-	.bLength =		sizeof otg_descriptor,
-	.bDescriptorType =	USB_DT_OTG,
-
-	/* REVISIT SRP-only hardware is possible, although
-	 * it would not be called "OTG" ...
-	 */
-	.bmAttributes =		USB_OTG_SRP | USB_OTG_HNP,
-};
-
-static const struct usb_descriptor_header *otg_desc[] = {
-	(struct usb_descriptor_header *) &otg_descriptor,
-	NULL,
-};
+static const struct usb_descriptor_header *otg_desc[2];
 
 /*-------------------------------------------------------------------------*/
 
@@ -174,6 +161,16 @@ static int audio_do_config(struct usb_configuration *c)
 	/* FIXME alloc iConfiguration string, set it in c->strings */
 
 	if (gadget_is_otg(c->cdev->gadget)) {
+		if (!otg_desc[0]) {
+			struct usb_descriptor_header *usb_desc;
+
+			usb_desc = usb_otg_descriptor_alloc(c->cdev->gadget);
+			if (!usb_desc)
+				return -ENOMEM;
+			usb_otg_descriptor_init(c->cdev->gadget, usb_desc);
+			otg_desc[0] = usb_desc;
+			otg_desc[1] = NULL;
+		}
 		c->descriptors = otg_desc;
 		c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
 	}
@@ -289,6 +286,9 @@ static int audio_unbind(struct usb_composite_dev *cdev)
 	if (!IS_ERR_OR_NULL(fi_uac2))
 		usb_put_function_instance(fi_uac2);
 #endif
+	kfree(otg_desc[0]);
+	otg_desc[0] = NULL;
+
 	return 0;
 }
 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH v4 15/23] usb: gadget: cdc2: allocate and init otg descriptor by otg capabilities
       [not found] ` <1434519835-27745-1-git-send-email-jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
                     ` (13 preceding siblings ...)
  2015-06-17  5:43   ` [PATCH v4 14/23] usb: gadget: audio: " Li Jun
@ 2015-06-17  5:43   ` Li Jun
  2015-06-17  5:43   ` [PATCH v4 16/23] usb: gadget: g_ffs: " Li Jun
                     ` (7 subsequent siblings)
  22 siblings, 0 replies; 36+ messages in thread
From: Li Jun @ 2015-06-17  5:43 UTC (permalink / raw)
  To: gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r, balbi-l0cyMroinI0,
	peter.chen-KZfg59tc24xl57MIdRCFDg,
	robh+dt-DgEjT+Ai2ygdnm+yROfE0A
  Cc: linux-usb-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA, pawel.moll-5wv7dgnIgG8,
	mark.rutland-5wv7dgnIgG8, macpaul-Re5JQEeQqe8AvxtiuMwx3w,
	rogerq-l0cyMroinI0, Li Jun

Allocate and initialize usb otg descriptor according to gadget otg
capabilities, add it for each usb configurations, free it while
composite unbind. If otg capability is not defined, keep its otg
descriptor unchanged.

Signed-off-by: Li Jun <jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
---
 drivers/usb/gadget/legacy/cdc2.c | 29 ++++++++++++++---------------
 1 file changed, 14 insertions(+), 15 deletions(-)

diff --git a/drivers/usb/gadget/legacy/cdc2.c b/drivers/usb/gadget/legacy/cdc2.c
index afd3e37..bb85b7a 100644
--- a/drivers/usb/gadget/legacy/cdc2.c
+++ b/drivers/usb/gadget/legacy/cdc2.c
@@ -60,21 +60,7 @@ static struct usb_device_descriptor device_desc = {
 	.bNumConfigurations =	1,
 };
 
-static struct usb_otg_descriptor otg_descriptor = {
-	.bLength =		sizeof otg_descriptor,
-	.bDescriptorType =	USB_DT_OTG,
-
-	/* REVISIT SRP-only hardware is possible, although
-	 * it would not be called "OTG" ...
-	 */
-	.bmAttributes =		USB_OTG_SRP | USB_OTG_HNP,
-};
-
-static const struct usb_descriptor_header *otg_desc[] = {
-	(struct usb_descriptor_header *) &otg_descriptor,
-	NULL,
-};
-
+static const struct usb_descriptor_header *otg_desc[2];
 
 /* string IDs are assigned dynamically */
 static struct usb_string strings_dev[] = {
@@ -109,6 +95,16 @@ static int cdc_do_config(struct usb_configuration *c)
 	int	status;
 
 	if (gadget_is_otg(c->cdev->gadget)) {
+		if (!otg_desc[0]) {
+			struct usb_descriptor_header *usb_desc;
+
+			usb_desc = usb_otg_descriptor_alloc(c->cdev->gadget);
+			if (!usb_desc)
+				return -ENOMEM;
+			usb_otg_descriptor_init(c->cdev->gadget, usb_desc);
+			otg_desc[0] = usb_desc;
+			otg_desc[1] = NULL;
+		}
 		c->descriptors = otg_desc;
 		c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
 	}
@@ -219,6 +215,9 @@ static int cdc_unbind(struct usb_composite_dev *cdev)
 		usb_put_function(f_ecm);
 	if (!IS_ERR_OR_NULL(fi_ecm))
 		usb_put_function_instance(fi_ecm);
+	kfree(otg_desc[0]);
+	otg_desc[0] = NULL;
+
 	return 0;
 }
 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH v4 16/23] usb: gadget: g_ffs: allocate and init otg descriptor by otg capabilities
       [not found] ` <1434519835-27745-1-git-send-email-jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
                     ` (14 preceding siblings ...)
  2015-06-17  5:43   ` [PATCH v4 15/23] usb: gadget: cdc2: " Li Jun
@ 2015-06-17  5:43   ` Li Jun
  2015-06-17  5:43   ` [PATCH v4 17/23] usb: gadget: hid: " Li Jun
                     ` (6 subsequent siblings)
  22 siblings, 0 replies; 36+ messages in thread
From: Li Jun @ 2015-06-17  5:43 UTC (permalink / raw)
  To: gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r, balbi-l0cyMroinI0,
	peter.chen-KZfg59tc24xl57MIdRCFDg,
	robh+dt-DgEjT+Ai2ygdnm+yROfE0A
  Cc: linux-usb-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA, pawel.moll-5wv7dgnIgG8,
	mark.rutland-5wv7dgnIgG8, macpaul-Re5JQEeQqe8AvxtiuMwx3w,
	rogerq-l0cyMroinI0, Li Jun

Allocate and initialize usb otg descriptor according to gadget otg
capabilities, add it for each usb configurations, free it while
composite unbind. If otg capability is not defined, keep its otg
descriptor unchanged.

Signed-off-by: Li Jun <jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
---
 drivers/usb/gadget/legacy/g_ffs.c | 29 ++++++++++++++---------------
 1 file changed, 14 insertions(+), 15 deletions(-)

diff --git a/drivers/usb/gadget/legacy/g_ffs.c b/drivers/usb/gadget/legacy/g_ffs.c
index 7b9ef7e..828a99c 100644
--- a/drivers/usb/gadget/legacy/g_ffs.c
+++ b/drivers/usb/gadget/legacy/g_ffs.c
@@ -88,21 +88,7 @@ MODULE_PARM_DESC(bDeviceProtocol, "USB Device protocol");
 module_param_array_named(functions, func_names, charp, &func_num, 0);
 MODULE_PARM_DESC(functions, "USB Functions list");
 
-static const struct usb_descriptor_header *gfs_otg_desc[] = {
-	(const struct usb_descriptor_header *)
-	&(const struct usb_otg_descriptor) {
-		.bLength		= sizeof(struct usb_otg_descriptor),
-		.bDescriptorType	= USB_DT_OTG,
-
-		/*
-		 * REVISIT SRP-only hardware is possible, although
-		 * it would not be called "OTG" ...
-		 */
-		.bmAttributes		= USB_OTG_SRP | USB_OTG_HNP,
-	},
-
-	NULL
-};
+static const struct usb_descriptor_header *gfs_otg_desc[2];
 
 /* String IDs are assigned dynamically */
 static struct usb_string gfs_strings[] = {
@@ -471,6 +457,9 @@ static int gfs_unbind(struct usb_composite_dev *cdev)
 	for (i = 0; i < N_CONF * func_num; ++i)
 		usb_put_function(*(f_ffs[0] + i));
 
+	kfree(gfs_otg_desc[0]);
+	gfs_otg_desc[0] = NULL;
+
 	return 0;
 }
 
@@ -489,6 +478,16 @@ static int gfs_do_config(struct usb_configuration *c)
 		return -ENODEV;
 
 	if (gadget_is_otg(c->cdev->gadget)) {
+		if (!gfs_otg_desc[0]) {
+			struct usb_descriptor_header *usb_desc;
+
+			usb_desc = usb_otg_descriptor_alloc(c->cdev->gadget);
+			if (!usb_desc)
+				return -ENOMEM;
+			usb_otg_descriptor_init(c->cdev->gadget, usb_desc);
+			gfs_otg_desc[0] = usb_desc;
+			gfs_otg_desc[1] = NULL;
+		}
 		c->descriptors = gfs_otg_desc;
 		c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
 	}
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH v4 17/23] usb: gadget: hid: allocate and init otg descriptor by otg capabilities
       [not found] ` <1434519835-27745-1-git-send-email-jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
                     ` (15 preceding siblings ...)
  2015-06-17  5:43   ` [PATCH v4 16/23] usb: gadget: g_ffs: " Li Jun
@ 2015-06-17  5:43   ` Li Jun
  2015-06-17  5:43   ` [PATCH v4 18/23] usb: gadget: mass_storage: " Li Jun
                     ` (5 subsequent siblings)
  22 siblings, 0 replies; 36+ messages in thread
From: Li Jun @ 2015-06-17  5:43 UTC (permalink / raw)
  To: gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r, balbi-l0cyMroinI0,
	peter.chen-KZfg59tc24xl57MIdRCFDg,
	robh+dt-DgEjT+Ai2ygdnm+yROfE0A
  Cc: linux-usb-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA, pawel.moll-5wv7dgnIgG8,
	mark.rutland-5wv7dgnIgG8, macpaul-Re5JQEeQqe8AvxtiuMwx3w,
	rogerq-l0cyMroinI0, Li Jun

Allocate and initialize usb otg descriptor according to gadget otg
capabilities, add it for each usb configurations, free it while
composite unbind. If otg capability is not defined, keep its otg
descriptor unchanged.

Signed-off-by: Li Jun <jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
---
 drivers/usb/gadget/legacy/hid.c | 30 +++++++++++++++---------------
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/drivers/usb/gadget/legacy/hid.c b/drivers/usb/gadget/legacy/hid.c
index 2baa572..09889bc 100644
--- a/drivers/usb/gadget/legacy/hid.c
+++ b/drivers/usb/gadget/legacy/hid.c
@@ -68,21 +68,7 @@ static struct usb_device_descriptor device_desc = {
 	.bNumConfigurations =	1,
 };
 
-static struct usb_otg_descriptor otg_descriptor = {
-	.bLength =		sizeof otg_descriptor,
-	.bDescriptorType =	USB_DT_OTG,
-
-	/* REVISIT SRP-only hardware is possible, although
-	 * it would not be called "OTG" ...
-	 */
-	.bmAttributes =		USB_OTG_SRP | USB_OTG_HNP,
-};
-
-static const struct usb_descriptor_header *otg_desc[] = {
-	(struct usb_descriptor_header *) &otg_descriptor,
-	NULL,
-};
-
+static const struct usb_descriptor_header *otg_desc[2];
 
 /* string IDs are assigned dynamically */
 static struct usb_string strings_dev[] = {
@@ -112,6 +98,16 @@ static int do_config(struct usb_configuration *c)
 	int status = 0;
 
 	if (gadget_is_otg(c->cdev->gadget)) {
+		if (!otg_desc[0]) {
+			struct usb_descriptor_header *usb_desc;
+
+			usb_desc = usb_otg_descriptor_alloc(c->cdev->gadget);
+			if (!usb_desc)
+				return -ENOMEM;
+			usb_otg_descriptor_init(c->cdev->gadget, usb_desc);
+			otg_desc[0] = usb_desc;
+			otg_desc[1] = NULL;
+		}
 		c->descriptors = otg_desc;
 		c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
 	}
@@ -213,6 +209,10 @@ static int hid_unbind(struct usb_composite_dev *cdev)
 		usb_put_function(n->f);
 		usb_put_function_instance(n->fi);
 	}
+
+	kfree(otg_desc[0]);
+	otg_desc[0] = NULL;
+
 	return 0;
 }
 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH v4 18/23] usb: gadget: mass_storage: allocate and init otg descriptor by otg capabilities
       [not found] ` <1434519835-27745-1-git-send-email-jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
                     ` (16 preceding siblings ...)
  2015-06-17  5:43   ` [PATCH v4 17/23] usb: gadget: hid: " Li Jun
@ 2015-06-17  5:43   ` Li Jun
  2015-06-17  5:43   ` [PATCH v4 19/23] usb: gadget: multi: " Li Jun
                     ` (4 subsequent siblings)
  22 siblings, 0 replies; 36+ messages in thread
From: Li Jun @ 2015-06-17  5:43 UTC (permalink / raw)
  To: gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r, balbi-l0cyMroinI0,
	peter.chen-KZfg59tc24xl57MIdRCFDg,
	robh+dt-DgEjT+Ai2ygdnm+yROfE0A
  Cc: linux-usb-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA, pawel.moll-5wv7dgnIgG8,
	mark.rutland-5wv7dgnIgG8, macpaul-Re5JQEeQqe8AvxtiuMwx3w,
	rogerq-l0cyMroinI0, Li Jun

Allocate and initialize usb otg descriptor according to gadget otg
capabilities, add it for each usb configurations, free it while
composite unbind. If otg capability is not defined, keep its otg
descriptor unchanged.

Signed-off-by: Li Jun <jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
---
 drivers/usb/gadget/legacy/mass_storage.c | 29 ++++++++++++++---------------
 1 file changed, 14 insertions(+), 15 deletions(-)

diff --git a/drivers/usb/gadget/legacy/mass_storage.c b/drivers/usb/gadget/legacy/mass_storage.c
index e7bfb08..1645e07 100644
--- a/drivers/usb/gadget/legacy/mass_storage.c
+++ b/drivers/usb/gadget/legacy/mass_storage.c
@@ -64,21 +64,7 @@ static struct usb_device_descriptor msg_device_desc = {
 	.bNumConfigurations =	1,
 };
 
-static struct usb_otg_descriptor otg_descriptor = {
-	.bLength =		sizeof otg_descriptor,
-	.bDescriptorType =	USB_DT_OTG,
-
-	/*
-	 * REVISIT SRP-only hardware is possible, although
-	 * it would not be called "OTG" ...
-	 */
-	.bmAttributes =		USB_OTG_SRP | USB_OTG_HNP,
-};
-
-static const struct usb_descriptor_header *otg_desc[] = {
-	(struct usb_descriptor_header *) &otg_descriptor,
-	NULL,
-};
+static const struct usb_descriptor_header *otg_desc[2];
 
 static struct usb_string strings_dev[] = {
 	[USB_GADGET_MANUFACTURER_IDX].s = "",
@@ -136,6 +122,16 @@ static int msg_do_config(struct usb_configuration *c)
 	int ret;
 
 	if (gadget_is_otg(c->cdev->gadget)) {
+		if (!otg_desc[0]) {
+			struct usb_descriptor_header *usb_desc;
+
+			usb_desc = usb_otg_descriptor_alloc(c->cdev->gadget);
+			if (!usb_desc)
+				return -ENOMEM;
+			usb_otg_descriptor_init(c->cdev->gadget, usb_desc);
+			otg_desc[0] = usb_desc;
+			otg_desc[1] = NULL;
+		}
 		c->descriptors = otg_desc;
 		c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
 	}
@@ -243,6 +239,9 @@ static int msg_unbind(struct usb_composite_dev *cdev)
 	if (!IS_ERR(fi_msg))
 		usb_put_function_instance(fi_msg);
 
+	kfree(otg_desc[0]);
+	otg_desc[0] = NULL;
+
 	return 0;
 }
 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH v4 19/23] usb: gadget: multi: allocate and init otg descriptor by otg capabilities
       [not found] ` <1434519835-27745-1-git-send-email-jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
                     ` (17 preceding siblings ...)
  2015-06-17  5:43   ` [PATCH v4 18/23] usb: gadget: mass_storage: " Li Jun
@ 2015-06-17  5:43   ` Li Jun
  2015-06-17  5:43   ` [PATCH v4 20/23] usb: gadget: ncm: " Li Jun
                     ` (3 subsequent siblings)
  22 siblings, 0 replies; 36+ messages in thread
From: Li Jun @ 2015-06-17  5:43 UTC (permalink / raw)
  To: gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r, balbi-l0cyMroinI0,
	peter.chen-KZfg59tc24xl57MIdRCFDg,
	robh+dt-DgEjT+Ai2ygdnm+yROfE0A
  Cc: linux-usb-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA, pawel.moll-5wv7dgnIgG8,
	mark.rutland-5wv7dgnIgG8, macpaul-Re5JQEeQqe8AvxtiuMwx3w,
	rogerq-l0cyMroinI0, Li Jun

Allocate and initialize usb otg descriptor according to gadget otg
capabilities, add it for each usb configurations, free it while
composite unbind. If otg capability is not defined, keep its otg
descriptor unchanged.

Signed-off-by: Li Jun <jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
---
 drivers/usb/gadget/legacy/multi.c | 39 ++++++++++++++++++++++++---------------
 1 file changed, 24 insertions(+), 15 deletions(-)

diff --git a/drivers/usb/gadget/legacy/multi.c b/drivers/usb/gadget/legacy/multi.c
index b21b51f..938b32c 100644
--- a/drivers/usb/gadget/legacy/multi.c
+++ b/drivers/usb/gadget/legacy/multi.c
@@ -78,21 +78,7 @@ static struct usb_device_descriptor device_desc = {
 	.idProduct =		cpu_to_le16(MULTI_PRODUCT_NUM),
 };
 
-
-static const struct usb_descriptor_header *otg_desc[] = {
-	(struct usb_descriptor_header *) &(struct usb_otg_descriptor){
-		.bLength =		sizeof(struct usb_otg_descriptor),
-		.bDescriptorType =	USB_DT_OTG,
-
-		/*
-		 * REVISIT SRP-only hardware is possible, although
-		 * it would not be called "OTG" ...
-		 */
-		.bmAttributes =		USB_OTG_SRP | USB_OTG_HNP,
-	},
-	NULL,
-};
-
+static const struct usb_descriptor_header *otg_desc[2];
 
 enum {
 	MULTI_STRING_RNDIS_CONFIG_IDX = USB_GADGET_FIRST_AVAIL_IDX,
@@ -155,6 +141,16 @@ static int rndis_do_config(struct usb_configuration *c)
 	int ret;
 
 	if (gadget_is_otg(c->cdev->gadget)) {
+		if (!otg_desc[0]) {
+			struct usb_descriptor_header *usb_desc;
+
+			usb_desc = usb_otg_descriptor_alloc(c->cdev->gadget);
+			if (!usb_desc)
+				return -ENOMEM;
+			usb_otg_descriptor_init(c->cdev->gadget, usb_desc);
+			otg_desc[0] = usb_desc;
+			otg_desc[1] = NULL;
+		}
 		c->descriptors = otg_desc;
 		c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
 	}
@@ -243,6 +239,16 @@ static int cdc_do_config(struct usb_configuration *c)
 	int ret;
 
 	if (gadget_is_otg(c->cdev->gadget)) {
+		if (!otg_desc[0]) {
+			struct usb_descriptor_header *usb_desc;
+
+			usb_desc = usb_otg_descriptor_alloc(c->cdev->gadget);
+			if (!usb_desc)
+				return -ENOMEM;
+			usb_otg_descriptor_init(c->cdev->gadget, usb_desc);
+			otg_desc[0] = usb_desc;
+			otg_desc[1] = NULL;
+		}
 		c->descriptors = otg_desc;
 		c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
 	}
@@ -490,6 +496,9 @@ static int multi_unbind(struct usb_composite_dev *cdev)
 	usb_put_function(f_ecm);
 	usb_put_function_instance(fi_ecm);
 #endif
+	kfree(otg_desc[0]);
+	otg_desc[0] = NULL;
+
 	return 0;
 }
 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH v4 20/23] usb: gadget: ncm: allocate and init otg descriptor by otg capabilities
       [not found] ` <1434519835-27745-1-git-send-email-jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
                     ` (18 preceding siblings ...)
  2015-06-17  5:43   ` [PATCH v4 19/23] usb: gadget: multi: " Li Jun
@ 2015-06-17  5:43   ` Li Jun
  2015-06-17  5:43   ` [PATCH v4 21/23] usb: gadget: printer: " Li Jun
                     ` (2 subsequent siblings)
  22 siblings, 0 replies; 36+ messages in thread
From: Li Jun @ 2015-06-17  5:43 UTC (permalink / raw)
  To: gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r, balbi-l0cyMroinI0,
	peter.chen-KZfg59tc24xl57MIdRCFDg,
	robh+dt-DgEjT+Ai2ygdnm+yROfE0A
  Cc: linux-usb-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA, pawel.moll-5wv7dgnIgG8,
	mark.rutland-5wv7dgnIgG8, macpaul-Re5JQEeQqe8AvxtiuMwx3w,
	rogerq-l0cyMroinI0, Li Jun

Allocate and initialize usb otg descriptor according to gadget otg
capabilities, add it for each usb configurations, free it while
composite unbind. If otg capability is not defined, keep its otg
descriptor unchanged.

Signed-off-by: Li Jun <jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
---
 drivers/usb/gadget/legacy/ncm.c | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/drivers/usb/gadget/legacy/ncm.c b/drivers/usb/gadget/legacy/ncm.c
index 6ce7421..6a11a4f 100644
--- a/drivers/usb/gadget/legacy/ncm.c
+++ b/drivers/usb/gadget/legacy/ncm.c
@@ -69,20 +69,7 @@ static struct usb_device_descriptor device_desc = {
 	.bNumConfigurations =	1,
 };
 
-static struct usb_otg_descriptor otg_descriptor = {
-	.bLength =		sizeof otg_descriptor,
-	.bDescriptorType =	USB_DT_OTG,
-
-	/* REVISIT SRP-only hardware is possible, although
-	 * it would not be called "OTG" ...
-	 */
-	.bmAttributes =		USB_OTG_SRP | USB_OTG_HNP,
-};
-
-static const struct usb_descriptor_header *otg_desc[] = {
-	(struct usb_descriptor_header *) &otg_descriptor,
-	NULL,
-};
+static const struct usb_descriptor_header *otg_desc[2];
 
 /* string IDs are assigned dynamically */
 static struct usb_string strings_dev[] = {
@@ -114,6 +101,16 @@ static int ncm_do_config(struct usb_configuration *c)
 	/* FIXME alloc iConfiguration string, set it in c->strings */
 
 	if (gadget_is_otg(c->cdev->gadget)) {
+		if (!otg_desc[0]) {
+			struct usb_descriptor_header *usb_desc;
+
+			usb_desc = usb_otg_descriptor_alloc(c->cdev->gadget);
+			if (!usb_desc)
+				return -ENOMEM;
+			usb_otg_descriptor_init(c->cdev->gadget, usb_desc);
+			otg_desc[0] = usb_desc;
+			otg_desc[1] = NULL;
+		}
 		c->descriptors = otg_desc;
 		c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
 	}
@@ -192,6 +189,9 @@ static int gncm_unbind(struct usb_composite_dev *cdev)
 		usb_put_function(f_ncm);
 	if (!IS_ERR_OR_NULL(f_ncm_inst))
 		usb_put_function_instance(f_ncm_inst);
+	kfree(otg_desc[0]);
+	otg_desc[0] = NULL;
+
 	return 0;
 }
 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH v4 21/23] usb: gadget: printer: allocate and init otg descriptor by otg capabilities
       [not found] ` <1434519835-27745-1-git-send-email-jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
                     ` (19 preceding siblings ...)
  2015-06-17  5:43   ` [PATCH v4 20/23] usb: gadget: ncm: " Li Jun
@ 2015-06-17  5:43   ` Li Jun
  2015-06-17  5:43   ` [PATCH v4 22/23] usb: gadget: serial: " Li Jun
  2015-06-17  5:43   ` [PATCH v4 23/23] usb: gadget: zero: " Li Jun
  22 siblings, 0 replies; 36+ messages in thread
From: Li Jun @ 2015-06-17  5:43 UTC (permalink / raw)
  To: gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r, balbi-l0cyMroinI0,
	peter.chen-KZfg59tc24xl57MIdRCFDg,
	robh+dt-DgEjT+Ai2ygdnm+yROfE0A
  Cc: linux-usb-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA, pawel.moll-5wv7dgnIgG8,
	mark.rutland-5wv7dgnIgG8, macpaul-Re5JQEeQqe8AvxtiuMwx3w,
	rogerq-l0cyMroinI0, Li Jun

Allocate and initialize usb otg descriptor according to gadget otg
capabilities, add it for each usb configurations, free it while
composite unbind. If otg capability is not defined, keep its otg
descriptor unchanged.

Signed-off-by: Li Jun <jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
---
 drivers/usb/gadget/legacy/printer.c | 25 ++++++++++++++-----------
 1 file changed, 14 insertions(+), 11 deletions(-)

diff --git a/drivers/usb/gadget/legacy/printer.c b/drivers/usb/gadget/legacy/printer.c
index 1ce7df1..4833890 100644
--- a/drivers/usb/gadget/legacy/printer.c
+++ b/drivers/usb/gadget/legacy/printer.c
@@ -82,16 +82,7 @@ static struct usb_device_descriptor device_desc = {
 	.bNumConfigurations =	1
 };
 
-static struct usb_otg_descriptor otg_descriptor = {
-	.bLength =              sizeof otg_descriptor,
-	.bDescriptorType =      USB_DT_OTG,
-	.bmAttributes =         USB_OTG_SRP,
-};
-
-static const struct usb_descriptor_header *otg_desc[] = {
-	(struct usb_descriptor_header *) &otg_descriptor,
-	NULL,
-};
+static const struct usb_descriptor_header *otg_desc[2];
 
 /*-------------------------------------------------------------------------*/
 
@@ -136,7 +127,16 @@ static int printer_do_config(struct usb_configuration *c)
 	usb_gadget_set_selfpowered(gadget);
 
 	if (gadget_is_otg(gadget)) {
-		otg_descriptor.bmAttributes |= USB_OTG_HNP;
+		if (!otg_desc[0]) {
+			struct usb_descriptor_header *usb_desc;
+
+			usb_desc = usb_otg_descriptor_alloc(gadget);
+			if (!usb_desc)
+				return -ENOMEM;
+			usb_otg_descriptor_init(gadget, usb_desc);
+			otg_desc[0] = usb_desc;
+			otg_desc[1] = NULL;
+		}
 		printer_cfg_driver.descriptors = otg_desc;
 		printer_cfg_driver.bmAttributes |= USB_CONFIG_ATT_WAKEUP;
 	}
@@ -196,6 +196,9 @@ static int printer_unbind(struct usb_composite_dev *cdev)
 	usb_put_function(f_printer);
 	usb_put_function_instance(fi_printer);
 
+	kfree(otg_desc[0]);
+	otg_desc[0] = NULL;
+
 	return 0;
 }
 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH v4 22/23] usb: gadget: serial: allocate and init otg descriptor by otg capabilities
       [not found] ` <1434519835-27745-1-git-send-email-jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
                     ` (20 preceding siblings ...)
  2015-06-17  5:43   ` [PATCH v4 21/23] usb: gadget: printer: " Li Jun
@ 2015-06-17  5:43   ` Li Jun
  2015-06-17  5:43   ` [PATCH v4 23/23] usb: gadget: zero: " Li Jun
  22 siblings, 0 replies; 36+ messages in thread
From: Li Jun @ 2015-06-17  5:43 UTC (permalink / raw)
  To: gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r, balbi-l0cyMroinI0,
	peter.chen-KZfg59tc24xl57MIdRCFDg,
	robh+dt-DgEjT+Ai2ygdnm+yROfE0A
  Cc: linux-usb-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA, pawel.moll-5wv7dgnIgG8,
	mark.rutland-5wv7dgnIgG8, macpaul-Re5JQEeQqe8AvxtiuMwx3w,
	rogerq-l0cyMroinI0, Li Jun

Allocate and initialize usb otg descriptor according to gadget otg
capabilities, add it for each usb configurations, free it while
composite unbind. If otg capability is not defined, keep its otg
descriptor unchanged.

Signed-off-by: Li Jun <jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
---
 drivers/usb/gadget/legacy/serial.c | 29 +++++++++++++++--------------
 1 file changed, 15 insertions(+), 14 deletions(-)

diff --git a/drivers/usb/gadget/legacy/serial.c b/drivers/usb/gadget/legacy/serial.c
index 8b7528f..d1cd025 100644
--- a/drivers/usb/gadget/legacy/serial.c
+++ b/drivers/usb/gadget/legacy/serial.c
@@ -79,20 +79,7 @@ static struct usb_device_descriptor device_desc = {
 	.bNumConfigurations =	1,
 };
 
-static struct usb_otg_descriptor otg_descriptor = {
-	.bLength =		sizeof otg_descriptor,
-	.bDescriptorType =	USB_DT_OTG,
-
-	/* REVISIT SRP-only hardware is possible, although
-	 * it would not be called "OTG" ...
-	 */
-	.bmAttributes =		USB_OTG_SRP | USB_OTG_HNP,
-};
-
-static const struct usb_descriptor_header *otg_desc[] = {
-	(struct usb_descriptor_header *) &otg_descriptor,
-	NULL,
-};
+static const struct usb_descriptor_header *otg_desc[2];
 
 /*-------------------------------------------------------------------------*/
 
@@ -191,6 +178,16 @@ static int gs_bind(struct usb_composite_dev *cdev)
 	serial_config_driver.iConfiguration = status;
 
 	if (gadget_is_otg(cdev->gadget)) {
+		if (!otg_desc[0]) {
+			struct usb_descriptor_header *usb_desc;
+
+			usb_desc = usb_otg_descriptor_alloc(cdev->gadget);
+			if (!usb_desc)
+				return -ENOMEM;
+			usb_otg_descriptor_init(cdev->gadget, usb_desc);
+			otg_desc[0] = usb_desc;
+			otg_desc[1] = NULL;
+		}
 		serial_config_driver.descriptors = otg_desc;
 		serial_config_driver.bmAttributes |= USB_CONFIG_ATT_WAKEUP;
 	}
@@ -227,6 +224,10 @@ static int gs_unbind(struct usb_composite_dev *cdev)
 		usb_put_function(f_serial[i]);
 		usb_put_function_instance(fi_serial[i]);
 	}
+
+	kfree(otg_desc[0]);
+	otg_desc[0] = NULL;
+
 	return 0;
 }
 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH v4 23/23] usb: gadget: zero: allocate and init otg descriptor by otg capabilities
       [not found] ` <1434519835-27745-1-git-send-email-jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
                     ` (21 preceding siblings ...)
  2015-06-17  5:43   ` [PATCH v4 22/23] usb: gadget: serial: " Li Jun
@ 2015-06-17  5:43   ` Li Jun
  22 siblings, 0 replies; 36+ messages in thread
From: Li Jun @ 2015-06-17  5:43 UTC (permalink / raw)
  To: gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r, balbi-l0cyMroinI0,
	peter.chen-KZfg59tc24xl57MIdRCFDg,
	robh+dt-DgEjT+Ai2ygdnm+yROfE0A
  Cc: linux-usb-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA, pawel.moll-5wv7dgnIgG8,
	mark.rutland-5wv7dgnIgG8, macpaul-Re5JQEeQqe8AvxtiuMwx3w,
	rogerq-l0cyMroinI0, Li Jun

Allocate and initialize usb otg descriptor according to gadget otg
capabilities, add it for each usb configurations, free it while
composite unbind. If otg capability is not defined, keep its otg
descriptor unchanged.

Signed-off-by: Li Jun <jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
---
 drivers/usb/gadget/legacy/zero.c | 32 ++++++++++++++------------------
 1 file changed, 14 insertions(+), 18 deletions(-)

diff --git a/drivers/usb/gadget/legacy/zero.c b/drivers/usb/gadget/legacy/zero.c
index c986e8a..695c2cb 100644
--- a/drivers/usb/gadget/legacy/zero.c
+++ b/drivers/usb/gadget/legacy/zero.c
@@ -121,24 +121,7 @@ static struct usb_device_descriptor device_desc = {
 	.bNumConfigurations =	2,
 };
 
-#ifdef CONFIG_USB_OTG
-static struct usb_otg_descriptor otg_descriptor = {
-	.bLength =		sizeof otg_descriptor,
-	.bDescriptorType =	USB_DT_OTG,
-
-	/* REVISIT SRP-only hardware is possible, although
-	 * it would not be called "OTG" ...
-	 */
-	.bmAttributes =		USB_OTG_SRP | USB_OTG_HNP,
-};
-
-static const struct usb_descriptor_header *otg_desc[] = {
-	(struct usb_descriptor_header *) &otg_descriptor,
-	NULL,
-};
-#else
-#define otg_desc	NULL
-#endif
+static const struct usb_descriptor_header *otg_desc[2];
 
 /* string IDs are assigned dynamically */
 /* default serial number takes at least two packets */
@@ -341,6 +324,16 @@ static int zero_bind(struct usb_composite_dev *cdev)
 
 	/* support OTG systems */
 	if (gadget_is_otg(cdev->gadget)) {
+		if (!otg_desc[0]) {
+			struct usb_descriptor_header *usb_desc;
+
+			usb_desc = usb_otg_descriptor_alloc(cdev->gadget);
+			if (!usb_desc)
+				return -ENOMEM;
+			usb_otg_descriptor_init(cdev->gadget, usb_desc);
+			otg_desc[0] = usb_desc;
+			otg_desc[1] = NULL;
+		}
 		sourcesink_driver.descriptors = otg_desc;
 		sourcesink_driver.bmAttributes |= USB_CONFIG_ATT_WAKEUP;
 		loopback_driver.descriptors = otg_desc;
@@ -397,6 +390,9 @@ static int zero_unbind(struct usb_composite_dev *cdev)
 	if (!IS_ERR_OR_NULL(func_lb))
 		usb_put_function(func_lb);
 	usb_put_function_instance(func_inst_lb);
+	kfree(otg_desc[0]);
+	otg_desc[0] = NULL;
+
 	return 0;
 }
 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 36+ messages in thread

* Re: [PATCH v4 03/23] usb: otg: add usb_otg_caps structure for otg capabilities
       [not found]     ` <1434519835-27745-4-git-send-email-jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
@ 2015-06-17  8:25       ` Roger Quadros
  0 siblings, 0 replies; 36+ messages in thread
From: Roger Quadros @ 2015-06-17  8:25 UTC (permalink / raw)
  To: Li Jun
  Cc: gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r, balbi-l0cyMroinI0,
	peter.chen-KZfg59tc24xl57MIdRCFDg,
	robh+dt-DgEjT+Ai2ygdnm+yROfE0A, linux-usb-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA, pawel.moll-5wv7dgnIgG8,
	mark.rutland-5wv7dgnIgG8, macpaul-Re5JQEeQqe8AvxtiuMwx3w


On Wed, 17 Jun 2015 13:43:35 +0800
Li Jun <jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org> wrote:

> This patch adds a structure usb_otg_caps to cover all otg related
> capabilities of the device, including otg revision, and if hnp/srp/adp
> is supported.
> 
> Signed-off-by: Li Jun <jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org>

Reviewed-by: Roger Quadros <rogerq-l0cyMroinI0@public.gmane.org>

cheers,
-roger

> ---
>  include/linux/usb/otg.h | 15 +++++++++++++++
>  1 file changed, 15 insertions(+)
> 
> diff --git a/include/linux/usb/otg.h b/include/linux/usb/otg.h
> index 52661c5..bd1dcf8 100644
> --- a/include/linux/usb/otg.h
> +++ b/include/linux/usb/otg.h
> @@ -41,6 +41,21 @@ struct usb_otg {
>  
>  };
>  
> +/**
> + * struct usb_otg_caps - describes the otg capabilities of the device
> + * @otg_rev: The OTG revision number the device is compliant with, it's
> + *		in binary-coded decimal (i.e. 2.0 is 0200H).
> + * @hnp_support: Indicates if the device supports HNP.
> + * @srp_support: Indicates if the device supports SRP.
> + * @adp_support: Indicates if the device supports ADP.
> + */
> +struct usb_otg_caps {
> +	u16 otg_rev;
> +	bool hnp_support;
> +	bool srp_support;
> +	bool adp_support;
> +};
> +
>  extern const char *usb_otg_state_string(enum usb_otg_state state);
>  
>  /* Context: can sleep */

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v4 04/23] usb: add usb_otg_caps to usb_gadget structure.
       [not found]     ` <1434519835-27745-5-git-send-email-jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
@ 2015-06-17  8:29       ` Roger Quadros
  2015-06-17  8:50         ` Li Jun
  2015-06-17  8:53         ` Roger Quadros
  0 siblings, 2 replies; 36+ messages in thread
From: Roger Quadros @ 2015-06-17  8:29 UTC (permalink / raw)
  To: Li Jun
  Cc: gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r, balbi-l0cyMroinI0,
	peter.chen-KZfg59tc24xl57MIdRCFDg,
	robh+dt-DgEjT+Ai2ygdnm+yROfE0A, linux-usb-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA, pawel.moll-5wv7dgnIgG8,
	mark.rutland-5wv7dgnIgG8, macpaul-Re5JQEeQqe8AvxtiuMwx3w


On Wed, 17 Jun 2015 13:43:36 +0800
Li Jun <jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org> wrote:

> From: Macpaul Lin <macpaul-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> 
> Add usb_otg_caps pointer to usb_gadget structure to indicate its
> otg capabilities.
> 
> Signed-off-by: Macpaul Lin <macpaul-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> Signed-off-by: Li Jun <jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
> ---
>  include/linux/usb/gadget.h | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
> index 4f3dfb7..6b39087 100644
> --- a/include/linux/usb/gadget.h
> +++ b/include/linux/usb/gadget.h
> @@ -511,6 +511,7 @@ struct usb_gadget_ops {
>   * @dev: Driver model state for this abstract device.
>   * @out_epnum: last used out ep number
>   * @in_epnum: last used in ep number
> + * @otg_caps: OTG capabilities of this gadget.
>   * @sg_supported: true if we can handle scatter-gather
>   * @is_otg: True if the USB device port uses a Mini-AB jack, so that the
>   *	gadget driver must provide a USB OTG descriptor.
> @@ -559,6 +560,7 @@ struct usb_gadget {
>  	struct device			dev;
>  	unsigned			out_epnum;
>  	unsigned			in_epnum;
> +	struct usb_otg_caps		*otg_caps;

Why does this need to be a pointer?

>  
>  	unsigned			sg_supported:1;
>  	unsigned			is_otg:1;


cheers,
-roger
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v4 06/23] doc: dt-binding: usb: add otg related properties
       [not found]     ` <1434519835-27745-7-git-send-email-jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
@ 2015-06-17  8:30       ` Roger Quadros
  0 siblings, 0 replies; 36+ messages in thread
From: Roger Quadros @ 2015-06-17  8:30 UTC (permalink / raw)
  To: Li Jun
  Cc: gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r, balbi-l0cyMroinI0,
	peter.chen-KZfg59tc24xl57MIdRCFDg,
	robh+dt-DgEjT+Ai2ygdnm+yROfE0A, linux-usb-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA, pawel.moll-5wv7dgnIgG8,
	mark.rutland-5wv7dgnIgG8, macpaul-Re5JQEeQqe8AvxtiuMwx3w


On Wed, 17 Jun 2015 13:43:38 +0800
Li Jun <jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org> wrote:

> Add otg version, srp, hnp and adp support for usb OTG port, then those OTG
> features don't have to be decided by usb gadget drivers.
> 
> Signed-off-by: Li Jun <jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org>

Reviewed-by: Roger Quadros <rogerq-l0cyMroinI0@public.gmane.org>

cheers,
-roger

> ---
>  Documentation/devicetree/bindings/usb/generic.txt | 15 +++++++++++++++
>  1 file changed, 15 insertions(+)
> 
> diff --git a/Documentation/devicetree/bindings/usb/generic.txt b/Documentation/devicetree/bindings/usb/generic.txt
> index 477d5bb..bba8257 100644
> --- a/Documentation/devicetree/bindings/usb/generic.txt
> +++ b/Documentation/devicetree/bindings/usb/generic.txt
> @@ -11,6 +11,19 @@ Optional properties:
>  			"peripheral" and "otg". In case this attribute isn't
>  			passed via DT, USB DRD controllers should default to
>  			OTG.
> + - otg-rev: tells usb driver the release number of the OTG and EH supplement
> +			with which the device and its descriptors are compliant,
> +			in binary-coded decimal (i.e. 2.0 is 0200H). This
> +			property is used if any real OTG features(HNP/SRP/ADP)
> +			is enabled, if ADP is required, otg-rev should be
> +			0x0200 or above.
> + - hnp-disable: tells OTG controllers we want to disable OTG HNP, normally HNP
> +			is the basic function of real OTG except you want it
> +			to be a srp-capable only B device.
> + - srp-disable: tells OTG controllers we want to disable OTG SRP, SRP is
> +			optional for OTG device.
> + - adp-disable: tells OTG controllers we want to disable OTG ADP, ADP is
> +			optional for OTG device.
>  
>  This is an attribute to a USB controller such as:
>  
> @@ -21,4 +34,6 @@ dwc3@4a030000 {
>  	usb-phy = <&usb2_phy>, <&usb3,phy>;
>  	maximum-speed = "super-speed";
>  	dr_mode = "otg";
> +	otg-rev = <0x0200>;
> +	adp-disable;
>  };

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v4 07/23] usb: common: add API to get usb otg features from device tree
       [not found]     ` <1434519835-27745-8-git-send-email-jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
@ 2015-06-17  8:45       ` Roger Quadros
  2015-06-17  9:19         ` Li Jun
  0 siblings, 1 reply; 36+ messages in thread
From: Roger Quadros @ 2015-06-17  8:45 UTC (permalink / raw)
  To: Li Jun
  Cc: gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r, balbi-l0cyMroinI0,
	peter.chen-KZfg59tc24xl57MIdRCFDg,
	robh+dt-DgEjT+Ai2ygdnm+yROfE0A, linux-usb-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA, pawel.moll-5wv7dgnIgG8,
	mark.rutland-5wv7dgnIgG8, macpaul-Re5JQEeQqe8AvxtiuMwx3w


On Wed, 17 Jun 2015 13:43:39 +0800
Li Jun <jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org> wrote:

> Check property of usb hardware to get otg version and if SRP, HNP and ADP
> are supported.
> 
> Signed-off-by: Li Jun <jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
> ---
>  drivers/usb/common/common.c | 29 +++++++++++++++++++++++++++++
>  include/linux/usb/of.h      |  7 +++++++
>  2 files changed, 36 insertions(+)
> 
> diff --git a/drivers/usb/common/common.c b/drivers/usb/common/common.c
> index b530fd4..b846172 100644
> --- a/drivers/usb/common/common.c
> +++ b/drivers/usb/common/common.c
> @@ -154,6 +154,35 @@ bool of_usb_host_tpl_support(struct device_node *np)
>  	return false;
>  }
>  EXPORT_SYMBOL_GPL(of_usb_host_tpl_support);
> +
> +/**
> + * of_usb_get_otg_caps - to get usb otg capabilities according to
> + * the passed properties in DT.
> + * @np: Pointer to the given device_node
> + * @otg_caps: Pointer to the target usb_otg_caps to be set
> + *
> + * The function gets and sets the otg capabilities
> + */
> +void of_usb_get_otg_caps(struct device_node *np, struct usb_otg_caps *otg_caps)
> +{
> +	u32 otg_rev;
> +
> +	if (!otg_caps)
> +		return;
> +
> +	if (!of_property_read_u32(np, "otg-rev", &otg_rev)) {
> +		otg_caps->otg_rev = otg_rev;
> +		if (!of_find_property(np, "hnp-disable", NULL))
> +			otg_caps->hnp_support = true;
> +		if (!of_find_property(np, "srp-disable", NULL))
> +			otg_caps->hnp_support = true;

srp_support = true;

> +		if (!of_find_property(np, "adp-disable", NULL) &&
> +					(otg_caps->otg_rev >= 0x0200))
> +			otg_caps->hnp_support = true;

adp_support = true;

> +	}

I think we are loosing information here.
The DT disable flags get changed to enable flags (xyz_support)
and after this we can't really tell if the device tree really
wanted us to disable the feature or enable it based on
otg_rev/controller capabilities.

Why not pass controller caps in otg_caps and then disable the
flags if requested from DT?
	if (of_find_property(np, "foo-disbale", NULL))
		otg_caps->foo_support = false;

The controller can still override anything afterwards
if it things something is wrong.
My guess is most controllers won't have to.

> +}
> +EXPORT_SYMBOL_GPL(of_usb_get_otg_caps);
> +
>  #endif
>  
>  MODULE_LICENSE("GPL");
> diff --git a/include/linux/usb/of.h b/include/linux/usb/of.h
> index cfe0528..bbf302b9 100644
> --- a/include/linux/usb/of.h
> +++ b/include/linux/usb/of.h
> @@ -15,6 +15,8 @@
>  enum usb_dr_mode of_usb_get_dr_mode(struct device_node *np);
>  enum usb_device_speed of_usb_get_maximum_speed(struct device_node *np);
>  bool of_usb_host_tpl_support(struct device_node *np);
> +void of_usb_get_otg_caps(struct device_node *np,
> +			struct usb_otg_caps *otg_caps);
>  #else
>  static inline enum usb_dr_mode of_usb_get_dr_mode(struct device_node *np)
>  {
> @@ -30,6 +32,11 @@ static inline bool of_usb_host_tpl_support(struct device_node *np)
>  {
>  	return false;
>  }
> +static inline void of_usb_get_otg_caps(struct device_node *np,
> +				struct usb_otg_caps *otg_caps)
> +{
> +
> +}
>  #endif
>  
>  #if IS_ENABLED(CONFIG_OF) && IS_ENABLED(CONFIG_USB_SUPPORT)

cheers,
-roger
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v4 04/23] usb: add usb_otg_caps to usb_gadget structure.
  2015-06-17  8:29       ` Roger Quadros
@ 2015-06-17  8:50         ` Li Jun
  2015-06-17  8:53         ` Roger Quadros
  1 sibling, 0 replies; 36+ messages in thread
From: Li Jun @ 2015-06-17  8:50 UTC (permalink / raw)
  To: Roger Quadros
  Cc: Li Jun, gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r,
	balbi-l0cyMroinI0, peter.chen-KZfg59tc24xl57MIdRCFDg,
	robh+dt-DgEjT+Ai2ygdnm+yROfE0A, linux-usb-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA, pawel.moll-5wv7dgnIgG8,
	mark.rutland-5wv7dgnIgG8, macpaul-Re5JQEeQqe8AvxtiuMwx3w

On Wed, Jun 17, 2015 at 11:29:36AM +0300, Roger Quadros wrote:
> 
> On Wed, 17 Jun 2015 13:43:36 +0800
> Li Jun <jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org> wrote:
> 
> > From: Macpaul Lin <macpaul-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> > 
> > Add usb_otg_caps pointer to usb_gadget structure to indicate its
> > otg capabilities.
> > 
> > Signed-off-by: Macpaul Lin <macpaul-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> > Signed-off-by: Li Jun <jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
> > ---
> >  include/linux/usb/gadget.h | 2 ++
> >  1 file changed, 2 insertions(+)
> > 
> > diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
> > index 4f3dfb7..6b39087 100644
> > --- a/include/linux/usb/gadget.h
> > +++ b/include/linux/usb/gadget.h
> > @@ -511,6 +511,7 @@ struct usb_gadget_ops {
> >   * @dev: Driver model state for this abstract device.
> >   * @out_epnum: last used out ep number
> >   * @in_epnum: last used in ep number
> > + * @otg_caps: OTG capabilities of this gadget.
> >   * @sg_supported: true if we can handle scatter-gather
> >   * @is_otg: True if the USB device port uses a Mini-AB jack, so that the
> >   *	gadget driver must provide a USB OTG descriptor.
> > @@ -559,6 +560,7 @@ struct usb_gadget {
> >  	struct device			dev;
> >  	unsigned			out_epnum;
> >  	unsigned			in_epnum;
> > +	struct usb_otg_caps		*otg_caps;
> 
> Why does this need to be a pointer?
> 
we need create the same struct in controller driver anyway;
usb_otg_caps is not only used for gadget, can be used for whole OTG,
it's not proper we judge host's otg capability by gadget's setting;
with a pointer, we need not create another one and no need data copy,
instead, we have only one this struct in whole OTG device.

Li Jun
> >  
> >  	unsigned			sg_supported:1;
> >  	unsigned			is_otg:1;
> 
> 
> cheers,
> -roger
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v4 10/23] usb: gadget: add usb otg descriptor allocate and init interface
       [not found]     ` <1434519835-27745-11-git-send-email-jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
@ 2015-06-17  8:51       ` Roger Quadros
  0 siblings, 0 replies; 36+ messages in thread
From: Roger Quadros @ 2015-06-17  8:51 UTC (permalink / raw)
  To: Li Jun
  Cc: gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r, balbi-l0cyMroinI0,
	peter.chen-KZfg59tc24xl57MIdRCFDg,
	robh+dt-DgEjT+Ai2ygdnm+yROfE0A, linux-usb-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA, pawel.moll-5wv7dgnIgG8,
	mark.rutland-5wv7dgnIgG8, macpaul-Re5JQEeQqe8AvxtiuMwx3w


On Wed, 17 Jun 2015 13:43:42 +0800
Li Jun <jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org> wrote:

> Allocate usb otg descriptor and initialize it according to gadget's otg
> capabilities, if usb_otg_caps is not set, keep settings as current gadget
> drivers. With this 2 new interfaces, gadget can use usb_otg_descriptor
> for OTG 1.x, and usb_otg20_descriptor for OTG 2.0 or above, and otg
> features can be decided by the combination of usb hardware property
> and driver config.
> 
> Signed-off-by: Li Jun <jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
> ---
>  drivers/usb/gadget/config.c | 56 +++++++++++++++++++++++++++++++++++++++++++++
>  include/linux/usb/gadget.h  |  4 ++++
>  2 files changed, 60 insertions(+)
> 
> diff --git a/drivers/usb/gadget/config.c b/drivers/usb/gadget/config.c
> index 34e12fc..0fafa7a 100644
> --- a/drivers/usb/gadget/config.c
> +++ b/drivers/usb/gadget/config.c
> @@ -20,6 +20,7 @@
>  #include <linux/usb/ch9.h>
>  #include <linux/usb/gadget.h>
>  #include <linux/usb/composite.h>
> +#include <linux/usb/otg.h>
>  
>  /**
>   * usb_descriptor_fillbuf - fill buffer with descriptors
> @@ -195,3 +196,58 @@ void usb_free_all_descriptors(struct usb_function *f)
>  	usb_free_descriptors(f->ss_descriptors);
>  }
>  EXPORT_SYMBOL_GPL(usb_free_all_descriptors);
> +
> +struct usb_descriptor_header *usb_otg_descriptor_alloc(
> +				struct usb_gadget *gadget)
> +{
> +	struct usb_descriptor_header *otg_desc;
> +	unsigned length = 0;
> +
> +	if (gadget->otg_caps && (gadget->otg_caps->otg_rev >= 0x0200))
> +		length = sizeof(struct usb_otg20_descriptor);
> +	else
> +		length = sizeof(struct usb_otg_descriptor);
> +
> +	otg_desc = kzalloc(length, GFP_KERNEL);
> +	return otg_desc;
> +}
> +EXPORT_SYMBOL_GPL(usb_otg_descriptor_alloc);
> +
> +int usb_otg_descriptor_init(struct usb_gadget *gadget,
> +		struct usb_descriptor_header *otg_desc)
> +{
> +	struct usb_otg_descriptor *otg1x_desc;
> +	struct usb_otg20_descriptor *otg20_desc;
> +	struct usb_otg_caps *otg_caps = gadget->otg_caps;
> +	u8 otg_attributes = 0;
> +
> +	if (!otg_desc)
> +		return -EINVAL;
> +
> +	if (otg_caps && otg_caps->otg_rev) {

OK now I see why usb_gadget->otg_caps needs to be a pointer. :)

> +		if (otg_caps->hnp_support)
> +			otg_attributes |= USB_OTG_HNP;
> +		if (otg_caps->srp_support)
> +			otg_attributes |= USB_OTG_SRP;
> +		if (otg_caps->adp_support && (otg_caps->otg_rev >= 0x0200))
> +			otg_attributes |= USB_OTG_ADP;
> +	} else {
> +		otg_attributes = USB_OTG_SRP | USB_OTG_HNP;
> +	}
> +
> +	if (otg_caps && (otg_caps->otg_rev >= 0x0200)) {
> +		otg20_desc = (struct usb_otg20_descriptor *)otg_desc;
> +		otg20_desc->bLength = sizeof(struct usb_otg20_descriptor);
> +		otg20_desc->bDescriptorType = USB_DT_OTG;
> +		otg20_desc->bmAttributes = otg_attributes;
> +		otg20_desc->bcdOTG = cpu_to_le16(otg_caps->otg_rev);
> +	} else {
> +		otg1x_desc = (struct usb_otg_descriptor *)otg_desc;
> +		otg1x_desc->bLength = sizeof(struct usb_otg_descriptor);
> +		otg1x_desc->bDescriptorType = USB_DT_OTG;
> +		otg1x_desc->bmAttributes = otg_attributes;
> +	}
> +
> +	return 0;
> +}
> +EXPORT_SYMBOL_GPL(usb_otg_descriptor_init);
> diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
> index 6b39087..5f65bd2 100644
> --- a/include/linux/usb/gadget.h
> +++ b/include/linux/usb/gadget.h
> @@ -1004,6 +1004,10 @@ int usb_assign_descriptors(struct usb_function *f,
>  		struct usb_descriptor_header **ss);
>  void usb_free_all_descriptors(struct usb_function *f);
>  
> +struct usb_descriptor_header *usb_otg_descriptor_alloc(
> +				struct usb_gadget *gadget);
> +int usb_otg_descriptor_init(struct usb_gadget *gadget,
> +		struct usb_descriptor_header *otg_desc);
>  /*-------------------------------------------------------------------------*/
>  
>  /* utility to simplify map/unmap of usb_requests to/from DMA */

Reviewed-by: Roger Quadros <rogerq-l0cyMroinI0@public.gmane.org>

cheers,
-roger
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v4 04/23] usb: add usb_otg_caps to usb_gadget structure.
  2015-06-17  8:29       ` Roger Quadros
  2015-06-17  8:50         ` Li Jun
@ 2015-06-17  8:53         ` Roger Quadros
  1 sibling, 0 replies; 36+ messages in thread
From: Roger Quadros @ 2015-06-17  8:53 UTC (permalink / raw)
  To: Li Jun
  Cc: gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r, balbi-l0cyMroinI0,
	peter.chen-KZfg59tc24xl57MIdRCFDg,
	robh+dt-DgEjT+Ai2ygdnm+yROfE0A, linux-usb-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA, pawel.moll-5wv7dgnIgG8,
	mark.rutland-5wv7dgnIgG8, macpaul-Re5JQEeQqe8AvxtiuMwx3w


On Wed, 17 Jun 2015 11:29:36 +0300
Roger Quadros <rogerq-l0cyMroinI0@public.gmane.org> wrote:

> 
> On Wed, 17 Jun 2015 13:43:36 +0800
> Li Jun <jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org> wrote:
> 
> > From: Macpaul Lin <macpaul-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> > 
> > Add usb_otg_caps pointer to usb_gadget structure to indicate its
> > otg capabilities.
> > 
> > Signed-off-by: Macpaul Lin <macpaul-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> > Signed-off-by: Li Jun <jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
> > ---
> >  include/linux/usb/gadget.h | 2 ++
> >  1 file changed, 2 insertions(+)
> > 
> > diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
> > index 4f3dfb7..6b39087 100644
> > --- a/include/linux/usb/gadget.h
> > +++ b/include/linux/usb/gadget.h
> > @@ -511,6 +511,7 @@ struct usb_gadget_ops {
> >   * @dev: Driver model state for this abstract device.
> >   * @out_epnum: last used out ep number
> >   * @in_epnum: last used in ep number
> > + * @otg_caps: OTG capabilities of this gadget.
> >   * @sg_supported: true if we can handle scatter-gather
> >   * @is_otg: True if the USB device port uses a Mini-AB jack, so that the
> >   *	gadget driver must provide a USB OTG descriptor.
> > @@ -559,6 +560,7 @@ struct usb_gadget {
> >  	struct device			dev;
> >  	unsigned			out_epnum;
> >  	unsigned			in_epnum;
> > +	struct usb_otg_caps		*otg_caps;
> 
> Why does this need to be a pointer?

I got it. So that we can check if it is a legacy controller driver.
> 
> >  
> >  	unsigned			sg_supported:1;
> >  	unsigned			is_otg:1;

So,

Reviewed-by: Roger Quadros <rogerq-l0cyMroinI0@public.gmane.org>

cheers,
-roger
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v4 11/23] usb: gadget: configfs: allocate and init otg descriptor by otg capabilities
       [not found]     ` <1434519835-27745-12-git-send-email-jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
@ 2015-06-17  9:01       ` Roger Quadros
  0 siblings, 0 replies; 36+ messages in thread
From: Roger Quadros @ 2015-06-17  9:01 UTC (permalink / raw)
  To: Li Jun
  Cc: gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r, balbi-l0cyMroinI0,
	peter.chen-KZfg59tc24xl57MIdRCFDg,
	robh+dt-DgEjT+Ai2ygdnm+yROfE0A, linux-usb-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA, pawel.moll-5wv7dgnIgG8,
	mark.rutland-5wv7dgnIgG8, macpaul-Re5JQEeQqe8AvxtiuMwx3w


On Wed, 17 Jun 2015 13:43:43 +0800
Li Jun <jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org> wrote:

> Allocate and initialize usb otg descriptor according to gadget otg
> capabilities, add it for each usb configurations, free it while
> composite unbind. If otg capability is not defined, keep its otg
> descriptor unchanged.
> 
> Signed-off-by: Li Jun <jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org>

Reviewed-by: Roger Quadros <rogerq-l0cyMroinI0@public.gmane.org>

cheers,
-roger

> ---
>  drivers/usb/gadget/configfs.c | 29 ++++++++++++++++++++---------
>  1 file changed, 20 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/usb/gadget/configfs.c b/drivers/usb/gadget/configfs.c
> index 0495c94..c7b62ef 100644
> --- a/drivers/usb/gadget/configfs.c
> +++ b/drivers/usb/gadget/configfs.c
> @@ -41,6 +41,8 @@ int check_user_usb_string(const char *name,
>  #define MAX_NAME_LEN	40
>  #define MAX_USB_STRING_LANGS 2
>  
> +static const struct usb_descriptor_header *otg_desc[2];
> +
>  struct gadget_info {
>  	struct config_group group;
>  	struct config_group functions_group;
> @@ -55,9 +57,6 @@ struct gadget_info {
>  	struct list_head available_func;
>  
>  	const char *udc_name;
> -#ifdef CONFIG_USB_OTG
> -	struct usb_otg_descriptor otg;
> -#endif
>  	struct usb_composite_driver composite;
>  	struct usb_composite_dev cdev;
>  	bool use_os_desc;
> @@ -1376,6 +1375,19 @@ static int configfs_composite_bind(struct usb_gadget *gadget,
>  		memcpy(cdev->qw_sign, gi->qw_sign, OS_STRING_QW_SIGN_LEN);
>  	}
>  
> +	if (gadget_is_otg(gadget) && !otg_desc[0]) {
> +		struct usb_descriptor_header *usb_desc;
> +
> +		usb_desc = usb_otg_descriptor_alloc(gadget);
> +		if (!usb_desc) {
> +			ret = -ENOMEM;
> +			goto err_comp_cleanup;
> +		}
> +		usb_otg_descriptor_init(gadget, usb_desc);
> +		otg_desc[0] = usb_desc;
> +		otg_desc[1] = NULL;
> +	}
> +
>  	/* Go through all configs, attach all functions */
>  	list_for_each_entry(c, &gi->cdev.configs, list) {
>  		struct config_usb_cfg *cfg;
> @@ -1383,6 +1395,9 @@ static int configfs_composite_bind(struct usb_gadget *gadget,
>  		struct usb_function *tmp;
>  		struct gadget_config_name *cn;
>  
> +		if (gadget_is_otg(gadget))
> +			c->descriptors = otg_desc;
> +
>  		cfg = container_of(c, struct config_usb_cfg, c);
>  		if (!list_empty(&cfg->string_list)) {
>  			i = 0;
> @@ -1437,6 +1452,8 @@ static void configfs_composite_unbind(struct usb_gadget *gadget)
>  	cdev = get_gadget_data(gadget);
>  	gi = container_of(cdev, struct gadget_info, cdev);
>  
> +	kfree(otg_desc[0]);
> +	otg_desc[0] = NULL;
>  	purge_configs_funcs(gi);
>  	composite_dev_cleanup(cdev);
>  	usb_ep_autoconfig_reset(cdev->gadget);
> @@ -1510,12 +1527,6 @@ static struct config_group *gadgets_make(
>  	if (!gi->composite.gadget_driver.function)
>  		goto err;
>  
> -#ifdef CONFIG_USB_OTG
> -	gi->otg.bLength = sizeof(struct usb_otg_descriptor);
> -	gi->otg.bDescriptorType = USB_DT_OTG;
> -	gi->otg.bmAttributes = USB_OTG_SRP | USB_OTG_HNP;
> -#endif
> -
>  	config_group_init_type_name(&gi->group, name,
>  				&gadget_root_type);
>  	return &gi->group;

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v4 12/23] usb: gadget: ether: allocate and init otg descriptor by otg capabilities
       [not found]     ` <1434519835-27745-13-git-send-email-jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
@ 2015-06-17  9:03       ` Roger Quadros
  2015-06-17  9:53         ` Li Jun
  0 siblings, 1 reply; 36+ messages in thread
From: Roger Quadros @ 2015-06-17  9:03 UTC (permalink / raw)
  To: Li Jun
  Cc: gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r, balbi-l0cyMroinI0,
	peter.chen-KZfg59tc24xl57MIdRCFDg,
	robh+dt-DgEjT+Ai2ygdnm+yROfE0A, linux-usb-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA, pawel.moll-5wv7dgnIgG8,
	mark.rutland-5wv7dgnIgG8, macpaul-Re5JQEeQqe8AvxtiuMwx3w


On Wed, 17 Jun 2015 13:43:44 +0800
Li Jun <jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org> wrote:

> Allocate and initialize usb otg descriptor according to gadget otg
> capabilities, add it for each usb configurations, free it while
> composite unbind. If otg capability is not defined, keep its otg
> descriptor unchanged.
> 
> Signed-off-by: Li Jun <jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
> ---
>  drivers/usb/gadget/legacy/ether.c | 38 ++++++++++++++++++++++++--------------
>  1 file changed, 24 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/usb/gadget/legacy/ether.c b/drivers/usb/gadget/legacy/ether.c
> index a3323dc..06f4a30 100644
> --- a/drivers/usb/gadget/legacy/ether.c
> +++ b/drivers/usb/gadget/legacy/ether.c
> @@ -171,20 +171,7 @@ static struct usb_device_descriptor device_desc = {
>  	.bNumConfigurations =	1,
>  };
>  
> -static struct usb_otg_descriptor otg_descriptor = {
> -	.bLength =		sizeof otg_descriptor,
> -	.bDescriptorType =	USB_DT_OTG,
> -
> -	/* REVISIT SRP-only hardware is possible, although
> -	 * it would not be called "OTG" ...
> -	 */
> -	.bmAttributes =		USB_OTG_SRP | USB_OTG_HNP,
> -};
> -
> -static const struct usb_descriptor_header *otg_desc[] = {
> -	(struct usb_descriptor_header *) &otg_descriptor,
> -	NULL,
> -};
> +static const struct usb_descriptor_header *otg_desc[2];
>  
>  static struct usb_string strings_dev[] = {
>  	[USB_GADGET_MANUFACTURER_IDX].s = "",
> @@ -229,6 +216,16 @@ static int rndis_do_config(struct usb_configuration *c)
>  	/* FIXME alloc iConfiguration string, set it in c->strings */
>  
>  	if (gadget_is_otg(c->cdev->gadget)) {
> +		if (!otg_desc[0]) {
> +			struct usb_descriptor_header *usb_desc;
> +
> +			usb_desc = usb_otg_descriptor_alloc(c->cdev->gadget);
> +			if (!usb_desc)
> +				return -ENOMEM;
> +			usb_otg_descriptor_init(c->cdev->gadget, usb_desc);
> +			otg_desc[0] = usb_desc;
> +			otg_desc[1] = NULL;
> +		}

Why can't you do the otg_desc alloc/init in eth_bind()?
That way you don't have to have this code twice
in rndis_do_config() and eth_do_config().

It also matches the free being done in eth_unbind().

>  		c->descriptors = otg_desc;
>  		c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
>  	}
> @@ -271,6 +268,16 @@ static int eth_do_config(struct usb_configuration *c)
>  	/* FIXME alloc iConfiguration string, set it in c->strings */
>  
>  	if (gadget_is_otg(c->cdev->gadget)) {
> +		if (!otg_desc[0]) {
> +			struct usb_descriptor_header *usb_desc;
> +
> +			usb_desc = usb_otg_descriptor_alloc(c->cdev->gadget);
> +			if (!usb_desc)
> +				return -ENOMEM;
> +			usb_otg_descriptor_init(c->cdev->gadget, usb_desc);
> +			otg_desc[0] = usb_desc;
> +			otg_desc[1] = NULL;
> +		}
>  		c->descriptors = otg_desc;
>  		c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
>  	}
> @@ -463,6 +470,9 @@ static int eth_unbind(struct usb_composite_dev *cdev)
>  		usb_put_function(f_geth);
>  		usb_put_function_instance(fi_geth);
>  	}
> +	kfree(otg_desc[0]);
> +	otg_desc[0] = NULL;
> +
>  	return 0;
>  }
>  

cheers,
-roger
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v4 13/23] usb: gadget: acm_ms: allocate and init otg descriptor by otg capabilities
       [not found]     ` <1434519835-27745-14-git-send-email-jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
@ 2015-06-17  9:11       ` Roger Quadros
  0 siblings, 0 replies; 36+ messages in thread
From: Roger Quadros @ 2015-06-17  9:11 UTC (permalink / raw)
  To: Li Jun
  Cc: gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r, balbi-l0cyMroinI0,
	peter.chen-KZfg59tc24xl57MIdRCFDg,
	robh+dt-DgEjT+Ai2ygdnm+yROfE0A, linux-usb-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA, pawel.moll-5wv7dgnIgG8,
	mark.rutland-5wv7dgnIgG8, macpaul-Re5JQEeQqe8AvxtiuMwx3w


On Wed, 17 Jun 2015 13:43:45 +0800
Li Jun <jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org> wrote:

> Allocate and initialize usb otg descriptor according to gadget otg
> capabilities, add it for each usb configurations, free it while
> composite unbind. If otg capability is not defined, keep its otg

there is no composite unbind in acm_ms.c.

> descriptor unchanged.
> 
> Signed-off-by: Li Jun <jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
> ---
>  drivers/usb/gadget/legacy/acm_ms.c | 29 ++++++++++++++---------------
>  1 file changed, 14 insertions(+), 15 deletions(-)
> 
> diff --git a/drivers/usb/gadget/legacy/acm_ms.c b/drivers/usb/gadget/legacy/acm_ms.c
> index 1194b09..f9b7b31 100644
> --- a/drivers/usb/gadget/legacy/acm_ms.c
> +++ b/drivers/usb/gadget/legacy/acm_ms.c
> @@ -58,21 +58,7 @@ static struct usb_device_descriptor device_desc = {
>  	/*.bNumConfigurations =	DYNAMIC*/
>  };
>  
> -static struct usb_otg_descriptor otg_descriptor = {
> -	.bLength =		sizeof otg_descriptor,
> -	.bDescriptorType =	USB_DT_OTG,
> -
> -	/*
> -	 * REVISIT SRP-only hardware is possible, although
> -	 * it would not be called "OTG" ...
> -	 */
> -	.bmAttributes =		USB_OTG_SRP | USB_OTG_HNP,
> -};
> -
> -static const struct usb_descriptor_header *otg_desc[] = {
> -	(struct usb_descriptor_header *) &otg_descriptor,
> -	NULL,
> -};
> +static const struct usb_descriptor_header *otg_desc[2];
>  
>  /* string IDs are assigned dynamically */
>  static struct usb_string strings_dev[] = {
> @@ -127,6 +113,16 @@ static int acm_ms_do_config(struct usb_configuration *c)
>  	int	status;
>  
>  	if (gadget_is_otg(c->cdev->gadget)) {
> +		if (!otg_desc[0]) {
> +			struct usb_descriptor_header *usb_desc;
> +
> +			usb_desc = usb_otg_descriptor_alloc(c->cdev->gadget);
> +			if (!usb_desc)
> +				return -ENOMEM;
> +			usb_otg_descriptor_init(c->cdev->gadget, usb_desc);
> +			otg_desc[0] = usb_desc;
> +			otg_desc[1] = NULL;

I think it is symmetric to put this code in acm_ms_bind()
as you are freeing the descriptor in acm_ms_unbind().

Same applies for all other gadgets as well.

> +		}
>  		c->descriptors = otg_desc;
>  		c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
>  	}
> @@ -255,6 +251,9 @@ static int acm_ms_unbind(struct usb_composite_dev *cdev)
>  	usb_put_function_instance(fi_msg);
>  	usb_put_function(f_acm);
>  	usb_put_function_instance(f_acm_inst);
> +	kfree(otg_desc[0]);
> +	otg_desc[0] = NULL;
> +
>  	return 0;
>  }
>  

cheers,
-roger
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v4 07/23] usb: common: add API to get usb otg features from device tree
  2015-06-17  8:45       ` Roger Quadros
@ 2015-06-17  9:19         ` Li Jun
  0 siblings, 0 replies; 36+ messages in thread
From: Li Jun @ 2015-06-17  9:19 UTC (permalink / raw)
  To: Roger Quadros
  Cc: Li Jun, gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r,
	balbi-l0cyMroinI0, peter.chen-KZfg59tc24xl57MIdRCFDg,
	robh+dt-DgEjT+Ai2ygdnm+yROfE0A, linux-usb-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA, pawel.moll-5wv7dgnIgG8,
	mark.rutland-5wv7dgnIgG8, macpaul-Re5JQEeQqe8AvxtiuMwx3w

On Wed, Jun 17, 2015 at 11:45:45AM +0300, Roger Quadros wrote:
> 
> On Wed, 17 Jun 2015 13:43:39 +0800
> Li Jun <jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org> wrote:
> 
> > Check property of usb hardware to get otg version and if SRP, HNP and ADP
> > are supported.
> > 
> > Signed-off-by: Li Jun <jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
> > ---
> >  drivers/usb/common/common.c | 29 +++++++++++++++++++++++++++++
> >  include/linux/usb/of.h      |  7 +++++++
> >  2 files changed, 36 insertions(+)
> > 
> > diff --git a/drivers/usb/common/common.c b/drivers/usb/common/common.c
> > index b530fd4..b846172 100644
> > --- a/drivers/usb/common/common.c
> > +++ b/drivers/usb/common/common.c
> > @@ -154,6 +154,35 @@ bool of_usb_host_tpl_support(struct device_node *np)
> >  	return false;
> >  }
> >  EXPORT_SYMBOL_GPL(of_usb_host_tpl_support);
> > +
> > +/**
> > + * of_usb_get_otg_caps - to get usb otg capabilities according to
> > + * the passed properties in DT.
> > + * @np: Pointer to the given device_node
> > + * @otg_caps: Pointer to the target usb_otg_caps to be set
> > + *
> > + * The function gets and sets the otg capabilities
> > + */
> > +void of_usb_get_otg_caps(struct device_node *np, struct usb_otg_caps *otg_caps)
> > +{
> > +	u32 otg_rev;
> > +
> > +	if (!otg_caps)
> > +		return;
> > +
> > +	if (!of_property_read_u32(np, "otg-rev", &otg_rev)) {
> > +		otg_caps->otg_rev = otg_rev;
> > +		if (!of_find_property(np, "hnp-disable", NULL))
> > +			otg_caps->hnp_support = true;
> > +		if (!of_find_property(np, "srp-disable", NULL))
> > +			otg_caps->hnp_support = true;
> 
> srp_support = true;
> 

My fault.

> > +		if (!of_find_property(np, "adp-disable", NULL) &&
> > +					(otg_caps->otg_rev >= 0x0200))
> > +			otg_caps->hnp_support = true;
> 
> adp_support = true;
> 

My fault.

> > +	}
> 
> I think we are loosing information here.
> The DT disable flags get changed to enable flags (xyz_support)
> and after this we can't really tell if the device tree really
> wanted us to disable the feature or enable it based on
> otg_rev/controller capabilities.
> 
> Why not pass controller caps in otg_caps and then disable the
> flags if requested from DT?
> 	if (of_find_property(np, "foo-disbale", NULL))
> 		otg_caps->foo_support = false;
> 
> The controller can still override anything afterwards
> if it things something is wrong.
> My guess is most controllers won't have to.
> 

After more thinking, I think I can use the normal usage of disable flags
to handle this, I will update, thanks.

Li Jun
> > +}
> > +EXPORT_SYMBOL_GPL(of_usb_get_otg_caps);
> > +
> >  #endif
> >  
> >  MODULE_LICENSE("GPL");
> > diff --git a/include/linux/usb/of.h b/include/linux/usb/of.h
> > index cfe0528..bbf302b9 100644
> > --- a/include/linux/usb/of.h
> > +++ b/include/linux/usb/of.h
> > @@ -15,6 +15,8 @@
> >  enum usb_dr_mode of_usb_get_dr_mode(struct device_node *np);
> >  enum usb_device_speed of_usb_get_maximum_speed(struct device_node *np);
> >  bool of_usb_host_tpl_support(struct device_node *np);
> > +void of_usb_get_otg_caps(struct device_node *np,
> > +			struct usb_otg_caps *otg_caps);
> >  #else
> >  static inline enum usb_dr_mode of_usb_get_dr_mode(struct device_node *np)
> >  {
> > @@ -30,6 +32,11 @@ static inline bool of_usb_host_tpl_support(struct device_node *np)
> >  {
> >  	return false;
> >  }
> > +static inline void of_usb_get_otg_caps(struct device_node *np,
> > +				struct usb_otg_caps *otg_caps)
> > +{
> > +
> > +}
> >  #endif
> >  
> >  #if IS_ENABLED(CONFIG_OF) && IS_ENABLED(CONFIG_USB_SUPPORT)
> 
> cheers,
> -roger
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v4 12/23] usb: gadget: ether: allocate and init otg descriptor by otg capabilities
  2015-06-17  9:03       ` Roger Quadros
@ 2015-06-17  9:53         ` Li Jun
  0 siblings, 0 replies; 36+ messages in thread
From: Li Jun @ 2015-06-17  9:53 UTC (permalink / raw)
  To: Roger Quadros
  Cc: Li Jun, gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r,
	balbi-l0cyMroinI0, peter.chen-KZfg59tc24xl57MIdRCFDg,
	robh+dt-DgEjT+Ai2ygdnm+yROfE0A, linux-usb-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA, pawel.moll-5wv7dgnIgG8,
	mark.rutland-5wv7dgnIgG8, macpaul-Re5JQEeQqe8AvxtiuMwx3w

On Wed, Jun 17, 2015 at 12:03:04PM +0300, Roger Quadros wrote:
> 
> >  
> >  	if (gadget_is_otg(c->cdev->gadget)) {
> > +		if (!otg_desc[0]) {
> > +			struct usb_descriptor_header *usb_desc;
> > +
> > +			usb_desc = usb_otg_descriptor_alloc(c->cdev->gadget);
> > +			if (!usb_desc)
> > +				return -ENOMEM;
> > +			usb_otg_descriptor_init(c->cdev->gadget, usb_desc);
> > +			otg_desc[0] = usb_desc;
> > +			otg_desc[1] = NULL;
> > +		}
> 
> Why can't you do the otg_desc alloc/init in eth_bind()?
> That way you don't have to have this code twice
> in rndis_do_config() and eth_do_config().
> 
> It also matches the free being done in eth_unbind().
> >  

Okay, I will update for all legacy gadget drivers.

Li Jun
> 
> cheers,
> -roger
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 36+ messages in thread

end of thread, other threads:[~2015-06-17  9:53 UTC | newest]

Thread overview: 36+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-17  5:43 [PATCH v4 00/23] usb gadget update for OTG 2.0 Li Jun
     [not found] ` <1434519835-27745-1-git-send-email-jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
2015-06-17  5:43   ` [PATCH v4 01/23] usb: add usb_otg20_descriptor for OTG 2.0 and above Li Jun
2015-06-17  5:43   ` [PATCH v4 02/23] usb: add USB_OTG_ADP definition Li Jun
2015-06-17  5:43   ` [PATCH v4 03/23] usb: otg: add usb_otg_caps structure for otg capabilities Li Jun
     [not found]     ` <1434519835-27745-4-git-send-email-jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
2015-06-17  8:25       ` Roger Quadros
2015-06-17  5:43   ` [PATCH v4 04/23] usb: add usb_otg_caps to usb_gadget structure Li Jun
     [not found]     ` <1434519835-27745-5-git-send-email-jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
2015-06-17  8:29       ` Roger Quadros
2015-06-17  8:50         ` Li Jun
2015-06-17  8:53         ` Roger Quadros
2015-06-17  5:43   ` [PATCH v4 05/23] usb: gadget: composite: add USB_DT_OTG request handling Li Jun
2015-06-17  5:43   ` [PATCH v4 06/23] doc: dt-binding: usb: add otg related properties Li Jun
     [not found]     ` <1434519835-27745-7-git-send-email-jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
2015-06-17  8:30       ` Roger Quadros
2015-06-17  5:43   ` [PATCH v4 07/23] usb: common: add API to get usb otg features from device tree Li Jun
     [not found]     ` <1434519835-27745-8-git-send-email-jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
2015-06-17  8:45       ` Roger Quadros
2015-06-17  9:19         ` Li Jun
2015-06-17  5:43   ` [PATCH v4 08/23] usb: chipidea: set usb gadeget's otg capabilities Li Jun
2015-06-17  5:43   ` [PATCH v4 09/23] usb: chipidea: update ci_otg_is_fsm_mode conditions Li Jun
2015-06-17  5:43   ` [PATCH v4 10/23] usb: gadget: add usb otg descriptor allocate and init interface Li Jun
     [not found]     ` <1434519835-27745-11-git-send-email-jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
2015-06-17  8:51       ` Roger Quadros
2015-06-17  5:43   ` [PATCH v4 11/23] usb: gadget: configfs: allocate and init otg descriptor by otg capabilities Li Jun
     [not found]     ` <1434519835-27745-12-git-send-email-jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
2015-06-17  9:01       ` Roger Quadros
2015-06-17  5:43   ` [PATCH v4 12/23] usb: gadget: ether: " Li Jun
     [not found]     ` <1434519835-27745-13-git-send-email-jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
2015-06-17  9:03       ` Roger Quadros
2015-06-17  9:53         ` Li Jun
2015-06-17  5:43   ` [PATCH v4 13/23] usb: gadget: acm_ms: " Li Jun
     [not found]     ` <1434519835-27745-14-git-send-email-jun.li-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
2015-06-17  9:11       ` Roger Quadros
2015-06-17  5:43   ` [PATCH v4 14/23] usb: gadget: audio: " Li Jun
2015-06-17  5:43   ` [PATCH v4 15/23] usb: gadget: cdc2: " Li Jun
2015-06-17  5:43   ` [PATCH v4 16/23] usb: gadget: g_ffs: " Li Jun
2015-06-17  5:43   ` [PATCH v4 17/23] usb: gadget: hid: " Li Jun
2015-06-17  5:43   ` [PATCH v4 18/23] usb: gadget: mass_storage: " Li Jun
2015-06-17  5:43   ` [PATCH v4 19/23] usb: gadget: multi: " Li Jun
2015-06-17  5:43   ` [PATCH v4 20/23] usb: gadget: ncm: " Li Jun
2015-06-17  5:43   ` [PATCH v4 21/23] usb: gadget: printer: " Li Jun
2015-06-17  5:43   ` [PATCH v4 22/23] usb: gadget: serial: " Li Jun
2015-06-17  5:43   ` [PATCH v4 23/23] usb: gadget: zero: " Li Jun

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.