USB core changes for supporting OTG on MSM SoC
Subsystems (3)
cover USB core changes for supporting OTG on MSM SoC
This patch series adds OTG 2.0 enhancements and misc changes required for supporting SRP & HNP in MSM OTG driver. As these patches modify the USB core code, I would like to receive feedback before posting driver patches. The driver patches are available at
https://www.codeaurora.org/gitweb/quic/la/?p=kernel/msm.git;a=commitdiff;h=05535a995e9eb34c3c41d874d09955a443008cd5
Pavankumar Kondeti (5):
USB: core: Add input prompt and help text for USB_OTG config
USB: core: OTG Supplement Revision 2.0 updates
USB: gadget: OTG supplement revision 2.0 updates
USB: EHCI: Notify HCD about HNP enabled port suspend
USB: Eliminate delays involved in root hub initialization during HNP
.../testing/sysfs-devices-platform-_UDC_-gadget | 14 +++ drivers/usb/core/Kconfig | 12 +++- drivers/usb/core/driver.c | 50 ++++++++++++ drivers/usb/core/hcd.c | 7 ++ drivers/usb/core/hub.c | 84 +++++++++++++++++--- drivers/usb/core/usb.h | 4 + drivers/usb/gadget/composite.c | 25 ++++++- drivers/usb/gadget/zero.c | 3 + drivers/usb/host/ehci-hub.c | 11 +++ drivers/usb/host/ehci.h | 2 + include/linux/usb.h | 2 + include/linux/usb/ch9.h | 11 ++- include/linux/usb/gadget.h | 21 +++++ 13 files changed, 231 insertions(+), 15 deletions(-)
--
Sent by a consultant of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
RFC 1/5 USB: core: Add input prompt and help text for USB_OTG config
bd6882 commit removes the duplicate USB_OTG config from gadget/Kconfig. But does not copy the input prompt and help text to the original config defined in core/Kconfig. Add them now.
--- drivers/usb/core/Kconfig | 12 ++++++++++-- 1 files changed, 10 insertions(+), 2 deletions(-)
drivers/usb/core/Kconfig +10 -2
@@ -107,11 +107,19 @@ config USB_SUSPEND If you are unsure about this, say N here. config USB_OTG - bool + bool "OTG support" depends on USB && EXPERIMENTAL depends on USB_SUSPEND default n - + help + The most notable feature of USB OTG is support for a + "Dual-Role" device, which can act as either a device + or a host. The initial role is decided by the type of + plug inserted and can be changed later when two dual + role devices talk to each other. + + Select this only if your board has Mini-AB/Micro-AB + connector. config USB_OTG_WHITELIST bool "Rely on OTG Targeted Peripherals List"
Signature · 5 lines
1.7.1 -- Sent by a consultant of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
Re: [RFC 1/5] USB: core: Add input prompt and help text for USB_OTG config
Hello.
Quoted 1 line · Pavankumar Kondeti
bd6882 commit removes the duplicate
USB_OTGconfig from
Linus has asked to also specify the commit summary in parens.
Quoted 5 lines
gadget/Kconfig. But does not copy the input prompt and help text to the original config defined in core/Kconfig. Add them now.
Signed-off-by Pavankumar Kondeti<[email protected]>
WBR, Sergei
Re: [RFC 1/5] USB: core: Add input prompt and help text for USB_OTG config
In reply to Pavankumar KondetiQuoted 6 lines · Pavankumar Kondeti
bd6882 commit removes the duplicate
USB_OTGconfig from gadget/Kconfig. But does not copy the input prompt and help text to the original config defined in core/Kconfig. Add them now.Signed-off-by Pavankumar Kondeti <[email protected]>
This looks valid to be applied, now, right?
thanks,
greg k-h
Re: [RFC 1/5] USB: core: Add input prompt and help text for USB_OTG config
Quoted 11 lines · Greg KH
Quoted 6 lines · Pavankumar Kondeti
bd6882 commit removes the duplicate
USB_OTGconfig from gadget/Kconfig. But does not copy the input prompt and help text to the original config defined in core/Kconfig. Add them now.Signed-off-by Pavankumar Kondeti <[email protected]>This looks valid to be applied, now, right?
Yes. It can be applied now.
I will fix the commit Sergei's comment about commit description and resend the patch.
Thanks,
Pavan
Signature · 2 lines
Sent by a consultant of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
RFC 2/5 USB: core: OTG Supplement Revision 2.0 updates
In reply to Pavankumar KondetiOTG supplement revision 2.0 spec introduces Attach Detection Protocol (ADP) for detecting peripheral connection without applying power on VBUS. ADP is optional and is included in the OTG descriptor along with SRP and HNP.
HNP polling is introduced for peripheral to notify its wish to become host. Host polls (GET_STATUS on DEVICE) peripheral for host_request and suspend the bus when peripheral returns host_request TRUE. The spec insists the polling frequency to be in 1-2 sec range and bus should be suspended with in 2 sec from host_request is set.
a_alt_hnp_support feature is obsolete and a_hnp_support feature is limited to only legacy OTG B-device. The newly introduced bcdOTG field in the OTG descriptor is used for identifying the 2.0 compliant B-device.
--- drivers/usb/core/driver.c | 50 +++++++++++++++++++++++++++++++ drivers/usb/core/hcd.c | 3 ++ drivers/usb/core/hub.c | 71 ++++++++++++++++++++++++++++++++++++++------ drivers/usb/core/usb.h | 4 ++ include/linux/usb.h | 2 + include/linux/usb/ch9.h | 11 ++++++- 6 files changed, 129 insertions(+), 12 deletions(-)
drivers/usb/core/driver.c +50 -0
@@ -1207,6 +1207,19 @@ static int usb_suspend_both(struct usb_device *udev, pm_message_t msg)* and flush any outstanding URBs. */ }else { +#ifdef CONFIG_USB_OTG +/* According to OTG supplement Rev 2.0 section 6.3 +* Unless an A-device enables b_hnp_enable before entering +* suspend it shall also continue polling while the bus is +* suspended. +* +* We don't have to perform HNP polling, as we are going to +* enable b_hnp_enable before suspending. +*/ +if (udev->bus->hnp_support && + udev->portnum == udev->bus->otg_port) +cancel_delayed_work (&udev->bus->hnp_polling); +#endif udev->can_submit =0 ;for (i =0 ; i <16 ; ++i) {usb_hcd_flush_endpoint (udev, udev->ep_out[i]);
@@ -1270,6 +1283,43 @@ static int usb_resume_both(struct usb_device *udev, pm_message_t msg)return status; } +#ifdef CONFIG_USB_OTG +void usb_hnp_polling_work (struct work_struct *work) +{ +int ret; +struct usb_bus *bus = + container_of(work, struct usb_bus, hnp_polling.work); +struct usb_device *udev = bus->root_hub->children[bus->otg_port -1 ]; +u8 *status =kmalloc (sizeof (*status),GFP_KERNEL ); + +if (!status) +return ; + + ret =usb_control_msg (udev,usb_rcvctrlpipe (udev,0 ), +USB_REQ_GET_STATUS ,USB_DIR_IN |USB_RECIP_DEVICE , +0 ,OTG_STATUS_SELECTOR , status,sizeof (*status), +USB_CTRL_GET_TIMEOUT ); +if (ret <0 ) { +/* Peripheral may not be supporting HNP polling */ +dev_vdbg (&udev->dev,"HNP polling failed. status %d\n" , ret); + goto out; + } + +/* Spec says host must suspend the bus with in 2 sec. */ +if (*status & (1 <<HOST_REQUEST_FLAG )) { +do_unbind_rebind (udev,DO_UNBIND ); + ret =usb_suspend_both (udev,PMSG_USER_SUSPEND ); +if (ret) +dev_info (&udev->dev,"suspend failed\n" ); + }else { +schedule_delayed_work (&bus->hnp_polling, +msecs_to_jiffies (THOST_REQ_POLL )); + } +out: +kfree (status); +} +#endif +static void choose_wakeup (struct usb_device *udev,pm_message_t msg) {int w;
drivers/usb/core/hcd.c +3 -0
@@ -869,6 +869,9 @@ static void usb_bus_init (struct usb_bus *bus) bus->bandwidth_isoc_reqs =0 ;INIT_LIST_HEAD (&bus->bus_list); +#ifdef CONFIG_USB_OTG +INIT_DELAYED_WORK (&bus->hnp_polling, usb_hnp_polling_work); +#endif }/*-------------------------------------------------------------------------*/
drivers/usb/core/hub.c +61 -10
118 lines not on this page · raw message
drivers/usb/core/usb.h +4 -0
@@ -72,6 +72,10 @@ static inline int usb_port_resume(struct usb_device *udev, pm_message_t msg)#endif +#ifdef CONFIG_USB_OTG +extern void usb_hnp_polling_work (struct work_struct *work); +#endif +#ifdef CONFIG_USB_SUSPEND extern void usb_autosuspend_device (struct usb_device *udev);
include/linux/usb.h +2 -0
@@ -317,6 +317,8 @@ struct usb_bus {u8 otg_port;/* 0, or number of OTG/HNP port */ unsigned is_b_host:1; /* true during some HNP roleswitches */ unsigned b_hnp_enable:1; /* OTG: did A-Host enable HNP? */ + unsigned hnp_support:1; /* OTG: HNP is supported on OTG port */ +struct delayed_work hnp_polling;/* OTG: HNP polling work */ unsigned sg_tablesize;/* 0 or largest number of sg list entries */ int devnum_next;/* Next open device number in
include/linux/usb/ch9.h +9 -2
@@ -151,6 +151,11 @@#define USB_DEV_STAT_U2_ENABLED 3/* transition into U2 state */ #define USB_DEV_STAT_LTM_ENABLED 4/* Latency tolerance messages */ +/* OTG 2.0 spec 6.2 and 6.3 sections */ +#define OTG_STATUS_SELECTOR 0xF000 +#define THOST_REQ_POLL 1500/* 1000 - 2000 msec */ +#define HOST_REQUEST_FLAG 0 +/** * struct usb_ctrlrequest - SETUP data for a USB device control request * @bRequestType: matches the USB bmRequestType field
@@ -605,17 +610,19 @@ struct usb_qualifier_descriptor {/*-------------------------------------------------------------------------*/ -/* USB_DT_OTG (from OTG 1.0a supplement) */ +/* USB_DT_OTG (from OTG 2.0 supplement) */ struct usb_otg_descriptor {__u8 bLength;__u8 bDescriptorType; -__u8 bmAttributes;/* support for HNP, SRP, etc */ +__u8 bmAttributes;/* support for HNP, SRP, ADP etc */ +__le16 bcdOTG; } __attribute__ ((packed));/* 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)/* Attach detection protocol */ /*-------------------------------------------------------------------------*/
Signature · 5 lines
1.7.1 -- Sent by a consultant of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
Re: [RFC 2/5] USB: core: OTG Supplement Revision 2.0 updates
Hi,
Quoted 10 lines · Pavankumar Kondeti
OTG supplement revision 2.0 spec introduces Attach Detection Protocol (ADP) for detecting peripheral connection without applying power on VBUS. ADP is optional and is included in the OTG descriptor along with SRP and HNP.
HNP polling is introduced for peripheral to notify its wish to become host. Host polls (
GET_STATUSon DEVICE) peripheral forhost_requestand suspend the bus when peripheral returnshost_requestTRUE. The spec insists the polling frequency to be in 1-2 sec range and bus should be suspended with in 2 sec fromhost_requestis set.
within ?
Quoted 25 lines
drivers/usb/core/driver.c +13
-0@@ -1207,6 +1207,19 @@ static int usb_suspend_both(struct usb_device *udev, pm_message_t msg)* and flush any outstanding URBs. */ }else { +#ifdef CONFIG_USB_OTG +/* According to OTG supplement Rev 2.0 section 6.3 +* Unless an A-device enables b_hnp_enable before entering +* suspend it shall also continue polling while the bus is +* suspended. +* +* We don't have to perform HNP polling, as we are going to +* enable b_hnp_enable before suspending. +*/ +if (udev->bus->hnp_support && + udev->portnum == udev->bus->otg_port) +cancel_delayed_work (&udev->bus->hnp_polling); +#endif udev->can_submit =0 ;for (i =0 ; i <16 ; ++i) {usb_hcd_flush_endpoint (udev, udev->ep_out[i]);
drivers/usb/core/driver.c static int usb_resume_both(struct usb_device *udev, pm_message_t msg) · line 1287
Quoted 5 lines
drivers/usb/core/driver.c +2
-0@@ -1270,6 +1283,43 @@ static int usb_resume_both(struct usb_device *udev, pm_message_t msg)return status; } +#ifdef CONFIG_USB_OTG +void usb_hnp_polling_work (struct work_struct *work)
do you really need this to be exported ??
drivers/usb/core/driver.c static int usb_resume_both(struct usb_device *udev, pm_message_t msg) · line 1293
Quoted 6 lines
drivers/usb/core/driver.c +6
-0+{ +int ret; +struct usb_bus *bus = + container_of(work, struct usb_bus, hnp_polling.work); +struct usb_device *udev = bus->root_hub->children[bus->otg_port -1 ]; +u8 *status =kmalloc (sizeof (*status),GFP_KERNEL );
how about:
u8 status;
and...
drivers/usb/core/driver.c static int usb_resume_both(struct usb_device *udev, pm_message_t msg) · line 1300
Quoted 6 lines
drivers/usb/core/driver.c +6
-0+if (!status) +return ; + + ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), + USB_REQ_GET_STATUS, USB_DIR_IN | USB_RECIP_DEVICE, + 0, OTG_STATUS_SELECTOR, status, sizeof(*status),
0, OTG_STATUS_SELECTOR, &status, sizeof(status);
??
Signature · 1 line
balbi
Alan Stern
maintainerRe: [RFC 2/5] USB: core: OTG Supplement Revision 2.0 updates
Quoted 13 lines · Felipe Balbi
drivers/usb/core/driver.c static int usb_resume_both(struct usb_device *udev, pm_message_t msg) · line 1293
Quoted 6 lines
drivers/usb/core/driver.c +6
-0+{ +int ret; +struct usb_bus *bus = + container_of(work, struct usb_bus, hnp_polling.work); +struct usb_device *udev = bus->root_hub->children[bus->otg_port -1 ]; +u8 *status =kmalloc (sizeof (*status),GFP_KERNEL );how about:
u8 status;
and...
Quoted 9 lines
drivers/usb/core/driver.c static int usb_resume_both(struct usb_device *udev, pm_message_t msg) · line 1300
Quoted 6 lines
drivers/usb/core/driver.c +6
-0+if (!status) +return ; + + ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), + USB_REQ_GET_STATUS, USB_DIR_IN | USB_RECIP_DEVICE, + 0, OTG_STATUS_SELECTOR, status, sizeof(*status),0,
OTG_STATUS_SELECTOR, &status, sizeof(status);
??
You mustn't do DMA to addresses on the stack.
Alan Stern
Re: [RFC 2/5] USB: core: OTG Supplement Revision 2.0 updates
Quoted 25 lines · Alan Stern
Quoted 13 lines · Felipe Balbi
drivers/usb/core/driver.c static int usb_resume_both(struct usb_device *udev, pm_message_t msg) · line 1293
Quoted 6 lines
drivers/usb/core/driver.c +6
-0+{ +int ret; +struct usb_bus *bus = + container_of(work, struct usb_bus, hnp_polling.work); +struct usb_device *udev = bus->root_hub->children[bus->otg_port -1 ]; +u8 *status =kmalloc (sizeof (*status),GFP_KERNEL );how about:
u8 status;
and...
Quoted 9 lines
drivers/usb/core/driver.c static int usb_resume_both(struct usb_device *udev, pm_message_t msg) · line 1300
Quoted 6 lines
drivers/usb/core/driver.c +6
-0+if (!status) +return ; + + ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), + USB_REQ_GET_STATUS, USB_DIR_IN | USB_RECIP_DEVICE, + 0, OTG_STATUS_SELECTOR, status, sizeof(*status),0,
OTG_STATUS_SELECTOR, &status, sizeof(status);
??
Quoted 1 line
You mustn't do DMA to addresses on the stack.
oh, ok. Forgot other controllers will do DMA for control message too. MUSB won't.
Signature · 1 line
balbi
Re: [RFC 2/5] USB: core: OTG Supplement Revision 2.0 updates
In reply to Felipe BalbiQuoted 8 lines · Felipe Balbi
Hi,
Quoted 5 lines · Pavankumar Kondeti
OTG supplement revision 2.0 spec introduces Attach Detection Protocol (ADP) for detecting peripheral connection without applying power on VBUS. ADP is optional and is included in the OTG descriptor along with SRP and HNP.
Quoted 8 lines
Quoted 5 lines
HNP polling is introduced for peripheral to notify its wish to become host. Host polls (
GET_STATUSon DEVICE) peripheral forhost_requestand suspend the bus when peripheral returnshost_requestTRUE. The spec insists the polling frequency to be in 1-2 sec range and bus should be suspended with in 2 sec fromhost_requestis set.within ?
yeah. will fix it in V2.
Quoted 28 lines
Quoted 28 lines
drivers/usb/core/driver.c +13
-0@@ -1207,6 +1207,19 @@ static int usb_suspend_both(struct usb_device *udev, pm_message_t msg)* and flush any outstanding URBs. */ }else { +#ifdef CONFIG_USB_OTG +/* According to OTG supplement Rev 2.0 section 6.3 +* Unless an A-device enables b_hnp_enable before entering +* suspend it shall also continue polling while the bus is +* suspended. +* +* We don't have to perform HNP polling, as we are going to +* enable b_hnp_enable before suspending. +*/ +if (udev->bus->hnp_support && + udev->portnum == udev->bus->otg_port) +cancel_delayed_work (&udev->bus->hnp_polling); +#endif udev->can_submit =0 ;for (i =0 ; i <16 ; ++i) {usb_hcd_flush_endpoint (udev, udev->ep_out[i]);@@ -1270,6 +1283,43 @@ static int usb_resume_both(struct usb_device *udev, pm_message_t msg)return status; }
Quoted 5 lines
drivers/usb/core/driver.c static int usb_resume_both(struct usb_device *udev, pm_message_t msg) · line 1287
Quoted 2 lines
drivers/usb/core/driver.c +2
-0+#ifdef CONFIG_USB_OTG +void usb_hnp_polling_work (struct work_struct *work)do you really need this to be exported ??
The work struct is per USB bus. The bus is initialized in core/hcd.c. I kept the work function here as it it belongs to usb core (I mean not HCD specific) like other USB auto suspend functions.
Thanks,
Pavan
Signature · 2 lines
Sent by a consultant of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
Re: [RFC 2/5] USB: core: OTG Supplement Revision 2.0 updates
Hi,
Quoted 10 lines · Pavan Kondeti
Quoted 9 lines
drivers/usb/core/driver.c static int usb_resume_both(struct usb_device *udev, pm_message_t msg) · line 1287
Quoted 6 lines
drivers/usb/core/driver.c +2
-0@@ -1270,6 +1283,43 @@ static int usb_resume_both(struct usb_device *udev, pm_message_t msg)return status; } +#ifdef CONFIG_USB_OTG +void usb_hnp_polling_work (struct work_struct *work)do you really need this to be exported ??
Quoted 3 lines
The work struct is per USB bus. The bus is initialized in
core/hcd.c. I kept the work function here as it it belongs to usb core (I mean not HCD specific) like other USB auto suspend functions.
I see, it wasn't obvious from the patch, sorry :-)
Signature · 1 line
balbi
Alan Stern
maintainerRe: [RFC 2/5] USB: core: OTG Supplement Revision 2.0 updates
In reply to Pavankumar KondetiQuoted 35 lines · Pavankumar Kondeti
OTG supplement revision 2.0 spec introduces Attach Detection Protocol (ADP) for detecting peripheral connection without applying power on VBUS. ADP is optional and is included in the OTG descriptor along with SRP and HNP.
HNP polling is introduced for peripheral to notify its wish to become host. Host polls (
GET_STATUSon DEVICE) peripheral forhost_requestand suspend the bus when peripheral returnshost_requestTRUE. The spec insists the polling frequency to be in 1-2 sec range and bus should be suspended with in 2 sec fromhost_requestis set.
a_alt_hnp_supportfeature is obsolete anda_hnp_supportfeature is limited to only legacy OTG B-device. The newly introduced bcdOTG field in the OTG descriptor is used for identifying the 2.0 compliant B-device.Signed-off-by Pavankumar Kondeti <[email protected]>--- drivers/usb/core/driver.c | 50 +++++++++++++++++++++++++++++++ drivers/usb/core/hcd.c | 3 ++ drivers/usb/core/hub.c | 71 ++++++++++++++++++++++++++++++++++++++------ drivers/usb/core/usb.h | 4 ++ include/linux/usb.h | 2 + include/linux/usb/ch9.h | 11 ++++++- 6 files changed, 129 insertions(+), 12 deletions(-)drivers/usb/core/driver.c +1
-0@@ -1270,6 +1283,43 @@ static int usb_resume_both(struct usb_device *udev, pm_message_t msg)return status; } +#ifdef CONFIG_USB_OTG
drivers/usb/core/driver.c static int usb_resume_both(struct usb_device *udev, pm_message_t msg) · line 1296
Quoted 10 lines
drivers/usb/core/driver.c +10
-0+void usb_hnp_polling_work (struct work_struct *work) +{ +int ret; +struct usb_bus *bus = + container_of(work, struct usb_bus, hnp_polling.work); +struct usb_device *udev = bus->root_hub->children[bus->otg_port -1 ]; +u8 *status =kmalloc (sizeof (*status),GFP_KERNEL ); + +if (!status) +return ;
Shouldn't you reschedule the delayed work? A memory allocation failure is likely to be temporary.
Quoted 4 lines
drivers/usb/core/driver.c +4
-0+ + ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), + USB_REQ_GET_STATUS, USB_DIR_IN | USB_RECIP_DEVICE, + 0, OTG_STATUS_SELECTOR, status, sizeof(*status),
drivers/usb/core/driver.c static int usb_resume_both(struct usb_device *udev, pm_message_t msg) · line 1310
Quoted 10 lines
drivers/usb/core/driver.c +10
-0+ USB_CTRL_GET_TIMEOUT); +if (ret <0 ) { +/* Peripheral may not be supporting HNP polling */ +dev_vdbg (&udev->dev,"HNP polling failed. status %d\n" , ret); + goto out; + } + +/* Spec says host must suspend the bus with in 2 sec. */ +if (*status & (1 <<HOST_REQUEST_FLAG )) { +do_unbind_rebind (udev,DO_UNBIND );
You forget to set udev->do_remote_wakeup to 0.
drivers/usb/core/driver.c static int usb_resume_both(struct usb_device *udev, pm_message_t msg) · line 1321
Quoted 11 lines
drivers/usb/core/driver.c +11
-0+ ret =usb_suspend_both (udev,PMSG_USER_SUSPEND ); +if (ret) + dev_info(&udev->dev, "suspend failed\n"); + }else { +schedule_delayed_work (&bus->hnp_polling, +msecs_to_jiffies (THOST_REQ_POLL )); + } +out: +kfree (status); +} +#endif
Alan Stern
Re: [RFC 2/5] USB: core: OTG Supplement Revision 2.0 updates
Quoted 36 lines · Alan Stern
Quoted 34 lines · Pavankumar Kondeti
OTG supplement revision 2.0 spec introduces Attach Detection Protocol (ADP) for detecting peripheral connection without applying power on VBUS. ADP is optional and is included in the OTG descriptor along with SRP and HNP.
HNP polling is introduced for peripheral to notify its wish to become host. Host polls (
GET_STATUSon DEVICE) peripheral forhost_requestand suspend the bus when peripheral returnshost_requestTRUE. The spec insists the polling frequency to be in 1-2 sec range and bus should be suspended with in 2 sec fromhost_requestis set.
a_alt_hnp_supportfeature is obsolete anda_hnp_supportfeature is limited to only legacy OTG B-device. The newly introduced bcdOTG field in the OTG descriptor is used for identifying the 2.0 compliant B-device.Signed-off-by Pavankumar Kondeti <[email protected]>--- drivers/usb/core/driver.c | 50 +++++++++++++++++++++++++++++++ drivers/usb/core/hcd.c | 3 ++ drivers/usb/core/hub.c | 71 ++++++++++++++++++++++++++++++++++++++------ drivers/usb/core/usb.h | 4 ++ include/linux/usb.h | 2 + include/linux/usb/ch9.h | 11 ++++++- 6 files changed, 129 insertions(+), 12 deletions(-)drivers/usb/core/driver.c +0
-0@@ -1270,6 +1283,43 @@ static int usb_resume_both(struct usb_device *udev, pm_message_t msg)return status; }
Quoted 15 lines
drivers/usb/core/driver.c static int usb_resume_both(struct usb_device *udev, pm_message_t msg) · line 1296
Quoted 11 lines
drivers/usb/core/driver.c +11
-0+#ifdef CONFIG_USB_OTG +void usb_hnp_polling_work (struct work_struct *work) +{ +int ret; +struct usb_bus *bus = + container_of(work, struct usb_bus, hnp_polling.work); +struct usb_device *udev = bus->root_hub->children[bus->otg_port -1 ]; +u8 *status =kmalloc (sizeof (*status),GFP_KERNEL ); + +if (!status) +return ;Shouldn't you reschedule the delayed work? A memory allocation failure is likely to be temporary.
Agreed. Will fix it in V2.
Quoted 8 lines
Quoted 8 lines
drivers/usb/core/driver.c +8
-0+ + ret =usb_control_msg (udev,usb_rcvctrlpipe (udev,0 ), +USB_REQ_GET_STATUS ,USB_DIR_IN |USB_RECIP_DEVICE , +0 ,OTG_STATUS_SELECTOR , status,sizeof (*status), +USB_CTRL_GET_TIMEOUT ); +if (ret <0 ) { +/* Peripheral may not be supporting HNP polling */ +dev_vdbg (&udev->dev,"HNP polling failed. status %d\n" , ret);
Quoted 9 lines
drivers/usb/core/driver.c static int usb_resume_both(struct usb_device *udev, pm_message_t msg) · line 1310
Quoted 6 lines
drivers/usb/core/driver.c +6
-0+ goto out; + } + +/* Spec says host must suspend the bus with in 2 sec. */ +if (*status & (1 <<HOST_REQUEST_FLAG )) { +do_unbind_rebind (udev,DO_UNBIND );You forget to set
udev->do_remote_wakeupto 0.
Thanks for pointing this out. I will fix it in V2.
Thanks,
Pavan
Signature · 2 lines
Sent by a consultant of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
Re: [RFC 2/5] USB: core: OTG Supplement Revision 2.0 updates
In reply to Pavankumar Kondetidrivers/usb/core/driver.c static int usb_suspend_both(struct usb_device *udev, pm_message_t msg) · line 1210
Quoted 7 lines · Pavankumar Kondeti
drivers/usb/core/driver.c +1
-0@@ -1207,6 +1207,19 @@ static int usb_suspend_both(struct usb_device *udev, pm_message_t msg)* and flush any outstanding URBs. */ }else { +#ifdef CONFIG_USB_OTG
No ifdefs allowed, sorry.
Please rework this.
thanks,
greg k-h
Re: [RFC 2/5] USB: core: OTG Supplement Revision 2.0 updates
Quoted 11 lines · Greg KH
drivers/usb/core/driver.c static int usb_suspend_both(struct usb_device *udev, pm_message_t msg) · line 1210
Quoted 7 lines · Pavankumar Kondeti
drivers/usb/core/driver.c +1
-0@@ -1207,6 +1207,19 @@ static int usb_suspend_both(struct usb_device *udev, pm_message_t msg)* and flush any outstanding URBs. */ }else { +#ifdef CONFIG_USB_OTG No ifdefs allowed, sorry.
Quoted 2 lines
Please rework this.
I have seen using CONFIG_USB_OTG in core/hub.c and followed the same. But the code I have added does not have to depend on CONFGI_USB_OTG.
I will fix this in V2 patch set.
Thanks,
Pavan
Signature · 2 lines
Sent by a consultant of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
RFC 3/5 USB: gadget: OTG supplement revision 2.0 updates
In reply to Pavankumar KondetiIntroduce otg_version field in usb_gadget struct. UDC can advertise OTG spec version compatibility by setting otg_version field appropriately. Gadget drivers fill the bcdOTG field in OTG descriptor based on UDC's OTG version.
Add sysfs file for host_request and UDC returns the same when HNP polling request arrives from the host.
---
This patch changes only gadget Zero. But the final patch will add OTG2.0 support for all the gadget drivers.
.../testing/sysfs-devices-platform-_UDC_-gadget | 14 +++++++++++ drivers/usb/gadget/composite.c | 25 +++++++++++++++++++- drivers/usb/gadget/zero.c | 3 ++ include/linux/usb/gadget.h | 21 ++++++++++++++++ 4 files changed, 62 insertions(+), 1 deletions(-)
Documentation/ABI/testing/sysfs-devices-platform-_UDC_-gadget +14 -0
@@ -19,3 +19,17 @@ Description: Possible values are: 1 -> ignore the FUA flag 0 -> obey the FUA flag + +What: /sys/devices/platform/_UDC_/gadget/host_request +Date: December 2010 +Contact: Pavan Kondeti <[email protected]> +Description: + OTG 2.0 compliant host keeps polling OTG2.0 peripheral + for host role. Set host_request flag, which tells host + to give up the host role to peripheral. + + 1 -> host role is requested + 0 -> no effect (automatically cleared upon reset/disconnect) + + (_UDC_ is the name of the USB Device Controller driver) +
drivers/usb/gadget/composite.c +24 -1
@@ -978,6 +978,7 @@ static void composite_disconnect(struct usb_gadget *gadget)struct usb_composite_dev *cdev =get_gadget_data (gadget);unsigned long flags; + gadget->host_request =0 ;/* REVISIT: should we have config and device level * disconnect callbacks? */
@@ -1003,6 +1004,23 @@ static ssize_t composite_show_suspended(struct device *dev, static DEVICE_ATTR(suspended, 0444, composite_show_suspended, NULL); +static ssize_t composite_set_host_request (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count) +{ +struct usb_gadget *gadget =dev_to_usb_gadget (dev); +int value; + +if (sscanf (buf,"%d" , &value) !=1 ) +return -EINVAL ; + + gadget->host_request = !!value; +return count; + +} + +static DEVICE_ATTR(host_request, S_IWUSR, NULL, composite_set_host_request); +static void composite_unbind (struct usb_gadget *gadget) {
@@ -1047,9 +1065,10 @@ composite_unbind(struct usb_gadget *gadget)kfree (cdev->req->buf);usb_ep_free_request (gadget->ep0, cdev->req); } +device_remove_file (&gadget->dev, &dev_attr_host_request); +device_remove_file (&gadget->dev, &dev_attr_suspended);kfree (cdev);set_gadget_data (gadget,NULL ); -device_remove_file (&gadget->dev, &dev_attr_suspended); composite =NULL ; }
@@ -1158,6 +1177,10 @@ static int composite_bind(struct usb_gadget *gadget)if (status) goto fail; + status =device_create_file (&gadget->dev, &dev_attr_host_request); +if (status) +DBG (cdev,"unable to create host_request sysfs file\n" ); +INFO (cdev,"%s ready\n" , composite->name);return 0 ;
drivers/usb/gadget/zero.c +3 -0
@@ -293,6 +293,9 @@ static int __init zero_bind(struct usb_composite_dev *cdev)setup_timer (&autoresume_timer, zero_autoresume, (unsigned long ) cdev); +if (gadget_is_otg2 (cdev->gadget)) + otg_descriptor.bcdOTG =__constant_cpu_to_le16 (0x0200 ); +/* Register primary, then secondary configuration. Note that * SH3 only allows one config... */
include/linux/usb/gadget.h +21 -0
@@ -443,6 +443,8 @@ struct usb_gadget_ops {* operation. If it does, the gadget driver must also support both. * @is_otg: True if the USB device port uses a Mini-AB jack, so that the * gadget driver must provide a USB OTG descriptor. +* @otg_version: UDC OTG version based on which gadget driver fills the +* bcdOTG field in a USB OTG descriptor. * @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.
@@ -452,6 +454,7 @@ struct usb_gadget_ops {* only supports HNP on a different root port. * @b_hnp_enable: OTG device feature flag, indicating that the A-Host * enabled HNP support. +* @host_request: A Flag, indicating that user wishes to take the host role. * @name: Identifies the controller hardware type. Used in diagnostics * and sometimes configuration. * @dev: Driver model state for this abstract device.
@@ -482,10 +485,14 @@ struct usb_gadget {enum usb_device_speed speed; unsigned is_dualspeed:1; unsigned is_otg:1; +u16 otg_version; +#define UDC_OTG1 0x0000 +#define UDC_OTG2 0x0001 unsigned is_a_peripheral:1; unsigned b_hnp_enable:1; unsigned a_hnp_support:1; unsigned a_alt_hnp_support:1; + unsigned host_request:1;const char *name;struct device dev; };
@@ -537,6 +544,20 @@ static inline int gadget_is_otg(struct usb_gadget *g) }/** +* gadget_is_otg2 - return true if UDC is compliant to OTG 2.0 +* @g: controller that might have a Mini-AB/Micro-AB connector +* +*/ +static inline int gadget_is_otg2 (struct usb_gadget *g) +{ +#ifdef CONFIG_USB_OTG +return g->otg_version &&UDC_OTG2 ; +#else +return 0 ; +#endif +} + +/** * usb_gadget_frame_number - returns the current frame number * @gadget: controller that reports the frame number *
Signature · 5 lines
1.7.1 -- Sent by a consultant of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
Re: [RFC 3/5] USB: gadget: OTG supplement revision 2.0 updates
Hi,
drivers/usb/gadget/composite.c composite_unbind(struct usb_gadget *gadget) · line 1052
Quoted 9 lines · Pavankumar Kondeti
drivers/usb/gadget/composite.c +2
-1@@ -1047,9 +1065,10 @@ composite_unbind(struct usb_gadget *gadget)kfree (cdev->req->buf);usb_ep_free_request (gadget->ep0, cdev->req); } +device_remove_file (&gadget->dev, &dev_attr_host_request); +device_remove_file (&gadget->dev, &dev_attr_suspended);kfree (cdev);set_gadget_data (gadget,NULL ); -device_remove_file (&gadget->dev, &dev_attr_suspended);
this looks like something that shouldn't be part of this patch ?!?
Signature · 1 line
balbi
Re: [RFC 3/5] USB: gadget: OTG supplement revision 2.0 updates
Quoted 15 lines · Felipe Balbi
Hi,
drivers/usb/gadget/composite.c composite_unbind(struct usb_gadget *gadget) · line 1052
Quoted 9 lines · Pavankumar Kondeti
drivers/usb/gadget/composite.c +2
-1@@ -1047,9 +1065,10 @@ composite_unbind(struct usb_gadget *gadget)kfree (cdev->req->buf);usb_ep_free_request (gadget->ep0, cdev->req); } +device_remove_file (&gadget->dev, &dev_attr_host_request); +device_remove_file (&gadget->dev, &dev_attr_suspended);kfree (cdev);set_gadget_data (gadget,NULL ); -device_remove_file (&gadget->dev, &dev_attr_suspended);this looks like something that shouldn't be part of this patch ?!?
Yeah. I will send another patch for removing suspended sysfs file before freeing the cdev.
Thanks,
Pavan
Signature · 2 lines
Sent by a consultant of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
RFC 4/5 USB: EHCI: Notify HCD about HNP enabled port suspend
In reply to Pavankumar KondetiIntroduce start_hnp callback function for HCD to receive notification from EHCI core that HNP enabled port is suspended. HCD may initiate HNP or notify the same to OTG via otg_start_hnp().
This patch is inspired by "USB: Hook start_hnp into ohci struct" (e8b24450).
--- drivers/usb/host/ehci-hub.c | 11 +++++++++++ drivers/usb/host/ehci.h | 2 ++ 2 files changed, 13 insertions(+), 0 deletions(-)
drivers/usb/host/ehci-hub.c +11 -0
@@ -1018,6 +1018,17 @@ static int ehci_hub_control ( || (temp & PORT_RESET) != 0) goto error; +#ifdef CONFIG_USB_OTG +if (hcd->self.otg_port == (wIndex +1 ) && + hcd->self.b_hnp_enable && + ehci->start_hnp) { +ehci_writel (ehci, temp |PORT_SUSPEND , + status_reg); +set_bit (wIndex, &ehci->suspended_ports); + ehci->start_hnp (ehci); +break ; + } +#endif /* After above check the port must be connected. * Set appropriate bit thus could put phy into low power * mode if we have hostpc feature
drivers/usb/host/ehci.h +2 -0
@@ -122,6 +122,8 @@ struct ehci_hcd { /* one per controller */ktime_t last_periodic_enable;u32 command; +void (*start_hnp)(struct ehci_hcd *ehci); +/* SILICON QUIRKS */ unsigned no_selective_suspend:1; unsigned has_fsl_port_bug:1; /* FreeScale */
Signature · 5 lines
1.7.1 -- Sent by a consultant of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
Re: [RFC 4/5] USB: EHCI: Notify HCD about HNP enabled port suspend
Hi,
Quoted 20 lines · Pavankumar Kondeti
Introduce
start_hnpcallback function for HCD to receive notification from EHCI core that HNP enabled port is suspended. HCD may initiate HNP or notify the same to OTG viaotg_start_hnp().This patch is inspired by "USB: Hook
start_hnpinto ohci struct" (e8b24450).Change-Id I8e258a6fdf42c166ea9cb3a727e4d3d28a8adc72Signed-off-by Pavankumar Kondeti <[email protected]>---
drivers/usb/host/ehci-hub.c| 11 +++++++++++drivers/usb/host/ehci.h| 2 ++2 files changed, 13 insertions(+), 0 deletions(-)drivers/usb/host/ehci-hub.c +0
-0@@ -1018,6 +1018,17 @@ static int ehci_hub_control ( || (temp & PORT_RESET) != 0)
drivers/usb/host/ehci-hub.c static int ehci_hub_control ( · line 1028
Quoted 10 lines
drivers/usb/host/ehci-hub.c +8
-0goto error; +#ifdef CONFIG_USB_OTG +if (hcd->self.otg_port == (wIndex +1 ) && + hcd->self.b_hnp_enable && + ehci->start_hnp) { +ehci_writel (ehci, temp |PORT_SUSPEND , + status_reg); +set_bit (wIndex, &ehci->suspended_ports); + ehci->start_hnp (ehci);
should you check if this pointer is valid before ?
Signature · 1 line
balbi
Re: [RFC 4/5] USB: EHCI: Notify HCD about HNP enabled port suspend
Quoted 25 lines · Felipe Balbi
Hi,
Quoted 22 lines · Pavankumar Kondeti
Introduce
start_hnpcallback function for HCD to receive notification from EHCI core that HNP enabled port is suspended. HCD may initiate HNP or notify the same to OTG viaotg_start_hnp().This patch is inspired by "USB: Hook
start_hnpinto ohci struct" (e8b24450).Change-Id I8e258a6fdf42c166ea9cb3a727e4d3d28a8adc72Signed-off-by Pavankumar Kondeti <[email protected]>---
drivers/usb/host/ehci-hub.c| 11 +++++++++++drivers/usb/host/ehci.h| 2 ++2 files changed, 13 insertions(+), 0 deletions(-)drivers/usb/host/ehci-hub.c +0
-0@@ -1018,6 +1018,17 @@ static int ehci_hub_control ( || (temp & PORT_RESET) != 0) goto error;
Quoted 4 lines
drivers/usb/host/ehci-hub.c static int ehci_hub_control ( · line 1024
Quoted 4 lines
drivers/usb/host/ehci-hub.c +4
-0+#ifdef CONFIG_USB_OTG +if (hcd->self.otg_port == (wIndex +1 ) && + hcd->self.b_hnp_enable && + ehci->start_hnp) {
The pointer is checked here...
Quoted 7 lines
drivers/usb/host/ehci-hub.c static int ehci_hub_control ( · line 1028
Quoted 4 lines
drivers/usb/host/ehci-hub.c +4
-0+ehci_writel (ehci, temp |PORT_SUSPEND , + status_reg); +set_bit (wIndex, &ehci->suspended_ports); + ehci->start_hnp (ehci);should you check if this pointer is valid before ?
Signature · 2 lines
Sent by a consultant of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
RFC 5/5 USB: Eliminate delays involved in root hub initialization during HNP
In reply to Pavankumar KondetiSome USB controllers have common resources (IRQ, register address space) for Host, Peripheral and OTG. So HCD is added only before entering into Host mode. Root hub initialization is done in different steps to decrease boot up time. But this makes B-device difficult to meet HNP timings. Hence eliminate delays involved in root hub initialization for B-host.
This patch also marks hnp_supported flag TURE for B-host while registering the bus.
--- drivers/usb/core/hcd.c | 4 ++++ drivers/usb/core/hub.c | 13 +++++++++++++ 2 files changed, 17 insertions(+), 0 deletions(-)
drivers/usb/core/hcd.c +4 -0
@@ -902,6 +902,10 @@ static int usb_register_bus(struct usb_bus *bus)list_add (&bus->bus_list, &usb_bus_list);mutex_unlock (&usb_bus_list_lock); +#ifdef CONFIG_USB_OTG +if (bus->is_b_host) + bus->hnp_support =1 ; +#endif usb_notify_add_bus (bus); dev_info (bus->controller, "new USB bus registered, assigned bus "
drivers/usb/core/hub.c +13 -0
@@ -706,6 +706,10 @@ static void hub_activate(struct usb_hub *hub, enum hub_activation_type type)*/ if (type ==HUB_INIT ) { delay =hub_power_on (hub, false); +#ifdef CONFIG_USB_OTG +if (hdev->bus->is_b_host) + goto init2; +#endif PREPARE_DELAYED_WORK (&hub->init_work, hub_init_func2);schedule_delayed_work (&hub->init_work,msecs_to_jiffies (delay));
@@ -811,6 +815,11 @@ static void hub_activate(struct usb_hub *hub, enum hub_activation_type type) } } +#ifdef CONFIG_USB_OTG +if (hdev->bus->is_b_host && type ==HUB_INIT ) + goto init3; +#endif +/* If no port-status-change flags were set, we don't need any * debouncing. If flags were set we can try to debounce the * ports all at once right now, instead of letting khubd do them
@@ -844,6 +853,10 @@ static void hub_activate(struct usb_hub *hub, enum hub_activation_type type)/* Scan all ports that need attention */ kick_khubd (hub); +#ifdef CONFIG_USB_OTG +if (hdev->bus->is_b_host && type ==HUB_INIT ) +return ; +#endif /* Allow autosuspend if it was suppressed */ if (type <=HUB_INIT3 )usb_autopm_put_interface_async (to_usb_interface (hub->intfdev));
Signature · 5 lines
1.7.1 -- Sent by a consultant of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
Re: [RFC 5/5] USB: Eliminate delays involved in root hub initialization during HNP
Quoted 6 lines · Pavankumar Kondeti
Some USB controllers have common resources (IRQ, register address space) for Host, Peripheral and OTG. So HCD is added only before entering into Host mode. Root hub initialization is done in different steps to decrease boot up time. But this makes B-device difficult to meet HNP timings. Hence eliminate delays involved in root hub initialization for B-host.
I wonder if this is the best approach. Would it be easier to not touch usbcore, probe the entire stack during boot but have a "core" layer handling synchronization to shared resources ?
Maybe you could make your device an MFD device that allocates platform_devices for its children (HCI, UDC, OTG, etc) and pass in a bunch of read/write functions as platform_data for them to use as accessors to shared register space ?!? Would that work ?
Quoted 1 line
This patch also marks
hnp_supportedflag TURE for B-host while
s/TURE/TRUE
Signature · 1 line
balbi
Re: [RFC 5/5] USB: Eliminate delays involved in root hub initialization during HNP
Quoted 8 lines · Felipe Balbi
Quoted 6 lines · Pavankumar Kondeti
Some USB controllers have common resources (IRQ, register address space) for Host, Peripheral and OTG. So HCD is added only before entering into Host mode. Root hub initialization is done in different steps to decrease boot up time. But this makes B-device difficult to meet HNP timings. Hence eliminate delays involved in root hub initialization for B-host.
Quoted 4 lines
I wonder if this is the best approach. Would it be easier to not touch usbcore, probe the entire stack during boot but have a "core" layer handling synchronization to shared resources ?
The implementation is like this:
Actually OTG synchronizes UDC and HCD. OTG driver probe will be called first and it takes care of turning on clocks, resetting controller and PHY and enabling interrupts (VBUS and Id). UDC and HCD will not modify hardware registers in their probe functions. So HCD will not call usb_add_hcd() function in it's probe(). After HCD and UDC registers with OTG via otg_set_xxx(), OTG activates HCD (by calling usb_add_hcd()) or UDC (usb_gadget_connect()) based on Id/VBUS status. When gadget is active, HCD is detached from USB core (usb_remove_hcd()). So user space can not poke into sysfs/debugfs nodes provided in the usb core.
Quoted 5 lines
Maybe you could make your device an MFD device that allocates
platform_devicesfor its children (HCI, UDC, OTG, etc) and pass in a bunch of read/write functions asplatform_datafor them to use as accessors to shared register space ?!? Would that work ?
The easy way to deal this problem is removing HCD when Mini/Micro -A cable is detached.
This patch addresses the issues (usb_add_hcd() taking too much time )when B-peripheral becomes B-host.
Quoted 4 lines
Quoted 1 line
This patch also marks
hnp_supportedflag TURE for B-host whiles/TURE/TRUE
Fixed in V2.
Thanks,
Pavan
Signature · 2 lines
Sent by a consultant of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
Re: [RFC 5/5] USB: Eliminate delays involved in root hub initialization during HNP
Quoted 25 lines · Pavan Kondeti
Quoted 8 lines · Felipe Balbi
Quoted 6 lines · Pavankumar Kondeti
Some USB controllers have common resources (IRQ, register address space) for Host, Peripheral and OTG. So HCD is added only before entering into Host mode. Root hub initialization is done in different steps to decrease boot up time. But this makes B-device difficult to meet HNP timings. Hence eliminate delays involved in root hub initialization for B-host.
Quoted 4 lines
I wonder if this is the best approach. Would it be easier to not touch usbcore, probe the entire stack during boot but have a "core" layer handling synchronization to shared resources ?
The implementation is like this:
Actually OTG synchronizes UDC and HCD. OTG driver probe will be called first and it takes care of turning on clocks, resetting controller and PHY and enabling interrupts (VBUS and Id). UDC and HCD will not modify hardware registers in their probe functions. So HCD will not call
usb_add_hcd()function in it'sprobe(). After HCD and UDC registers with OTG viaotg_set_xxx(), OTG activates HCD (by callingusb_add_hcd()) or UDC (usb_gadget_connect()) based on Id/VBUS status. When gadget is active, HCD is detached from USB core (usb_remove_hcd()). So user space can not poke into sysfs/debugfs nodes provided in the usb core.
Quoted 7 lines
Quoted 5 lines
Maybe you could make your device an MFD device that allocates
platform_devicesfor its children (HCI, UDC, OTG, etc) and pass in a bunch of read/write functions asplatform_datafor them to use as accessors to shared register space ?!? Would that work ?The easy way to deal this problem is removing HCD when Mini/Micro -A cable is detached.
But why do you need to do that isn't clear. What's the problem in keeping HCD always available ? If it's a mini/micro-B cable you will enter peripheral role anyway.
Signature · 1 line
balbi
Re: [RFC 5/5] USB: Eliminate delays involved in root hub initialization during HNP
Quoted 31 lines · Felipe Balbi
Quoted 30 lines · Pavan Kondeti
Quoted 8 lines · Felipe Balbi
Quoted 6 lines · Pavankumar Kondeti
Some USB controllers have common resources (IRQ, register address space) for Host, Peripheral and OTG. So HCD is added only before entering into Host mode. Root hub initialization is done in different steps to decrease boot up time. But this makes B-device difficult to meet HNP timings. Hence eliminate delays involved in root hub initialization for B-host.
Quoted 4 lines
I wonder if this is the best approach. Would it be easier to not touch usbcore, probe the entire stack during boot but have a "core" layer handling synchronization to shared resources ?
The implementation is like this:
Actually OTG synchronizes UDC and HCD. OTG driver probe will be called first and it takes care of turning on clocks, resetting controller and PHY and enabling interrupts (VBUS and Id). UDC and HCD will not modify hardware registers in their probe functions. So HCD will not call
usb_add_hcd()function in it'sprobe(). After HCD and UDC registers with OTG viaotg_set_xxx(), OTG activates HCD (by callingusb_add_hcd()) or UDC (usb_gadget_connect()) based on Id/VBUS status. When gadget is active, HCD is detached from USB core (usb_remove_hcd()). So user space can not poke into sysfs/debugfs nodes provided in the usb core.Quoted 5 lines
Maybe you could make your device an MFD device that allocates
platform_devicesfor its children (HCI, UDC, OTG, etc) and pass in a bunch of read/write functions asplatform_datafor them to use as accessors to shared register space ?!? Would that work ?
Quoted 7 lines
Quoted 2 lines
The easy way to deal this problem is removing HCD when Mini/Micro -A cable is detached.
But why do you need to do that isn't clear. What's the problem in keeping HCD always available ? If it's a mini/micro-B cable you will enter peripheral role anyway.
If you keep the HCD, root hub auto/system suspend can happen, user may un-configure the root hub or remove the HCD etc. There is not standard way of guarding against PM & user for this kind of HCD.
We had a discussion about this some time back.
Please see http://www.spinics.net/lists/linux-usb/msg35847.html
Thanks,
Pavan
Signature · 2 lines
Sent by a consultant of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
Re: [RFC 5/5] USB: Eliminate delays involved in root hub initialization during HNP
In reply to Pavankumar KondetiQuoted 36 lines · Pavankumar Kondeti
Some USB controllers have common resources (IRQ, register address space) for Host, Peripheral and OTG. So HCD is added only before entering into Host mode. Root hub initialization is done in different steps to decrease boot up time. But this makes B-device difficult to meet HNP timings. Hence eliminate delays involved in root hub initialization for B-host.
This patch also marks
hnp_supportedflag TURE for B-host while registering the bus.Signed-off-by Pavankumar Kondeti <[email protected]>--- drivers/usb/core/hcd.c | 4 ++++ drivers/usb/core/hub.c | 13 +++++++++++++ 2 files changed, 17 insertions(+), 0 deletions(-)drivers/usb/core/hcd.c +4
-0@@ -902,6 +902,10 @@ static int usb_register_bus(struct usb_bus *bus)list_add (&bus->bus_list, &usb_bus_list);mutex_unlock (&usb_bus_list_lock); +#ifdef CONFIG_USB_OTG +if (bus->is_b_host) + bus->hnp_support =1 ; +#endif usb_notify_add_bus (bus); dev_info (bus->controller, "new USB bus registered, assigned bus "drivers/usb/core/hub.c +0
-0
drivers/usb/core/hub.c static void hub_activate(struct usb_hub *hub, enum hub_activation_type type) · line 712
Quoted 7 lines
drivers/usb/core/hub.c +4
-0@@ -706,6 +706,10 @@ static void hub_activate(struct usb_hub *hub, enum hub_activation_type type)*/ if (type ==HUB_INIT ) { delay =hub_power_on (hub, false); +#ifdef CONFIG_USB_OTG +if (hdev->bus->is_b_host) + goto init2; +#endif
Never have #ifdefs in .c code, that is totally unacceptable and unworkable for stuff like this.
Come on, you know better than this...
thanks,
greg k-h
Alan Stern
maintainerQuoted 6 lines · Pavankumar Kondeti
This patch series adds OTG 2.0 enhancements and misc changes required for supporting SRP & HNP in MSM OTG driver. As these patches modify the USB core code, I would like to receive feedback before posting driver patches. The driver patches are available at
https://www.codeaurora.org/gitweb/quic/la/?p=kernel/msm.git;a=commitdiff;h=05535a995e9eb34c3c41d874d09955a443008cd5
All those "#ifdef CONFIG_USB_OTG" lines you are sprinkling throughout the core are very annoying. A few simple inline routines should allow you to eliminate many of them.
Also, in the 5/5 patch in hub_activate(), all those
if (hdev->bus->is_b_host && type == HUB_INIT)
tests are distracting. You can make the test once, at the start of the function, and store the result in a local variable.
Alan Stern
Quoted 9 lines · Alan Stern
Quoted 6 lines · Pavankumar Kondeti
This patch series adds OTG 2.0 enhancements and misc changes required for supporting SRP & HNP in MSM OTG driver. As these patches modify the USB core code, I would like to receive feedback before posting driver patches. The driver patches are available at
https://www.codeaurora.org/gitweb/quic/la/?p=kernel/msm.git;a=commitdiff;h=05535a995e9eb34c3c41d874d09955a443008cd5
Quoted 4 lines
All those "#ifdef
CONFIG_USB_OTG" lines you are sprinkling throughout the core are very annoying. A few simple inline routines should allow you to eliminate many of them.
I am doing OTG specific operations only after checking bus->hnp_support, udev->port == bus->otg_port, which will be true only for OTG device and CONFIG_USB_OTG is enabled. So I guess I can put them directly without #ifdef.
Quoted 7 lines
Also, in the 5/5 patch in
hub_activate(), all thoseif (hdev->bus->is_b_host && type == HUB_INIT)tests are distracting. You can make the test once, at the start of the function, and store the result in a local variable.
Okay. I will fix this in V2.
Thanks,
Pavan
Signature · 2 lines
Sent by a consultant of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.