]> Pileus Git - ~andy/linux/blobdiff - drivers/scsi/scsi_sysfs.c
Merge branch 'x86-hwmon-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git...
[~andy/linux] / drivers / scsi / scsi_sysfs.c
index 5f85f8e831f30c710809c197ad67b7409e8bc1b5..c3f67373a4f8f2193505603e24b019dca1d051d9 100644 (file)
@@ -11,6 +11,7 @@
 #include <linux/init.h>
 #include <linux/blkdev.h>
 #include <linux/device.h>
+#include <linux/pm_runtime.h>
 
 #include <scsi/scsi.h>
 #include <scsi/scsi_device.h>
@@ -380,7 +381,9 @@ struct bus_type scsi_bus_type = {
         .name          = "scsi",
         .match         = scsi_bus_match,
        .uevent         = scsi_bus_uevent,
+#ifdef CONFIG_PM_OPS
        .pm             = &scsi_bus_pm_ops,
+#endif
 };
 EXPORT_SYMBOL_GPL(scsi_bus_type);
 
@@ -802,8 +805,6 @@ static int scsi_target_add(struct scsi_target *starget)
        if (starget->state != STARGET_CREATED)
                return 0;
 
-       device_enable_async_suspend(&starget->dev);
-
        error = device_add(&starget->dev);
        if (error) {
                dev_err(&starget->dev, "target device_add failed, error %d\n", error);
@@ -812,6 +813,10 @@ static int scsi_target_add(struct scsi_target *starget)
        transport_add_device(&starget->dev);
        starget->state = STARGET_RUNNING;
 
+       pm_runtime_set_active(&starget->dev);
+       pm_runtime_enable(&starget->dev);
+       device_enable_async_suspend(&starget->dev);
+
        return 0;
 }
 
@@ -841,7 +846,20 @@ int scsi_sysfs_add_sdev(struct scsi_device *sdev)
                return error;
 
        transport_configure_device(&starget->dev);
+
        device_enable_async_suspend(&sdev->sdev_gendev);
+       scsi_autopm_get_target(starget);
+       pm_runtime_set_active(&sdev->sdev_gendev);
+       pm_runtime_forbid(&sdev->sdev_gendev);
+       pm_runtime_enable(&sdev->sdev_gendev);
+       scsi_autopm_put_target(starget);
+
+       /* The following call will keep sdev active indefinitely, until
+        * its driver does a corresponding scsi_autopm_pm_device().  Only
+        * drivers supporting autosuspend will do this.
+        */
+       scsi_autopm_get_device(sdev);
+
        error = device_add(&sdev->sdev_gendev);
        if (error) {
                printk(KERN_INFO "error 1\n");