From: Roger Quadros <rogerq@ti.com>
To: <gregkh@linuxfoundation.org>, <balbi@ti.com>,
<stern@rowland.harvard.edu>
Cc: <dan.j.williams@intel.com>, <peter.chen@freescale.com>,
<jun.li@freescale.com>, <mathias.nyman@linux.intel.com>,
<linux-usb@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<linux-omap@vger.kernel.org>, Roger Quadros <rogerq@ti.com>
Subject: [RFC][PATCH 1/9] usb: hcd: Introduce usb_start/stop_hcd()
Date: Wed, 18 Mar 2015 15:55:55 +0200 [thread overview]
Message-ID: <1426686963-11613-2-git-send-email-rogerq@ti.com> (raw)
In-Reply-To: <1426686963-11613-1-git-send-email-rogerq@ti.com>
To support OTG we want a mechanism to start and stop
the HCD from the OTG state machine. Add usb_start_hcd()
and usb_stop_hcd().
Signed-off-by: Roger Quadros <rogerq@ti.com>
---
drivers/usb/core/hcd.c | 147 ++++++++++++++++++++++++++++++++----------------
include/linux/usb/hcd.h | 2 +
2 files changed, 100 insertions(+), 49 deletions(-)
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index 45a915c..e28bd9d 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -2613,7 +2613,76 @@ static void usb_put_invalidate_rhdev(struct usb_hcd *hcd)
}
/**
- * usb_add_hcd - finish generic HCD structure initialization and register
+ * usb_start_hcd - start the HCD
+ * @hcd: the usb_hcd structure to initialize
+ *
+ * calls the drivers start() routine, registers the root hub
+ * and creates the USB sysfs attributes.
+ */
+int usb_start_hcd(struct usb_hcd *hcd)
+{
+ int retval;
+ struct usb_device *rhdev = hcd->self.root_hub;
+
+ if (hcd->state != HC_STATE_HALT) {
+ dev_err(hcd->self.controller, "not starting a running HCD\n");
+ return -EINVAL;
+ }
+
+ hcd->state = HC_STATE_RUNNING;
+ retval = hcd->driver->start(hcd);
+ if (retval < 0) {
+ dev_err(hcd->self.controller, "startup error %d\n", retval);
+ hcd->state = HC_STATE_HALT;
+ return retval;
+ }
+
+ /* starting here, usbcore will pay attention to this root hub */
+ if ((retval = register_root_hub(hcd)) != 0)
+ goto err_register_root_hub;
+
+ retval = sysfs_create_group(&rhdev->dev.kobj, &usb_bus_attr_group);
+ if (retval < 0) {
+ pr_err("Cannot register USB bus sysfs attributes: %d\n",
+ retval);
+ goto error_create_attr_group;
+ }
+ if (hcd->uses_new_polling && HCD_POLL_RH(hcd))
+ usb_hcd_poll_rh_status(hcd);
+
+ return retval;
+
+error_create_attr_group:
+ clear_bit(HCD_FLAG_RH_RUNNING, &hcd->flags);
+ if (HC_IS_RUNNING(hcd->state))
+ hcd->state = HC_STATE_QUIESCING;
+ spin_lock_irq(&hcd_root_hub_lock);
+ hcd->rh_registered = 0;
+ spin_unlock_irq(&hcd_root_hub_lock);
+
+#ifdef CONFIG_PM
+ cancel_work_sync(&hcd->wakeup_work);
+#endif
+ mutex_lock(&usb_bus_list_lock);
+ usb_disconnect(&rhdev); /* Sets rhdev to NULL */
+ mutex_unlock(&usb_bus_list_lock);
+err_register_root_hub:
+ hcd->rh_pollable = 0;
+ clear_bit(HCD_FLAG_POLL_RH, &hcd->flags);
+ del_timer_sync(&hcd->rh_timer);
+ hcd->driver->stop(hcd);
+ hcd->state = HC_STATE_HALT;
+
+ /* In case the HCD restarted the timer, stop it again. */
+ clear_bit(HCD_FLAG_POLL_RH, &hcd->flags);
+ del_timer_sync(&hcd->rh_timer);
+
+ return retval;
+}
+EXPORT_SYMBOL_GPL(usb_start_hcd);
+
+/**
+ * usb_add_hcd - finish generic HCD structure initialization and register.
* @hcd: the usb_hcd structure to initialize
* @irqnum: Interrupt line to allocate
* @irqflags: Interrupt type flags
@@ -2757,50 +2826,12 @@ int usb_add_hcd(struct usb_hcd *hcd,
goto err_request_irq;
}
- hcd->state = HC_STATE_RUNNING;
- retval = hcd->driver->start(hcd);
- if (retval < 0) {
- dev_err(hcd->self.controller, "startup error %d\n", retval);
+ retval = usb_start_hcd(hcd);
+ if (retval)
goto err_hcd_driver_start;
- }
-
- /* starting here, usbcore will pay attention to this root hub */
- if ((retval = register_root_hub(hcd)) != 0)
- goto err_register_root_hub;
-
- retval = sysfs_create_group(&rhdev->dev.kobj, &usb_bus_attr_group);
- if (retval < 0) {
- printk(KERN_ERR "Cannot register USB bus sysfs attributes: %d\n",
- retval);
- goto error_create_attr_group;
- }
- if (hcd->uses_new_polling && HCD_POLL_RH(hcd))
- usb_hcd_poll_rh_status(hcd);
-
- return retval;
-error_create_attr_group:
- clear_bit(HCD_FLAG_RH_RUNNING, &hcd->flags);
- if (HC_IS_RUNNING(hcd->state))
- hcd->state = HC_STATE_QUIESCING;
- spin_lock_irq(&hcd_root_hub_lock);
- hcd->rh_registered = 0;
- spin_unlock_irq(&hcd_root_hub_lock);
+ return 0;
-#ifdef CONFIG_PM
- cancel_work_sync(&hcd->wakeup_work);
-#endif
- mutex_lock(&usb_bus_list_lock);
- usb_disconnect(&rhdev); /* Sets rhdev to NULL */
- mutex_unlock(&usb_bus_list_lock);
-err_register_root_hub:
- hcd->rh_pollable = 0;
- clear_bit(HCD_FLAG_POLL_RH, &hcd->flags);
- del_timer_sync(&hcd->rh_timer);
- hcd->driver->stop(hcd);
- hcd->state = HC_STATE_HALT;
- clear_bit(HCD_FLAG_POLL_RH, &hcd->flags);
- del_timer_sync(&hcd->rh_timer);
err_hcd_driver_start:
if (usb_hcd_is_primary_hcd(hcd) && hcd->irq > 0)
free_irq(irqnum, hcd);
@@ -2830,18 +2861,20 @@ err_phy:
EXPORT_SYMBOL_GPL(usb_add_hcd);
/**
- * usb_remove_hcd - shutdown processing for generic HCDs
- * @hcd: the usb_hcd structure to remove
- * Context: !in_interrupt()
+ * usb_stop_hcd - stop the HCD
+ * @hcd: the usb_hcd structure to initialize
*
- * Disconnects the root hub, then reverses the effects of usb_add_hcd(),
- * invoking the HCD's stop() method.
+ * removes the USB sysfs attributes, disconnects the root hub
+ * and calls the driver's stop() routine.
*/
-void usb_remove_hcd(struct usb_hcd *hcd)
+void usb_stop_hcd(struct usb_hcd *hcd)
{
struct usb_device *rhdev = hcd->self.root_hub;
- dev_info(hcd->self.controller, "remove, state %x\n", hcd->state);
+ if (hcd->state == HC_STATE_HALT) {
+ dev_err(hcd->self.controller, "not stopping a halted HCD\n");
+ return;
+ }
usb_get_dev(rhdev);
sysfs_remove_group(&rhdev->dev.kobj, &usb_bus_attr_group);
@@ -2888,6 +2921,22 @@ void usb_remove_hcd(struct usb_hcd *hcd)
/* In case the HCD restarted the timer, stop it again. */
clear_bit(HCD_FLAG_POLL_RH, &hcd->flags);
del_timer_sync(&hcd->rh_timer);
+}
+EXPORT_SYMBOL_GPL(usb_stop_hcd);
+
+/**
+ * usb_remove_hcd - shutdown processing for generic HCDs
+ * @hcd: the usb_hcd structure to remove
+ * Context: !in_interrupt()
+ *
+ * Disconnects the root hub, then reverses the effects of usb_add_hcd(),
+ * invoking the HCD's stop() method.
+ */
+void usb_remove_hcd(struct usb_hcd *hcd)
+{
+ dev_info(hcd->self.controller, "remove, state %x\n", hcd->state);
+
+ usb_stop_hcd(hcd);
if (usb_hcd_is_primary_hcd(hcd)) {
if (hcd->irq > 0)
diff --git a/include/linux/usb/hcd.h b/include/linux/usb/hcd.h
index 68b1e83..12aaf4c 100644
--- a/include/linux/usb/hcd.h
+++ b/include/linux/usb/hcd.h
@@ -433,6 +433,8 @@ extern void usb_put_hcd(struct usb_hcd *hcd);
extern int usb_hcd_is_primary_hcd(struct usb_hcd *hcd);
extern int usb_add_hcd(struct usb_hcd *hcd,
unsigned int irqnum, unsigned long irqflags);
+extern int usb_start_hcd(struct usb_hcd *hcd);
+extern void usb_stop_hcd(struct usb_hcd *hcd);
extern void usb_remove_hcd(struct usb_hcd *hcd);
extern int usb_hcd_find_raw_port_number(struct usb_hcd *hcd, int port1);
--
2.1.0
next prev parent reply other threads:[~2015-03-18 13:56 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-18 13:55 [RFC][PATCH 0/9] USB: OTG Core functionality Roger Quadros
2015-03-18 13:55 ` Roger Quadros [this message]
2015-03-18 19:49 ` [RFC][PATCH 1/9] usb: hcd: Introduce usb_start/stop_hcd() Alan Stern
2015-03-18 21:41 ` Tony Lindgren
2015-03-19 1:51 ` Alan Stern
2015-03-19 2:38 ` Tony Lindgren
2015-03-19 11:38 ` Roger Quadros
2015-03-19 14:17 ` Alan Stern
2015-03-20 6:32 ` Peter Chen
2015-03-20 9:49 ` Roger Quadros
2015-03-19 1:46 ` Peter Chen
2015-03-18 13:55 ` [RFC][PATCH 2/9] usb: gadget: add usb_gadget_start/stop() Roger Quadros
2015-03-19 3:30 ` Peter Chen
2015-03-19 10:14 ` Roger Quadros
2015-03-19 14:09 ` Li Jun
2015-03-19 14:50 ` Roger Quadros
2015-03-20 7:18 ` Peter Chen
2015-03-20 9:46 ` Roger Quadros
2015-03-20 11:08 ` Roger Quadros
2015-03-21 1:30 ` Peter Chen
2015-03-18 13:55 ` [RFC][PATCH 3/9] usb: otg: add OTG core Roger Quadros
2015-03-19 3:40 ` Peter Chen
2015-03-19 10:18 ` Roger Quadros
2015-03-20 7:45 ` Peter Chen
2015-03-20 9:18 ` Roger Quadros
2015-03-20 9:32 ` Peter Chen
2015-03-19 8:26 ` Li Jun
2015-03-19 10:30 ` Roger Quadros
2015-03-19 14:41 ` Li Jun
2015-03-19 14:54 ` Roger Quadros
2015-03-18 13:55 ` [RFC][PATCH 4/9] usb: otg: hub: Notify OTG fsm when A device sets b_hnp_enable Roger Quadros
2015-03-18 13:55 ` [RFC][PATCH 5/9] usb: hcd: adapt to OTG Roger Quadros
2015-03-18 13:56 ` [RFC][PATCH 6/9] usb: gadget: udc: " Roger Quadros
2015-03-18 13:56 ` [RFC][PATCH 7/9] usb: dwc3: adapt to OTG core Roger Quadros
2015-03-18 13:56 ` [RFC][PATCH 8/9] usb: otg-fsm: Remove unused members in struct otg_fsm Roger Quadros
2015-03-19 3:46 ` Peter Chen
2015-03-19 10:20 ` Roger Quadros
2015-03-18 13:56 ` [RFC][PATCH 9/9] usb: otg-fsm: Add documentation for " Roger Quadros
2015-03-18 17:37 ` [RFC][PATCH 0/9] USB: OTG Core functionality Tony Lindgren
2015-03-19 10:31 ` Roger Quadros
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1426686963-11613-2-git-send-email-rogerq@ti.com \
--to=rogerq@ti.com \
--cc=balbi@ti.com \
--cc=dan.j.williams@intel.com \
--cc=gregkh@linuxfoundation.org \
--cc=jun.li@freescale.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-omap@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=mathias.nyman@linux.intel.com \
--cc=peter.chen@freescale.com \
--cc=stern@rowland.harvard.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®