From: Lu Baolu <baolu.lu@linux.intel.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Mathias Nyman <mathias.nyman@intel.com>,
Alan Stern <stern@rowland.harvard.edu>
Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
Lu Baolu <baolu.lu@linux.intel.com>
Subject: [PATCH v2 2/3] usb: xhci: implement device_suspend/device_resume entries
Date: Wed, 6 May 2015 15:40:01 +0800 [thread overview]
Message-ID: <1430898002-24748-3-git-send-email-baolu.lu@linux.intel.com> (raw)
In-Reply-To: <1430898002-24748-1-git-send-email-baolu.lu@linux.intel.com>
This patch implements device_suspend/device_resume entries for xHC driver.
device_suspend will be called when a USB device is about to suspend. It
will issue a stop endpoint command for each endpoint in this device. The
Suspend(SP) bit in the command TRB will set which will give xHC a hint
about the suspend. device_resume will be called when a USB device is just
resumed. It will ring doorbells of all endpoint unconditionally. XHC may
use these suspend/resume hints to optimize its operation.
Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
---
drivers/usb/host/xhci-hub.c | 2 +-
drivers/usb/host/xhci.c | 40 ++++++++++++++++++++++++++++++++++++++++
drivers/usb/host/xhci.h | 5 +++++
3 files changed, 46 insertions(+), 1 deletion(-)
diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c
index 0827d7c..a83e82e 100644
--- a/drivers/usb/host/xhci-hub.c
+++ b/drivers/usb/host/xhci-hub.c
@@ -266,7 +266,7 @@ int xhci_find_slot_id_by_port(struct usb_hcd *hcd, struct xhci_hcd *xhci,
* to complete.
* suspend will set to 1, if suspend bit need to set in command.
*/
-static int xhci_stop_device(struct xhci_hcd *xhci, int slot_id, int suspend)
+int xhci_stop_device(struct xhci_hcd *xhci, int slot_id, int suspend)
{
struct xhci_virt_device *virt_dev;
struct xhci_command *cmd;
diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index ec8ac16..b639627 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -4680,6 +4680,30 @@ int xhci_disable_usb3_lpm_timeout(struct usb_hcd *hcd,
return ret;
return 0;
}
+
+void xhci_device_suspend(struct usb_hcd *hcd,
+ struct usb_device *udev, pm_message_t msg)
+{
+ struct xhci_hcd *xhci;
+
+ xhci = hcd_to_xhci(hcd);
+ if (!xhci || !xhci->devs[udev->slot_id])
+ return;
+
+ xhci_stop_device(xhci, udev->slot_id, 1);
+}
+
+void xhci_device_resume(struct usb_hcd *hcd,
+ struct usb_device *udev, pm_message_t msg)
+{
+ struct xhci_hcd *xhci;
+
+ xhci = hcd_to_xhci(hcd);
+ if (!xhci || !xhci->devs[udev->slot_id])
+ return;
+
+ xhci_ring_device(xhci, udev->slot_id);
+}
#else /* CONFIG_PM */
int xhci_set_usb2_hardware_lpm(struct usb_hcd *hcd,
@@ -4704,6 +4728,16 @@ int xhci_disable_usb3_lpm_timeout(struct usb_hcd *hcd,
{
return 0;
}
+
+void xhci_device_suspend(struct usb_hcd *hcd,
+ struct usb_device *udev, pm_message_t msg)
+{
+}
+
+void xhci_device_resume(struct usb_hcd *hcd,
+ struct usb_device *udev, pm_message_t msg)
+{
+}
#endif /* CONFIG_PM */
/*-------------------------------------------------------------------------*/
@@ -4976,6 +5010,12 @@ static const struct hc_driver xhci_hc_driver = {
.enable_usb3_lpm_timeout = xhci_enable_usb3_lpm_timeout,
.disable_usb3_lpm_timeout = xhci_disable_usb3_lpm_timeout,
.find_raw_port_number = xhci_find_raw_port_number,
+
+ /*
+ * call back when devices suspend or resume
+ */
+ .device_suspend = xhci_device_suspend,
+ .device_resume = xhci_device_resume,
};
void xhci_init_driver(struct hc_driver *drv, int (*setup_fn)(struct usb_hcd *))
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index 8e421b8..3d1f73b 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -1867,10 +1867,15 @@ u32 xhci_port_state_to_neutral(u32 state);
int xhci_find_slot_id_by_port(struct usb_hcd *hcd, struct xhci_hcd *xhci,
u16 port);
void xhci_ring_device(struct xhci_hcd *xhci, int slot_id);
+int xhci_stop_device(struct xhci_hcd *xhci, int slot_id, int suspend);
/* xHCI contexts */
struct xhci_input_control_ctx *xhci_get_input_control_ctx(struct xhci_container_ctx *ctx);
struct xhci_slot_ctx *xhci_get_slot_ctx(struct xhci_hcd *xhci, struct xhci_container_ctx *ctx);
struct xhci_ep_ctx *xhci_get_ep_ctx(struct xhci_hcd *xhci, struct xhci_container_ctx *ctx, unsigned int ep_index);
+void xhci_device_suspend(struct usb_hcd *hcd,
+ struct usb_device *udev, pm_message_t msg);
+void xhci_device_resume(struct usb_hcd *hcd,
+ struct usb_device *udev, pm_message_t msg);
#endif /* __LINUX_XHCI_HCD_H */
--
2.1.0
next prev parent reply other threads:[~2015-05-06 7:40 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-06 7:39 [PATCH v2 0/3] usb: notify hcd when USB device suspend or resume Lu Baolu
2015-05-06 7:40 ` [PATCH v2 1/3] " Lu Baolu
2015-05-06 14:35 ` Alan Stern
2015-05-07 0:27 ` Lu, Baolu
2015-05-07 14:34 ` Alan Stern
2015-05-08 1:14 ` Lu, Baolu
2015-05-08 14:21 ` Alan Stern
2015-05-09 0:42 ` Lu, Baolu
2015-05-11 14:25 ` Alan Stern
2015-05-12 2:05 ` Lu, Baolu
2015-05-12 15:54 ` Alan Stern
2015-05-13 2:36 ` Lu, Baolu
2015-05-13 14:14 ` Alan Stern
2015-05-08 7:55 ` Lu, Baolu
2015-05-06 7:40 ` Lu Baolu [this message]
2015-05-06 14:30 ` [PATCH v2 2/3] usb: xhci: implement device_suspend/device_resume entries Alan Stern
2015-05-07 0:30 ` Lu, Baolu
2015-05-06 7:40 ` [PATCH v2 3/3] usb: xhci: remove stop device and ring doorbell in hub control and bus suspend Lu Baolu
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=1430898002-24748-3-git-send-email-baolu.lu@linux.intel.com \
--to=baolu.lu@linux.intel.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=mathias.nyman@intel.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