usb gadget update for OTG 2.0
v3 cover usb gadget update for OTG 2.0
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.
Changes for v2:
- Use zero-length array as Peter Chen suggested to support usb_otg_descriptors with different size.
- Add a new property otg-rev to specify the OTG release number with which the device is compliant.
- Add a new interfate usb_otg_descriptor_add() to allocate and init usb_otg_descriptor according to gadget otg options, for those do not use new otg options, keep the usb_otg_descriptor setting unchanged.
- Remove static usb_otg_descriptor definitions in all legacy gadget driver, but use usb_otg_descriptor_add to handle it while build usb configurations.
- Handle usb_otg_descriptor through usb_otg_descriptor_add and add it in each usb configurations for configfs driver.
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. keep one usb_otg_descriptor definition, add bcdOTG by zero-length array, which 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. Init usb_otg_descriptor according to otg options in each gadget driver.
Li Jun (18):
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 config
usb: chipidea: update ci_otg_is_fsm_mode conditions
usb: gadget: add usb_otg_descriptor_add interface to init
usb_otg_descriptor
usb: gadget: configfs: init and add usb_otg_descriptor for usb
configurations
usb: gadget: ether: init usb_otg_descriptor via usb_otg_descriptor_add
usb: gadget: acm_ms: init usb_otg_descriptor via
usb_otg_descriptor_add
usb: gadget: audio: init usb_otg_descriptor via usb_otg_descriptor_add
usb: gadget: cdc2: init usb_otg_descriptor via usb_otg_descriptor_add
usb: gadget: g_ffs: init usb_otg_descriptor via usb_otg_descriptor_add
usb: gadget: hid: init usb_otg_descriptor via usb_otg_descriptor_add
usb: gadget: mass_storage: init usb_otg_descriptor via
usb_otg_descriptor_add
usb: gadget: multi: init usb_otg_descriptor via usb_otg_descriptor_add
usb: gadget: ncm: init usb_otg_descriptor via usb_otg_descriptor_add
usb: gadget: printer: init usb_otg_descriptor via
usb_otg_descriptor_add
usb: gadget: serial: init usb_otg_descriptor via
usb_otg_descriptor_add
usb: gadget: zero: init usb_otg_descriptor via usb_otg_descriptor_add
Macpaul Lin (4):
usb: add usb_otg20_descriptor for OTG 2.0 and above
usb: add USB_OTG_ADP definition
usb: add OTG feature options to gadget structure.
usb: gadget: composite: add USB_DT_OTG request handling
Documentation/devicetree/bindings/usb/generic.txt | 18 +++++++ drivers/usb/chipidea/ci.h | 3 +- drivers/usb/chipidea/core.c | 18 +++++++ drivers/usb/chipidea/debug.c | 1 + drivers/usb/chipidea/udc.c | 20 ++++++- drivers/usb/common/common.c | 64 +++++++++++++++++++++++ drivers/usb/gadget/composite.c | 25 +++++++++ drivers/usb/gadget/config.c | 39 ++++++++++++++ drivers/usb/gadget/configfs.c | 34 ++++++++---- drivers/usb/gadget/legacy/acm_ms.c | 34 ++++++------ drivers/usb/gadget/legacy/audio.c | 33 +++++++----- drivers/usb/gadget/legacy/cdc2.c | 34 ++++++------ drivers/usb/gadget/legacy/ether.c | 48 ++++++++++++----- drivers/usb/gadget/legacy/g_ffs.c | 34 ++++++------ drivers/usb/gadget/legacy/hid.c | 35 +++++++------ drivers/usb/gadget/legacy/mass_storage.c | 34 ++++++------ drivers/usb/gadget/legacy/multi.c | 49 +++++++++++------ drivers/usb/gadget/legacy/ncm.c | 33 +++++++----- drivers/usb/gadget/legacy/printer.c | 30 +++++++---- drivers/usb/gadget/legacy/serial.c | 34 +++++++----- drivers/usb/gadget/legacy/zero.c | 37 ++++++------- include/linux/usb/chipidea.h | 4 ++ include/linux/usb/gadget.h | 13 +++++ include/linux/usb/of.h | 20 +++++++ include/uapi/linux/usb/ch9.h | 12 +++++ 25 files changed, 520 insertions(+), 186 deletions(-)
Signature · 6 lines
1.9.1 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v3 1/22 usb: add usb_otg20_descriptor for OTG 2.0 and above
In reply to a message not in the archiveFrom: Macpaul Lin <[email protected]>
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.
--- include/uapi/linux/usb/ch9.h | 11 +++++++++++ 1 file changed, 11 insertions(+)
include/uapi/linux/usb/ch9.h +11 -0
@@ -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 */
Signature · 6 lines
1.9.1 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v3 2/22 usb: add USB_OTG_ADP definition
In reply to a message not in the archiveFrom: Macpaul Lin <[email protected]>
Add USB_OTG_ADP definition for usb_otg_descriptor.bmAttributes.
--- include/uapi/linux/usb/ch9.h | 1 + 1 file changed, 1 insertion(+)
include/uapi/linux/usb/ch9.h +1 -0
@@ -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 */ /*-------------------------------------------------------------------------*/
Signature · 6 lines
1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v3 3/22 usb: add OTG feature options to gadget structure.
In reply to a message not in the archiveFrom: Macpaul Lin <[email protected]>
Add ADP, HNP and SRP feature options and otg version to gadget structure.
--- include/linux/usb/gadget.h | 11 +++++++++++ 1 file changed, 11 insertions(+)
include/linux/usb/gadget.h +11 -0
@@ -514,6 +514,12 @@ struct usb_gadget_ops {* @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. +* @adp_support: OTG device feature flag, indicating that the device +supports ADP at this port. +* @hnp_support: OTG device feature flag, indicating that the device +supports HNP at this port. +* @srp_support: OTG device feature flag, indicating that the device +supports SRP at this port. * @is_a_peripheral: False unless is_otg, the "A" end of a USB cable * is in the Mini-AB jack, and HNP has been used to switch roles * so that the "A" device currently acts as A-Peripheral, not A-Host.
@@ -526,6 +532,7 @@ struct usb_gadget_ops {* @quirk_ep_out_aligned_size: epout requires buffer size to be aligned to * MaxPacketSize. * @is_selfpowered: if the gadget is self-powered. +* @otg_rev: The OTG reversion number the device is compliant to. * * Gadgets have a mostly-portable "gadget driver" implementing device * functions, handling all usb configurations and interfaces. Gadget
@@ -562,12 +569,16 @@ struct usb_gadget { unsigned sg_supported:1; unsigned is_otg:1; + unsigned adp_support:1; + unsigned hnp_support:1; + unsigned srp_support:1; unsigned is_a_peripheral:1; unsigned b_hnp_enable:1; unsigned a_hnp_support:1; unsigned a_alt_hnp_support:1; unsigned quirk_ep_out_aligned_size:1; unsigned is_selfpowered:1; +u16 otg_rev; };#define work_to_gadget (w) (container_of((w), struct usb_gadget, work))
Signature · 6 lines
1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v3 4/22 usb: gadget: composite: add USB_DT_OTG request handling
In reply to a message not in the archiveFrom: Macpaul Lin <[email protected]>
Copy usb_otg_descriptor from config's descriptor if host requests USB_DT_OTG.
--- drivers/usb/gadget/composite.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
drivers/usb/gadget/composite.c +25 -0
@@ -1534,6 +1534,31 @@ 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_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 ;
Signature · 6 lines
1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v3 5/22 doc: dt-binding: usb: add otg related properties
In reply to a message not in the archiveAdd 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.
--- Documentation/devicetree/bindings/usb/generic.txt | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
Documentation/devicetree/bindings/usb/generic.txt +18 -0
@@ -11,6 +11,20 @@ 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, also if ADP is enabled, 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, if not passed, otg-rev should + be set to be 0x0200 or above. This is an attribute to a USB controller such as:
@@ -21,4 +35,8 @@ dwc3@4a030000 { usb-phy = <&usb2_phy>, <&usb3,phy>; maximum-speed = "super-speed"; dr_mode = "otg"; + otg-rev = <0x0200>; + hnp-disable; + srp-disable; + adp-disable; };
Signature · 6 lines
1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v3 6/22 usb: common: add API to get usb otg features from device tree
In reply to a message not in the archiveCheck property of usb hardware to get otg version and if SRP, HNP and ADP are supported.
--- drivers/usb/common/common.c | 64 +++++++++++++++++++++++++++++++++++++++++++++ include/linux/usb/of.h | 20 ++++++++++++++ 2 files changed, 84 insertions(+)
drivers/usb/common/common.c +64 -0
@@ -154,6 +154,70 @@ bool of_usb_host_tpl_support(struct device_node *np)return false; }EXPORT_SYMBOL_GPL (of_usb_host_tpl_support); + +/** +* of_usb_otg_srp_disabled - to get if otg srp is disabled for the device +* @np: Pointer to the given device_node +* +* The function gets if SRP is disabled on the otg port +*/ +bool of_usb_otg_srp_disabled (struct device_node *np) +{ +if (of_find_property (np,"srp-disable" ,NULL )) +return true; + +return false; +} +EXPORT_SYMBOL_GPL (of_usb_otg_srp_disabled); + +/** +* of_usb_otg_hnp_disabled - to get if otg hnp is disabled for the device +* @np: Pointer to the given device_node +* +* The function gets if HNP is disabled on the otg port +*/ +bool of_usb_otg_hnp_disabled (struct device_node *np) +{ +if (of_find_property (np,"hnp-disable" ,NULL )) +return true; + +return false; +} +EXPORT_SYMBOL_GPL (of_usb_otg_hnp_disabled); + +/** +* of_usb_otg_adp_disabled - to get if otg adp is disabled for the device +* @np: Pointer to the given device_node +* +* The function gets if ADP is disabled on the otg port +*/ +bool of_usb_otg_adp_disabled (struct device_node *np) +{ +if (of_find_property (np,"adp-disable" ,NULL )) +return true; + +return false; +} +EXPORT_SYMBOL_GPL (of_usb_otg_adp_disabled); + +/** +* of_usb_get_otg_rev - to get the otg release number the device is +* compliant with. +* @np: Pointer to the given device_node +* +* The function gets OTG and EH supplement release number in binary-coded +* decimal (i.e. 2.0 is 0200H). +*/ +int of_usb_get_otg_rev (struct device_node *np) +{ +u32 otg_rev; + +if (!of_property_read_u32 (np,"otg-rev" , &otg_rev)) +return otg_rev; + +return 0 ; +} +EXPORT_SYMBOL_GPL (of_usb_get_otg_rev);#endif MODULE_LICENSE ("GPL" );
include/linux/usb/of.h +20 -0
@@ -15,6 +15,10 @@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); +bool of_usb_otg_srp_disabled (struct device_node *np); +bool of_usb_otg_hnp_disabled (struct device_node *np); +bool of_usb_otg_adp_disabled (struct device_node *np); +int of_usb_get_otg_rev (struct device_node *np);#else static inline enum usb_dr_mode of_usb_get_dr_mode (struct device_node *np) {
@@ -30,6 +34,22 @@ static inline bool of_usb_host_tpl_support(struct device_node *np) {return false; } +static inline bool of_usb_otg_srp_disabled (struct device_node *np) +{ +return false; +} +static inline bool of_usb_otg_hnp_disabled (struct device_node *np) +{ +return false; +} +static inline bool of_usb_otg_adp_disabled (struct device_node *np) +{ +return false; +} +static inline int of_usb_get_otg_rev (struct device_node *np) +{ +return 0 ; +}#endif #if IS_ENABLED (CONFIG_OF ) &&IS_ENABLED (CONFIG_USB_SUPPORT )
Signature · 6 lines
1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v3 7/22 usb: chipidea: set usb gadeget's otg config
In reply to a message not in the archiveSet gadget's otg features according to controller's capability and usb property in device tree.
--- drivers/usb/chipidea/core.c | 18 ++++++++++++++++++ drivers/usb/chipidea/udc.c | 20 +++++++++++++++++++- include/linux/usb/chipidea.h | 4 ++++ 3 files changed, 41 insertions(+), 1 deletion(-)
drivers/usb/chipidea/core.c +18 -0
@@ -588,6 +588,24 @@ static int ci_get_platdata(struct device *dev,of_usb_host_tpl_support (dev->of_node); } +if (platdata->dr_mode ==USB_DR_MODE_OTG ) { +if (!platdata->otg_rev) { + platdata->otg_rev = +of_usb_get_otg_rev (dev->of_node); + } +if (platdata->otg_rev) { +if (!platdata->srp_support) + platdata->srp_support = + !of_usb_otg_srp_disabled (dev->of_node); +if (!platdata->hnp_support) + platdata->hnp_support = + !of_usb_otg_hnp_disabled (dev->of_node); +if (!platdata->adp_support) + platdata->adp_support = + !of_usb_otg_adp_disabled (dev->of_node); + } + } +if (of_usb_get_maximum_speed (dev->of_node) ==USB_SPEED_FULL ) platdata->flags |=CI_HDRC_FORCE_FULLSPEED ;
drivers/usb/chipidea/udc.c +19 -1
@@ -1821,6 +1821,24 @@ static irqreturn_t udc_irq(struct ci_hdrc *ci) }/** +* udc_update_otg_config: update gadget otg config +* * @ci: chipidea controller +*/ +static void udc_update_otg_config (struct ci_hdrc *ci) +{ +if (!ci->is_otg) +return ; + + ci->gadget.otg_rev = ci->platdata->otg_rev; + ci->gadget.srp_support = ci->platdata->srp_support; + ci->gadget.hnp_support = ci->platdata->hnp_support; + ci->gadget.adp_support = ci->platdata->adp_support; +if (ci->gadget.srp_support || ci->gadget.hnp_support || + ci->gadget.adp_support) + ci->gadget.is_otg =1 ; +} + +/** * udc_start: initialize gadget role * @ci: chipidea controller */
@@ -1834,9 +1852,9 @@ 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; +udc_update_otg_config (ci);INIT_LIST_HEAD (&ci->gadget.ep_list);/* alloc resources */
include/linux/usb/chipidea.h +4 -0
@@ -34,7 +34,11 @@ struct ci_hdrc_platform_data {#define CI_HDRC_CONTROLLER_STOPPED_EVENT 1void (*notify_event) (struct ci_hdrc *ci,unsigned event);struct regulator *reg_vbus; +u16 otg_rev;bool tpl_support; +bool srp_support; +bool hnp_support; +bool adp_support; };/* Default offset of capability registers */
Signature · 6 lines
1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v3 8/22 usb: chipidea: update ci_otg_is_fsm_mode conditions
In reply to a message not in the archiveAfter 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.
--- drivers/usb/chipidea/ci.h | 3 ++- drivers/usb/chipidea/debug.c | 1 + 2 files changed, 3 insertions(+), 1 deletion(-)
drivers/usb/chipidea/ci.h +2 -1
@@ -407,7 +407,8 @@ static inline bool ci_otg_is_fsm_mode(struct ci_hdrc *ci) {#ifdef CONFIG_USB_OTG_FSM return ci->is_otg && ci->roles[CI_ROLE_HOST ] && - ci->roles[CI_ROLE_GADGET ]; + ci->roles[CI_ROLE_GADGET ] && (ci->platdata->srp_support || + ci->platdata->hnp_support || ci->platdata->adp_support);#else return false;#endif
drivers/usb/chipidea/debug.c +1 -0
@@ -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"
Signature · 6 lines
1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v3 9/22 usb: gadget: add usb_otg_descriptor_add interface to init usb_otg_descriptor
In reply to a message not in the archiveAllocate usb_otg_descriptor and initialize it according to gadget otg options, if none of options is not set, keep bmAttributes setting as current gadget drivers, with this new interface, usb_otg_descriptor can include bcdOTG if OTG 2.0 or later, and otg features can be decided by the combination of usb hardware property and driver config.
--- drivers/usb/gadget/config.c | 39 +++++++++++++++++++++++++++++++++++++++ include/linux/usb/gadget.h | 2 ++ 2 files changed, 41 insertions(+)
drivers/usb/gadget/config.c +39 -0
@@ -195,3 +195,42 @@ void usb_free_all_descriptors(struct usb_function *f)usb_free_descriptors (f->ss_descriptors); }EXPORT_SYMBOL_GPL (usb_free_all_descriptors); + +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; +u8 otg_attributes =0 ; + +if (!otg_desc) +return -EINVAL ; + +if (gadget->adp_support || gadget->hnp_support || + gadget->srp_support) { +if (gadget->adp_support) + otg_attributes |=USB_OTG_ADP ; +if (gadget->hnp_support) + otg_attributes |=USB_OTG_HNP ; +if (gadget->srp_support) + otg_attributes |=USB_OTG_SRP ; + }else { + otg_attributes =USB_OTG_SRP |USB_OTG_HNP ; + } + +if (gadget->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 (gadget->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);
include/linux/usb/gadget.h +2 -0
@@ -1013,6 +1013,8 @@ int usb_assign_descriptors(struct usb_function *f, struct usb_descriptor_header **ss);void usb_free_all_descriptors (struct usb_function *f); +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 */
Signature · 6 lines
1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v3 10/22 usb: gadget: configfs: init and add usb_otg_descriptor for usb configurations
In reply to a message not in the archiveUse usb_otg_descriptor_add to allocate and initialize usb_otg_descriptor, add it for each usb configurations, free it while composite unbind.
--- drivers/usb/gadget/configfs.c | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-)
drivers/usb/gadget/configfs.c +25 -8
@@ -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,24 @@ 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; +unsigned length; + +if (gadget->otg_rev >=0x0200 ) + length =sizeof (struct usb_otg20_descriptor ); +else + length =sizeof (struct usb_otg_descriptor ); + usb_desc =kzalloc (length,GFP_KERNEL ); +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 +1400,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 +1457,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 +1532,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
PATCH v3 11/22 usb: gadget: ether: init usb_otg_descriptor via usb_otg_descriptor_add
In reply to a message not in the archiveUse usb_otg_descriptor_add to allocate and initialize usb_otg_descriptor, free it while composite unbind.
--- drivers/usb/gadget/legacy/ether.c | 48 +++++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 14 deletions(-)
drivers/usb/gadget/legacy/ether.c +34 -14
@@ -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,21 @@ 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; +unsigned length; + +if (c->cdev->gadget->otg_rev >=0x0200 ) + length =sizeof (struct usb_otg20_descriptor ); +else + length =sizeof (struct usb_otg_descriptor ); + usb_desc =kzalloc (length,GFP_KERNEL ); +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 +273,21 @@ 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; +unsigned length; + +if (c->cdev->gadget->otg_rev >=0x0200 ) + length =sizeof (struct usb_otg20_descriptor ); +else + length =sizeof (struct usb_otg_descriptor ); + usb_desc =kzalloc (length,GFP_KERNEL ); +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 +480,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 ; }
Signature · 6 lines
1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v3 12/22 usb: gadget: acm_ms: init usb_otg_descriptor via usb_otg_descriptor_add
In reply to a message not in the archiveUse usb_otg_descriptor_add to allocate and initialize usb_otg_descriptor, free it while composite unbind.
--- drivers/usb/gadget/legacy/acm_ms.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-)
drivers/usb/gadget/legacy/acm_ms.c +19 -15
@@ -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,21 @@ 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; +unsigned length; + +if (c->cdev->gadget->otg_rev >=0x0200 ) + length =sizeof (struct usb_otg20_descriptor ); +else + length =sizeof (struct usb_otg_descriptor ); + usb_desc =kzalloc (length,GFP_KERNEL ); +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 +256,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 ; }
Signature · 6 lines
1.9.1 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v3 13/22 usb: gadget: audio: init usb_otg_descriptor via usb_otg_descriptor_add
In reply to a message not in the archiveUse usb_otg_descriptor_add to allocate and initialize usb_otg_descriptor, free it while composite unbind.
--- drivers/usb/gadget/legacy/audio.c | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-)
drivers/usb/gadget/legacy/audio.c +19 -14
@@ -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,21 @@ 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; +unsigned length; + +if (c->cdev->gadget->otg_rev >=0x0200 ) + length =sizeof (struct usb_otg20_descriptor ); +else + length =sizeof (struct usb_otg_descriptor ); + usb_desc =kzalloc (length,GFP_KERNEL ); +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 +291,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 ; }
Signature · 6 lines
1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v3 14/22 usb: gadget: cdc2: init usb_otg_descriptor via usb_otg_descriptor_add
In reply to a message not in the archiveUse usb_otg_descriptor_add to allocate and initialize usb_otg_descriptor, free it while composite unbind.
--- drivers/usb/gadget/legacy/cdc2.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-)
drivers/usb/gadget/legacy/cdc2.c +19 -15
@@ -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,21 @@ 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; +unsigned length; + +if (c->cdev->gadget->otg_rev >=0x0200 ) + length =sizeof (struct usb_otg20_descriptor ); +else + length =sizeof (struct usb_otg_descriptor ); + usb_desc =kzalloc (length,GFP_KERNEL ); +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 +220,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 ; }
Signature · 6 lines
1.9.1 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v3 15/22 usb: gadget: g_ffs: init usb_otg_descriptor via usb_otg_descriptor_add
In reply to a message not in the archiveUse usb_otg_descriptor_add to allocate and initialize usb_otg_descriptor, free it while composite unbind.
--- drivers/usb/gadget/legacy/g_ffs.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-)
drivers/usb/gadget/legacy/g_ffs.c +19 -15
@@ -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,21 @@ 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; +unsigned length; + +if (c->cdev->gadget->otg_rev >=0x0200 ) + length =sizeof (struct usb_otg20_descriptor ); +else + length =sizeof (struct usb_otg_descriptor ); + usb_desc =kzalloc (length,GFP_KERNEL ); +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 ; }
Signature · 6 lines
1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v3 16/22 usb: gadget: hid: init usb_otg_descriptor via usb_otg_descriptor_add
In reply to a message not in the archiveUse usb_otg_descriptor_add to allocate and initialize usb_otg_descriptor, free it while composite unbind.
--- drivers/usb/gadget/legacy/hid.c | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-)
drivers/usb/gadget/legacy/hid.c +20 -15
@@ -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,21 @@ 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; +unsigned length; + +if (c->cdev->gadget->otg_rev >=0x0200 ) + length =sizeof (struct usb_otg20_descriptor ); +else + length =sizeof (struct usb_otg_descriptor ); + usb_desc =kzalloc (length,GFP_KERNEL ); +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 +214,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 ; }
Signature · 6 lines
1.9.1 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v3 17/22 usb: gadget: mass_storage: init usb_otg_descriptor via usb_otg_descriptor_add
In reply to a message not in the archiveUse usb_otg_descriptor_add to allocate and initialize usb_otg_descriptor, free it while composite unbind.
--- drivers/usb/gadget/legacy/mass_storage.c | 34 ++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 15 deletions(-)
drivers/usb/gadget/legacy/mass_storage.c +19 -15
@@ -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,21 @@ 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; +unsigned length; + +if (c->cdev->gadget->otg_rev >=0x0200 ) + length =sizeof (struct usb_otg20_descriptor ); +else + length =sizeof (struct usb_otg_descriptor ); + usb_desc =kzalloc (length,GFP_KERNEL ); +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 +244,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 ; }
Signature · 6 lines
1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v3 18/22 usb: gadget: multi: init usb_otg_descriptor via usb_otg_descriptor_add
In reply to a message not in the archiveUse usb_otg_descriptor_add to allocate and initialize usb_otg_descriptor, free it while composite unbind.
--- drivers/usb/gadget/legacy/multi.c | 49 +++++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 15 deletions(-)
drivers/usb/gadget/legacy/multi.c +34 -15
@@ -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,21 @@ 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; +unsigned length; + +if (c->cdev->gadget->otg_rev >=0x0200 ) + length =sizeof (struct usb_otg20_descriptor ); +else + length =sizeof (struct usb_otg_descriptor ); + usb_desc =kzalloc (length,GFP_KERNEL ); +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 +244,21 @@ 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; +unsigned length; + +if (c->cdev->gadget->otg_rev >=0x0200 ) + length =sizeof (struct usb_otg20_descriptor ); +else + length =sizeof (struct usb_otg_descriptor ); + usb_desc =kzalloc (length,GFP_KERNEL ); +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 +506,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 ; }
Signature · 6 lines
1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v3 19/22 usb: gadget: ncm: init usb_otg_descriptor via usb_otg_descriptor_add
In reply to a message not in the archiveUse usb_otg_descriptor_add to allocate and initialize usb_otg_descriptor, free it while composite unbind.
--- drivers/usb/gadget/legacy/ncm.c | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-)
drivers/usb/gadget/legacy/ncm.c +19 -14
@@ -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,21 @@ 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; +unsigned length; + +if (c->cdev->gadget->otg_rev >=0x0200 ) + length =sizeof (struct usb_otg20_descriptor ); +else + length =sizeof (struct usb_otg_descriptor ); + usb_desc =kzalloc (length,GFP_KERNEL ); +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 +194,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 ; }
Signature · 6 lines
1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v3 20/22 usb: gadget: printer: init usb_otg_descriptor via usb_otg_descriptor_add
In reply to a message not in the archiveUse usb_otg_descriptor_add to allocate and initialize usb_otg_descriptor, free it while composite unbind.
--- drivers/usb/gadget/legacy/printer.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-)
drivers/usb/gadget/legacy/printer.c +19 -11
@@ -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,21 @@ 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; +unsigned length; + +if (gadget->otg_rev >=0x0200 ) + length =sizeof (struct usb_otg20_descriptor ); +else + length =sizeof (struct usb_otg_descriptor ); + usb_desc =kzalloc (length,GFP_KERNEL ); +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 +201,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 ; }
Signature · 6 lines
1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v3 21/22 usb: gadget: serial: init usb_otg_descriptor via usb_otg_descriptor_add
In reply to a message not in the archiveUse usb_otg_descriptor_add to allocate and initialize usb_otg_descriptor, free it while composite unbind.
--- drivers/usb/gadget/legacy/serial.c | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-)
drivers/usb/gadget/legacy/serial.c +20 -14
@@ -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,21 @@ 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; +unsigned length; + +if (cdev->gadget->otg_rev >=0x0200 ) + length =sizeof (struct usb_otg20_descriptor ); +else + length =sizeof (struct usb_otg_descriptor ); + usb_desc =kzalloc (length,GFP_KERNEL ); +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 +229,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 ; }
Signature · 6 lines
1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v3 22/22 usb: gadget: zero: init usb_otg_descriptor via usb_otg_descriptor_add
In reply to a message not in the archiveUse usb_otg_descriptor_add to allocate and initialize usb_otg_descriptor, free it while composite unbind.
--- drivers/usb/gadget/legacy/zero.c | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-)
drivers/usb/gadget/legacy/zero.c +19 -18
@@ -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,21 @@ 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; +unsigned length; + +if (cdev->gadget->otg_rev >=0x0200 ) + length =sizeof (struct usb_otg20_descriptor ); +else + length =sizeof (struct usb_otg_descriptor ); + usb_desc =kzalloc (length,GFP_KERNEL ); +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 +395,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 ; }
Signature · 6 lines
1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Roger Quadros
Reviewed-byRe: [PATCH v3 01/22] usb: add usb_otg20_descriptor for OTG 2.0 and above
In reply to a message not in the archiveQuoted 8 lines · On Tue, 16 Jun 2015 14:51:51 +0800 Li Jun…
From: Macpaul Lin <[email protected]>
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_descriptorfor OTG 2.0 and above.Signed-off-by Macpaul Lin <[email protected]>Signed-off-by Li Jun <[email protected]>
cheers,
-roger
Quoted 16 lines
--- include/uapi/linux/usb/ch9.h | 11 +++++++++++ 1 file changed, 11 insertions(+)include/uapi/linux/usb/ch9.h +4
-0@@ -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;
include/uapi/linux/usb/ch9.h struct usb_otg_descriptor { · line 690
Quoted 10 lines
include/uapi/linux/usb/ch9.h +7
-0+ +__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 */
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Roger Quadros
Reviewed-byRe: [PATCH v3 03/22] usb: add OTG feature options to gadget structure.
In reply to a message not in the archiveQuoted 28 lines · On Tue, 16 Jun 2015 14:51:53 +0800 Li Jun…
From: Macpaul Lin <[email protected]>
Add ADP, HNP and SRP feature options and otg version to gadget structure.
Signed-off-by Macpaul Lin <[email protected]>Signed-off-by Li Jun <[email protected]>--- include/linux/usb/gadget.h | 11 +++++++++++ 1 file changed, 11 insertions(+)include/linux/usb/gadget.h +6
-0@@ -514,6 +514,12 @@ struct usb_gadget_ops {* @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. +* @adp_support: OTG device feature flag, indicating that the device +supports ADP at this port. +* @hnp_support: OTG device feature flag, indicating that the device +supports HNP at this port. +* @srp_support: OTG device feature flag, indicating that the device +supports SRP at this port. * @is_a_peripheral: False unless is_otg, the "A" end of a USB cable * is in the Mini-AB jack, and HNP has been used to switch roles * so that the "A" device currently acts as A-Peripheral, not A-Host.
include/linux/usb/gadget.h struct usb_gadget_ops { · line 535
Quoted 4 lines
include/linux/usb/gadget.h +1
-0@@ -526,6 +532,7 @@ struct usb_gadget_ops {* @quirk_ep_out_aligned_size: epout requires buffer size to be aligned to * MaxPacketSize. * @is_selfpowered: if the gadget is self-powered. +* @otg_rev: The OTG reversion number the device is compliant to.
reversion -> revision
Also you might want to say that it is BCD encoded with an example e.g. 2.0 -> 0x0200
Quoted 10 lines
include/linux/usb/gadget.h +3
-0* * Gadgets have a mostly-portable "gadget driver" implementing device * functions, handling all usb configurations and interfaces. Gadget @@ -562,12 +569,16 @@ struct usb_gadget { unsigned sg_supported:1; unsigned is_otg:1; + unsigned adp_support:1; + unsigned hnp_support:1; + unsigned srp_support:1;
include/linux/usb/gadget.h struct usb_gadget { · line 584
Quoted 10 lines
include/linux/usb/gadget.h +1
-0unsigned is_a_peripheral:1; unsigned b_hnp_enable:1; unsigned a_hnp_support:1; unsigned a_alt_hnp_support:1; unsigned quirk_ep_out_aligned_size:1; unsigned is_selfpowered:1; +u16 otg_rev; };#define work_to_gadget (w) (container_of((w), struct usb_gadget, work))
with that change you can add my
cheers,
-roger
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Roger Quadros
Reviewed-byRe: [PATCH v3 04/22] usb: gadget: composite: add USB_DT_OTG request handling
In reply to a message not in the archiveQuoted 7 lines · On Tue, 16 Jun 2015 14:51:54 +0800 Li Jun…
From: Macpaul Lin <[email protected]>
Copy
usb_otg_descriptorfrom config's descriptor if host requestsUSB_DT_OTG.Signed-off-by Macpaul Lin <[email protected]>Signed-off-by Li Jun <[email protected]>
cheers,
-roger
Quoted 30 lines
--- drivers/usb/gadget/composite.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)drivers/usb/gadget/composite.c +18
-0@@ -1534,6 +1534,31 @@ 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_rev >=0x0200 ) + otg_desc_len +=sizeof ( +struct usb_otg20_descriptor ); +else
drivers/usb/gadget/composite.c composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) · line 1564
Quoted 10 lines
drivers/usb/gadget/composite.c +7
-0+ 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 ;
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v3 10/22] usb: gadget: configfs: init and add usb_otg_descriptor for usb configurations
In reply to a message not in the archiveQuoted 38 lines · On Tue, 16 Jun 2015 14:52:00 +0800 Li Jun…
Use
usb_otg_descriptor_addto allocate and initializeusb_otg_descriptor, add it for each usb configurations, free it while composite unbind.Signed-off-by Li Jun <[email protected]>--- drivers/usb/gadget/configfs.c | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-)drivers/usb/gadget/configfs.c +5
-3@@ -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,24 @@ 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; +unsigned length;
drivers/usb/gadget/configfs.c static int configfs_composite_bind(struct usb_gadget *gadget, · line 1390
Quoted 10 lines
drivers/usb/gadget/configfs.c +10
-0+ +if (gadget->otg_rev >=0x0200 ) + length =sizeof (struct usb_otg20_descriptor ); +else + length =sizeof (struct usb_otg_descriptor ); + usb_desc =kzalloc (length,GFP_KERNEL ); +if (!usb_desc) { + ret = -ENOMEM ; + goto err_comp_cleanup; + }
This code seems to be common across all gadgets.
Can we have usb_otg_descriptor_alloc() that takes care of allocating the right size based on descriptor version?
Then we can have
usb_desc = usb_otg_descriptor_alloc(gadget);
if (IS_ERR(usb_desc)) {
ret = PTR_ERR(usb_desc);
goto err_comp_cleanup;
}Quoted 30 lines
drivers/usb/gadget/configfs.c +10
-0+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 +1400,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 +1457,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 +1532,6 @@ static struct config_group *gadgets_make(if (!gi->composite.gadget_driver.function) goto err;
drivers/usb/gadget/configfs.c static struct config_group *gadgets_make( · line 1537
Quoted 10 lines
drivers/usb/gadget/configfs.c +0
-6-#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;
cheers,
-roger
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v3 09/22] usb: gadget: add usb_otg_descriptor_add interface to init usb_otg_descriptor
In reply to a message not in the archiveQuoted 32 lines · On Tue, 16 Jun 2015 14:51:59 +0800 Li Jun…
Allocate
usb_otg_descriptorand initialize it according to gadget otg options, if none of options is not set, keep bmAttributes setting as current gadget drivers, with this new interface,usb_otg_descriptorcan include bcdOTG if OTG 2.0 or later, and otg features can be decided by the combination of usb hardware property and driver config.Signed-off-by Li Jun <[email protected]>--- drivers/usb/gadget/config.c | 39 +++++++++++++++++++++++++++++++++++++++ include/linux/usb/gadget.h | 2 ++ 2 files changed, 41 insertions(+)drivers/usb/gadget/config.c +12
-0@@ -195,3 +195,42 @@ void usb_free_all_descriptors(struct usb_function *f)usb_free_descriptors (f->ss_descriptors); }EXPORT_SYMBOL_GPL (usb_free_all_descriptors); + +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; +u8 otg_attributes =0 ; + +if (!otg_desc) +return -EINVAL ; + + if (gadget->adp_support || gadget->hnp_support ||
drivers/usb/gadget/config.c void usb_free_all_descriptors(struct usb_function *f) · line 219
Quoted 10 lines
drivers/usb/gadget/config.c +10
-0+ gadget->srp_support) { + if (gadget->adp_support) + otg_attributes |= USB_OTG_ADP; + if (gadget->hnp_support) + otg_attributes |= USB_OTG_HNP; + if (gadget->srp_support) + otg_attributes |= USB_OTG_SRP; + } else { + otg_attributes =USB_OTG_SRP |USB_OTG_HNP ; + }
Didn't we agree that if otg_rev is not set then only we will use the legacy method?
Quoted 22 lines
drivers/usb/gadget/config.c +17
-0+ +if (gadget->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 (gadget->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);include/linux/usb/gadget.h +0
-0
include/linux/usb/gadget.h int usb_assign_descriptors(struct usb_function *f, · line 1020
Quoted 8 lines
include/linux/usb/gadget.h +2
-0@@ -1013,6 +1013,8 @@ int usb_assign_descriptors(struct usb_function *f, struct usb_descriptor_header **ss);void usb_free_all_descriptors (struct usb_function *f); +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 */
cheers,
-roger
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v3 03/22] usb: add OTG feature options to gadget structure.
In reply to Roger QuadrosQuoted 32 lines · Roger Quadros
Quoted 28 lines · On Tue, 16 Jun 2015 14:51:53 +0800 Li Jun…
From: Macpaul Lin <[email protected]>
Add ADP, HNP and SRP feature options and otg version to gadget structure.
Signed-off-by Macpaul Lin <[email protected]>Signed-off-by Li Jun <[email protected]>--- include/linux/usb/gadget.h | 11 +++++++++++ 1 file changed, 11 insertions(+)include/linux/usb/gadget.h +6
-0@@ -514,6 +514,12 @@ struct usb_gadget_ops {* @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. +* @adp_support: OTG device feature flag, indicating that the device +supports ADP at this port. +* @hnp_support: OTG device feature flag, indicating that the device +supports HNP at this port. +* @srp_support: OTG device feature flag, indicating that the device +supports SRP at this port. * @is_a_peripheral: False unless is_otg, the "A" end of a USB cable * is in the Mini-AB jack, and HNP has been used to switch roles * so that the "A" device currently acts as A-Peripheral, not A-Host. @@ -526,6 +532,7 @@ struct usb_gadget_ops {
Quoted 9 lines
include/linux/usb/gadget.h struct usb_gadget_ops { · line 535
Quoted 4 lines
include/linux/usb/gadget.h +1
-0* @quirk_ep_out_aligned_size: epout requires buffer size to be aligned to * MaxPacketSize. * @is_selfpowered: if the gadget is self-powered. +* @otg_rev: The OTG reversion number the device is compliant to. reversion -> revision
Also you might want to say that it is BCD encoded with an example e.g. 2.0 ->0x0200
Yes, I will add that.
Li Jun
Quoted 23 lines
Quoted 10 lines
include/linux/usb/gadget.h +3
-0* * Gadgets have a mostly-portable "gadget driver" implementing device * functions, handling all usb configurations and interfaces. Gadget @@ -562,12 +569,16 @@ struct usb_gadget { unsigned sg_supported:1; unsigned is_otg:1; + unsigned adp_support:1; + unsigned hnp_support:1; + unsigned srp_support:1;include/linux/usb/gadget.h struct usb_gadget { · line 584
Quoted 10 lines
include/linux/usb/gadget.h +1
-0unsigned is_a_peripheral:1; unsigned b_hnp_enable:1; unsigned a_hnp_support:1; unsigned a_alt_hnp_support:1; unsigned quirk_ep_out_aligned_size:1; unsigned is_selfpowered:1; +u16 otg_rev; };#define work_to_gadget (w) (container_of((w), struct usb_gadget, work))with that change you can add my
Quoted 4 lines
Reviewed-by Roger Quadros <[email protected]>cheers,
-roger
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v3 10/22] usb: gadget: configfs: init and add usb_otg_descriptor for usb configurations
In reply to Roger QuadrosQuoted 57 lines · Roger Quadros
Quoted 38 lines · On Tue, 16 Jun 2015 14:52:00 +0800 Li Jun…
Use
usb_otg_descriptor_addto allocate and initializeusb_otg_descriptor, add it for each usb configurations, free it while composite unbind.Signed-off-by Li Jun <[email protected]>--- drivers/usb/gadget/configfs.c | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-)drivers/usb/gadget/configfs.c +5
-3@@ -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,24 @@ 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; +unsigned length;drivers/usb/gadget/configfs.c static int configfs_composite_bind(struct usb_gadget *gadget, · line 1390
Quoted 10 lines
drivers/usb/gadget/configfs.c +10
-0+ +if (gadget->otg_rev >=0x0200 ) + length =sizeof (struct usb_otg20_descriptor ); +else + length =sizeof (struct usb_otg_descriptor ); + usb_desc =kzalloc (length,GFP_KERNEL ); +if (!usb_desc) { + ret = -ENOMEM ; + goto err_comp_cleanup; + }This code seems to be common across all gadgets.
Can we haveusb_otg_descriptor_alloc()that takes care of allocating the right size based on descriptor version?
Quoted 7 lines
Then we can have
usb_desc = usb_otg_descriptor_alloc(gadget); if (IS_ERR(usb_desc)) { ret = PTR_ERR(usb_desc); goto err_comp_cleanup; }
That's better, I will update in next version.
Li Jun
Quoted 31 lines
Quoted 31 lines
drivers/usb/gadget/configfs.c +10
-0+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 +1400,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 +1457,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 +1532,6 @@ static struct config_group *gadgets_make(if (!gi->composite.gadget_driver.function) goto err;
Quoted 12 lines
drivers/usb/gadget/configfs.c static struct config_group *gadgets_make(
Quoted 9 lines
drivers/usb/gadget/configfs.c +0
-6-#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;cheers,
-roger
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v3 09/22] usb: gadget: add usb_otg_descriptor_add interface to init usb_otg_descriptor
In reply to Roger QuadrosQuoted 41 lines · Roger Quadros
Quoted 37 lines · On Tue, 16 Jun 2015 14:51:59 +0800 Li Jun…
Allocate
usb_otg_descriptorand initialize it according to gadget otg options, if none of options is not set, keep bmAttributes setting as current gadget drivers, with this new interface,usb_otg_descriptorcan include bcdOTG if OTG 2.0 or later, and otg features can be decided by the combination of usb hardware property and driver config.Signed-off-by Li Jun <[email protected]>--- drivers/usb/gadget/config.c | 39 +++++++++++++++++++++++++++++++++++++++ include/linux/usb/gadget.h | 2 ++ 2 files changed, 41 insertions(+)drivers/usb/gadget/config.c +17
-0@@ -195,3 +195,42 @@ void usb_free_all_descriptors(struct usb_function *f)usb_free_descriptors (f->ss_descriptors); }EXPORT_SYMBOL_GPL (usb_free_all_descriptors); + +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; +u8 otg_attributes =0 ; + +if (!otg_desc) +return -EINVAL ; + +if (gadget->adp_support || gadget->hnp_support || + gadget->srp_support) { +if (gadget->adp_support) + otg_attributes |=USB_OTG_ADP ; +if (gadget->hnp_support) + otg_attributes |=USB_OTG_HNP ;
Quoted 9 lines
drivers/usb/gadget/config.c void usb_free_all_descriptors(struct usb_function *f) · line 219
Quoted 5 lines
drivers/usb/gadget/config.c +5
-0+if (gadget->srp_support) + otg_attributes |=USB_OTG_SRP ; + }else { + otg_attributes =USB_OTG_SRP |USB_OTG_HNP ; + }Didn't we agree that if
otg_revis not set then only we will use the legacy method?
oh, yes, we had agreed that approach, seems I missed the update here, it's easier to use otg_rev to judge legacy platform, I will update.
Li Jun
Quoted 25 lines
Quoted 25 lines
drivers/usb/gadget/config.c +17
-0+ +if (gadget->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 (gadget->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);include/linux/usb/gadget.h +0
-0@@ -1013,6 +1013,8 @@ int usb_assign_descriptors(struct usb_function *f, struct usb_descriptor_header **ss);void usb_free_all_descriptors (struct usb_function *f);
Quoted 8 lines
include/linux/usb/gadget.h int usb_assign_descriptors(struct usb_function *f, · line 1020
Quoted 5 lines
include/linux/usb/gadget.h +2
-0+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 */ cheers,
-roger
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v3 05/22] doc: dt-binding: usb: add otg related properties
In reply to a message not in the archiveQuoted 13 lines · On Tue, 16 Jun 2015 14:51:55 +0800 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 <[email protected]>--- Documentation/devicetree/bindings/usb/generic.txt | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)Documentation/devicetree/bindings/usb/generic.txt +0
-0
Documentation/devicetree/bindings/usb/generic.txt Optional properties: · line 19
Quoted 9 lines
Documentation/devicetree/bindings/usb/generic.txt +6
-0@@ -11,6 +11,20 @@ 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, also if ADP is enabled, otg-rev should be + 0x0200 or above.
How about saying "if ADP is required, otg-rev should be 0x0200 or above"
Documentation/devicetree/bindings/usb/generic.txt Optional properties: · line 27
Quoted 8 lines
Documentation/devicetree/bindings/usb/generic.txt +8
-0+ - 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, if not passed, otg-rev should + be set to be 0x0200 or above.
Why should we place this constraint on DT? Isn't is better to handle it automatically in the USB code?
Not specifying the disable flag doesn't mean that it has to be enabled. It means that enable it if it can be. i.e. supported by OTG rev and controller.
Documentation/devicetree/bindings/usb/generic.txt dwc3@4a030000 { · line 42
Quoted 12 lines
Documentation/devicetree/bindings/usb/generic.txt +4
-0This is an attribute to a USB controller such as:@@ -21,4 +35,8 @@ dwc3@4a030000 { usb-phy = <&usb2_phy>, <&usb3,phy>; maximum-speed = "super-speed"; dr_mode = "otg"; + otg-rev = <0x0200>; + hnp-disable; + srp-disable; + adp-disable; };
How about a more real world example? We don't want hnp/srp disabled.
cheers,
-roger
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v3 05/22] doc: dt-binding: usb: add otg related properties
Quoted 12 lines · Roger Quadros
Quoted 8 lines · On Tue, 16 Jun 2015 14:51:55 +0800 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 <[email protected]>--- Documentation/devicetree/bindings/usb/generic.txt | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
Quoted 17 lines
Quoted 5 lines
Documentation/devicetree/bindings/usb/generic.txt +0
-0Documentation/devicetree/bindings/usb/generic.txt Optional properties: · line 19
Quoted 9 lines
Documentation/devicetree/bindings/usb/generic.txt +6
-0@@ -11,6 +11,20 @@ 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, also if ADP is enabled, otg-rev should be + 0x0200 or above.How about saying "if ADP is required, otg-rev should be
0x0200or above"
okay.
Quoted 12 lines
Documentation/devicetree/bindings/usb/generic.txt Optional properties: · line 27
Quoted 8 lines
Documentation/devicetree/bindings/usb/generic.txt +8
-0+ - 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, if not passed, otg-rev should + be set to be 0x0200 or above.Why should we place this constraint on DT? Isn't is better to handle it automatically in the USB code?
You are right, this can be done in USB code, I will remove this constraint from it.
Quoted 3 lines
Not specifying the disable flag doesn't mean that it has to be enabled. It means that enable it if it can be. i.e. supported by OTG rev and controller.
Exactly.
Quoted 15 lines
Documentation/devicetree/bindings/usb/generic.txt dwc3@4a030000 { · line 42
Quoted 12 lines
Documentation/devicetree/bindings/usb/generic.txt +4
-0This is an attribute to a USB controller such as:@@ -21,4 +35,8 @@ dwc3@4a030000 { usb-phy = <&usb2_phy>, <&usb3,phy>; maximum-speed = "super-speed"; dr_mode = "otg"; + otg-rev = <0x0200>; + hnp-disable; + srp-disable; + adp-disable; };How about a more real world example? We don't want hnp/srp disabled.
My fault, actually it's a wrong example, I will update with a typical setting as you pointed.
Li Jun
Quoted 3 lines
cheers,
-roger
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v3 07/22] usb: chipidea: set usb gadeget's otg config
In reply to a message not in the archiveQuoted 26 lines · On Tue, 16 Jun 2015 14:51:57 +0800 Li Jun…
Set gadget's otg features according to controller's capability and usb property in device tree.
Signed-off-by Li Jun <[email protected]>--- drivers/usb/chipidea/core.c | 18 ++++++++++++++++++ drivers/usb/chipidea/udc.c | 20 +++++++++++++++++++- include/linux/usb/chipidea.h | 4 ++++ 3 files changed, 41 insertions(+), 1 deletion(-)drivers/usb/chipidea/core.c +8
-0@@ -588,6 +588,24 @@ static int ci_get_platdata(struct device *dev,of_usb_host_tpl_support (dev->of_node); } +if (platdata->dr_mode ==USB_DR_MODE_OTG ) { +if (!platdata->otg_rev) { + platdata->otg_rev = +of_usb_get_otg_rev (dev->of_node); + } +if (platdata->otg_rev) { +if (!platdata->srp_support) + platdata->srp_support =
drivers/usb/chipidea/core.c static int ci_get_platdata(struct device *dev, · line 608
Quoted 10 lines
drivers/usb/chipidea/core.c +10
-0+ !of_usb_otg_srp_disabled (dev->of_node); +if (!platdata->hnp_support) + platdata->hnp_support = + !of_usb_otg_hnp_disabled (dev->of_node); +if (!platdata->adp_support) + platdata->adp_support = + !of_usb_otg_adp_disabled (dev->of_node); + } + } +
Looks like there is some scope of sharing this code among controller drivers and also adding sanity check.
How about adding
struct usb_otg_caps {
u16 otg_rev;
bool srp_support;
bool hnp_support;
bool adp_support;
};And below API
/* sets device otg capabilities based on controller capabilities and device tree flags */
void of_usb_otg_set_capabilities(sturct device_node *node, struct usb_otg_caps *cntrl_caps, struct usb_otg_caps *device_caps)
{
u16 otg_rev = of_usb_get_otg_rev(dev->of_node);
*device_caps = *cntrl_caps;
if (!otg_rev) { /* legacy platform */
device_caps->adp_support = false;
/* For SRP/HNP respect what controller supports */
return;
}
if (otg_rev < cntrl_caps->otg_rev)
device_caps->otg_rev = cntrl_caps->otg_rev;
if (of_usb_otg_srp_disabled(dev->of_node))
device_caps->srp_support = false;
if (of_usb_otg_hnp_disabled(dev->of_node))
device_caps->hnp_support = false;
if (of_usb_otg_adp_disabled(dev->of_node))
device_caps->adp_support = false;
/* sanity check */
if ((otg_rev < 0x0200) && device_caps->adp_support) {
/* pre otg 2.0 doesn't support ADP */
device_caps->adp_support = false;
}
return;
}Quoted 48 lines
drivers/usb/chipidea/core.c +0
-0if (of_usb_get_maximum_speed (dev->of_node) ==USB_SPEED_FULL ) platdata->flags |=CI_HDRC_FORCE_FULLSPEED ;drivers/usb/chipidea/udc.c +19
-1@@ -1821,6 +1821,24 @@ static irqreturn_t udc_irq(struct ci_hdrc *ci) }/** +* udc_update_otg_config: update gadget otg config +* * @ci: chipidea controller +*/ +static void udc_update_otg_config (struct ci_hdrc *ci) +{ +if (!ci->is_otg) +return ; + + ci->gadget.otg_rev = ci->platdata->otg_rev; + ci->gadget.srp_support = ci->platdata->srp_support; + ci->gadget.hnp_support = ci->platdata->hnp_support; + ci->gadget.adp_support = ci->platdata->adp_support; +if (ci->gadget.srp_support || ci->gadget.hnp_support || + ci->gadget.adp_support) + ci->gadget.is_otg =1 ; +} + +/** * udc_start: initialize gadget role * @ci: chipidea controller */ @@ -1834,9 +1852,9 @@ 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; +udc_update_otg_config (ci);INIT_LIST_HEAD (&ci->gadget.ep_list);/* alloc resources */ include/linux/usb/chipidea.h +0
-0
include/linux/usb/chipidea.h struct ci_hdrc_platform_data { · line 41
Quoted 8 lines
include/linux/usb/chipidea.h +4
-0@@ -34,7 +34,11 @@ struct ci_hdrc_platform_data {#define CI_HDRC_CONTROLLER_STOPPED_EVENT 1void (*notify_event) (struct ci_hdrc *ci,unsigned event);struct regulator *reg_vbus; +u16 otg_rev;bool tpl_support; +bool srp_support; +bool hnp_support; +bool adp_support;
this then changes to
struct usb_otg_caps otg_caps;
include/linux/usb/chipidea.h struct ci_hdrc_platform_data { · line 44
Quoted 3 lines
include/linux/usb/chipidea.h +0
-0};/* Default offset of capability registers */
cheers,
-roger
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v3 07/22] usb: chipidea: set usb gadeget's otg config
Quoted 44 lines · Roger Quadros
Quoted 26 lines · On Tue, 16 Jun 2015 14:51:57 +0800 Li Jun…
Set gadget's otg features according to controller's capability and usb property in device tree.
Signed-off-by Li Jun <[email protected]>--- drivers/usb/chipidea/core.c | 18 ++++++++++++++++++ drivers/usb/chipidea/udc.c | 20 +++++++++++++++++++- include/linux/usb/chipidea.h | 4 ++++ 3 files changed, 41 insertions(+), 1 deletion(-)drivers/usb/chipidea/core.c +8
-0@@ -588,6 +588,24 @@ static int ci_get_platdata(struct device *dev,of_usb_host_tpl_support (dev->of_node); } +if (platdata->dr_mode ==USB_DR_MODE_OTG ) { +if (!platdata->otg_rev) { + platdata->otg_rev = +of_usb_get_otg_rev (dev->of_node); + } +if (platdata->otg_rev) { +if (!platdata->srp_support) + platdata->srp_support =drivers/usb/chipidea/core.c static int ci_get_platdata(struct device *dev, · line 608
Quoted 10 lines
drivers/usb/chipidea/core.c +10
-0+ !of_usb_otg_srp_disabled (dev->of_node); +if (!platdata->hnp_support) + platdata->hnp_support = + !of_usb_otg_hnp_disabled (dev->of_node); +if (!platdata->adp_support) + platdata->adp_support = + !of_usb_otg_adp_disabled (dev->of_node); + } + } +Looks like there is some scope of sharing this code among controller drivers and also adding sanity check.
Quoted 9 lines
How about adding
struct usb_otg_caps { u16 otg_rev; bool srp_support; bool hnp_support; bool adp_support; };
I agree there is some sharing code across all controller drivers, thus usb_otg_caps maybe desirable.
Quoted 4 lines
And below API
/* sets device otg capabilities based on controller capabilities and device tree flags */
voidof_usb_otg_set_capabilities(sturct device_node *node, struct usb_otg_caps *cntrl_caps, struct usb_otg_caps *device_caps)
I think cntrl_caps is not needed, only device_caps of controller is okay; If DT is used, then all capabilities are updated by DT, after that, controller driver can override some of them if it wants to correct some wrong property in DT(not disable some feature the controller can not support).
Quoted 4 lines
{
u16 otg_rev = of_usb_get_otg_rev(dev->of_node);
*device_caps = *cntrl_caps;Quoted 8 lines
if (!otg_rev) { /* legacy platform */
device_caps->adp_support = false;
/* For SRP/HNP respect what controller supports */
return;
}
if (otg_rev < cntrl_caps->otg_rev)
device_caps->otg_rev = cntrl_caps->otg_rev;Not catch your point, if controller can support a higher version protocol, even passed a lower setting in DT, we still use higher version?
Quoted 74 lines
if (of_usb_otg_srp_disabled(dev->of_node)) device_caps->srp_support = false; if (of_usb_otg_hnp_disabled(dev->of_node)) device_caps->hnp_support = false; if (of_usb_otg_adp_disabled(dev->of_node)) device_caps->adp_support = false; /* sanity check */ if ((otg_rev < 0x0200) && device_caps->adp_support) { /* pre otg 2.0 doesn't support ADP */ device_caps->adp_support = false; } return; }Quoted 48 lines
drivers/usb/chipidea/core.c +0
-0if (of_usb_get_maximum_speed (dev->of_node) ==USB_SPEED_FULL ) platdata->flags |=CI_HDRC_FORCE_FULLSPEED ;drivers/usb/chipidea/udc.c +19
-1@@ -1821,6 +1821,24 @@ static irqreturn_t udc_irq(struct ci_hdrc *ci) }/** +* udc_update_otg_config: update gadget otg config +* * @ci: chipidea controller +*/ +static void udc_update_otg_config (struct ci_hdrc *ci) +{ +if (!ci->is_otg) +return ; + + ci->gadget.otg_rev = ci->platdata->otg_rev; + ci->gadget.srp_support = ci->platdata->srp_support; + ci->gadget.hnp_support = ci->platdata->hnp_support; + ci->gadget.adp_support = ci->platdata->adp_support; +if (ci->gadget.srp_support || ci->gadget.hnp_support || + ci->gadget.adp_support) + ci->gadget.is_otg =1 ; +} + +/** * udc_start: initialize gadget role * @ci: chipidea controller */ @@ -1834,9 +1852,9 @@ 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; +udc_update_otg_config (ci);INIT_LIST_HEAD (&ci->gadget.ep_list);/* alloc resources */ include/linux/usb/chipidea.h +0
-0include/linux/usb/chipidea.h struct ci_hdrc_platform_data { · line 41
Quoted 8 lines
include/linux/usb/chipidea.h +4
-0@@ -34,7 +34,11 @@ struct ci_hdrc_platform_data {#define CI_HDRC_CONTROLLER_STOPPED_EVENT 1void (*notify_event) (struct ci_hdrc *ci,unsigned event);struct regulator *reg_vbus; +u16 otg_rev;bool tpl_support; +bool srp_support; +bool hnp_support; +bool adp_support;this then changes to
Quoted 8 lines
struct usb_otg_caps otg_caps;include/linux/usb/chipidea.h struct ci_hdrc_platform_data { · line 44
Quoted 3 lines
include/linux/usb/chipidea.h +0
-0};/* Default offset of capability registers */ cheers,
-roger
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v3 07/22] usb: chipidea: set usb gadeget's otg config
Quoted 59 lines · On Tue, 16 Jun 2015 17:21:50 +0800 Li Jun…
Quoted 44 lines · Roger Quadros
Quoted 26 lines · On Tue, 16 Jun 2015 14:51:57 +0800 Li Jun…
Set gadget's otg features according to controller's capability and usb property in device tree.
Signed-off-by Li Jun <[email protected]>--- drivers/usb/chipidea/core.c | 18 ++++++++++++++++++ drivers/usb/chipidea/udc.c | 20 +++++++++++++++++++- include/linux/usb/chipidea.h | 4 ++++ 3 files changed, 41 insertions(+), 1 deletion(-)drivers/usb/chipidea/core.c +8
-0@@ -588,6 +588,24 @@ static int ci_get_platdata(struct device *dev,of_usb_host_tpl_support (dev->of_node); } +if (platdata->dr_mode ==USB_DR_MODE_OTG ) { +if (!platdata->otg_rev) { + platdata->otg_rev = +of_usb_get_otg_rev (dev->of_node); + } +if (platdata->otg_rev) { +if (!platdata->srp_support) + platdata->srp_support =drivers/usb/chipidea/core.c static int ci_get_platdata(struct device *dev, · line 608
Quoted 10 lines
drivers/usb/chipidea/core.c +10
-0+ !of_usb_otg_srp_disabled (dev->of_node); +if (!platdata->hnp_support) + platdata->hnp_support = + !of_usb_otg_hnp_disabled (dev->of_node); +if (!platdata->adp_support) + platdata->adp_support = + !of_usb_otg_adp_disabled (dev->of_node); + } + } +Looks like there is some scope of sharing this code among controller drivers and also adding sanity check.
Quoted 9 lines
How about adding
struct usb_otg_caps { u16 otg_rev; bool srp_support; bool hnp_support; bool adp_support; };I agree there is some sharing code across all controller drivers, thus
usb_otg_capsmaybe desirable.Quoted 2 lines
And below API
Quoted 7 lines
Quoted 2 lines
/* sets device otg capabilities based on controller capabilities and device tree flags */
voidof_usb_otg_set_capabilities(sturct device_node *node, struct usb_otg_caps *cntrl_caps, struct usb_otg_caps *device_caps)I think
cntrl_capsis not needed, onlydevice_capsof controller is okay; If DT is used, then all capabilities are updated by DT, after that, controller driver can override some of them if it wants to correct some wrong property in DT(not disable some feature the controller can not support).
OK.
Quoted 10 lines
Quoted 10 lines
{ u16 otg_rev = of_usb_get_otg_rev(dev->of_node); *device_caps = *cntrl_caps; if (!otg_rev) { /* legacy platform */ device_caps->adp_support = false; /* For SRP/HNP respect what controller supports */ return; }
Quoted 5 lines
Quoted 2 lines
if (otg_rev < cntrl_caps->otg_rev) device_caps->otg_rev = cntrl_caps->otg_rev;Not catch your point, if controller can support a higher version protocol, even passed a lower setting in DT, we still use higher version?
My mistake. Should have been
if (otg_rev < cntrl_caps->otg_rev) device_caps->org_rev = otg_rev;
Quoted 7 lines
Quoted 7 lines
if (of_usb_otg_srp_disabled(dev->of_node)) device_caps->srp_support = false; if (of_usb_otg_hnp_disabled(dev->of_node)) device_caps->hnp_support = false; if (of_usb_otg_adp_disabled(dev->of_node)) device_caps->adp_support = false;
Quoted 8 lines
Quoted 8 lines
/* sanity check */ if ((otg_rev < 0x0200) && device_caps->adp_support) { /* pre otg 2.0 doesn't support ADP */ device_caps->adp_support = false; } return; }
cheers,
-roger
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html