linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3] HID: intel-ish-hid: Replace PCI_DEV_FLAGS_NO_D3 with pci_save_state
@ 2020-06-29  4:16 Kai-Heng Feng
  2020-06-29 18:43 ` Srinivas Pandruvada
  2020-07-07 10:19 ` Jiri Kosina
  0 siblings, 2 replies; 3+ messages in thread
From: Kai-Heng Feng @ 2020-06-29  4:16 UTC (permalink / raw)
  To: srinivas.pandruvada
  Cc: Kai-Heng Feng, Jiri Kosina, Benjamin Tissoires, Zhang Lixu,
	Even Xu, open list:INTEL INTEGRATED SENSOR HUB DRIVER, open list

PCI_DEV_FLAGS_NO_D3 should not be used outside of PCI core.

Instead, we can use pci_save_state() to hint PCI core that the device
should stay at D0 during suspend. By doing so, PCI core will let the
upstream bridges also stays at D0 so the entire hierarchy is in the
correct power state as PCI spec mandates.

Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
---
v3:
 - Use multi-line comments.
v2:
 - Wording change.

 drivers/hid/intel-ish-hid/ipc/pci-ish.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/drivers/hid/intel-ish-hid/ipc/pci-ish.c b/drivers/hid/intel-ish-hid/ipc/pci-ish.c
index f491d8b4e24c..c6d48a8648b7 100644
--- a/drivers/hid/intel-ish-hid/ipc/pci-ish.c
+++ b/drivers/hid/intel-ish-hid/ipc/pci-ish.c
@@ -106,6 +106,11 @@ static inline bool ish_should_enter_d0i3(struct pci_dev *pdev)
 	return !pm_suspend_via_firmware() || pdev->device == CHV_DEVICE_ID;
 }
 
+static inline bool ish_should_leave_d0i3(struct pci_dev *pdev)
+{
+	return !pm_resume_via_firmware() || pdev->device == CHV_DEVICE_ID;
+}
+
 /**
  * ish_probe() - PCI driver probe callback
  * @pdev:	pci device
@@ -215,9 +220,7 @@ static void __maybe_unused ish_resume_handler(struct work_struct *work)
 	struct ishtp_device *dev = pci_get_drvdata(pdev);
 	int ret;
 
-	/* Check the NO_D3 flag to distinguish the resume paths */
-	if (pdev->dev_flags & PCI_DEV_FLAGS_NO_D3) {
-		pdev->dev_flags &= ~PCI_DEV_FLAGS_NO_D3;
+	if (ish_should_leave_d0i3(pdev) && !dev->suspend_flag) {
 		disable_irq_wake(pdev->irq);
 
 		ishtp_send_resume(dev);
@@ -281,8 +284,11 @@ static int __maybe_unused ish_suspend(struct device *device)
 			 */
 			ish_disable_dma(dev);
 		} else {
-			/* Set the NO_D3 flag, the ISH would enter D0i3 */
-			pdev->dev_flags |= PCI_DEV_FLAGS_NO_D3;
+			/*
+			 * Save state so PCI core will keep the device at D0,
+			 * the ISH would enter D0i3
+			 */
+			pci_save_state(pdev);
 
 			enable_irq_wake(pdev->irq);
 		}
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v3] HID: intel-ish-hid: Replace PCI_DEV_FLAGS_NO_D3 with pci_save_state
  2020-06-29  4:16 [PATCH v3] HID: intel-ish-hid: Replace PCI_DEV_FLAGS_NO_D3 with pci_save_state Kai-Heng Feng
@ 2020-06-29 18:43 ` Srinivas Pandruvada
  2020-07-07 10:19 ` Jiri Kosina
  1 sibling, 0 replies; 3+ messages in thread
From: Srinivas Pandruvada @ 2020-06-29 18:43 UTC (permalink / raw)
  To: Kai-Heng Feng
  Cc: Jiri Kosina, Benjamin Tissoires, Zhang Lixu, Even Xu,
	open list:INTEL INTEGRATED SENSOR HUB DRIVER, open list

On Mon, 2020-06-29 at 12:16 +0800, Kai-Heng Feng wrote:
> PCI_DEV_FLAGS_NO_D3 should not be used outside of PCI core.
> 
> Instead, we can use pci_save_state() to hint PCI core that the device
> should stay at D0 during suspend. By doing so, PCI core will let the
> upstream bridges also stays at D0 so the entire hierarchy is in the
> correct power state as PCI spec mandates.
> 
> Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
Acked-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>

