From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752720AbbEHK1I (ORCPT ); Fri, 8 May 2015 06:27:08 -0400 Received: from mga09.intel.com ([134.134.136.24]:59207 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752605AbbEHK1E (ORCPT ); Fri, 8 May 2015 06:27:04 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.13,390,1427785200"; d="scan'208";a="568295479" From: Lu Baolu To: Greg Kroah-Hartman , Mathias Nyman , Alan Stern Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH v4 2/3] usb: xhci: implement device_suspend/device_resume entries Date: Fri, 8 May 2015 18:26:27 +0800 Message-Id: <1431080788-20674-3-git-send-email-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1431080788-20674-1-git-send-email-baolu.lu@linux.intel.com> References: <1431080788-20674-1-git-send-email-baolu.lu@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- drivers/usb/host/xhci-hub.c | 2 +- drivers/usb/host/xhci.c | 38 ++++++++++++++++++++++++++++++++++++++ drivers/usb/host/xhci.h | 9 +++++++++ 3 files changed, 48 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..330961d 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -4680,6 +4680,38 @@ int xhci_disable_usb3_lpm_timeout(struct usb_hcd *hcd, return ret; return 0; } + +/* + * xHCI compatible host controller driver expects to be notified prior to + * selectively suspending a device. xHCI hcd could optimize the endpoint + * cache for power saving purpose. Refer to 4.15.1.1 of xHCI 1.1. + */ +void xhci_device_suspend(struct usb_hcd *hcd, struct usb_device *udev) +{ + 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); +} + +/* + * xHCI compatible host controller driver expects to be notified after a + * USB device is resumed. xHCI hcd could optimize the endpoint cache + * to reduce the latency. Refer to 4.15.1.1 of xHCI 1.1. + */ +void xhci_device_resume(struct usb_hcd *hcd, struct usb_device *udev) +{ + 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, @@ -4976,6 +5008,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..67c13c5 100644 --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h @@ -1867,10 +1867,19 @@ 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); +#ifdef CONFIG_PM +void xhci_device_suspend(struct usb_hcd *hcd, struct usb_device *udev); +void xhci_device_resume(struct usb_hcd *hcd, struct usb_device *udev); +#else +#define xhci_device_suspend NULL +#define xhci_device_resume NULL +#endif /* CONFIG_PM */ + #endif /* __LINUX_XHCI_HCD_H */ -- 2.1.0