diff mbox

[v2,3/3] ata: allow runtime pm of transport layer if no devices attached

Message ID 20180420101834.15783-3-0v3rdr0n3@gmail.com (mailing list archive)
State Not Applicable, archived
Headers show

Commit Message

0v3rdr0n3@gmail.com April 20, 2018, 10:18 a.m. UTC
From: Samuel Morris <samorris@lexmark.com>

If no devices are detected on boot, and hotplug is disabled, let the
transport layer suspend automatically to save power.

Signed-off-by: Samuel Morris <samorris@lexmark.com>
---
Changes:
- camel case -> snake case
---
 drivers/ata/libata-scsi.c | 8 ++++++++
 1 file changed, 8 insertions(+)
diff mbox

Patch

diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
index 89a9d4a2efc8..7c47a0f8aba9 100644
--- a/drivers/ata/libata-scsi.c
+++ b/drivers/ata/libata-scsi.c
@@ -51,6 +51,7 @@ 
 #include <linux/suspend.h>
 #include <asm/unaligned.h>
 #include <linux/ioprio.h>
+#include <linux/pm_runtime.h>
 
 #include "libata.h"
 #include "libata-transport.h"
@@ -4568,6 +4569,7 @@  int ata_scsi_add_hosts(struct ata_host *host, struct scsi_host_template *sht)
 void ata_scsi_scan_host(struct ata_port *ap, int sync)
 {
 	int tries = 5;
+	int dev_attached = 0;
 	struct ata_device *last_failed_dev = NULL;
 	struct ata_link *link;
 	struct ata_device *dev;
@@ -4591,12 +4593,18 @@  void ata_scsi_scan_host(struct ata_port *ap, int sync)
 			if (!IS_ERR(sdev)) {
 				dev->sdev = sdev;
 				scsi_device_put(sdev);
+				dev_attached = 1;
 			} else {
 				dev->sdev = NULL;
 			}
 		}
 	}
 
+#ifdef CONFIG_AHCI_HOTPLUG_DISABLED
+	if (!dev_attached)
+		pm_runtime_allow(&ap->tdev);
+#endif
+
 	/* If we scanned while EH was in progress or allocation
 	 * failure occurred, scan would have failed silently.  Check
 	 * whether all devices are attached.