> ---
> v3:
>  - Use multi-line comments.
> v2:
>  - Wording change.
> 
>  drivers/hid/intel-ish-hid/ipc/pci-ish.c | 16 +++++++++++-----
>  1 file changed, 11 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/hid/intel-ish-hid/ipc/pci-ish.c
> b/drivers/hid/intel-ish-hid/ipc/pci-ish.c
> index f491d8b4e24c..c6d48a8648b7 100644
> --- a/drivers/hid/intel-ish-hid/ipc/pci-ish.c
> +++ b/drivers/hid/intel-ish-hid/ipc/pci-ish.c
> @@ -106,6 +106,11 @@ static inline bool ish_should_enter_d0i3(struct
> pci_dev *pdev)
>  	return !pm_suspend_via_firmware() || pdev->device ==
> CHV_DEVICE_ID;
>  }
>  
> +static inline bool ish_should_leave_d0i3(struct pci_dev *pdev)
> +{
> +	return !pm_resume_via_firmware() || pdev->device ==
> CHV_DEVICE_ID;
> +}
> +
>  /**
>   * ish_probe() - PCI driver probe callback
>   * @pdev:	pci device
> @@ -215,9 +220,7 @@ static void __maybe_unused
> ish_resume_handler(struct work_struct *work)
>  	struct ishtp_device *dev = pci_get_drvdata(pdev);
>  	int ret;
>  
> -	/* Check the NO_D3 flag to distinguish the resume paths */
> -	if (pdev->dev_flags & PCI_DEV_FLAGS_NO_D3) {
> -		pdev->dev_flags &= ~PCI_DEV_FLAGS_NO_D3;
> +	if (ish_should_leave_d0i3(pdev) && !dev->suspend_flag) {
>  		disable_irq_wake(pdev->irq);
>  
>  		ishtp_send_resume(dev);
> @@ -281,8 +284,11 @@ static int __maybe_unused ish_suspend(struct
> device *device)
>  			 */
>  			ish_disable_dma(dev);
>  		} else {
> -			/* Set the NO_D3 flag, the ISH would enter D0i3
> */
> -			pdev->dev_flags |= PCI_DEV_FLAGS_NO_D3;
> +			/*
> +			 * Save state so PCI core will keep the device
> at D0,
> +			 * the ISH would enter D0i3
> +			 */
> +			pci_save_state(pdev);
>  
>  			enable_irq_wake(pdev->irq);
>  		}


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v3] HID: intel-ish-hid: Replace PCI_DEV_FLAGS_NO_D3 with pci_save_state
  2020-06-29  4:16 [PATCH v3] HID: intel-ish-hid: Replace PCI_DEV_FLAGS_NO_D3 with pci_save_state Kai-Heng Feng
  2020-06-29 18:43 ` Srinivas Pandruvada
@ 2020-07-07 10:19 ` Jiri Kosina
  1 sibling, 0 replies; 3+ messages in thread
From: Jiri Kosina @ 2020-07-07 10:19 UTC (permalink / raw)
  To: Kai-Heng Feng
  Cc: srinivas.pandruvada, Benjamin Tissoires, Zhang Lixu, Even Xu,
	open list:INTEL INTEGRATED SENSOR HUB DRIVER, open list

On Mon, 29 Jun 2020, Kai-Heng Feng wrote:

> PCI_DEV_FLAGS_NO_D3 should not be used outside of PCI core.
> 
> Instead, we can use pci_save_state() to hint PCI core that the device
> should stay at D0 during suspend. By doing so, PCI core will let the
> upstream bridges also stays at D0 so the entire hierarchy is in the
> correct power state as PCI spec mandates.
> 
> Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
> ---
> v3:
>  - Use multi-line comments.
> v2:
>  - Wording change.

Applied, thanks.

-- 
Jiri Kosina
SUSE Labs


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-07-07 10:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-06-29  4:16 [PATCH v3] HID: intel-ish-hid: Replace PCI_DEV_FLAGS_NO_D3 with pci_save_state Kai-Heng Feng
2020-06-29 18:43 ` Srinivas Pandruvada
2020-07-07 10:19 ` Jiri Kosina

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).